mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-17 17:25:28 +00:00
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:
parent
c731126545
commit
be1f634eae
@ -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
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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() {
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -101,14 +101,13 @@ 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
|
||||
}
|
||||
}
|
||||
return &filters.CreateIssueResponse{
|
||||
IssueID: strconv.FormatInt(int64(issue.ID), 10),
|
||||
IssueURL: issue.WebURL,
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -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
|
||||
)
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user