diff --git a/go.mod b/go.mod index 4fc625ed..7c030b72 100644 --- a/go.mod +++ b/go.mod @@ -81,7 +81,7 @@ require ( github.com/projectdiscovery/goflags v0.1.42 github.com/projectdiscovery/gologger v1.1.12 github.com/projectdiscovery/gostruct v0.0.2 - github.com/projectdiscovery/gozero v0.0.1 + github.com/projectdiscovery/gozero v0.0.2-0.20240305085154-99aa5ddb9f98 github.com/projectdiscovery/httpx v1.5.0 github.com/projectdiscovery/mapcidr v1.1.16 github.com/projectdiscovery/n3iwf v0.0.0-20230523120440-b8cd232ff1f5 diff --git a/go.sum b/go.sum index a2c290ba..d24d2d9d 100644 --- a/go.sum +++ b/go.sum @@ -830,6 +830,8 @@ github.com/projectdiscovery/gostruct v0.0.2 h1:s8gP8ApugGM4go1pA+sVlPDXaWqNP5BBD github.com/projectdiscovery/gostruct v0.0.2/go.mod h1:H86peL4HKwMXcQQtEa6lmC8FuD9XFt6gkNR0B/Mu5PE= github.com/projectdiscovery/gozero v0.0.1 h1:f08ZnYlbDZV/TNGDvIXV9s/oB/sAI+HWaSbW4em4aKM= github.com/projectdiscovery/gozero v0.0.1/go.mod h1:/dHwbly+1lhOX9UreVure4lEe7K4hIHeu/c/wZGNTDo= +github.com/projectdiscovery/gozero v0.0.2-0.20240305085154-99aa5ddb9f98 h1:KKS26wFrlcfPxKDmop+2NmI8HbGn8pgotHJBTh+3R4k= +github.com/projectdiscovery/gozero v0.0.2-0.20240305085154-99aa5ddb9f98/go.mod h1:/dHwbly+1lhOX9UreVure4lEe7K4hIHeu/c/wZGNTDo= github.com/projectdiscovery/hmap v0.0.40 h1:WGAIXXMY2vbV0ep7Q8s27Up/ejs8Wo1hh5AEhynLfmw= github.com/projectdiscovery/hmap v0.0.40/go.mod h1:5JkQW9t/UNK95YEY6irOXHqrS/xVBUtrYEhtq61ttII= github.com/projectdiscovery/httpx v1.5.0 h1:YJziMpdF2G5Iy7sDd1mNSpB5LyohYWZpqk+Oq2TeUQQ= diff --git a/internal/runner/runner.go b/internal/runner/runner.go index f7954c2c..e6a3631e 100644 --- a/internal/runner/runner.go +++ b/internal/runner/runner.go @@ -85,6 +85,8 @@ type Runner struct { pprofServer *http.Server // pdcp auto-save options pdcpUploadErrMsg string + //general purpose temporary directory + tmpDir string } const pprofServerAddress = "127.0.0.1:8086" @@ -315,6 +317,11 @@ func New(options *types.Options) (*Runner, error) { } else { runner.rateLimiter = ratelimit.NewUnlimited(context.Background()) } + + if tmpDir, err := os.MkdirTemp("", "nuclei-tmp-*"); err == nil { + runner.tmpDir = tmpDir + } + return runner, nil } @@ -349,6 +356,9 @@ func (r *Runner) Close() { if r.browser != nil { r.browser.Close() } + if r.tmpDir != "" { + _ = os.RemoveAll(r.tmpDir) + } } // setupPDCPUpload sets up the PDCP upload writer @@ -407,19 +417,20 @@ func (r *Runner) RunEnumeration() error { // Create the executor options which will be used throughout the execution // stage by the nuclei engine modules. executorOpts := protocols.ExecutorOptions{ - Output: r.output, - Options: r.options, - Progress: r.progress, - Catalog: r.catalog, - IssuesClient: r.issuesClient, - RateLimiter: r.rateLimiter, - Interactsh: r.interactsh, - ProjectFile: r.projectFile, - Browser: r.browser, - Colorizer: r.colorizer, - ResumeCfg: r.resumeCfg, - ExcludeMatchers: excludematchers.New(r.options.ExcludeMatchers), - InputHelper: input.NewHelper(), + Output: r.output, + Options: r.options, + Progress: r.progress, + Catalog: r.catalog, + IssuesClient: r.issuesClient, + RateLimiter: r.rateLimiter, + Interactsh: r.interactsh, + ProjectFile: r.projectFile, + Browser: r.browser, + Colorizer: r.colorizer, + ResumeCfg: r.resumeCfg, + ExcludeMatchers: excludematchers.New(r.options.ExcludeMatchers), + InputHelper: input.NewHelper(), + TemporaryDirectory: r.tmpDir, } if r.options.ShouldUseHostError() { diff --git a/pkg/protocols/code/code.go b/pkg/protocols/code/code.go index 7a8f3b67..fcac9c32 100644 --- a/pkg/protocols/code/code.go +++ b/pkg/protocols/code/code.go @@ -83,7 +83,7 @@ func (request *Request) Compile(options *protocols.ExecutorOptions) error { var src *gozero.Source - src, err = gozero.NewSourceWithString(request.Source, request.Pattern) + src, err = gozero.NewSourceWithString(request.Source, request.Pattern, request.options.TemporaryDirectory) if err != nil { return err } @@ -125,7 +125,7 @@ func (request *Request) GetID() string { // ExecuteWithResults executes the protocol requests and returns results instead of writing them. func (request *Request) ExecuteWithResults(input *contextargs.Context, dynamicValues, previous output.InternalEvent, callback protocols.OutputEventCallback) (err error) { - metaSrc, err := gozero.NewSourceWithString(input.MetaInput.Input, "") + metaSrc, err := gozero.NewSourceWithString(input.MetaInput.Input, "", request.options.TemporaryDirectory) if err != nil { return err } diff --git a/pkg/protocols/protocols.go b/pkg/protocols/protocols.go index 670375cc..32b09841 100644 --- a/pkg/protocols/protocols.go +++ b/pkg/protocols/protocols.go @@ -116,6 +116,8 @@ type ExecutorOptions struct { // based on given logic. by default nuclei reverts to using value of `-c` when threads count // is not specified or is 0 in template OverrideThreadsCount PayloadThreadSetterCallback + //TemporaryDirectory is the directory to store temporary files + TemporaryDirectory string } // GetThreadsForPayloadRequests returns the number of threads to use as default for