Add Alive Proxy into Options (#5903)

* Move proxy variable from global to options

- Provides ability to pass diff proxy in single nuclei instance using sdk

* add type check (resolve comments)
This commit is contained in:
Shubham Rasal 2024-12-13 04:23:27 +05:30 committed by GitHub
parent c731126545
commit be1f634eae
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 39 additions and 46 deletions

View File

@ -14,6 +14,10 @@ import (
proxyutils "github.com/projectdiscovery/utils/proxy" proxyutils "github.com/projectdiscovery/utils/proxy"
) )
const (
HTTP_PROXY_ENV = "HTTP_PROXY"
)
// loadProxyServers load list of proxy servers from file or comma separated // loadProxyServers load list of proxy servers from file or comma separated
func loadProxyServers(options *types.Options) error { func loadProxyServers(options *types.Options) error {
if len(options.Proxy) == 0 { 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) return errorutil.WrapfWithNil(err, "failed to parse proxy got %v", err)
} }
if options.ProxyInternal { 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 { 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()) gologger.Verbose().Msgf("Using %s as proxy server", proxyURL.String())
options.AliveHttpProxy = proxyURL.String()
} else if proxyURL.Scheme == proxyutils.SOCKS5 { } else if proxyURL.Scheme == proxyutils.SOCKS5 {
types.ProxyURL = "" options.AliveSocksProxy = proxyURL.String()
types.ProxySocksURL = proxyURL.String()
gologger.Verbose().Msgf("Using %s as socket proxy server", proxyURL.String()) gologger.Verbose().Msgf("Using %s as socket proxy server", proxyURL.String())
} }
return nil return nil

View File

@ -182,7 +182,7 @@ func New(options *types.Options) (*Runner, error) {
runner.catalog = disk.NewCatalog(config.DefaultConfig.TemplatesDirectory) runner.catalog = disk.NewCatalog(config.DefaultConfig.TemplatesDirectory)
var httpclient *retryablehttp.Client var httpclient *retryablehttp.Client
if options.ProxyInternal && types.ProxyURL != "" || types.ProxySocksURL != "" { if options.ProxyInternal && options.AliveHttpProxy != "" || options.AliveSocksProxy != "" {
var err error var err error
httpclient, err = httpclientpool.Get(options, &httpclientpool.Configuration{}) httpclient, err = httpclientpool.Get(options, &httpclientpool.Configuration{})
if err != nil { if err != nil {

View File

@ -120,7 +120,7 @@ func (e *NucleiEngine) init(ctx context.Context) error {
_ = protocolinit.Init(e.opts) _ = 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{}) httpclient, err := httpclientpool.Get(e.opts, &httpclientpool.Configuration{})
if err != nil { if err != nil {
return err return err

View File

@ -109,8 +109,8 @@ func Init(options *types.Options) error {
}, },
} }
} }
if types.ProxySocksURL != "" { if options.AliveSocksProxy != "" {
proxyURL, err := url.Parse(types.ProxySocksURL) proxyURL, err := url.Parse(options.AliveSocksProxy)
if err != nil { if err != nil {
return err return err
} }

View File

@ -73,8 +73,8 @@ func New(options *types.Options) (*Browser, error) {
} else { } else {
chromeLauncher = chromeLauncher.Headless(true) chromeLauncher = chromeLauncher.Headless(true)
} }
if types.ProxyURL != "" { if options.AliveHttpProxy != "" {
chromeLauncher = chromeLauncher.Proxy(types.ProxyURL) chromeLauncher = chromeLauncher.Proxy(options.AliveHttpProxy)
} }
for k, v := range options.ParseHeadlessOptionalArguments() { for k, v := range options.ParseHeadlessOptionalArguments() {

View File

@ -56,12 +56,12 @@ func newHttpClient(options *types.Options) (*http.Client, error) {
MaxConnsPerHost: 500, MaxConnsPerHost: 500,
TLSClientConfig: tlsConfig, TLSClientConfig: tlsConfig,
} }
if types.ProxyURL != "" { if options.AliveHttpProxy != "" {
if proxyURL, err := url.Parse(types.ProxyURL); err == nil { if proxyURL, err := url.Parse(options.AliveHttpProxy); err == nil {
transport.Proxy = http.ProxyURL(proxyURL) transport.Proxy = http.ProxyURL(proxyURL)
} }
} else if types.ProxySocksURL != "" { } else if options.AliveSocksProxy != "" {
socksURL, proxyErr := url.Parse(types.ProxySocksURL) socksURL, proxyErr := url.Parse(options.AliveSocksProxy)
if proxyErr != nil { if proxyErr != nil {
return nil, err return nil, err
} }

View File

@ -157,10 +157,10 @@ func (c *Configuration) HasStandardOptions() bool {
func GetRawHTTP(options *protocols.ExecutorOptions) *rawhttp.Client { func GetRawHTTP(options *protocols.ExecutorOptions) *rawhttp.Client {
rawHttpClientOnce.Do(func() { rawHttpClientOnce.Do(func() {
rawHttpOptions := rawhttp.DefaultOptions rawHttpOptions := rawhttp.DefaultOptions
if types.ProxyURL != "" { if options.Options.AliveHttpProxy != "" {
rawHttpOptions.Proxy = types.ProxyURL rawHttpOptions.Proxy = options.Options.AliveHttpProxy
} else if types.ProxySocksURL != "" { } else if options.Options.AliveSocksProxy != "" {
rawHttpOptions.Proxy = types.ProxySocksURL rawHttpOptions.Proxy = options.Options.AliveSocksProxy
} else if protocolstate.Dialer != nil { } else if protocolstate.Dialer != nil {
rawHttpOptions.FastDialer = protocolstate.Dialer rawHttpOptions.FastDialer = protocolstate.Dialer
} }
@ -278,12 +278,12 @@ func wrappedGet(options *types.Options, configuration *Configuration) (*retryabl
ResponseHeaderTimeout: responseHeaderTimeout, ResponseHeaderTimeout: responseHeaderTimeout,
} }
if types.ProxyURL != "" { if options.AliveHttpProxy != "" {
if proxyURL, err := url.Parse(types.ProxyURL); err == nil { if proxyURL, err := url.Parse(options.AliveHttpProxy); err == nil {
transport.Proxy = http.ProxyURL(proxyURL) transport.Proxy = http.ProxyURL(proxyURL)
} }
} else if types.ProxySocksURL != "" { } else if options.AliveSocksProxy != "" {
socksURL, proxyErr := url.Parse(types.ProxySocksURL) socksURL, proxyErr := url.Parse(options.AliveSocksProxy)
if proxyErr != nil { if proxyErr != nil {
return nil, proxyErr return nil, proxyErr
} }

View File

@ -15,7 +15,6 @@ import (
"github.com/projectdiscovery/nuclei/v3/pkg/reporting/exporters/markdown/util" "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/format"
"github.com/projectdiscovery/nuclei/v3/pkg/reporting/trackers/filters" "github.com/projectdiscovery/nuclei/v3/pkg/reporting/trackers/filters"
"github.com/projectdiscovery/nuclei/v3/pkg/types"
"github.com/projectdiscovery/retryablehttp-go" "github.com/projectdiscovery/retryablehttp-go"
"golang.org/x/oauth2" "golang.org/x/oauth2"
) )
@ -63,11 +62,9 @@ func New(options *Options) (*Integration, error) {
) )
tc := oauth2.NewClient(ctx, ts) tc := oauth2.NewClient(ctx, ts)
// patch transport to support proxy - only http if options.HttpClient != nil && options.HttpClient.HTTPClient != nil {
// TODO: investigate if it's possible to reuse existing retryablehttp if tcTransport, ok := tc.Transport.(*http.Transport); ok {
if types.ProxyURL != "" { tcTransport.Proxy = options.HttpClient.HTTPClient.Transport.(*http.Transport).Proxy
if proxyURL, err := url.Parse(types.ProxyURL); err == nil {
tc.Transport.(*http.Transport).Proxy = http.ProxyURL(proxyURL)
} }
} }

View File

@ -101,14 +101,13 @@ func (i *Integration) CreateIssue(event *output.ResultEvent) (*filters.CreateIss
} }
if issue.State == "closed" { if issue.State == "closed" {
reopen := "reopen" 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, StateEvent: &reopen,
}) })
fmt.Sprintln(resp, err)
}
if err != nil { if err != nil {
return nil, err return nil, err
} }
}
return &filters.CreateIssueResponse{ return &filters.CreateIssueResponse{
IssueID: strconv.FormatInt(int64(issue.ID), 10), IssueID: strconv.FormatInt(int64(issue.ID), 10),
IssueURL: issue.WebURL, IssueURL: issue.WebURL,

View File

@ -60,6 +60,9 @@ func New(options *Options) (*Integration, error) {
Key: options.APIKey, Key: options.APIKey,
}, },
} }
if options.HttpClient != nil {
httpClient.Transport = options.HttpClient.HTTPClient.Transport
}
integration := &Integration{ integration := &Integration{
url: "https://api.linear.app/graphql", url: "https://api.linear.app/graphql",

View File

@ -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
)

View File

@ -94,6 +94,10 @@ type Options struct {
ListDslSignatures bool ListDslSignatures bool
// List of HTTP(s)/SOCKS5 proxy to use (comma separated or file input) // List of HTTP(s)/SOCKS5 proxy to use (comma separated or file input)
Proxy goflags.StringSlice 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 // TemplatesDirectory is the directory to use for storing templates
NewTemplatesDirectory string NewTemplatesDirectory string
// TraceLogFile specifies a file to write with the trace of all requests // TraceLogFile specifies a file to write with the trace of all requests