diff --git a/README_CN.md b/README_CN.md index df29e3f2..05c0dff3 100644 --- a/README_CN.md +++ b/README_CN.md @@ -7,7 +7,7 @@

- + diff --git a/go.mod b/go.mod index 00a24fe7..7a2d1adb 100644 --- a/go.mod +++ b/go.mod @@ -133,7 +133,7 @@ require ( github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect github.com/dlclark/regexp2 v1.10.0 // indirect github.com/docker/cli v24.0.5+incompatible // indirect - github.com/docker/docker v24.0.5+incompatible // indirect + github.com/docker/docker v24.0.7+incompatible // indirect github.com/docker/go-connections v0.4.0 // indirect github.com/fatih/color v1.15.0 // indirect github.com/free5gc/util v1.0.5-0.20230511064842-2e120956883b // indirect diff --git a/go.sum b/go.sum index 63399da5..0b589c76 100644 --- a/go.sum +++ b/go.sum @@ -269,8 +269,8 @@ github.com/dnaeon/go-vcr v1.2.0 h1:zHCHvJYTMh1N7xnV7zf1m1GPBF9Ad0Jk/whtQ1663qI= github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ= github.com/docker/cli v24.0.5+incompatible h1:WeBimjvS0eKdH4Ygx+ihVq1Q++xg36M/rMi4aXAvodc= github.com/docker/cli v24.0.5+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8= -github.com/docker/docker v24.0.5+incompatible h1:WmgcE4fxyI6EEXxBRxsHnZXrO1pQ3smi0k/jho4HLeY= -github.com/docker/docker v24.0.5+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= +github.com/docker/docker v24.0.7+incompatible h1:Wo6l37AuwP3JaMnZa226lzVXGA3F9Ig1seQen0cKYlM= +github.com/docker/docker v24.0.7+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ= github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec= github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4= diff --git a/pkg/js/global/helpers.go b/pkg/js/global/helpers.go new file mode 100644 index 00000000..1dae2af0 --- /dev/null +++ b/pkg/js/global/helpers.go @@ -0,0 +1,40 @@ +package global + +import ( + "encoding/base64" + + "github.com/dop251/goja" + "github.com/projectdiscovery/nuclei/v3/pkg/js/gojs" +) + +func registerAdditionalHelpers(runtime *goja.Runtime) { + _ = gojs.RegisterFuncWithSignature(runtime, gojs.FuncOpts{ + Name: "atob", + Signatures: []string{ + "atob(string) string", + }, + Description: "Base64 decodes a given string", + FuncDecl: func(call goja.FunctionCall) goja.Value { + input := call.Argument(0).String() + + decoded, err := base64.StdEncoding.DecodeString(input) + if err != nil { + return goja.Null() + } + return runtime.ToValue(string(decoded)) + }, + }) + + _ = gojs.RegisterFuncWithSignature(runtime, gojs.FuncOpts{ + Name: "btoa", + Signatures: []string{ + "bota(string) string", + }, + Description: "Base64 encodes a given string", + FuncDecl: func(call goja.FunctionCall) goja.Value { + input := call.Argument(0).String() + encoded := base64.StdEncoding.EncodeToString([]byte(input)) + return runtime.ToValue(encoded) + }, + }) +} diff --git a/pkg/js/global/scripts.go b/pkg/js/global/scripts.go index 7c697935..64d6b25c 100644 --- a/pkg/js/global/scripts.go +++ b/pkg/js/global/scripts.go @@ -172,6 +172,9 @@ func initBuiltInFunc(runtime *goja.Runtime) { return runtime.ToValue(buff.String()) }, }) + + // register additional helpers + registerAdditionalHelpers(runtime) } // RegisterNativeScripts are js scripts that were added for convenience