mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-17 21:05:26 +00:00
Fixing nil pointer reference + use map helper (#3421)
* Fixing nil pointer reference + use map helper * bump tlsx version to v1.0.6 * increase interactsh polling in integration_test * fix nil pointer dereference in integration_test * fix lint error --------- Co-authored-by: Tarun Koyalwar <tarun@projectdiscovery.io>
This commit is contained in:
parent
3f3f23264b
commit
0bf8fc027d
@ -69,7 +69,10 @@ func executeNucleiAsCode(templatePath, templateURL string) ([]string, error) {
|
|||||||
defer cache.Close()
|
defer cache.Close()
|
||||||
|
|
||||||
mockProgress := &testutils.MockProgressClient{}
|
mockProgress := &testutils.MockProgressClient{}
|
||||||
reportingClient, _ := reporting.New(&reporting.Options{}, "")
|
reportingClient, err := reporting.New(&reporting.Options{}, "")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
defer reportingClient.Close()
|
defer reportingClient.Close()
|
||||||
|
|
||||||
outputWriter := testutils.NewMockOutputWriter()
|
outputWriter := testutils.NewMockOutputWriter()
|
||||||
|
|||||||
@ -8,7 +8,6 @@ import (
|
|||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"net/http/httputil"
|
"net/http/httputil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -833,13 +832,16 @@ func (h *httpRequestSelfContainedFileInput) Execute(filePath string) error {
|
|||||||
defer server.Close()
|
defer server.Close()
|
||||||
|
|
||||||
// create temp file
|
// create temp file
|
||||||
FileLoc := filepath.Join(os.TempDir(), "httpselfcontained.yaml")
|
FileLoc, err := os.CreateTemp("", "self-contained-payload-*.txt")
|
||||||
err := os.WriteFile(FileLoc, []byte("one\ntwo\n"), 0600)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errorutil.NewWithErr(err).Msgf("failed to create temporary file").WithTag(filePath)
|
return errorutil.NewWithErr(err).Msgf("failed to create temp file")
|
||||||
}
|
}
|
||||||
|
if _, err := FileLoc.Write([]byte("one\ntwo\n")); err != nil {
|
||||||
|
return errorutil.NewWithErr(err).Msgf("failed to write payload to temp file")
|
||||||
|
}
|
||||||
|
defer FileLoc.Close()
|
||||||
|
|
||||||
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "", debug, "-V", "test="+FileLoc)
|
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "", debug, "-V", "test="+FileLoc.Name())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,13 +4,9 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/projectdiscovery/nuclei/v2/pkg/testutils"
|
"github.com/projectdiscovery/nuclei/v2/pkg/testutils"
|
||||||
|
errorutil "github.com/projectdiscovery/utils/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getTemplatesDir() string {
|
|
||||||
temp := os.TempDir()
|
|
||||||
return temp
|
|
||||||
}
|
|
||||||
|
|
||||||
var templatesDirTestCases = map[string]testutils.TestCase{
|
var templatesDirTestCases = map[string]testutils.TestCase{
|
||||||
"dns/cname-fingerprint.yaml": &templateDirWithTargetTest{},
|
"dns/cname-fingerprint.yaml": &templateDirWithTargetTest{},
|
||||||
}
|
}
|
||||||
@ -19,9 +15,13 @@ type templateDirWithTargetTest struct{}
|
|||||||
|
|
||||||
// Execute executes a test case and returns an error if occurred
|
// Execute executes a test case and returns an error if occurred
|
||||||
func (h *templateDirWithTargetTest) Execute(filePath string) error {
|
func (h *templateDirWithTargetTest) Execute(filePath string) error {
|
||||||
defer os.RemoveAll(getTemplatesDir())
|
tempdir, err := os.MkdirTemp("", "nuclei-update-dir-*")
|
||||||
|
if err != nil {
|
||||||
|
return errorutil.NewWithErr(err).Msgf("failed to create temp dir")
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tempdir)
|
||||||
|
|
||||||
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "8x8exch02.8x8.com", debug, "-ud", getTemplatesDir())
|
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "8x8exch02.8x8.com", debug, "-ud", tempdir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,6 +23,7 @@ import (
|
|||||||
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/http"
|
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/http"
|
||||||
templateTypes "github.com/projectdiscovery/nuclei/v2/pkg/templates/types"
|
templateTypes "github.com/projectdiscovery/nuclei/v2/pkg/templates/types"
|
||||||
"github.com/projectdiscovery/nuclei/v2/pkg/types"
|
"github.com/projectdiscovery/nuclei/v2/pkg/types"
|
||||||
|
"github.com/projectdiscovery/nuclei/v2/pkg/types/scanstrategy"
|
||||||
"github.com/projectdiscovery/nuclei/v2/pkg/utils/monitor"
|
"github.com/projectdiscovery/nuclei/v2/pkg/utils/monitor"
|
||||||
errorutil "github.com/projectdiscovery/utils/errors"
|
errorutil "github.com/projectdiscovery/utils/errors"
|
||||||
fileutil "github.com/projectdiscovery/utils/file"
|
fileutil "github.com/projectdiscovery/utils/file"
|
||||||
@ -243,7 +244,6 @@ on extensive configurability, massive extensibility and ease of use.`)
|
|||||||
flagSet.IntVarP(&options.HeadlessBulkSize, "headless-bulk-size", "hbs", 10, "maximum number of headless hosts to be analyzed in parallel per template"),
|
flagSet.IntVarP(&options.HeadlessBulkSize, "headless-bulk-size", "hbs", 10, "maximum number of headless hosts to be analyzed in parallel per template"),
|
||||||
flagSet.IntVarP(&options.HeadlessTemplateThreads, "headless-concurrency", "headc", 10, "maximum number of headless templates to be executed in parallel"),
|
flagSet.IntVarP(&options.HeadlessTemplateThreads, "headless-concurrency", "headc", 10, "maximum number of headless templates to be executed in parallel"),
|
||||||
)
|
)
|
||||||
|
|
||||||
flagSet.CreateGroup("optimization", "Optimizations",
|
flagSet.CreateGroup("optimization", "Optimizations",
|
||||||
flagSet.IntVar(&options.Timeout, "timeout", 10, "time to wait in seconds before timeout"),
|
flagSet.IntVar(&options.Timeout, "timeout", 10, "time to wait in seconds before timeout"),
|
||||||
flagSet.IntVar(&options.Retries, "retries", 1, "number of times to retry a failed request"),
|
flagSet.IntVar(&options.Retries, "retries", 1, "number of times to retry a failed request"),
|
||||||
@ -256,9 +256,9 @@ on extensive configurability, massive extensibility and ease of use.`)
|
|||||||
flagSet.BoolVarP(&options.StopAtFirstMatch, "stop-at-first-match", "spm", false, "stop processing HTTP requests after the first match (may break template/workflow logic)"),
|
flagSet.BoolVarP(&options.StopAtFirstMatch, "stop-at-first-match", "spm", false, "stop processing HTTP requests after the first match (may break template/workflow logic)"),
|
||||||
flagSet.BoolVar(&options.Stream, "stream", false, "stream mode - start elaborating without sorting the input"),
|
flagSet.BoolVar(&options.Stream, "stream", false, "stream mode - start elaborating without sorting the input"),
|
||||||
flagSet.EnumVarP(&options.ScanStrategy, "scan-strategy", "ss", goflags.EnumVariable(0), "strategy to use while scanning(auto/host-spray/template-spray)", goflags.AllowdTypes{
|
flagSet.EnumVarP(&options.ScanStrategy, "scan-strategy", "ss", goflags.EnumVariable(0), "strategy to use while scanning(auto/host-spray/template-spray)", goflags.AllowdTypes{
|
||||||
"auto": goflags.EnumVariable(0),
|
scanstrategy.Auto.String(): goflags.EnumVariable(0),
|
||||||
"host-spray": goflags.EnumVariable(1),
|
scanstrategy.HostSpray.String(): goflags.EnumVariable(1),
|
||||||
"template-spray": goflags.EnumVariable(2),
|
scanstrategy.TemplateSpray.String(): goflags.EnumVariable(2),
|
||||||
}),
|
}),
|
||||||
flagSet.DurationVarP(&options.InputReadTimeout, "input-read-timeout", "irt", time.Duration(3*time.Minute), "timeout on input read"),
|
flagSet.DurationVarP(&options.InputReadTimeout, "input-read-timeout", "irt", time.Duration(3*time.Minute), "timeout on input read"),
|
||||||
flagSet.BoolVarP(&options.DisableHTTPProbe, "no-httpx", "nh", false, "disable httpx probing for non-url input"),
|
flagSet.BoolVarP(&options.DisableHTTPProbe, "no-httpx", "nh", false, "disable httpx probing for non-url input"),
|
||||||
|
|||||||
@ -22,7 +22,6 @@ import (
|
|||||||
"github.com/projectdiscovery/nuclei/v2/pkg/types"
|
"github.com/projectdiscovery/nuclei/v2/pkg/types"
|
||||||
"github.com/projectdiscovery/stringsutil"
|
"github.com/projectdiscovery/stringsutil"
|
||||||
fileutil "github.com/projectdiscovery/utils/file"
|
fileutil "github.com/projectdiscovery/utils/file"
|
||||||
logutil "github.com/projectdiscovery/utils/log"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func ConfigureOptions() error {
|
func ConfigureOptions() error {
|
||||||
@ -251,7 +250,7 @@ func configureOutput(options *types.Options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// disable standard logger (ref: https://github.com/golang/go/issues/19895)
|
// disable standard logger (ref: https://github.com/golang/go/issues/19895)
|
||||||
logutil.DisableDefaultLogger()
|
// logutil.DisableDefaultLogger()
|
||||||
}
|
}
|
||||||
|
|
||||||
// loadResolvers loads resolvers from both user provided flag and file
|
// loadResolvers loads resolvers from both user provided flag and file
|
||||||
|
|||||||
@ -10,6 +10,7 @@ import (
|
|||||||
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/contextargs"
|
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/contextargs"
|
||||||
"github.com/projectdiscovery/nuclei/v2/pkg/templates"
|
"github.com/projectdiscovery/nuclei/v2/pkg/templates"
|
||||||
"github.com/projectdiscovery/nuclei/v2/pkg/templates/types"
|
"github.com/projectdiscovery/nuclei/v2/pkg/templates/types"
|
||||||
|
"github.com/projectdiscovery/nuclei/v2/pkg/types/scanstrategy"
|
||||||
stringsutil "github.com/projectdiscovery/utils/strings"
|
stringsutil "github.com/projectdiscovery/utils/strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -40,10 +41,10 @@ func (e *Engine) ExecuteScanWithOpts(templatesList []*templates.Template, target
|
|||||||
finalTemplates = templatesList
|
finalTemplates = templatesList
|
||||||
}
|
}
|
||||||
|
|
||||||
if stringsutil.EqualFoldAny(e.options.ScanStrategy, "auto", "") {
|
if stringsutil.EqualFoldAny(e.options.ScanStrategy, scanstrategy.Auto.String(), "") {
|
||||||
// TODO: this is only a placeholder, auto scan strategy should choose scan strategy
|
// TODO: this is only a placeholder, auto scan strategy should choose scan strategy
|
||||||
// based on no of hosts , templates , stream and other optimization parameters
|
// based on no of hosts , templates , stream and other optimization parameters
|
||||||
e.options.ScanStrategy = "template-spray"
|
e.options.ScanStrategy = scanstrategy.TemplateSpray.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
filtered := []*templates.Template{}
|
filtered := []*templates.Template{}
|
||||||
@ -60,11 +61,11 @@ func (e *Engine) ExecuteScanWithOpts(templatesList []*templates.Template, target
|
|||||||
// Execute All SelfContained in parallel
|
// Execute All SelfContained in parallel
|
||||||
e.executeAllSelfContained(selfContained, results, selfcontainedWg)
|
e.executeAllSelfContained(selfContained, results, selfcontainedWg)
|
||||||
|
|
||||||
var strategyResult *atomic.Bool
|
strategyResult := &atomic.Bool{}
|
||||||
switch e.options.ScanStrategy {
|
switch e.options.ScanStrategy {
|
||||||
case "template-spray":
|
case scanstrategy.TemplateSpray.String():
|
||||||
strategyResult = e.executeTemplateSpray(filtered, target)
|
strategyResult = e.executeTemplateSpray(filtered, target)
|
||||||
case "host-spray":
|
case scanstrategy.TemplateSpray.String():
|
||||||
strategyResult = e.executeHostSpray(filtered, target)
|
strategyResult = e.executeHostSpray(filtered, target)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -50,6 +50,8 @@ func RunNucleiBareArgsAndGetResults(debug bool, extra ...string) ([]string, erro
|
|||||||
extra = append(extra, ExtraDebugArgs...)
|
extra = append(extra, ExtraDebugArgs...)
|
||||||
cmd.Args = append(cmd.Args, extra...)
|
cmd.Args = append(cmd.Args, extra...)
|
||||||
cmd.Args = append(cmd.Args, "-duc") // disable auto updates
|
cmd.Args = append(cmd.Args, "-duc") // disable auto updates
|
||||||
|
cmd.Args = append(cmd.Args, "-interactions-poll-duration", "1")
|
||||||
|
cmd.Args = append(cmd.Args, "-interactions-cooldown-period", "10")
|
||||||
if debug {
|
if debug {
|
||||||
cmd.Args = append(cmd.Args, "-debug")
|
cmd.Args = append(cmd.Args, "-debug")
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
@ -98,6 +100,7 @@ func RunNucleiBinaryAndGetLoadedTemplates(nucleiBinary string, debug bool, args
|
|||||||
return matches[0][1], nil
|
return matches[0][1], nil
|
||||||
}
|
}
|
||||||
func RunNucleiBinaryAndGetCombinedOutput(debug bool, args []string) (string, error) {
|
func RunNucleiBinaryAndGetCombinedOutput(debug bool, args []string) (string, error) {
|
||||||
|
args = append(args, "-interactions-cooldown-period", "10", "-interactions-poll-duration", "1")
|
||||||
cmd := exec.Command("./nuclei", args...)
|
cmd := exec.Command("./nuclei", args...)
|
||||||
if debug {
|
if debug {
|
||||||
cmd.Args = append(cmd.Args, "-debug")
|
cmd.Args = append(cmd.Args, "-debug")
|
||||||
|
|||||||
28
v2/pkg/types/scanstrategy/scan_strategy.go
Normal file
28
v2/pkg/types/scanstrategy/scan_strategy.go
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
package scanstrategy
|
||||||
|
|
||||||
|
import (
|
||||||
|
mapsutil "github.com/projectdiscovery/utils/maps"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ScanStrategy supported
|
||||||
|
type ScanStrategy uint8
|
||||||
|
|
||||||
|
const (
|
||||||
|
Auto ScanStrategy = iota
|
||||||
|
HostSpray
|
||||||
|
TemplateSpray
|
||||||
|
)
|
||||||
|
|
||||||
|
var strategies mapsutil.Map[ScanStrategy, string]
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
strategies = make(mapsutil.Map[ScanStrategy, string])
|
||||||
|
strategies[Auto] = "auto"
|
||||||
|
strategies[HostSpray] = "host-spray"
|
||||||
|
strategies[TemplateSpray] = "template-spray"
|
||||||
|
}
|
||||||
|
|
||||||
|
// String representation of the scan strategy
|
||||||
|
func (s ScanStrategy) String() string {
|
||||||
|
return strategies[s]
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user