mirror of https://github.com/daffainfo/nuclei.git
commit
909c9765d9
|
@ -11,6 +11,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html"
|
"html"
|
||||||
|
"io"
|
||||||
"math"
|
"math"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
@ -101,12 +102,26 @@ func init() {
|
||||||
buffer := &bytes.Buffer{}
|
buffer := &bytes.Buffer{}
|
||||||
writer := gzip.NewWriter(buffer)
|
writer := gzip.NewWriter(buffer)
|
||||||
if _, err := writer.Write([]byte(args[0].(string))); err != nil {
|
if _, err := writer.Write([]byte(args[0].(string))); err != nil {
|
||||||
|
_ = writer.Close()
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
_ = writer.Close()
|
_ = writer.Close()
|
||||||
|
|
||||||
return buffer.String(), nil
|
return buffer.String(), nil
|
||||||
}),
|
}),
|
||||||
|
"gzip_decode": makeDslFunction(1, func(args ...interface{}) (interface{}, error) {
|
||||||
|
reader, err := gzip.NewReader(strings.NewReader(args[0].(string)))
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
data, err := io.ReadAll(reader)
|
||||||
|
if err != nil {
|
||||||
|
_ = reader.Close()
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
_ = reader.Close()
|
||||||
|
return string(data), nil
|
||||||
|
}),
|
||||||
"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])))
|
||||||
|
|
|
@ -1,12 +1,9 @@
|
||||||
package dsl
|
package dsl
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"compress/gzip"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"math"
|
"math"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -40,15 +37,18 @@ func TestDSLTimeComparison(t *testing.T) {
|
||||||
|
|
||||||
func TestDSLGzipSerialize(t *testing.T) {
|
func TestDSLGzipSerialize(t *testing.T) {
|
||||||
compiled, err := govaluate.NewEvaluableExpressionWithFunctions("gzip(\"hello world\")", HelperFunctions())
|
compiled, err := govaluate.NewEvaluableExpressionWithFunctions("gzip(\"hello world\")", HelperFunctions())
|
||||||
require.Nil(t, err, "could not compare time")
|
require.Nil(t, err, "could not compile encoder")
|
||||||
|
|
||||||
result, err := compiled.Evaluate(make(map[string]interface{}))
|
result, err := compiled.Evaluate(make(map[string]interface{}))
|
||||||
require.Nil(t, err, "could not evaluate compare time")
|
require.Nil(t, err, "could not evaluate compare time")
|
||||||
|
|
||||||
reader, _ := gzip.NewReader(strings.NewReader(types.ToString(result)))
|
compiled, err = govaluate.NewEvaluableExpressionWithFunctions("gzip_decode(data)", HelperFunctions())
|
||||||
data, _ := ioutil.ReadAll(reader)
|
require.Nil(t, err, "could not compile decoder")
|
||||||
|
|
||||||
require.Equal(t, "hello world", string(data), "could not get gzip encoded data")
|
data, err := compiled.Evaluate(map[string]interface{}{"data": result})
|
||||||
|
require.Nil(t, err, "could not evaluate decoded data")
|
||||||
|
|
||||||
|
require.Equal(t, "hello world", data.(string), "could not get gzip encoded data")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDslFunctionSignatures(t *testing.T) {
|
func TestDslFunctionSignatures(t *testing.T) {
|
||||||
|
@ -102,6 +102,7 @@ func TestGetPrintableDslFunctionSignatures(t *testing.T) {
|
||||||
[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
|
||||||
[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
|
||||||
|
[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_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
|
[93mhex_encode[0m(arg1 [38;5;208minterface{}[0m)[38;5;208m interface{}[0m
|
||||||
[93mhtml_escape[0m(arg1 [38;5;208minterface{}[0m)[38;5;208m interface{}[0m
|
[93mhtml_escape[0m(arg1 [38;5;208minterface{}[0m)[38;5;208m interface{}[0m
|
||||||
|
|
Loading…
Reference in New Issue