From 17827f4ab8bc9aaa7daad259b76d83205b0ffaa7 Mon Sep 17 00:00:00 2001 From: Mzack9999 Date: Sat, 24 Oct 2020 01:27:46 +0200 Subject: [PATCH] fixing global dealer --- v2/internal/runner/processor.go | 1 + v2/internal/runner/runner.go | 10 ++++++++++ v2/pkg/executer/executer_http.go | 15 ++++++--------- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/v2/internal/runner/processor.go b/v2/internal/runner/processor.go index 34dfeff1b..fcab2b537 100644 --- a/v2/internal/runner/processor.go +++ b/v2/internal/runner/processor.go @@ -72,6 +72,7 @@ func (r *Runner) processTemplateWithList(p progress.IProgress, template *templat Decolorizer: r.decolorizer, StopAtFirstMatch: r.options.StopAtFirstMatch, PF: r.pf, + Dialer: &r.dialer, }) } diff --git a/v2/internal/runner/runner.go b/v2/internal/runner/runner.go index b537f6cb3..aee2aed7e 100644 --- a/v2/internal/runner/runner.go +++ b/v2/internal/runner/runner.go @@ -12,6 +12,7 @@ import ( "github.com/logrusorgru/aurora" "github.com/pkg/errors" "github.com/projectdiscovery/gologger" + "github.com/projectdiscovery/httpx/common/cache" "github.com/projectdiscovery/nuclei/v2/internal/bufwriter" "github.com/projectdiscovery/nuclei/v2/internal/progress" "github.com/projectdiscovery/nuclei/v2/internal/tracelog" @@ -48,6 +49,9 @@ type Runner struct { // output coloring colorizer colorizer.NucleiColorizer decolorizer *regexp.Regexp + + // http dialer + dialer cache.DialerFunc } // New creates a new client for running enumeration process. @@ -194,6 +198,12 @@ func New(options *Options) (*Runner, error) { collaborator.DefaultCollaborator.Collab.AddBIID(options.BurpCollaboratorBiid) } + // Create Dialer + runner.dialer, err = cache.NewDialer(cache.DefaultOptions) + if err != nil { + return nil, err + } + return runner, nil } diff --git a/v2/pkg/executer/executer_http.go b/v2/pkg/executer/executer_http.go index d85dc55b1..1ce341706 100644 --- a/v2/pkg/executer/executer_http.go +++ b/v2/pkg/executer/executer_http.go @@ -89,14 +89,16 @@ type HTTPOptions struct { ColoredOutput bool StopAtFirstMatch bool PF *projetctfile.ProjectFile + Dialer *cache.DialerFunc } // NewHTTPExecuter creates a new HTTP executer from a template // and a HTTP request query. func NewHTTPExecuter(options *HTTPOptions) (*HTTPExecuter, error) { - var proxyURL *url.URL - - var err error + var ( + proxyURL *url.URL + err error + ) if options.ProxyURL != "" { proxyURL, err = url.Parse(options.ProxyURL) @@ -601,13 +603,8 @@ func makeHTTPClient(proxyURL *url.URL, options *HTTPOptions) (*retryablehttp.Cli followRedirects := options.BulkHTTPRequest.Redirects maxRedirects := options.BulkHTTPRequest.MaxRedirects - dialer, err := cache.NewDialer(cache.DefaultOptions) - if err != nil { - return nil, err - } - transport := &http.Transport{ - DialContext: dialer, + DialContext: *options.Dialer, MaxIdleConns: maxIdleConns, MaxIdleConnsPerHost: maxIdleConnsPerHost, MaxConnsPerHost: maxConnsPerHost,