Skip to content

Commit

Permalink
Merge pull request projectdiscovery#691 from projectdiscovery/dev
Browse files Browse the repository at this point in the history
Minor bugfix release
  • Loading branch information
ehsandeep authored Apr 28, 2021
2 parents 851d1c2 + 4e390db commit 34b9e1f
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 43 deletions.
4 changes: 2 additions & 2 deletions v2/internal/runner/banner.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ const banner = `
____ __ _______/ /__ (_)
/ __ \/ / / / ___/ / _ \/ /
/ / / / /_/ / /__/ / __/ /
/_/ /_/\__,_/\___/_/\___/_/ v2.3.4
/_/ /_/\__,_/\___/_/\___/_/ v2.3.5
`

// 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
func showBanner() {
Expand Down
2 changes: 2 additions & 0 deletions v2/internal/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/projectdiscovery/nuclei/v2/pkg/projectfile"
"github.com/projectdiscovery/nuclei/v2/pkg/protocols"
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/clusterer"
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/protocolinit"
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/headless/engine"
"github.com/projectdiscovery/nuclei/v2/pkg/reporting"
"github.com/projectdiscovery/nuclei/v2/pkg/reporting/exporters/disk"
Expand Down Expand Up @@ -218,6 +219,7 @@ func (r *Runner) Close() {
if r.projectFile != nil {
r.projectFile.Close()
}
protocolinit.Close()
}

// RunEnumeration sets up the input layer for giving input nuclei.
Expand Down
8 changes: 8 additions & 0 deletions v2/pkg/protocols/common/protocolinit/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package protocolinit

import (
"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/http/httpclientpool"
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/network/networkclientpool"
Expand All @@ -12,6 +13,9 @@ import (
func Init(options *types.Options) error {
uarand.Default = uarand.NewWithCustomList(userAgents)

if err := protocolstate.Init(options); err != nil {
return err
}
if err := dnsclientpool.Init(options); err != nil {
return err
}
Expand Down Expand Up @@ -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 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.137 Safari/4E423F",
}

func Close() {
protocolstate.Dialer.Close()
}
31 changes: 31 additions & 0 deletions v2/pkg/protocols/common/protocolstate/state.go
Original file line number Diff line number Diff line change
@@ -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()
}
}
5 changes: 1 addition & 4 deletions v2/pkg/protocols/headless/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,7 @@ func New(options *types.Options) (*Browser, error) {
if customAgent == "" {
customAgent = uarand.GetRandom()
}
httpclient, err := newhttpClient(options)
if err != nil {
return nil, err
}
httpclient := newhttpClient(options)
engine := &Browser{
tempDir: dataStore,
customAgent: customAgent,
Expand Down
20 changes: 4 additions & 16 deletions v2/pkg/protocols/headless/engine/http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,13 @@ import (
"net/http"
"time"

"github.com/pkg/errors"
"github.com/projectdiscovery/fastdialer/fastdialer"
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/protocolstate"
"github.com/projectdiscovery/nuclei/v2/pkg/types"
)

// newhttpClient creates a new http client for headless communication with a timeout
func newhttpClient(options *types.Options) (*http.Client, 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 nil, errors.Wrap(err, "could not create dialer")
}

func newhttpClient(options *types.Options) *http.Client {
dialer := protocolstate.Dialer
transport := &http.Transport{
DialContext: dialer.Dial,
MaxIdleConns: 500,
Expand All @@ -34,5 +22,5 @@ func newhttpClient(options *types.Options) (*http.Client, error) {
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}
}
13 changes: 13 additions & 0 deletions v2/pkg/protocols/headless/engine/page_actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ import (
"testing"
"time"

"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/protocolstate"
"github.com/projectdiscovery/nuclei/v2/pkg/types"
"github.com/stretchr/testify/require"
)

func TestActionNavigate(t *testing.T) {
_ = protocolstate.Init(&types.Options{})

browser, err := New(&types.Options{ShowBrowser: false})
require.Nil(t, err, "could not create browser")
defer browser.Close()
Expand Down Expand Up @@ -46,6 +49,8 @@ func TestActionNavigate(t *testing.T) {
}

func TestActionScript(t *testing.T) {
_ = protocolstate.Init(&types.Options{})

browser, err := New(&types.Options{ShowBrowser: false})
require.Nil(t, err, "could not create browser")
defer browser.Close()
Expand Down Expand Up @@ -113,6 +118,8 @@ func TestActionScript(t *testing.T) {
}

func TestActionClick(t *testing.T) {
_ = protocolstate.Init(&types.Options{})

browser, err := New(&types.Options{ShowBrowser: false})
require.Nil(t, err, "could not create browser")
defer browser.Close()
Expand Down Expand Up @@ -151,6 +158,8 @@ func TestActionClick(t *testing.T) {
}

func TestActionRightClick(t *testing.T) {
_ = protocolstate.Init(&types.Options{})

browser, err := New(&types.Options{ShowBrowser: false})
require.Nil(t, err, "could not create browser")
defer browser.Close()
Expand Down Expand Up @@ -197,6 +206,8 @@ func TestActionRightClick(t *testing.T) {
}

func TestActionTextInput(t *testing.T) {
_ = protocolstate.Init(&types.Options{})

browser, err := New(&types.Options{ShowBrowser: false})
require.Nil(t, err, "could not create browser")
defer browser.Close()
Expand Down Expand Up @@ -236,6 +247,8 @@ func TestActionTextInput(t *testing.T) {
}

func TestActionHeadersChange(t *testing.T) {
_ = protocolstate.Init(&types.Options{})

browser, err := New(&types.Options{ShowBrowser: false})
require.Nil(t, err, "could not create browser")
defer browser.Close()
Expand Down
10 changes: 2 additions & 8 deletions v2/pkg/protocols/http/httpclientpool/clientpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

"github.com/pkg/errors"
"github.com/projectdiscovery/fastdialer/fastdialer"
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/protocolstate"
"github.com/projectdiscovery/nuclei/v2/pkg/types"
"github.com/projectdiscovery/rawhttp"
"github.com/projectdiscovery/retryablehttp-go"
Expand Down Expand Up @@ -97,14 +98,7 @@ func wrappedGet(options *types.Options, configuration *Configuration) (*retryabl
var err error

if Dialer == nil {
opts := fastdialer.DefaultOptions
if options.SystemResolvers {
opts.EnableFallback = true
}
if options.ResolversFile != "" {
opts.BaseResolvers = options.InternalResolversList
}
Dialer, err = fastdialer.NewDialer(opts)
Dialer = protocolstate.Dialer
}
if err != nil {
return nil, errors.Wrap(err, "could not create dialer")
Expand Down
3 changes: 3 additions & 0 deletions v2/pkg/protocols/http/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,9 @@ func (r *Request) executeRequest(reqURL string, request *generatedRequest, previ
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)
if i := strings.LastIndex(hostname, ":"); i != -1 {
hostname = hostname[:i]
}
outputEvent["ip"] = httpclientpool.Dialer.GetDialedIP(hostname)
outputEvent["redirect-chain"] = tostring.UnsafeToString(redirectedResponse)
for k, v := range previous {
Expand Down
15 changes: 2 additions & 13 deletions v2/pkg/protocols/network/networkclientpool/clientpool.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package networkclientpool

import (
"github.com/pkg/errors"
"github.com/projectdiscovery/fastdialer/fastdialer"
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/protocolstate"
"github.com/projectdiscovery/nuclei/v2/pkg/types"
)

Expand All @@ -16,18 +16,7 @@ func Init(options *types.Options) error {
if normalClient != nil {
return nil
}
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")
}
normalClient = dialer
normalClient = protocolstate.Dialer
return nil
}

Expand Down

0 comments on commit 34b9e1f

Please sign in to comment.