From 9adfc531c7724ea9828bd23697faadc2d7d964f3 Mon Sep 17 00:00:00 2001 From: Mzack9999 Date: Wed, 15 May 2024 15:34:59 +0200 Subject: [PATCH 1/9] uniforming sizes with utils --- cmd/integration-test/http.go | 3 ++- cmd/nuclei/main.go | 3 ++- go.mod | 4 ++-- go.sum | 8 ++++---- internal/pdcp/writer.go | 5 +++-- pkg/output/output.go | 3 ++- pkg/protocols/common/automaticscan/automaticscan.go | 3 ++- pkg/protocols/http/request.go | 11 ++++++----- pkg/protocols/offlinehttp/request.go | 3 ++- pkg/protocols/protocols.go | 3 ++- pkg/reporting/format/format_utils.go | 3 ++- pkg/testutils/testutils.go | 3 ++- pkg/types/types.go | 5 +++-- pkg/utils/monitor/monitor.go | 3 ++- 14 files changed, 36 insertions(+), 24 deletions(-) diff --git a/cmd/integration-test/http.go b/cmd/integration-test/http.go index b4f957e692..5b218aa53b 100644 --- a/cmd/integration-test/http.go +++ b/cmd/integration-test/http.go @@ -23,6 +23,7 @@ import ( logutil "github.com/projectdiscovery/utils/log" sliceutil "github.com/projectdiscovery/utils/slice" stringsutil "github.com/projectdiscovery/utils/strings" + unitutils "github.com/projectdiscovery/utils/unit" ) var httpTestcases = []TestCaseInfo{ @@ -509,7 +510,7 @@ func (h *httpPostMultipartBody) Execute(filePath string) error { var routerErr error router.POST("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { - if err := r.ParseMultipartForm(1 * 1024); err != nil { + if err := r.ParseMultipartForm(unitutils.Mega); err != nil { routerErr = err return } diff --git a/cmd/nuclei/main.go b/cmd/nuclei/main.go index a1123b9ffc..8be0207797 100644 --- a/cmd/nuclei/main.go +++ b/cmd/nuclei/main.go @@ -38,6 +38,7 @@ import ( "github.com/projectdiscovery/nuclei/v3/pkg/utils/monitor" errorutil "github.com/projectdiscovery/utils/errors" fileutil "github.com/projectdiscovery/utils/file" + unitutils "github.com/projectdiscovery/utils/unit" updateutils "github.com/projectdiscovery/utils/update" ) @@ -301,7 +302,7 @@ on extensive configurability, massive extensibility and ease of use.`) flagSet.StringVarP(&options.AttackType, "attack-type", "at", "", "type of payload combinations to perform (batteringram,pitchfork,clusterbomb)"), flagSet.StringVarP(&options.SourceIP, "source-ip", "sip", "", "source ip address to use for network scan"), flagSet.IntVarP(&options.ResponseReadSize, "response-size-read", "rsr", 0, "max response size to read in bytes"), - flagSet.IntVarP(&options.ResponseSaveSize, "response-size-save", "rss", 1*1024*1024, "max response size to read in bytes"), + flagSet.IntVarP(&options.ResponseSaveSize, "response-size-save", "rss", unitutils.Mega, "max response size to read in bytes"), flagSet.DurationVarP(&options.ResponseReadTimeout, "response-read-timeout", "rrt", time.Duration(5*time.Second), "response read timeout in seconds"), flagSet.CallbackVar(resetCallback, "reset", "reset removes all nuclei configuration and data files (including nuclei-templates)"), flagSet.BoolVarP(&options.TlsImpersonate, "tls-impersonate", "tlsi", false, "enable experimental client hello (ja3) tls randomization"), diff --git a/go.mod b/go.mod index 1002e41efd..39156d2f6d 100644 --- a/go.mod +++ b/go.mod @@ -21,7 +21,7 @@ require ( github.com/pkg/errors v0.9.1 github.com/projectdiscovery/clistats v0.0.20 github.com/projectdiscovery/fastdialer v0.0.71 - github.com/projectdiscovery/hmap v0.0.41 + github.com/projectdiscovery/hmap v0.0.42 github.com/projectdiscovery/interactsh v1.1.9 github.com/projectdiscovery/rawhttp v0.1.47 github.com/projectdiscovery/retryabledns v1.0.59 @@ -94,7 +94,7 @@ require ( github.com/projectdiscovery/tlsx v1.1.6 github.com/projectdiscovery/uncover v1.0.7 github.com/projectdiscovery/useragent v0.0.49 - github.com/projectdiscovery/utils v0.0.92 + github.com/projectdiscovery/utils v0.0.94-0.20240515132152-3908d4bb5d2c github.com/projectdiscovery/wappalyzergo v0.0.122 github.com/redis/go-redis/v9 v9.1.0 github.com/seh-msft/burpxml v1.0.1 diff --git a/go.sum b/go.sum index dbc2f68aeb..4a95dbd040 100644 --- a/go.sum +++ b/go.sum @@ -853,8 +853,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.2 h1:8fJeaCjxL9tpm33uG/RsCQs6HGM/NE6eA3cjkilRQ+E= github.com/projectdiscovery/gozero v0.0.2/go.mod h1:d8bZvDWW07LWNYWrwjZ4OO1I0cpkfqaysyDfSs9ibK8= -github.com/projectdiscovery/hmap v0.0.41 h1:8IgTyDce3/2JzcfPVA4H+XpBRFfETULx8td3BMdSYVE= -github.com/projectdiscovery/hmap v0.0.41/go.mod h1:bCrai6x5Eijqm2U+jtcH0wZX5ZcaZhcvzoMGTZgLAf0= +github.com/projectdiscovery/hmap v0.0.42 h1:+P8CC7gAeTG0phe0d1FB7i3Vl15v1K+dJApwX4rvMAM= +github.com/projectdiscovery/hmap v0.0.42/go.mod h1:lbGBuL/bLoYWdlgphZmHXjZCYzteVDf4WfKsR/aH57c= github.com/projectdiscovery/httpx v1.6.0 h1:6g4UoSQpsOyZgaK+SMLLnZIAU0eYyTxBUwVl+jtm0JQ= github.com/projectdiscovery/httpx v1.6.0/go.mod h1:dzMzOWKfeofaXcXzac3O+YmuY24P0CRnviKGxvol6MM= github.com/projectdiscovery/interactsh v1.1.9 h1:b77SaSGrO+DtivmWwqGGY2dmNlQC3Zgmwlaj9L4Oqvc= @@ -889,8 +889,8 @@ github.com/projectdiscovery/uncover v1.0.7 h1:ut+2lTuvmftmveqF5RTjMWAgyLj8ltPQC7 github.com/projectdiscovery/uncover v1.0.7/go.mod h1:HFXgm1sRPuoN0D4oATljPIdmbo/EEh1wVuxQqo/dwFE= github.com/projectdiscovery/useragent v0.0.49 h1:wQc9i+Xy+mUMJ45Ralv1JsQImRWqEOEvpYUe6MchScg= github.com/projectdiscovery/useragent v0.0.49/go.mod h1:jQz6X/usiXrPYE6B/1uVKuzIrBJXgw9hLC9eeNy38+0= -github.com/projectdiscovery/utils v0.0.92 h1:lGCmjUJhzoNX4FQZWpp80058pRlD0/dYxLJOSs07EqY= -github.com/projectdiscovery/utils v0.0.92/go.mod h1:d5uvD5qcRiK3qxZbBy9eatCqrCSuj9SObL04w/WgXSg= +github.com/projectdiscovery/utils v0.0.94-0.20240515132152-3908d4bb5d2c h1:vGsulLeJNcFjQTp+aSAO7auX5wriKrLrZ8+SILxtRcM= +github.com/projectdiscovery/utils v0.0.94-0.20240515132152-3908d4bb5d2c/go.mod h1:wxPi+kCsLm5JCLMkZJyGwS+4Mn4PaPHHf0ayE8JphOw= github.com/projectdiscovery/wappalyzergo v0.0.122 h1:xfNJ7VNzU/OGlgYtsyB5ppuOHdfWzU2B8cYATwTz54c= github.com/projectdiscovery/wappalyzergo v0.0.122/go.mod h1:qW0PP+UBMcdQBBnwk+X6YYFs6huKNvn2BOVs4vQPru0= github.com/projectdiscovery/yamldoc-go v1.0.4 h1:eZoESapnMw6WAHiVgRwNqvbJEfNHEH148uthhFbG5jE= diff --git a/internal/pdcp/writer.go b/internal/pdcp/writer.go index a76d4ea31a..6e05410355 100644 --- a/internal/pdcp/writer.go +++ b/internal/pdcp/writer.go @@ -19,6 +19,7 @@ import ( "github.com/projectdiscovery/retryablehttp-go" pdcpauth "github.com/projectdiscovery/utils/auth/pdcp" errorutil "github.com/projectdiscovery/utils/errors" + unitutils "github.com/projectdiscovery/utils/unit" updateutils "github.com/projectdiscovery/utils/update" urlutil "github.com/projectdiscovery/utils/url" ) @@ -26,8 +27,8 @@ import ( const ( uploadEndpoint = "/v1/scans/import" appendEndpoint = "/v1/scans/%s/import" - flushTimer = time.Duration(1) * time.Minute - MaxChunkSize = 1024 * 1024 * 4 // 4 MB + flushTimer = time.Minute + MaxChunkSize = 4 * unitutils.Mega // 4 MB xidRe = `^[a-z0-9]{20}$` ) diff --git a/pkg/output/output.go b/pkg/output/output.go index 044d164f1f..23b2f0ec91 100644 --- a/pkg/output/output.go +++ b/pkg/output/output.go @@ -30,6 +30,7 @@ import ( "github.com/projectdiscovery/nuclei/v3/pkg/utils" fileutil "github.com/projectdiscovery/utils/file" osutils "github.com/projectdiscovery/utils/os" + unitutils "github.com/projectdiscovery/utils/unit" ) // Writer is an interface which writes output to somewhere for nuclei events. @@ -411,7 +412,7 @@ func (w *StandardWriter) WriteFailure(wrappedEvent *InternalWrappedEvent) error return w.Write(data) } -var maxTemplateFileSizeForEncoding = 1024 * 1024 +var maxTemplateFileSizeForEncoding = unitutils.Mega func (w *StandardWriter) encodeTemplate(templatePath string) string { data, err := os.ReadFile(templatePath) diff --git a/pkg/protocols/common/automaticscan/automaticscan.go b/pkg/protocols/common/automaticscan/automaticscan.go index 2a7988cb04..a5e51c177a 100644 --- a/pkg/protocols/common/automaticscan/automaticscan.go +++ b/pkg/protocols/common/automaticscan/automaticscan.go @@ -32,13 +32,14 @@ import ( sliceutil "github.com/projectdiscovery/utils/slice" stringsutil "github.com/projectdiscovery/utils/strings" syncutil "github.com/projectdiscovery/utils/sync" + unitutils "github.com/projectdiscovery/utils/unit" wappalyzer "github.com/projectdiscovery/wappalyzergo" "gopkg.in/yaml.v2" ) const ( mappingFilename = "wappalyzer-mapping.yml" - maxDefaultBody = 4 * 1024 * 1024 // 4MB + maxDefaultBody = 4 * unitutils.Mega ) // Options contains configuration options for automatic scan service diff --git a/pkg/protocols/http/request.go b/pkg/protocols/http/request.go index df914a785c..fc3df039ac 100644 --- a/pkg/protocols/http/request.go +++ b/pkg/protocols/http/request.go @@ -42,6 +42,7 @@ import ( "github.com/projectdiscovery/utils/reader" sliceutil "github.com/projectdiscovery/utils/slice" stringsutil "github.com/projectdiscovery/utils/strings" + unitutils "github.com/projectdiscovery/utils/unit" urlutil "github.com/projectdiscovery/utils/url" ) @@ -53,7 +54,7 @@ const ( ) var ( - MaxBodyRead = int64(10 * 1024 * 1024) // 10MB + MaxBodyRead = 10 * unitutils.Mega // ErrMissingVars is error occured when variables are missing ErrMissingVars = errors.New("stop execution due to unresolved variables") ) @@ -557,7 +558,7 @@ func (request *Request) ExecuteWithResults(input *contextargs.Context, dynamicVa return requestErr } -const drainReqSize = int64(8 * 1024) +const drainReqSize = int64(8 * unitutils.Kilo) // executeRequest executes the actual generated request and returns error if occurred func (request *Request) executeRequest(input *contextargs.Context, generatedRequest *generatedRequest, previousEvent output.InternalEvent, hasInteractMatchers bool, processEvent protocols.OutputEventCallback, requestCount int) (err error) { @@ -809,15 +810,15 @@ func (request *Request) executeRequest(input *contextargs.Context, generatedRequ // define max body read limit maxBodylimit := MaxBodyRead // 10MB if request.MaxSize > 0 { - maxBodylimit = int64(request.MaxSize) + maxBodylimit = request.MaxSize } if request.options.Options.ResponseReadSize != 0 { - maxBodylimit = int64(request.options.Options.ResponseReadSize) + maxBodylimit = request.options.Options.ResponseReadSize } // respChain is http response chain that reads response body // efficiently by reusing buffers and does all decoding and optimizations - respChain := httpUtils.NewResponseChain(resp, maxBodylimit) + respChain := httpUtils.NewResponseChain(resp, int64(maxBodylimit)) defer respChain.Close() // reuse buffers // we only intend to log/save the final redirected response diff --git a/pkg/protocols/offlinehttp/request.go b/pkg/protocols/offlinehttp/request.go index 4a440c167f..e913e02d8f 100644 --- a/pkg/protocols/offlinehttp/request.go +++ b/pkg/protocols/offlinehttp/request.go @@ -17,11 +17,12 @@ import ( templateTypes "github.com/projectdiscovery/nuclei/v3/pkg/templates/types" "github.com/projectdiscovery/utils/conversion" syncutil "github.com/projectdiscovery/utils/sync" + unitutils "github.com/projectdiscovery/utils/unit" ) var _ protocols.Request = &Request{} -const maxSize = 5 * 1024 * 1024 +const maxSize = 5 * unitutils.Mega // Type returns the type of the protocol request func (request *Request) Type() templateTypes.ProtocolType { diff --git a/pkg/protocols/protocols.go b/pkg/protocols/protocols.go index 6b4904c8d8..7804ea3c29 100644 --- a/pkg/protocols/protocols.go +++ b/pkg/protocols/protocols.go @@ -33,10 +33,11 @@ import ( "github.com/projectdiscovery/nuclei/v3/pkg/scan" templateTypes "github.com/projectdiscovery/nuclei/v3/pkg/templates/types" "github.com/projectdiscovery/nuclei/v3/pkg/types" + unitutils "github.com/projectdiscovery/utils/unit" ) var ( - MaxTemplateFileSizeForEncoding = 1024 * 1024 + MaxTemplateFileSizeForEncoding = unitutils.Mega ) // Executer is an interface implemented any protocol based request executer. diff --git a/pkg/reporting/format/format_utils.go b/pkg/reporting/format/format_utils.go index 62a3d75fe8..d5ec0adfb1 100644 --- a/pkg/reporting/format/format_utils.go +++ b/pkg/reporting/format/format_utils.go @@ -12,6 +12,7 @@ import ( "github.com/projectdiscovery/nuclei/v3/pkg/reporting/exporters/markdown/util" "github.com/projectdiscovery/nuclei/v3/pkg/types" "github.com/projectdiscovery/nuclei/v3/pkg/utils" + unitutils "github.com/projectdiscovery/utils/unit" ) // Summary returns a formatted built one line summary of the event @@ -71,7 +72,7 @@ func CreateReportDescription(event *output.ResultEvent, formatter ResultFormatte if event.Response != "" { var responseString string // If the response is larger than 5 kb, truncate it before writing. - maxKbSize := 5 * 1024 + maxKbSize := 5 * unitutils.Kilo if len(event.Response) > maxKbSize { responseString = event.Response[:maxKbSize] responseString += ".... Truncated ...." diff --git a/pkg/testutils/testutils.go b/pkg/testutils/testutils.go index 68410f7f1d..a54fbbcf40 100644 --- a/pkg/testutils/testutils.go +++ b/pkg/testutils/testutils.go @@ -23,6 +23,7 @@ import ( protocolUtils "github.com/projectdiscovery/nuclei/v3/pkg/protocols/utils" "github.com/projectdiscovery/nuclei/v3/pkg/types" "github.com/projectdiscovery/nuclei/v3/pkg/utils" + unitutils "github.com/projectdiscovery/utils/unit" ) // Init initializes the protocols and their configurations @@ -201,7 +202,7 @@ func (m *MockOutputWriter) WriteFailure(wrappedEvent *output.InternalWrappedEven return m.Write(data) } -var maxTemplateFileSizeForEncoding = 1024 * 1024 +var maxTemplateFileSizeForEncoding = unitutils.Mega func (w *MockOutputWriter) encodeTemplate(templatePath string) string { data, err := os.ReadFile(templatePath) diff --git a/pkg/types/types.go b/pkg/types/types.go index 0c31769ee1..577461b217 100644 --- a/pkg/types/types.go +++ b/pkg/types/types.go @@ -15,6 +15,7 @@ import ( errorutil "github.com/projectdiscovery/utils/errors" fileutil "github.com/projectdiscovery/utils/file" folderutil "github.com/projectdiscovery/utils/folder" + unitutils "github.com/projectdiscovery/utils/unit" ) var ( @@ -435,8 +436,8 @@ func DefaultOptions() *Options { Timeout: 5, Retries: 1, MaxHostError: 30, - ResponseReadSize: 10 * 1024 * 1024, - ResponseSaveSize: 1024 * 1024, + ResponseReadSize: 10 * unitutils.Mega, + ResponseSaveSize: unitutils.Mega, ResponseReadTimeout: 5 * time.Second, } } diff --git a/pkg/utils/monitor/monitor.go b/pkg/utils/monitor/monitor.go index 6441fdf20d..cefb9506b8 100644 --- a/pkg/utils/monitor/monitor.go +++ b/pkg/utils/monitor/monitor.go @@ -16,6 +16,7 @@ import ( "github.com/DataDog/gostackparse" "github.com/projectdiscovery/gologger" permissionutil "github.com/projectdiscovery/utils/permission" + unitutils "github.com/projectdiscovery/utils/unit" "github.com/rs/xid" ) @@ -118,7 +119,7 @@ func (s *Agent) monitorWorker(cancel context.CancelFunc) { // getStack returns full stack trace of the program var getStack = func(all bool) []byte { - for i := 1024 * 1024; ; i *= 2 { + for i := unitutils.Mega; ; i *= 2 { buf := make([]byte, i) if n := runtime.Stack(buf, all); n < i { return buf[:n-1] From 47ca8fe8427a5cd08886c08cf84cc2feebe3d1cd Mon Sep 17 00:00:00 2001 From: Mzack9999 Date: Wed, 15 May 2024 21:25:40 +0200 Subject: [PATCH 2/9] fix non gc-able dialer closes #5165 --- go.mod | 2 +- go.sum | 4 ++-- lib/sdk.go | 6 +++--- lib/sdk_private.go | 6 +++++- pkg/protocols/common/protocolinit/init.go | 3 +-- pkg/protocols/common/protocolstate/state.go | 5 +++++ .../http/httpclientpool/clientpool.go | 20 ++++++------------- pkg/protocols/http/request.go | 4 ++-- 8 files changed, 25 insertions(+), 25 deletions(-) diff --git a/go.mod b/go.mod index 39156d2f6d..98973239e5 100644 --- a/go.mod +++ b/go.mod @@ -99,7 +99,7 @@ require ( github.com/redis/go-redis/v9 v9.1.0 github.com/seh-msft/burpxml v1.0.1 github.com/stretchr/testify v1.9.0 - github.com/tarunKoyalwar/goleak v0.0.0-20240426214851-746d64600adc + github.com/tarunKoyalwar/goleak v0.0.0-20240429141123-0efa90dbdcf9 github.com/zmap/zgrab2 v0.1.8-0.20230806160807-97ba87c0e706 golang.org/x/term v0.19.0 gopkg.in/yaml.v3 v3.0.1 diff --git a/go.sum b/go.sum index 4a95dbd040..281ee725da 100644 --- a/go.sum +++ b/go.sum @@ -1016,8 +1016,8 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE= github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ= -github.com/tarunKoyalwar/goleak v0.0.0-20240426214851-746d64600adc h1:/5P5I7oDqdLee8W9Moof0xSD8tT1qEVzhObSI9CqHkg= -github.com/tarunKoyalwar/goleak v0.0.0-20240426214851-746d64600adc/go.mod h1:uQdBQGrE1fZ2EyOs0pLcCDd1bBV4rSThieuIIGhXZ50= +github.com/tarunKoyalwar/goleak v0.0.0-20240429141123-0efa90dbdcf9 h1:GXIyLuIJ5Qk46lI8WJ83qHBZKUI3zhmMmuoY9HICUIQ= +github.com/tarunKoyalwar/goleak v0.0.0-20240429141123-0efa90dbdcf9/go.mod h1:uQdBQGrE1fZ2EyOs0pLcCDd1bBV4rSThieuIIGhXZ50= github.com/tidwall/assert v0.1.0 h1:aWcKyRBUAdLoVebxo95N7+YZVTFF/ASTr7BN4sLP6XI= github.com/tidwall/assert v0.1.0/go.mod h1:QLYtGyeqse53vuELQheYl9dngGCJQ+mTtlxcktb+Kj8= github.com/tidwall/btree v1.7.0 h1:L1fkJH/AuEh5zBnnBbmTwQ5Lt+bRJ5A8EWecslvo9iI= diff --git a/lib/sdk.go b/lib/sdk.go index 63925f47ca..7a28cbc53e 100644 --- a/lib/sdk.go +++ b/lib/sdk.go @@ -18,7 +18,7 @@ import ( "github.com/projectdiscovery/nuclei/v3/pkg/protocols" "github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/hosterrorscache" "github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/interactsh" - "github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/protocolstate" + "github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/protocolinit" "github.com/projectdiscovery/nuclei/v3/pkg/protocols/headless/engine" "github.com/projectdiscovery/nuclei/v3/pkg/reporting" "github.com/projectdiscovery/nuclei/v3/pkg/templates" @@ -206,8 +206,6 @@ func (e *NucleiEngine) Close() { if e.rateLimiter != nil { e.rateLimiter.Stop() } - // close global shared resources - protocolstate.Close() if e.inputProvider != nil { e.inputProvider.Close() } @@ -217,6 +215,8 @@ func (e *NucleiEngine) Close() { if e.httpxClient != nil { _ = e.httpxClient.Close() } + // close global shared resources + protocolinit.Close() } // ExecuteCallbackWithCtx executes templates on targets and calls callback on each result(only if results are found) diff --git a/lib/sdk_private.go b/lib/sdk_private.go index 13e8746510..6f8c929e38 100644 --- a/lib/sdk_private.go +++ b/lib/sdk_private.go @@ -35,7 +35,7 @@ import ( "github.com/projectdiscovery/ratelimit" ) -var sharedInit sync.Once = sync.Once{} +var sharedInit *sync.Once // applyRequiredDefaults to options func (e *NucleiEngine) applyRequiredDefaults() { @@ -118,6 +118,10 @@ func (e *NucleiEngine) init() error { e.parser = templates.NewParser() + if sharedInit == nil || protocolstate.ShouldInit() { + sharedInit = &sync.Once{} + } + sharedInit.Do(func() { _ = protocolstate.Init(e.opts) _ = protocolinit.Init(e.opts) diff --git a/pkg/protocols/common/protocolinit/init.go b/pkg/protocols/common/protocolinit/init.go index 2ab5d7ca9c..c8268337f5 100644 --- a/pkg/protocols/common/protocolinit/init.go +++ b/pkg/protocols/common/protocolinit/init.go @@ -13,7 +13,6 @@ import ( // Init initializes the client pools for the protocols func Init(options *types.Options) error { - if err := protocolstate.Init(options); err != nil { return err } @@ -39,5 +38,5 @@ func Init(options *types.Options) error { } func Close() { - protocolstate.Dialer.Close() + protocolstate.Close() } diff --git a/pkg/protocols/common/protocolstate/state.go b/pkg/protocols/common/protocolstate/state.go index 67820ec074..02e30e06fd 100644 --- a/pkg/protocols/common/protocolstate/state.go +++ b/pkg/protocols/common/protocolstate/state.go @@ -22,6 +22,10 @@ var ( Dialer *fastdialer.Dialer ) +func ShouldInit() bool { + return Dialer == nil +} + // Init creates the Dialer instance based on user configuration func Init(options *types.Options) error { if Dialer != nil { @@ -210,5 +214,6 @@ func Close() { if Dialer != nil { Dialer.Close() } + Dialer = nil StopActiveMemGuardian() } diff --git a/pkg/protocols/http/httpclientpool/clientpool.go b/pkg/protocols/http/httpclientpool/clientpool.go index 3e2baf55a5..96b0939511 100644 --- a/pkg/protocols/http/httpclientpool/clientpool.go +++ b/pkg/protocols/http/httpclientpool/clientpool.go @@ -16,7 +16,6 @@ import ( "golang.org/x/net/proxy" "golang.org/x/net/publicsuffix" - "github.com/projectdiscovery/fastdialer/fastdialer" "github.com/projectdiscovery/fastdialer/fastdialer/ja3/impersonate" "github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/protocolstate" "github.com/projectdiscovery/nuclei/v3/pkg/protocols/utils" @@ -28,9 +27,6 @@ import ( ) var ( - // Dialer is a copy of the fastdialer from protocolstate - Dialer *fastdialer.Dialer - rawHttpClient *rawhttp.Client forceMaxRedirects int normalClient *retryablehttp.Client @@ -146,8 +142,8 @@ func GetRawHTTP(options *types.Options) *rawhttp.Client { rawHttpOptions.Proxy = types.ProxyURL } else if types.ProxySocksURL != "" { rawHttpOptions.Proxy = types.ProxySocksURL - } else if Dialer != nil { - rawHttpOptions.FastDialer = Dialer + } else if protocolstate.Dialer != nil { + rawHttpOptions.FastDialer = protocolstate.Dialer } rawHttpOptions.Timeout = GetHttpTimeout(options) rawHttpClient = rawhttp.NewClient(rawHttpOptions) @@ -167,10 +163,6 @@ func Get(options *types.Options, configuration *Configuration) (*retryablehttp.C func wrappedGet(options *types.Options, configuration *Configuration) (*retryablehttp.Client, error) { var err error - if Dialer == nil { - Dialer = protocolstate.Dialer - } - hash := configuration.Hash() if client, ok := clientPool.Get(hash); ok { return client, nil @@ -237,15 +229,15 @@ func wrappedGet(options *types.Options, configuration *Configuration) (*retryabl transport := &http.Transport{ ForceAttemptHTTP2: options.ForceAttemptHTTP2, - DialContext: Dialer.Dial, + DialContext: protocolstate.Dialer.Dial, DialTLSContext: func(ctx context.Context, network, addr string) (net.Conn, error) { if options.TlsImpersonate { - return Dialer.DialTLSWithConfigImpersonate(ctx, network, addr, tlsConfig, impersonate.Random, nil) + return protocolstate.Dialer.DialTLSWithConfigImpersonate(ctx, network, addr, tlsConfig, impersonate.Random, nil) } if options.HasClientCertificates() || options.ForceAttemptHTTP2 { - return Dialer.DialTLSWithConfig(ctx, network, addr, tlsConfig) + return protocolstate.Dialer.DialTLSWithConfig(ctx, network, addr, tlsConfig) } - return Dialer.DialTLS(ctx, network, addr) + return protocolstate.Dialer.DialTLS(ctx, network, addr) }, MaxIdleConns: maxIdleConns, MaxIdleConnsPerHost: maxIdleConnsPerHost, diff --git a/pkg/protocols/http/request.go b/pkg/protocols/http/request.go index fc3df039ac..c46db8f4b5 100644 --- a/pkg/protocols/http/request.go +++ b/pkg/protocols/http/request.go @@ -777,7 +777,7 @@ func (request *Request) executeRequest(input *contextargs.Context, generatedRequ if input.MetaInput.CustomIP != "" { outputEvent["ip"] = input.MetaInput.CustomIP } else { - outputEvent["ip"] = httpclientpool.Dialer.GetDialedIP(hostname) + outputEvent["ip"] = protocolstate.Dialer.GetDialedIP(hostname) } if len(generatedRequest.interactshURLs) > 0 { @@ -873,7 +873,7 @@ func (request *Request) executeRequest(input *contextargs.Context, generatedRequ if input.MetaInput.CustomIP != "" { outputEvent["ip"] = input.MetaInput.CustomIP } else { - outputEvent["ip"] = httpclientpool.Dialer.GetDialedIP(hostname) + outputEvent["ip"] = protocolstate.Dialer.GetDialedIP(hostname) } if request.options.Interactsh != nil { request.options.Interactsh.MakePlaceholders(generatedRequest.interactshURLs, outputEvent) From b820fb946457516559937d42d21fa3419381e367 Mon Sep 17 00:00:00 2001 From: Mzack9999 Date: Wed, 15 May 2024 21:43:43 +0200 Subject: [PATCH 3/9] fixing shared cleanup --- lib/multi.go | 2 +- lib/sdk.go | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/multi.go b/lib/multi.go index 5b2c7d6776..2ede35aecf 100644 --- a/lib/multi.go +++ b/lib/multi.go @@ -123,7 +123,7 @@ func (e *ThreadSafeNucleiEngine) ExecuteNucleiWithOptsCtx(ctx context.Context, t return err } } - defer tmpEngine.Close() + defer tmpEngine.closeInternal() // create ephemeral nuclei objects/instances/types using base nuclei engine unsafeOpts, err := createEphemeralObjects(e.eng, tmpEngine.opts) if err != nil { diff --git a/lib/sdk.go b/lib/sdk.go index 7a28cbc53e..4cfebb5c70 100644 --- a/lib/sdk.go +++ b/lib/sdk.go @@ -183,8 +183,7 @@ func (e *NucleiEngine) SignTemplate(tmplSigner *signer.TemplateSigner, data []by return buff.Bytes(), err } -// Close all resources used by nuclei engine -func (e *NucleiEngine) Close() { +func (e *NucleiEngine) closeInternal() { if e.interactshClient != nil { e.interactshClient.Close() } @@ -215,7 +214,11 @@ func (e *NucleiEngine) Close() { if e.httpxClient != nil { _ = e.httpxClient.Close() } - // close global shared resources +} + +// Close all resources used by nuclei engine +func (e *NucleiEngine) Close() { + e.closeInternal() protocolinit.Close() } From aaf5d262b2aefd07458edad4fcf316ac7c0260ad Mon Sep 17 00:00:00 2001 From: Mzack9999 Date: Thu, 16 May 2024 11:32:27 +0200 Subject: [PATCH 4/9] parallelize template loading --- pkg/catalog/loader/loader.go | 126 +++++++++++++++++++---------------- 1 file changed, 68 insertions(+), 58 deletions(-) diff --git a/pkg/catalog/loader/loader.go b/pkg/catalog/loader/loader.go index c719f71a5a..680a98c714 100644 --- a/pkg/catalog/loader/loader.go +++ b/pkg/catalog/loader/loader.go @@ -7,6 +7,7 @@ import ( "os" "sort" "strings" + "sync" "github.com/logrusorgru/aurora" "github.com/pkg/errors" @@ -441,75 +442,84 @@ func (store *Store) LoadTemplatesWithTags(templatesList, tags []string) []*templ } } + var wgLoadTemplates sync.WaitGroup + for templatePath := range templatePathMap { - loaded, err := store.config.ExecutorOptions.Parser.LoadTemplate(templatePath, store.tagFilter, tags, store.config.Catalog) - if loaded || store.pathFilter.MatchIncluded(templatePath) { - parsed, err := templates.Parse(templatePath, store.preprocessor, store.config.ExecutorOptions) - if err != nil { - // exclude templates not compatible with offline matching from total runtime warning stats - if !errors.Is(err, templates.ErrIncompatibleWithOfflineMatching) { - stats.Increment(templates.RuntimeWarningsStats) - } - gologger.Warning().Msgf("Could not parse template %s: %s\n", templatePath, err) - } else if parsed != nil { - if !parsed.Verified && store.config.ExecutorOptions.Options.DisableUnsignedTemplates { - // skip unverified templates when prompted to - stats.Increment(templates.SkippedUnsignedStats) - continue - } - // if template has request signature like aws then only signed and verified templates are allowed - if parsed.UsesRequestSignature() && !parsed.Verified { - stats.Increment(templates.SkippedRequestSignatureStats) - continue - } - // DAST only templates - if store.config.ExecutorOptions.Options.DAST { - // check if the template is a DAST template - if parsed.IsFuzzing() { - loadTemplate(parsed) + wgLoadTemplates.Add(1) + go func(templatePath string) { + defer wgLoadTemplates.Done() + + loaded, err := store.config.ExecutorOptions.Parser.LoadTemplate(templatePath, store.tagFilter, tags, store.config.Catalog) + if loaded || store.pathFilter.MatchIncluded(templatePath) { + parsed, err := templates.Parse(templatePath, store.preprocessor, store.config.ExecutorOptions) + if err != nil { + // exclude templates not compatible with offline matching from total runtime warning stats + if !errors.Is(err, templates.ErrIncompatibleWithOfflineMatching) { + stats.Increment(templates.RuntimeWarningsStats) } - } else if len(parsed.RequestsHeadless) > 0 && !store.config.ExecutorOptions.Options.Headless { - // donot include headless template in final list if headless flag is not set - stats.Increment(templates.ExcludedHeadlessTmplStats) - if config.DefaultConfig.LogAllEvents { - gologger.Print().Msgf("[%v] Headless flag is required for headless template '%s'.\n", aurora.Yellow("WRN").String(), templatePath) + gologger.Warning().Msgf("Could not parse template %s: %s\n", templatePath, err) + } else if parsed != nil { + if !parsed.Verified && store.config.ExecutorOptions.Options.DisableUnsignedTemplates { + // skip unverified templates when prompted to + stats.Increment(templates.SkippedUnsignedStats) + return } - } else if len(parsed.RequestsCode) > 0 && !store.config.ExecutorOptions.Options.EnableCodeTemplates { - // donot include 'Code' protocol custom template in final list if code flag is not set - stats.Increment(templates.ExcludedCodeTmplStats) - if config.DefaultConfig.LogAllEvents { - gologger.Print().Msgf("[%v] Code flag is required for code protocol template '%s'.\n", aurora.Yellow("WRN").String(), templatePath) + // if template has request signature like aws then only signed and verified templates are allowed + if parsed.UsesRequestSignature() && !parsed.Verified { + stats.Increment(templates.SkippedRequestSignatureStats) + return } - } else if len(parsed.RequestsCode) > 0 && !parsed.Verified && len(parsed.Workflows) == 0 { - // donot include unverified 'Code' protocol custom template in final list - stats.Increment(templates.SkippedCodeTmplTamperedStats) - // these will be skipped so increment skip counter - stats.Increment(templates.SkippedUnsignedStats) - if config.DefaultConfig.LogAllEvents { - gologger.Print().Msgf("[%v] Tampered/Unsigned template at %v.\n", aurora.Yellow("WRN").String(), templatePath) - } - } else if parsed.IsFuzzing() && !store.config.ExecutorOptions.Options.DAST { - stats.Increment(templates.ExludedDastTmplStats) - if config.DefaultConfig.LogAllEvents { - gologger.Print().Msgf("[%v] -dast flag is required for DAST template '%s'.\n", aurora.Yellow("WRN").String(), templatePath) + // DAST only templates + if store.config.ExecutorOptions.Options.DAST { + // check if the template is a DAST template + if parsed.IsFuzzing() { + loadTemplate(parsed) + } + } else if len(parsed.RequestsHeadless) > 0 && !store.config.ExecutorOptions.Options.Headless { + // donot include headless template in final list if headless flag is not set + stats.Increment(templates.ExcludedHeadlessTmplStats) + if config.DefaultConfig.LogAllEvents { + gologger.Print().Msgf("[%v] Headless flag is required for headless template '%s'.\n", aurora.Yellow("WRN").String(), templatePath) + } + } else if len(parsed.RequestsCode) > 0 && !store.config.ExecutorOptions.Options.EnableCodeTemplates { + // donot include 'Code' protocol custom template in final list if code flag is not set + stats.Increment(templates.ExcludedCodeTmplStats) + if config.DefaultConfig.LogAllEvents { + gologger.Print().Msgf("[%v] Code flag is required for code protocol template '%s'.\n", aurora.Yellow("WRN").String(), templatePath) + } + } else if len(parsed.RequestsCode) > 0 && !parsed.Verified && len(parsed.Workflows) == 0 { + // donot include unverified 'Code' protocol custom template in final list + stats.Increment(templates.SkippedCodeTmplTamperedStats) + // these will be skipped so increment skip counter + stats.Increment(templates.SkippedUnsignedStats) + if config.DefaultConfig.LogAllEvents { + gologger.Print().Msgf("[%v] Tampered/Unsigned template at %v.\n", aurora.Yellow("WRN").String(), templatePath) + } + } else if parsed.IsFuzzing() && !store.config.ExecutorOptions.Options.DAST { + stats.Increment(templates.ExludedDastTmplStats) + if config.DefaultConfig.LogAllEvents { + gologger.Print().Msgf("[%v] -dast flag is required for DAST template '%s'.\n", aurora.Yellow("WRN").String(), templatePath) + } + } else { + loadTemplate(parsed) } - } else { - loadTemplate(parsed) } } - } - if err != nil { - if strings.Contains(err.Error(), templates.ErrExcluded.Error()) { - stats.Increment(templates.TemplatesExcludedStats) - if config.DefaultConfig.LogAllEvents { - gologger.Print().Msgf("[%v] %v\n", aurora.Yellow("WRN").String(), err.Error()) + if err != nil { + if strings.Contains(err.Error(), templates.ErrExcluded.Error()) { + stats.Increment(templates.TemplatesExcludedStats) + if config.DefaultConfig.LogAllEvents { + gologger.Print().Msgf("[%v] %v\n", aurora.Yellow("WRN").String(), err.Error()) + } + return } - continue + gologger.Warning().Msg(err.Error()) } - gologger.Warning().Msg(err.Error()) - } + }(templatePath) } + wgLoadTemplates.Wait() + sort.SliceStable(loadedTemplates, func(i, j int) bool { return loadedTemplates[i].Path < loadedTemplates[j].Path }) From 3d5605530bc210557f6988c34cc73a0c9832a463 Mon Sep 17 00:00:00 2001 From: mzack9999 Date: Thu, 16 May 2024 13:42:40 +0200 Subject: [PATCH 5/9] race --- pkg/utils/stats/stats.go | 46 ++++++++++++++-------------------------- 1 file changed, 16 insertions(+), 30 deletions(-) diff --git a/pkg/utils/stats/stats.go b/pkg/utils/stats/stats.go index 590608d1e2..b6f9e9b36d 100644 --- a/pkg/utils/stats/stats.go +++ b/pkg/utils/stats/stats.go @@ -2,23 +2,22 @@ package stats import ( "fmt" - "sync" "sync/atomic" "github.com/logrusorgru/aurora" "github.com/projectdiscovery/gologger" + mapsutil "github.com/projectdiscovery/utils/maps" ) // Storage is a storage for storing statistics information // about the nuclei engine displaying it at user-defined intervals. type Storage struct { - data map[string]*storageDataItem - mutex *sync.RWMutex + data *mapsutil.SyncLockMap[string, *storageDataItem] } type storageDataItem struct { description string - value int64 + value atomic.Int64 } var Default *Storage @@ -59,38 +58,32 @@ func GetValue(name string) int64 { // New creates a new storage object func New() *Storage { - return &Storage{data: make(map[string]*storageDataItem), mutex: &sync.RWMutex{}} + data := mapsutil.NewSyncLockMap[string, *storageDataItem]() + return &Storage{data: data} } // NewEntry creates a new entry in the storage object func (s *Storage) NewEntry(name, description string) { - s.mutex.Lock() - s.data[name] = &storageDataItem{description: description, value: 0} - s.mutex.Unlock() + s.data.Set(name, &storageDataItem{description: description, value: atomic.Int64{}}) } // Increment increments the value for a name string func (s *Storage) Increment(name string) { - s.mutex.RLock() - data, ok := s.data[name] - s.mutex.RUnlock() + data, ok := s.data.Get(name) if !ok { return } - - atomic.AddInt64(&data.value, 1) + data.value.Add(1) } // Display displays the stats for a name func (s *Storage) Display(name string) { - s.mutex.RLock() - data, ok := s.data[name] - s.mutex.RUnlock() + data, ok := s.data.Get(name) if !ok { return } - dataValue := atomic.LoadInt64(&data.value) + dataValue := data.value.Load() if dataValue == 0 { return // don't show for nil stats } @@ -98,14 +91,12 @@ func (s *Storage) Display(name string) { } func (s *Storage) DisplayAsWarning(name string) { - s.mutex.RLock() - data, ok := s.data[name] - s.mutex.RUnlock() + data, ok := s.data.Get(name) if !ok { return } - dataValue := atomic.LoadInt64(&data.value) + dataValue := data.value.Load() if dataValue == 0 { return // don't show for nil stats } @@ -115,14 +106,12 @@ func (s *Storage) DisplayAsWarning(name string) { // ForceDisplayWarning forces the display of a warning // regardless of current verbosity level func (s *Storage) ForceDisplayWarning(name string) { - s.mutex.RLock() - data, ok := s.data[name] - s.mutex.RUnlock() + data, ok := s.data.Get(name) if !ok { return } - dataValue := atomic.LoadInt64(&data.value) + dataValue := data.value.Load() if dataValue == 0 { return // don't show for nil stats } @@ -131,13 +120,10 @@ func (s *Storage) ForceDisplayWarning(name string) { // GetValue returns the value for a set variable func (s *Storage) GetValue(name string) int64 { - s.mutex.RLock() - data, ok := s.data[name] - s.mutex.RUnlock() + data, ok := s.data.Get(name) if !ok { return 0 } - dataValue := atomic.LoadInt64(&data.value) - return dataValue + return data.value.Load() } From 06b0219839da372d1d93fd3166491a125d219773 Mon Sep 17 00:00:00 2001 From: mzack9999 Date: Thu, 16 May 2024 13:48:28 +0200 Subject: [PATCH 6/9] lint --- pkg/utils/stats/stats.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/utils/stats/stats.go b/pkg/utils/stats/stats.go index b6f9e9b36d..f1edf2ea33 100644 --- a/pkg/utils/stats/stats.go +++ b/pkg/utils/stats/stats.go @@ -64,7 +64,7 @@ func New() *Storage { // NewEntry creates a new entry in the storage object func (s *Storage) NewEntry(name, description string) { - s.data.Set(name, &storageDataItem{description: description, value: atomic.Int64{}}) + _ = s.data.Set(name, &storageDataItem{description: description, value: atomic.Int64{}}) } // Increment increments the value for a name string From f1b739f2a5df1184c45e1e264f9d2818274cd0d9 Mon Sep 17 00:00:00 2001 From: mzack9999 Date: Thu, 16 May 2024 14:57:33 +0200 Subject: [PATCH 7/9] fixing race --- go.mod | 2 +- go.sum | 2 ++ pkg/catalog/loader/loader.go | 11 ++++++----- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 98973239e5..3dfe4314bb 100644 --- a/go.mod +++ b/go.mod @@ -94,7 +94,7 @@ require ( github.com/projectdiscovery/tlsx v1.1.6 github.com/projectdiscovery/uncover v1.0.7 github.com/projectdiscovery/useragent v0.0.49 - github.com/projectdiscovery/utils v0.0.94-0.20240515132152-3908d4bb5d2c + github.com/projectdiscovery/utils v0.0.94-0.20240516124025-c3cf7603d51e github.com/projectdiscovery/wappalyzergo v0.0.122 github.com/redis/go-redis/v9 v9.1.0 github.com/seh-msft/burpxml v1.0.1 diff --git a/go.sum b/go.sum index 281ee725da..07ae0039f8 100644 --- a/go.sum +++ b/go.sum @@ -891,6 +891,8 @@ github.com/projectdiscovery/useragent v0.0.49 h1:wQc9i+Xy+mUMJ45Ralv1JsQImRWqEOE github.com/projectdiscovery/useragent v0.0.49/go.mod h1:jQz6X/usiXrPYE6B/1uVKuzIrBJXgw9hLC9eeNy38+0= github.com/projectdiscovery/utils v0.0.94-0.20240515132152-3908d4bb5d2c h1:vGsulLeJNcFjQTp+aSAO7auX5wriKrLrZ8+SILxtRcM= github.com/projectdiscovery/utils v0.0.94-0.20240515132152-3908d4bb5d2c/go.mod h1:wxPi+kCsLm5JCLMkZJyGwS+4Mn4PaPHHf0ayE8JphOw= +github.com/projectdiscovery/utils v0.0.94-0.20240516124025-c3cf7603d51e h1:PJbEUAFSSVT1egqY0J9V7yUi/ebz1agKBn+KPPUwBWA= +github.com/projectdiscovery/utils v0.0.94-0.20240516124025-c3cf7603d51e/go.mod h1:wxPi+kCsLm5JCLMkZJyGwS+4Mn4PaPHHf0ayE8JphOw= github.com/projectdiscovery/wappalyzergo v0.0.122 h1:xfNJ7VNzU/OGlgYtsyB5ppuOHdfWzU2B8cYATwTz54c= github.com/projectdiscovery/wappalyzergo v0.0.122/go.mod h1:qW0PP+UBMcdQBBnwk+X6YYFs6huKNvn2BOVs4vQPru0= github.com/projectdiscovery/yamldoc-go v1.0.4 h1:eZoESapnMw6WAHiVgRwNqvbJEfNHEH148uthhFbG5jE= diff --git a/pkg/catalog/loader/loader.go b/pkg/catalog/loader/loader.go index 680a98c714..e1d8371e35 100644 --- a/pkg/catalog/loader/loader.go +++ b/pkg/catalog/loader/loader.go @@ -24,6 +24,7 @@ import ( "github.com/projectdiscovery/nuclei/v3/pkg/workflows" "github.com/projectdiscovery/retryablehttp-go" errorutil "github.com/projectdiscovery/utils/errors" + sliceutil "github.com/projectdiscovery/utils/slice" stringsutil "github.com/projectdiscovery/utils/strings" urlutil "github.com/projectdiscovery/utils/url" ) @@ -426,10 +427,10 @@ func (store *Store) LoadTemplatesWithTags(templatesList, tags []string) []*templ store.logErroredTemplates(errs) templatePathMap := store.pathFilter.Match(includedTemplates) - loadedTemplates := make([]*templates.Template, 0, len(templatePathMap)) + loadedTemplates := sliceutil.NewSyncSlice[*templates.Template]() loadTemplate := func(tmpl *templates.Template) { - loadedTemplates = append(loadedTemplates, tmpl) + loadedTemplates.Append(tmpl) // increment signed/unsigned counters if tmpl.Verified { if tmpl.TemplateVerifier == "" { @@ -520,11 +521,11 @@ func (store *Store) LoadTemplatesWithTags(templatesList, tags []string) []*templ wgLoadTemplates.Wait() - sort.SliceStable(loadedTemplates, func(i, j int) bool { - return loadedTemplates[i].Path < loadedTemplates[j].Path + sort.SliceStable(loadedTemplates.Slice, func(i, j int) bool { + return loadedTemplates.Slice[i].Path < loadedTemplates.Slice[j].Path }) - return loadedTemplates + return loadedTemplates.Slice } // IsHTTPBasedProtocolUsed returns true if http/headless protocol is being used for From 3307517a6cef118d705fa27ccfae1246d50db941 Mon Sep 17 00:00:00 2001 From: mzack Date: Sat, 25 May 2024 02:52:55 +0200 Subject: [PATCH 8/9] conflict --- lib/sdk_private.go | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/sdk_private.go b/lib/sdk_private.go index c620340f37..0b05059d06 100644 --- a/lib/sdk_private.go +++ b/lib/sdk_private.go @@ -25,6 +25,7 @@ import ( "github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/hosterrorscache" "github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/interactsh" "github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/protocolinit" + "github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/protocolstate" "github.com/projectdiscovery/nuclei/v3/pkg/protocols/http/httpclientpool" "github.com/projectdiscovery/nuclei/v3/pkg/reporting" "github.com/projectdiscovery/nuclei/v3/pkg/templates" From 1e85e70d990cb463beb0e860fe4511c2605f90c1 Mon Sep 17 00:00:00 2001 From: Mzack9999 Date: Thu, 13 Jun 2024 17:24:07 +0200 Subject: [PATCH 9/9] removed as recommended --- lib/multi.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/multi.go b/lib/multi.go index a441c73fbe..44c13ddfe6 100644 --- a/lib/multi.go +++ b/lib/multi.go @@ -128,7 +128,7 @@ func (e *ThreadSafeNucleiEngine) ExecuteNucleiWithOptsCtx(ctx context.Context, t return err } } - defer tmpEngine.closeInternal() + // create ephemeral nuclei objects/instances/types using base nuclei engine unsafeOpts, err := createEphemeralObjects(ctx, e.eng, tmpEngine.opts) if err != nil {