mirror of https://github.com/daffainfo/nuclei.git
Additional helpers (#2359)
* add starts_with, ends_with helper functions * add test cases, update dsl signatures * change split_starts_with to line_starts_withdev
parent
d9f9324e12
commit
c4ba2b4edb
|
@ -81,6 +81,10 @@ requests:
|
|||
69: {{zlib("Hello")}}
|
||||
70: {{zlib_decode(hex_decode("789cf248cdc9c907040000ffff058c01f5"))}}
|
||||
71: {{hex_encode(aes_gcm("AES256Key-32Characters1234567890", "exampleplaintext"))}}
|
||||
72: {{starts_with("Hello", "He")}}
|
||||
73: {{ends_with("Hello", "lo")}}
|
||||
74: {{line_starts_with("Hi\nHello", "He")}}
|
||||
75: {{line_ends_with("Hello\nHi", "lo")}}
|
||||
|
||||
extractors:
|
||||
- type: regex
|
||||
|
|
|
@ -256,7 +256,7 @@ func (h *httpDSLFunctions) Execute(filePath string) error {
|
|||
}
|
||||
|
||||
totalExtracted := strings.Split(submatch[1], ",")
|
||||
numberOfDslFunctions := 71
|
||||
numberOfDslFunctions := 75
|
||||
if len(totalExtracted) != numberOfDslFunctions {
|
||||
return errors.New("incorrect number of results")
|
||||
}
|
||||
|
|
|
@ -246,6 +246,64 @@ func init() {
|
|||
"contains": makeDslFunction(2, func(args ...interface{}) (interface{}, error) {
|
||||
return strings.Contains(types.ToString(args[0]), types.ToString(args[1])), nil
|
||||
}),
|
||||
"starts_with": makeDslWithOptionalArgsFunction(
|
||||
"(str string, prefix ...string) bool",
|
||||
func(args ...interface{}) (interface{}, error) {
|
||||
if len(args) < 2 {
|
||||
return nil, invalidDslFunctionError
|
||||
}
|
||||
for _, prefix := range args[1:] {
|
||||
if strings.HasPrefix(types.ToString(args[0]), types.ToString(prefix)) {
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
return false, nil
|
||||
},
|
||||
),
|
||||
"line_starts_with": makeDslWithOptionalArgsFunction(
|
||||
"(str string, prefix ...string) bool", func(args ...interface{}) (interface{}, error) {
|
||||
if len(args) < 2 {
|
||||
return nil, invalidDslFunctionError
|
||||
}
|
||||
for _, line := range strings.Split(types.ToString(args[0]), "\n") {
|
||||
for _, prefix := range args[1:] {
|
||||
if strings.HasPrefix(line, types.ToString(prefix)) {
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
return false, nil
|
||||
},
|
||||
),
|
||||
"ends_with": makeDslWithOptionalArgsFunction(
|
||||
"(str string, suffix ...string) bool",
|
||||
func(args ...interface{}) (interface{}, error) {
|
||||
if len(args) < 2 {
|
||||
return nil, invalidDslFunctionError
|
||||
}
|
||||
for _, suffix := range args[1:] {
|
||||
if strings.HasSuffix(types.ToString(args[0]), types.ToString(suffix)) {
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
return false, nil
|
||||
},
|
||||
),
|
||||
"line_ends_with": makeDslWithOptionalArgsFunction(
|
||||
"(str string, suffix ...string) bool", func(args ...interface{}) (interface{}, error) {
|
||||
if len(args) < 2 {
|
||||
return nil, invalidDslFunctionError
|
||||
}
|
||||
for _, line := range strings.Split(types.ToString(args[0]), "\n") {
|
||||
for _, suffix := range args[1:] {
|
||||
if strings.HasSuffix(line, types.ToString(suffix)) {
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
return false, nil
|
||||
},
|
||||
),
|
||||
"concat": makeDslWithOptionalArgsFunction(
|
||||
"(args ...interface{}) string",
|
||||
func(arguments ...interface{}) (interface{}, error) {
|
||||
|
|
|
@ -142,6 +142,7 @@ func TestGetPrintableDslFunctionSignatures(t *testing.T) {
|
|||
[93mcontains[0m(arg1, arg2 [38;5;208minterface{}[0m)[38;5;208m interface{}[0m
|
||||
[93mdate_time[0m(dateTimeFormat [38;5;208mstring[0m, optionalUnixTime [38;5;208minterface{}[0m)[38;5;208m string[0m
|
||||
[93mdec_to_hex[0m(arg1 [38;5;208minterface{}[0m)[38;5;208m interface{}[0m
|
||||
[93mends_with[0m(str [38;5;208mstring[0m, suffix [38;5;208m...string[0m)[38;5;208m bool[0m
|
||||
[93mgenerate_java_gadget[0m(arg1, arg2, arg3 [38;5;208minterface{}[0m)[38;5;208m interface{}[0m
|
||||
[93mgzip[0m(arg1 [38;5;208minterface{}[0m)[38;5;208m interface{}[0m
|
||||
[93mgzip_decode[0m(arg1 [38;5;208minterface{}[0m)[38;5;208m interface{}[0m
|
||||
|
@ -152,6 +153,8 @@ func TestGetPrintableDslFunctionSignatures(t *testing.T) {
|
|||
[93mhtml_unescape[0m(arg1 [38;5;208minterface{}[0m)[38;5;208m interface{}[0m
|
||||
[93mjoin[0m(separator [38;5;208mstring[0m, elements [38;5;208m...interface{}[0m)[38;5;208m string[0m
|
||||
[93mlen[0m(arg1 [38;5;208minterface{}[0m)[38;5;208m interface{}[0m
|
||||
[93mline_ends_with[0m(str [38;5;208mstring[0m, suffix [38;5;208m...string[0m)[38;5;208m bool[0m
|
||||
[93mline_starts_with[0m(str [38;5;208mstring[0m, prefix [38;5;208m...string[0m)[38;5;208m bool[0m
|
||||
[93mmd5[0m(arg1 [38;5;208minterface{}[0m)[38;5;208m interface{}[0m
|
||||
[93mmmh3[0m(arg1 [38;5;208minterface{}[0m)[38;5;208m interface{}[0m
|
||||
[93mprint_debug[0m(args [38;5;208m...interface{}[0m)[38;5;208m[0m
|
||||
|
@ -170,6 +173,7 @@ func TestGetPrintableDslFunctionSignatures(t *testing.T) {
|
|||
[93mreverse[0m(arg1 [38;5;208minterface{}[0m)[38;5;208m interface{}[0m
|
||||
[93msha1[0m(arg1 [38;5;208minterface{}[0m)[38;5;208m interface{}[0m
|
||||
[93msha256[0m(arg1 [38;5;208minterface{}[0m)[38;5;208m interface{}[0m
|
||||
[93mstarts_with[0m(str [38;5;208mstring[0m, prefix [38;5;208m...string[0m)[38;5;208m bool[0m
|
||||
[93mto_lower[0m(arg1 [38;5;208minterface{}[0m)[38;5;208m interface{}[0m
|
||||
[93mto_number[0m(arg1 [38;5;208minterface{}[0m)[38;5;208m interface{}[0m
|
||||
[93mto_string[0m(arg1 [38;5;208minterface{}[0m)[38;5;208m interface{}[0m
|
||||
|
@ -248,6 +252,10 @@ func TestDslExpressions(t *testing.T) {
|
|||
`len("Hello")`: float64(5),
|
||||
`len(1234)`: float64(4),
|
||||
`contains("Hello", "lo")`: true,
|
||||
`starts_with("Hello", "He")`: true,
|
||||
`ends_with("Hello", "lo")`: true,
|
||||
"line_starts_with('Hi\nHello', 'He')": true, // back quotes do not support escape sequences
|
||||
"line_ends_with('Hii\nHello', 'ii')": true, // back quotes do not support escape sequences
|
||||
`regex("H([a-z]+)o", "Hello")`: true,
|
||||
`wait_for(1)`: nil,
|
||||
`print_debug(1+2, "Hello")`: nil,
|
||||
|
|
Loading…
Reference in New Issue