mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-18 04:15:24 +00:00
Add two new DSL helper functions
hmac_sha1 and concat_ws (with seperator) this are helpful in signing API requests.
This commit is contained in:
parent
f3514e9b92
commit
9d37bd6c0c
@ -241,6 +241,11 @@ func init() {
|
||||
h.Write([]byte(args[0].(string)))
|
||||
return hex.EncodeToString(h.Sum(nil)), nil
|
||||
}),
|
||||
"hmac_sha1": makeDslFunction(2, func(args ...interface{}) (interface{}, error) {
|
||||
h := hmac.New(sha1.New, []byte(args[1].(string)))
|
||||
h.Write([]byte(args[0].(string)))
|
||||
return hex.EncodeToString(h.Sum(nil)), nil
|
||||
}),
|
||||
"html_escape": makeDslFunction(1, func(args ...interface{}) (interface{}, error) {
|
||||
return html.EscapeString(types.ToString(args[0])), nil
|
||||
}),
|
||||
@ -283,6 +288,23 @@ func init() {
|
||||
return builder.String(), nil
|
||||
},
|
||||
),
|
||||
"concat_ws": makeDslWithOptionalArgsFunction(
|
||||
"(args ...interface{}) string",
|
||||
func(arguments ...interface{}) (interface{}, error) {
|
||||
builder := &strings.Builder{}
|
||||
separator := arguments[len(arguments)-1]
|
||||
arguments = arguments[:len(arguments)-1]
|
||||
|
||||
for i, argument := range arguments {
|
||||
builder.WriteString(types.ToString(argument))
|
||||
|
||||
if i != len(arguments)-1 {
|
||||
builder.WriteString(types.ToString(separator))
|
||||
}
|
||||
}
|
||||
return builder.String(), nil
|
||||
},
|
||||
),
|
||||
"regex": makeDslFunction(2, func(args ...interface{}) (interface{}, error) {
|
||||
compiled, err := regexp.Compile(types.ToString(args[0]))
|
||||
if err != nil {
|
||||
|
||||
@ -110,6 +110,7 @@ func TestGetPrintableDslFunctionSignatures(t *testing.T) {
|
||||
[93mbase64_py[0m(arg1 [38;5;208minterface{}[0m)[38;5;208m interface{}[0m
|
||||
[93mcompare_versions[0m(firstVersion, constraints [38;5;208m...string[0m)[38;5;208m bool[0m
|
||||
[93mconcat[0m(args [38;5;208m...interface{}[0m)[38;5;208m string[0m
|
||||
[93mconcat_ws[0m(args [38;5;208m...interface{}[0m)[38;5;208m string[0m
|
||||
[93mcontains[0m(arg1, arg2 [38;5;208minterface{}[0m)[38;5;208m interface{}[0m
|
||||
[93mdate[0m(arg1 [38;5;208minterface{}[0m)[38;5;208m interface{}[0m
|
||||
[93mdec_to_hex[0m(arg1 [38;5;208minterface{}[0m)[38;5;208m interface{}[0m
|
||||
@ -118,6 +119,7 @@ func TestGetPrintableDslFunctionSignatures(t *testing.T) {
|
||||
[93mgzip_decode[0m(arg1 [38;5;208minterface{}[0m)[38;5;208m interface{}[0m
|
||||
[93mhex_decode[0m(arg1 [38;5;208minterface{}[0m)[38;5;208m interface{}[0m
|
||||
[93mhex_encode[0m(arg1 [38;5;208minterface{}[0m)[38;5;208m interface{}[0m
|
||||
[93mhmac_sha1[0m(arg1, arg2 [38;5;208minterface{}[0m)[38;5;208m interface{}[0m
|
||||
[93mhmac_sha256[0m(arg1, arg2 [38;5;208minterface{}[0m)[38;5;208m interface{}[0m
|
||||
[93mhtml_escape[0m(arg1 [38;5;208minterface{}[0m)[38;5;208m interface{}[0m
|
||||
[93mhtml_unescape[0m(arg1 [38;5;208minterface{}[0m)[38;5;208m interface{}[0m
|
||||
@ -190,6 +192,7 @@ func TestDslExpressions(t *testing.T) {
|
||||
`remove_bad_chars("abcd", "bc")`: "ad",
|
||||
`replace("Hello", "He", "Ha")`: "Hallo",
|
||||
`concat("Hello", 123, "world")`: "Hello123world",
|
||||
`concat_ws("Hello", 123, "world", "_")`: "Hello_123_world",
|
||||
`repeat("a", 5)`: "aaaaa",
|
||||
`repeat("a", "5")`: "aaaaa",
|
||||
`repeat("../", "5")`: "../../../../../",
|
||||
@ -228,6 +231,7 @@ func TestDslExpressions(t *testing.T) {
|
||||
`compare_versions('v1.1.1', '>v1.1.0')`: true,
|
||||
`compare_versions('v1.0.0', '>v0.0.1,<v1.0.1')`: true,
|
||||
`compare_versions('v1.0.0', '>v0.0.1', '<v1.0.1')`: true,
|
||||
`hmac_sha1('test','scrt')`: "8856b111056d946d5c6c92a21b43c233596623c6",
|
||||
`hmac_sha256('test','scrt')`: "1f1bff5574f18426eb376d6dd5368a754e67a798aa2074644d5e3fd4c90c7a92",
|
||||
`time_format("02-01-2006 15:04")`: now.Format("02-01-2006 15:04"),
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user