mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-17 19:35:27 +00:00
* introducing execution id * wip * . * adding separate execution context id * lint * vet * fixing pg dialers * test ignore * fixing loader FD limit * test * fd fix * wip: remove CloseProcesses() from dev merge * wip: fix merge issue * protocolstate: stop memguarding on last dialer delete * avoid data race in dialers.RawHTTPClient * use shared logger and avoid race conditions * use shared logger and avoid race conditions * go mod * patch executionId into compiled template cache * clean up comment in Parse * go mod update * bump echarts * address merge issues * fix use of gologger * switch cmd/nuclei to options.Logger * address merge issues with go.mod * go vet: address copy of lock with new Copy function * fixing tests * disable speed control * fix nil ExecuterOptions * removing deprecated code * fixing result print * default logger * cli default logger * filter warning from results * fix performance test * hardcoding path * disable upload * refactor(runner): uses `Warning` instead of `Print` for `pdcpUploadErrMsg` Signed-off-by: Dwi Siswanto <git@dw1.io> * Revert "disable upload" This reverts commit 114fbe6663361bf41cf8b2645fd2d57083d53682. * Revert "hardcoding path" This reverts commit cf12ca800e0a0e974bd9fd4826a24e51547f7c00. --------- Signed-off-by: Dwi Siswanto <git@dw1.io> Co-authored-by: Mzack9999 <mzack9999@protonmail.com> Co-authored-by: Dwi Siswanto <git@dw1.io> Co-authored-by: Dwi Siswanto <25837540+dwisiswant0@users.noreply.github.com>
96 lines
2.7 KiB
Go
96 lines
2.7 KiB
Go
package engine
|
|
|
|
import (
|
|
"context"
|
|
"crypto/tls"
|
|
"fmt"
|
|
"net"
|
|
"net/http"
|
|
"net/http/cookiejar"
|
|
"net/url"
|
|
"time"
|
|
|
|
"golang.org/x/net/proxy"
|
|
|
|
"github.com/projectdiscovery/fastdialer/fastdialer/ja3/impersonate"
|
|
"github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/protocolstate"
|
|
"github.com/projectdiscovery/nuclei/v3/pkg/protocols/utils"
|
|
"github.com/projectdiscovery/nuclei/v3/pkg/types"
|
|
)
|
|
|
|
// newHttpClient creates a new http client for headless communication with a timeout
|
|
func newHttpClient(options *types.Options) (*http.Client, error) {
|
|
dialers := protocolstate.GetDialersWithId(options.ExecutionId)
|
|
if dialers == nil {
|
|
return nil, fmt.Errorf("dialers not initialized for %s", options.ExecutionId)
|
|
}
|
|
// Set the base TLS configuration definition
|
|
tlsConfig := &tls.Config{
|
|
Renegotiation: tls.RenegotiateOnceAsClient,
|
|
InsecureSkipVerify: true,
|
|
MinVersion: tls.VersionTLS10,
|
|
}
|
|
|
|
if options.SNI != "" {
|
|
tlsConfig.ServerName = options.SNI
|
|
}
|
|
|
|
// Add the client certificate authentication to the request if it's configured
|
|
var err error
|
|
tlsConfig, err = utils.AddConfiguredClientCertToRequest(tlsConfig, options)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
transport := &http.Transport{
|
|
ForceAttemptHTTP2: options.ForceAttemptHTTP2,
|
|
DialContext: dialers.Fastdialer.Dial,
|
|
DialTLSContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
|
|
if options.TlsImpersonate {
|
|
return dialers.Fastdialer.DialTLSWithConfigImpersonate(ctx, network, addr, tlsConfig, impersonate.Random, nil)
|
|
}
|
|
if options.HasClientCertificates() || options.ForceAttemptHTTP2 {
|
|
return dialers.Fastdialer.DialTLSWithConfig(ctx, network, addr, tlsConfig)
|
|
}
|
|
return dialers.Fastdialer.DialTLS(ctx, network, addr)
|
|
},
|
|
MaxIdleConns: 500,
|
|
MaxIdleConnsPerHost: 500,
|
|
MaxConnsPerHost: 500,
|
|
TLSClientConfig: tlsConfig,
|
|
}
|
|
if options.AliveHttpProxy != "" {
|
|
if proxyURL, err := url.Parse(options.AliveHttpProxy); err == nil {
|
|
transport.Proxy = http.ProxyURL(proxyURL)
|
|
}
|
|
} else if options.AliveSocksProxy != "" {
|
|
socksURL, proxyErr := url.Parse(options.AliveSocksProxy)
|
|
if proxyErr != nil {
|
|
return nil, err
|
|
}
|
|
dialer, err := proxy.FromURL(socksURL, proxy.Direct)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
dc := dialer.(interface {
|
|
DialContext(ctx context.Context, network, addr string) (net.Conn, error)
|
|
})
|
|
transport.DialContext = dc.DialContext
|
|
}
|
|
|
|
jar, _ := cookiejar.New(nil)
|
|
|
|
httpclient := &http.Client{
|
|
Transport: transport,
|
|
Timeout: time.Duration(options.Timeout*3) * time.Second,
|
|
Jar: jar,
|
|
CheckRedirect: func(req *http.Request, via []*http.Request) error {
|
|
// the browser should follow redirects not us
|
|
return http.ErrUseLastResponse
|
|
},
|
|
}
|
|
|
|
return httpclient, nil
|
|
}
|