diff --git a/internal/runner/proxy.go b/internal/runner/proxy.go index 3513d1c5e4..6160f54813 100644 --- a/internal/runner/proxy.go +++ b/internal/runner/proxy.go @@ -14,6 +14,10 @@ import ( proxyutils "github.com/projectdiscovery/utils/proxy" ) +const ( + HTTP_PROXY_ENV = "HTTP_PROXY" +) + // loadProxyServers load list of proxy servers from file or comma separated func loadProxyServers(options *types.Options) error { if len(options.Proxy) == 0 { @@ -48,15 +52,13 @@ func loadProxyServers(options *types.Options) error { return errorutil.WrapfWithNil(err, "failed to parse proxy got %v", err) } if options.ProxyInternal { - os.Setenv(types.HTTP_PROXY_ENV, proxyURL.String()) + os.Setenv(HTTP_PROXY_ENV, proxyURL.String()) } if proxyURL.Scheme == proxyutils.HTTP || proxyURL.Scheme == proxyutils.HTTPS { - types.ProxyURL = proxyURL.String() - types.ProxySocksURL = "" gologger.Verbose().Msgf("Using %s as proxy server", proxyURL.String()) + options.AliveHttpProxy = proxyURL.String() } else if proxyURL.Scheme == proxyutils.SOCKS5 { - types.ProxyURL = "" - types.ProxySocksURL = proxyURL.String() + options.AliveSocksProxy = proxyURL.String() gologger.Verbose().Msgf("Using %s as socket proxy server", proxyURL.String()) } return nil diff --git a/internal/runner/runner.go b/internal/runner/runner.go index 4af5184fce..bce579c48d 100644 --- a/internal/runner/runner.go +++ b/internal/runner/runner.go @@ -182,7 +182,7 @@ func New(options *types.Options) (*Runner, error) { runner.catalog = disk.NewCatalog(config.DefaultConfig.TemplatesDirectory) var httpclient *retryablehttp.Client - if options.ProxyInternal && types.ProxyURL != "" || types.ProxySocksURL != "" { + if options.ProxyInternal && options.AliveHttpProxy != "" || options.AliveSocksProxy != "" { var err error httpclient, err = httpclientpool.Get(options, &httpclientpool.Configuration{}) if err != nil { diff --git a/lib/sdk_private.go b/lib/sdk_private.go index 56d0f34529..6d3671cb09 100644 --- a/lib/sdk_private.go +++ b/lib/sdk_private.go @@ -120,7 +120,7 @@ func (e *NucleiEngine) init(ctx context.Context) error { _ = protocolinit.Init(e.opts) }) - if e.opts.ProxyInternal && types.ProxyURL != "" || types.ProxySocksURL != "" { + if e.opts.ProxyInternal && e.opts.AliveHttpProxy != "" || e.opts.AliveSocksProxy != "" { httpclient, err := httpclientpool.Get(e.opts, &httpclientpool.Configuration{}) if err != nil { return err diff --git a/pkg/protocols/common/protocolstate/state.go b/pkg/protocols/common/protocolstate/state.go index 5c56fdf77e..7d0f66b11c 100644 --- a/pkg/protocols/common/protocolstate/state.go +++ b/pkg/protocols/common/protocolstate/state.go @@ -109,8 +109,8 @@ func Init(options *types.Options) error { }, } } - if types.ProxySocksURL != "" { - proxyURL, err := url.Parse(types.ProxySocksURL) + if options.AliveSocksProxy != "" { + proxyURL, err := url.Parse(options.AliveSocksProxy) if err != nil { return err } diff --git a/pkg/protocols/headless/engine/engine.go b/pkg/protocols/headless/engine/engine.go index 04d6b2a655..3b34e220d6 100644 --- a/pkg/protocols/headless/engine/engine.go +++ b/pkg/protocols/headless/engine/engine.go @@ -73,8 +73,8 @@ func New(options *types.Options) (*Browser, error) { } else { chromeLauncher = chromeLauncher.Headless(true) } - if types.ProxyURL != "" { - chromeLauncher = chromeLauncher.Proxy(types.ProxyURL) + if options.AliveHttpProxy != "" { + chromeLauncher = chromeLauncher.Proxy(options.AliveHttpProxy) } for k, v := range options.ParseHeadlessOptionalArguments() { diff --git a/pkg/protocols/headless/engine/http_client.go b/pkg/protocols/headless/engine/http_client.go index 0029432e79..5ecddf7002 100644 --- a/pkg/protocols/headless/engine/http_client.go +++ b/pkg/protocols/headless/engine/http_client.go @@ -56,12 +56,12 @@ func newHttpClient(options *types.Options) (*http.Client, error) { MaxConnsPerHost: 500, TLSClientConfig: tlsConfig, } - if types.ProxyURL != "" { - if proxyURL, err := url.Parse(types.ProxyURL); err == nil { + if options.AliveHttpProxy != "" { + if proxyURL, err := url.Parse(options.AliveHttpProxy); err == nil { transport.Proxy = http.ProxyURL(proxyURL) } - } else if types.ProxySocksURL != "" { - socksURL, proxyErr := url.Parse(types.ProxySocksURL) + } else if options.AliveSocksProxy != "" { + socksURL, proxyErr := url.Parse(options.AliveSocksProxy) if proxyErr != nil { return nil, err } diff --git a/pkg/protocols/http/httpclientpool/clientpool.go b/pkg/protocols/http/httpclientpool/clientpool.go index 94ed61ff3f..042ee7ac0e 100644 --- a/pkg/protocols/http/httpclientpool/clientpool.go +++ b/pkg/protocols/http/httpclientpool/clientpool.go @@ -157,10 +157,10 @@ func (c *Configuration) HasStandardOptions() bool { func GetRawHTTP(options *protocols.ExecutorOptions) *rawhttp.Client { rawHttpClientOnce.Do(func() { rawHttpOptions := rawhttp.DefaultOptions - if types.ProxyURL != "" { - rawHttpOptions.Proxy = types.ProxyURL - } else if types.ProxySocksURL != "" { - rawHttpOptions.Proxy = types.ProxySocksURL + if options.Options.AliveHttpProxy != "" { + rawHttpOptions.Proxy = options.Options.AliveHttpProxy + } else if options.Options.AliveSocksProxy != "" { + rawHttpOptions.Proxy = options.Options.AliveSocksProxy } else if protocolstate.Dialer != nil { rawHttpOptions.FastDialer = protocolstate.Dialer } @@ -278,12 +278,12 @@ func wrappedGet(options *types.Options, configuration *Configuration) (*retryabl ResponseHeaderTimeout: responseHeaderTimeout, } - if types.ProxyURL != "" { - if proxyURL, err := url.Parse(types.ProxyURL); err == nil { + if options.AliveHttpProxy != "" { + if proxyURL, err := url.Parse(options.AliveHttpProxy); err == nil { transport.Proxy = http.ProxyURL(proxyURL) } - } else if types.ProxySocksURL != "" { - socksURL, proxyErr := url.Parse(types.ProxySocksURL) + } else if options.AliveSocksProxy != "" { + socksURL, proxyErr := url.Parse(options.AliveSocksProxy) if proxyErr != nil { return nil, proxyErr } diff --git a/pkg/reporting/trackers/github/github.go b/pkg/reporting/trackers/github/github.go index 8011d8da53..a8ec5837f0 100644 --- a/pkg/reporting/trackers/github/github.go +++ b/pkg/reporting/trackers/github/github.go @@ -15,7 +15,6 @@ import ( "github.com/projectdiscovery/nuclei/v3/pkg/reporting/exporters/markdown/util" "github.com/projectdiscovery/nuclei/v3/pkg/reporting/format" "github.com/projectdiscovery/nuclei/v3/pkg/reporting/trackers/filters" - "github.com/projectdiscovery/nuclei/v3/pkg/types" "github.com/projectdiscovery/retryablehttp-go" "golang.org/x/oauth2" ) @@ -63,11 +62,9 @@ func New(options *Options) (*Integration, error) { ) tc := oauth2.NewClient(ctx, ts) - // patch transport to support proxy - only http - // TODO: investigate if it's possible to reuse existing retryablehttp - if types.ProxyURL != "" { - if proxyURL, err := url.Parse(types.ProxyURL); err == nil { - tc.Transport.(*http.Transport).Proxy = http.ProxyURL(proxyURL) + if options.HttpClient != nil && options.HttpClient.HTTPClient != nil { + if tcTransport, ok := tc.Transport.(*http.Transport); ok { + tcTransport.Proxy = options.HttpClient.HTTPClient.Transport.(*http.Transport).Proxy } } diff --git a/pkg/reporting/trackers/gitlab/gitlab.go b/pkg/reporting/trackers/gitlab/gitlab.go index fdb2b948f1..75782502b6 100644 --- a/pkg/reporting/trackers/gitlab/gitlab.go +++ b/pkg/reporting/trackers/gitlab/gitlab.go @@ -101,13 +101,12 @@ func (i *Integration) CreateIssue(event *output.ResultEvent) (*filters.CreateIss } if issue.State == "closed" { reopen := "reopen" - _, resp, err := i.client.Issues.UpdateIssue(i.options.ProjectName, issue.IID, &gitlab.UpdateIssueOptions{ + _, _, err := i.client.Issues.UpdateIssue(i.options.ProjectName, issue.IID, &gitlab.UpdateIssueOptions{ StateEvent: &reopen, }) - fmt.Sprintln(resp, err) - } - if err != nil { - return nil, err + if err != nil { + return nil, err + } } return &filters.CreateIssueResponse{ IssueID: strconv.FormatInt(int64(issue.ID), 10), diff --git a/pkg/reporting/trackers/linear/linear.go b/pkg/reporting/trackers/linear/linear.go index 11712039f8..e46edfc84f 100644 --- a/pkg/reporting/trackers/linear/linear.go +++ b/pkg/reporting/trackers/linear/linear.go @@ -60,6 +60,9 @@ func New(options *Options) (*Integration, error) { Key: options.APIKey, }, } + if options.HttpClient != nil { + httpClient.Transport = options.HttpClient.HTTPClient.Transport + } integration := &Integration{ url: "https://api.linear.app/graphql", diff --git a/pkg/types/proxy.go b/pkg/types/proxy.go deleted file mode 100644 index 1db9ac3c00..0000000000 --- a/pkg/types/proxy.go +++ /dev/null @@ -1,12 +0,0 @@ -package types - -const ( - HTTP_PROXY_ENV = "HTTP_PROXY" -) - -var ( - // ProxyURL is the URL for the proxy server - ProxyURL string - // ProxySocksURL is the URL for the proxy socks server - ProxySocksURL string -) diff --git a/pkg/types/types.go b/pkg/types/types.go index 976e16b269..aa43683ecd 100644 --- a/pkg/types/types.go +++ b/pkg/types/types.go @@ -94,6 +94,10 @@ type Options struct { ListDslSignatures bool // List of HTTP(s)/SOCKS5 proxy to use (comma separated or file input) Proxy goflags.StringSlice + // AliveProxy is the alive proxy to use + AliveHttpProxy string + // AliveSocksProxy is the alive socks proxy to use + AliveSocksProxy string // TemplatesDirectory is the directory to use for storing templates NewTemplatesDirectory string // TraceLogFile specifies a file to write with the trace of all requests