Merge branch 'dev' into interactsh-server-support

This commit is contained in:
Sandeep Singh 2021-05-01 12:05:27 +05:30 committed by GitHub
commit 33f1e23e87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 68 additions and 43 deletions

View File

@ -7,11 +7,11 @@ const banner = `
____ __ _______/ /__ (_) ____ __ _______/ /__ (_)
/ __ \/ / / / ___/ / _ \/ / / __ \/ / / / ___/ / _ \/ /
/ / / / /_/ / /__/ / __/ / / / / / /_/ / /__/ / __/ /
/_/ /_/\__,_/\___/_/\___/_/ v2.3.4 /_/ /_/\__,_/\___/_/\___/_/ v2.3.5
` `
// Version is the current version of nuclei // Version is the current version of nuclei
const Version = `2.3.4` const Version = `2.3.5`
// showBanner is used to show the banner to the user // showBanner is used to show the banner to the user
func showBanner() { func showBanner() {

View File

@ -20,6 +20,7 @@ import (
"github.com/projectdiscovery/nuclei/v2/pkg/protocols" "github.com/projectdiscovery/nuclei/v2/pkg/protocols"
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/clusterer" "github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/clusterer"
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/interactsh" "github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/interactsh"
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/protocolinit"
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/headless/engine" "github.com/projectdiscovery/nuclei/v2/pkg/protocols/headless/engine"
"github.com/projectdiscovery/nuclei/v2/pkg/reporting" "github.com/projectdiscovery/nuclei/v2/pkg/reporting"
"github.com/projectdiscovery/nuclei/v2/pkg/reporting/exporters/disk" "github.com/projectdiscovery/nuclei/v2/pkg/reporting/exporters/disk"
@ -237,6 +238,7 @@ func (r *Runner) Close() {
if r.projectFile != nil { if r.projectFile != nil {
r.projectFile.Close() r.projectFile.Close()
} }
protocolinit.Close()
} }
// RunEnumeration sets up the input layer for giving input nuclei. // RunEnumeration sets up the input layer for giving input nuclei.

View File

@ -2,6 +2,7 @@ package protocolinit
import ( import (
"github.com/corpix/uarand" "github.com/corpix/uarand"
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/protocolstate"
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/dns/dnsclientpool" "github.com/projectdiscovery/nuclei/v2/pkg/protocols/dns/dnsclientpool"
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/http/httpclientpool" "github.com/projectdiscovery/nuclei/v2/pkg/protocols/http/httpclientpool"
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/network/networkclientpool" "github.com/projectdiscovery/nuclei/v2/pkg/protocols/network/networkclientpool"
@ -12,6 +13,9 @@ import (
func Init(options *types.Options) error { func Init(options *types.Options) error {
uarand.Default = uarand.NewWithCustomList(userAgents) uarand.Default = uarand.NewWithCustomList(userAgents)
if err := protocolstate.Init(options); err != nil {
return err
}
if err := dnsclientpool.Init(options); err != nil { if err := dnsclientpool.Init(options); err != nil {
return err return err
} }
@ -58,3 +62,7 @@ var userAgents = []string{
"Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1866.237 Safari/537.36", "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1866.237 Safari/537.36",
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.137 Safari/4E423F", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.137 Safari/4E423F",
} }
func Close() {
protocolstate.Dialer.Close()
}

View File

@ -0,0 +1,31 @@
package protocolstate
import (
"github.com/pkg/errors"
"github.com/projectdiscovery/fastdialer/fastdialer"
"github.com/projectdiscovery/nuclei/v2/pkg/types"
)
var Dialer *fastdialer.Dialer
func Init(options *types.Options) error {
opts := fastdialer.DefaultOptions
if options.SystemResolvers {
opts.EnableFallback = true
}
if options.ResolversFile != "" {
opts.BaseResolvers = options.InternalResolversList
}
dialer, err := fastdialer.NewDialer(opts)
if err != nil {
return errors.Wrap(err, "could not create dialer")
}
Dialer = dialer
return nil
}
func Close() {
if Dialer != nil {
Dialer.Close()
}
}

View File

@ -76,10 +76,7 @@ func New(options *types.Options) (*Browser, error) {
if customAgent == "" { if customAgent == "" {
customAgent = uarand.GetRandom() customAgent = uarand.GetRandom()
} }
httpclient, err := newhttpClient(options) httpclient := newhttpClient(options)
if err != nil {
return nil, err
}
engine := &Browser{ engine := &Browser{
tempDir: dataStore, tempDir: dataStore,
customAgent: customAgent, customAgent: customAgent,

View File

@ -5,25 +5,13 @@ import (
"net/http" "net/http"
"time" "time"
"github.com/pkg/errors" "github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/protocolstate"
"github.com/projectdiscovery/fastdialer/fastdialer"
"github.com/projectdiscovery/nuclei/v2/pkg/types" "github.com/projectdiscovery/nuclei/v2/pkg/types"
) )
// newhttpClient creates a new http client for headless communication with a timeout // newhttpClient creates a new http client for headless communication with a timeout
func newhttpClient(options *types.Options) (*http.Client, error) { func newhttpClient(options *types.Options) *http.Client {
opts := fastdialer.DefaultOptions dialer := protocolstate.Dialer
if options.SystemResolvers {
opts.EnableFallback = true
}
if options.ResolversFile != "" {
opts.BaseResolvers = options.InternalResolversList
}
dialer, err := fastdialer.NewDialer(opts)
if err != nil {
return nil, errors.Wrap(err, "could not create dialer")
}
transport := &http.Transport{ transport := &http.Transport{
DialContext: dialer.Dial, DialContext: dialer.Dial,
MaxIdleConns: 500, MaxIdleConns: 500,
@ -34,5 +22,5 @@ func newhttpClient(options *types.Options) (*http.Client, error) {
InsecureSkipVerify: true, InsecureSkipVerify: true,
}, },
} }
return &http.Client{Transport: transport, Timeout: time.Duration(options.Timeout*3) * time.Second}, nil return &http.Client{Transport: transport, Timeout: time.Duration(options.Timeout*3) * time.Second}
} }

View File

@ -9,11 +9,14 @@ import (
"testing" "testing"
"time" "time"
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/protocolstate"
"github.com/projectdiscovery/nuclei/v2/pkg/types" "github.com/projectdiscovery/nuclei/v2/pkg/types"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
func TestActionNavigate(t *testing.T) { func TestActionNavigate(t *testing.T) {
_ = protocolstate.Init(&types.Options{})
browser, err := New(&types.Options{ShowBrowser: false}) browser, err := New(&types.Options{ShowBrowser: false})
require.Nil(t, err, "could not create browser") require.Nil(t, err, "could not create browser")
defer browser.Close() defer browser.Close()
@ -46,6 +49,8 @@ func TestActionNavigate(t *testing.T) {
} }
func TestActionScript(t *testing.T) { func TestActionScript(t *testing.T) {
_ = protocolstate.Init(&types.Options{})
browser, err := New(&types.Options{ShowBrowser: false}) browser, err := New(&types.Options{ShowBrowser: false})
require.Nil(t, err, "could not create browser") require.Nil(t, err, "could not create browser")
defer browser.Close() defer browser.Close()
@ -113,6 +118,8 @@ func TestActionScript(t *testing.T) {
} }
func TestActionClick(t *testing.T) { func TestActionClick(t *testing.T) {
_ = protocolstate.Init(&types.Options{})
browser, err := New(&types.Options{ShowBrowser: false}) browser, err := New(&types.Options{ShowBrowser: false})
require.Nil(t, err, "could not create browser") require.Nil(t, err, "could not create browser")
defer browser.Close() defer browser.Close()
@ -151,6 +158,8 @@ func TestActionClick(t *testing.T) {
} }
func TestActionRightClick(t *testing.T) { func TestActionRightClick(t *testing.T) {
_ = protocolstate.Init(&types.Options{})
browser, err := New(&types.Options{ShowBrowser: false}) browser, err := New(&types.Options{ShowBrowser: false})
require.Nil(t, err, "could not create browser") require.Nil(t, err, "could not create browser")
defer browser.Close() defer browser.Close()
@ -197,6 +206,8 @@ func TestActionRightClick(t *testing.T) {
} }
func TestActionTextInput(t *testing.T) { func TestActionTextInput(t *testing.T) {
_ = protocolstate.Init(&types.Options{})
browser, err := New(&types.Options{ShowBrowser: false}) browser, err := New(&types.Options{ShowBrowser: false})
require.Nil(t, err, "could not create browser") require.Nil(t, err, "could not create browser")
defer browser.Close() defer browser.Close()
@ -236,6 +247,8 @@ func TestActionTextInput(t *testing.T) {
} }
func TestActionHeadersChange(t *testing.T) { func TestActionHeadersChange(t *testing.T) {
_ = protocolstate.Init(&types.Options{})
browser, err := New(&types.Options{ShowBrowser: false}) browser, err := New(&types.Options{ShowBrowser: false})
require.Nil(t, err, "could not create browser") require.Nil(t, err, "could not create browser")
defer browser.Close() defer browser.Close()

View File

@ -15,6 +15,7 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/projectdiscovery/fastdialer/fastdialer" "github.com/projectdiscovery/fastdialer/fastdialer"
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/protocolstate"
"github.com/projectdiscovery/nuclei/v2/pkg/types" "github.com/projectdiscovery/nuclei/v2/pkg/types"
"github.com/projectdiscovery/rawhttp" "github.com/projectdiscovery/rawhttp"
"github.com/projectdiscovery/retryablehttp-go" "github.com/projectdiscovery/retryablehttp-go"
@ -97,14 +98,7 @@ func wrappedGet(options *types.Options, configuration *Configuration) (*retryabl
var err error var err error
if Dialer == nil { if Dialer == nil {
opts := fastdialer.DefaultOptions Dialer = protocolstate.Dialer
if options.SystemResolvers {
opts.EnableFallback = true
}
if options.ResolversFile != "" {
opts.BaseResolvers = options.InternalResolversList
}
Dialer, err = fastdialer.NewDialer(opts)
} }
if err != nil { if err != nil {
return nil, errors.Wrap(err, "could not create dialer") return nil, errors.Wrap(err, "could not create dialer")

View File

@ -388,6 +388,9 @@ func (r *Request) executeRequest(reqURL string, request *generatedRequest, previ
finalEvent := make(output.InternalEvent) finalEvent := make(output.InternalEvent)
outputEvent := r.responseToDSLMap(resp, reqURL, matchedURL, tostring.UnsafeToString(dumpedRequest), tostring.UnsafeToString(dumpedResponse), tostring.UnsafeToString(data), headersToString(resp.Header), duration, request.meta) outputEvent := r.responseToDSLMap(resp, reqURL, matchedURL, tostring.UnsafeToString(dumpedRequest), tostring.UnsafeToString(dumpedResponse), tostring.UnsafeToString(data), headersToString(resp.Header), duration, request.meta)
if i := strings.LastIndex(hostname, ":"); i != -1 {
hostname = hostname[:i]
}
outputEvent["ip"] = httpclientpool.Dialer.GetDialedIP(hostname) outputEvent["ip"] = httpclientpool.Dialer.GetDialedIP(hostname)
outputEvent["redirect-chain"] = tostring.UnsafeToString(redirectedResponse) outputEvent["redirect-chain"] = tostring.UnsafeToString(redirectedResponse)
for k, v := range previous { for k, v := range previous {

View File

@ -1,8 +1,8 @@
package networkclientpool package networkclientpool
import ( import (
"github.com/pkg/errors"
"github.com/projectdiscovery/fastdialer/fastdialer" "github.com/projectdiscovery/fastdialer/fastdialer"
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/protocolstate"
"github.com/projectdiscovery/nuclei/v2/pkg/types" "github.com/projectdiscovery/nuclei/v2/pkg/types"
) )
@ -16,18 +16,7 @@ func Init(options *types.Options) error {
if normalClient != nil { if normalClient != nil {
return nil return nil
} }
opts := fastdialer.DefaultOptions normalClient = protocolstate.Dialer
if options.SystemResolvers {
opts.EnableFallback = true
}
if options.ResolversFile != "" {
opts.BaseResolvers = options.InternalResolversList
}
dialer, err := fastdialer.NewDialer(opts)
if err != nil {
return errors.Wrap(err, "could not create dialer")
}
normalClient = dialer
return nil return nil
} }