Skip to content

Commit bce3e7f

Browse files
committed
Merge remote-tracking branch 'origin'
2 parents 5957381 + 2d68ac2 commit bce3e7f

20 files changed

Lines changed: 123 additions & 30 deletions

File tree

cmd/integration-test/profile-loader.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,38 +16,39 @@ var profileLoaderTestcases = []TestCaseInfo{
1616
type profileLoaderByRelFile struct{}
1717

1818
func (h *profileLoaderByRelFile) Execute(testName string) error {
19-
results, err := testutils.RunNucleiWithArgsAndGetResults(false, "-tl", "-tp", "kev.yml")
19+
results, err := testutils.RunNucleiWithArgsAndGetResults(false, "-tl", "-tp", "cloud.yml")
2020
if err != nil {
2121
return errorutil.NewWithErr(err).Msgf("failed to load template with id")
2222
}
23-
if len(results) < 267 {
24-
return fmt.Errorf("incorrect result: expected more results than %d, got %v", 267, len(results))
23+
if len(results) <= 10 {
24+
return fmt.Errorf("incorrect result: expected more results than %d, got %v", 10, len(results))
2525
}
2626
return nil
2727
}
2828

2929
type profileLoaderById struct{}
3030

3131
func (h *profileLoaderById) Execute(testName string) error {
32-
results, err := testutils.RunNucleiWithArgsAndGetResults(false, "-tl", "-tp", "kev")
32+
results, err := testutils.RunNucleiWithArgsAndGetResults(false, "-tl", "-tp", "cloud")
3333
if err != nil {
3434
return errorutil.NewWithErr(err).Msgf("failed to load template with id")
3535
}
36-
if len(results) < 267 {
37-
return fmt.Errorf("incorrect result: expected more results than %d, got %v", 267, len(results))
36+
if len(results) <= 10 {
37+
return fmt.Errorf("incorrect result: expected more results than %d, got %v", 10, len(results))
3838
}
3939
return nil
4040
}
4141

42+
// this profile with load kevs
4243
type customProfileLoader struct{}
4344

4445
func (h *customProfileLoader) Execute(filepath string) error {
4546
results, err := testutils.RunNucleiWithArgsAndGetResults(false, "-tl", "-tp", filepath)
4647
if err != nil {
4748
return errorutil.NewWithErr(err).Msgf("failed to load template with id")
4849
}
49-
if len(results) < 267 {
50-
return fmt.Errorf("incorrect result: expected more results than %d, got %v", 267, len(results))
50+
if len(results) < 1 {
51+
return fmt.Errorf("incorrect result: expected more results than %d, got %v", 1, len(results))
5152
}
5253
return nil
5354
}

cmd/nuclei/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ on extensive configurability, massive extensibility and ease of use.`)
200200
*/
201201

202202
flagSet.CreateGroup("input", "Target",
203-
flagSet.StringSliceVarP(&options.Targets, "target", "u", nil, "target URLs/hosts to scan", goflags.StringSliceOptions),
203+
flagSet.StringSliceVarP(&options.Targets, "target", "u", nil, "target URLs/hosts to scan", goflags.CommaSeparatedStringSliceOptions),
204204
flagSet.StringVarP(&options.TargetsFilePath, "list", "l", "", "path to file containing a list of target URLs/hosts to scan (one per line)"),
205205
flagSet.StringSliceVarP(&options.ExcludeTargets, "exclude-hosts", "eh", nil, "hosts to exclude to scan from the input list (ip, cidr, hostname)", goflags.FileCommaSeparatedStringSliceOptions),
206206
flagSet.StringVar(&options.Resume, "resume", "", "resume scan using resume.cfg (clustering will be disabled)"),
@@ -414,6 +414,7 @@ on extensive configurability, massive extensibility and ease of use.`)
414414
flagSet.DynamicVar(&pdcpauth, "auth", "true", "configure projectdiscovery cloud (pdcp) api key"),
415415
flagSet.BoolVarP(&options.EnableCloudUpload, "cloud-upload", "cup", false, "upload scan results to pdcp dashboard"),
416416
flagSet.StringVarP(&options.ScanID, "scan-id", "sid", "", "upload scan results to given scan id"),
417+
flagSet.StringVarP(&options.ScanName, "scan-name", "sname", "", "scan name to set (optional)"),
417418
)
418419

419420
flagSet.CreateGroup("Authentication", "Authentication",

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ require (
9393
github.com/projectdiscovery/sarif v0.0.1
9494
github.com/projectdiscovery/tlsx v1.1.6
9595
github.com/projectdiscovery/uncover v1.0.7
96-
github.com/projectdiscovery/useragent v0.0.48
96+
github.com/projectdiscovery/useragent v0.0.49
9797
github.com/projectdiscovery/utils v0.0.92
9898
github.com/projectdiscovery/wappalyzergo v0.0.120
9999
github.com/redis/go-redis/v9 v9.1.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -887,8 +887,8 @@ github.com/projectdiscovery/tlsx v1.1.6 h1:iw2zwKbd2+kRQ8J1G4dLmS0CLyemd/tKz1Uzc
887887
github.com/projectdiscovery/tlsx v1.1.6/go.mod h1:s7SRRFdrwIZBK/RXXZi4CR/CubqFSvp8h5Bk1srEZIo=
888888
github.com/projectdiscovery/uncover v1.0.7 h1:ut+2lTuvmftmveqF5RTjMWAgyLj8ltPQC7siFy9sj0A=
889889
github.com/projectdiscovery/uncover v1.0.7/go.mod h1:HFXgm1sRPuoN0D4oATljPIdmbo/EEh1wVuxQqo/dwFE=
890-
github.com/projectdiscovery/useragent v0.0.48 h1:ITygElwcY9FlOt0F65kcW/oAALNr1nQOtO3kR9lRzaY=
891-
github.com/projectdiscovery/useragent v0.0.48/go.mod h1:ahQMoWlVNFVQxjHOKqOPHJJQ7Ovz1zJZuJbBsAwIcOw=
890+
github.com/projectdiscovery/useragent v0.0.49 h1:wQc9i+Xy+mUMJ45Ralv1JsQImRWqEOEvpYUe6MchScg=
891+
github.com/projectdiscovery/useragent v0.0.49/go.mod h1:jQz6X/usiXrPYE6B/1uVKuzIrBJXgw9hLC9eeNy38+0=
892892
github.com/projectdiscovery/utils v0.0.92 h1:lGCmjUJhzoNX4FQZWpp80058pRlD0/dYxLJOSs07EqY=
893893
github.com/projectdiscovery/utils v0.0.92/go.mod h1:d5uvD5qcRiK3qxZbBy9eatCqrCSuj9SObL04w/WgXSg=
894894
github.com/projectdiscovery/wappalyzergo v0.0.120 h1:dphOXnaT3rryo9h9fgbxnAVhtQ1uq61yyQZMYyHz960=

internal/pdcp/writer.go

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"io"
1010
"net/http"
1111
"net/url"
12+
"regexp"
1213
"sync/atomic"
1314
"time"
1415

@@ -27,9 +28,13 @@ const (
2728
appendEndpoint = "/v1/scans/%s/import"
2829
flushTimer = time.Duration(1) * time.Minute
2930
MaxChunkSize = 1024 * 1024 * 4 // 4 MB
31+
xidRe = `^[a-z0-9]{20}$`
3032
)
3133

32-
var _ output.Writer = &UploadWriter{}
34+
var (
35+
xidRegex = regexp.MustCompile(xidRe)
36+
_ output.Writer = &UploadWriter{}
37+
)
3338

3439
// UploadWriter is a writer that uploads its output to pdcp
3540
// server to enable web dashboard and more
@@ -41,6 +46,7 @@ type UploadWriter struct {
4146
cancel context.CancelFunc
4247
done chan struct{}
4348
scanID string
49+
scanName string
4450
counter atomic.Int32
4551
}
4652

@@ -86,8 +92,17 @@ func NewUploadWriter(ctx context.Context, creds *pdcpauth.PDCPCredentials) (*Upl
8692
}
8793

8894
// SetScanID sets the scan id for the upload writer
89-
func (u *UploadWriter) SetScanID(id string) {
95+
func (u *UploadWriter) SetScanID(id string) error {
96+
if !xidRegex.MatchString(id) {
97+
return fmt.Errorf("invalid scan id provided")
98+
}
9099
u.scanID = id
100+
return nil
101+
}
102+
103+
// SetScanName sets the scan name for the upload writer
104+
func (u *UploadWriter) SetScanName(name string) {
105+
u.scanName = name
91106
}
92107

93108
func (u *UploadWriter) autoCommit(ctx context.Context, r *io.PipeReader) {
@@ -220,7 +235,13 @@ func (u *UploadWriter) getRequest(bin []byte) (*retryablehttp.Request, error) {
220235
return nil, errorutil.NewWithErr(err).Msgf("could not create cloud upload request")
221236
}
222237
// add pdtm meta params
223-
req.URL.RawQuery = updateutils.GetpdtmParams(config.Version)
238+
req.URL.Params.Merge(updateutils.GetpdtmParams(config.Version))
239+
// if it is upload endpoint also include name if it exists
240+
if u.scanName != "" && req.URL.Path == uploadEndpoint {
241+
req.URL.Params.Add("name", u.scanName)
242+
}
243+
req.URL.Update()
244+
224245
req.Header.Set(pdcpauth.ApiKeyHeaderName, u.creds.APIKey)
225246
req.Header.Set("Content-Type", "application/octet-stream")
226247
req.Header.Set("Accept", "application/json")

internal/runner/runner.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,11 @@ func (r *Runner) setupPDCPUpload(writer output.Writer) output.Writer {
414414
return writer
415415
}
416416
if r.options.ScanID != "" {
417-
uploadWriter.SetScanID(r.options.ScanID)
417+
// ignore and use empty scan id if invalid
418+
_ = uploadWriter.SetScanID(r.options.ScanID)
419+
}
420+
if r.options.ScanName != "" {
421+
uploadWriter.SetScanName(r.options.ScanName)
418422
}
419423
return output.NewMultiWriter(writer, uploadWriter)
420424
}

lib/multi.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,11 @@ func (e *ThreadSafeNucleiEngine) GlobalResultCallback(callback func(event *outpu
111111
e.eng.resultCallbacks = []func(*output.ResultEvent){callback}
112112
}
113113

114-
// ExecuteNucleiWithOpts executes templates on targets and calls callback on each result(only if results are found)
114+
// ExecuteNucleiWithOptsCtx executes templates on targets and calls callback on each result(only if results are found)
115115
// This method can be called concurrently and it will use some global resources but can be runned parallelly
116116
// by invoking this method with different options and targets
117117
// Note: Not all options are thread-safe. this method will throw error if you try to use non-thread-safe options
118-
func (e *ThreadSafeNucleiEngine) ExecuteNucleiWithOpts(targets []string, opts ...NucleiSDKOptions) error {
118+
func (e *ThreadSafeNucleiEngine) ExecuteNucleiWithOptsCtx(ctx context.Context, targets []string, opts ...NucleiSDKOptions) error {
119119
baseOpts := *e.eng.opts
120120
tmpEngine := &NucleiEngine{opts: &baseOpts, mode: threadSafe}
121121
for _, option := range opts {
@@ -163,6 +163,12 @@ func (e *ThreadSafeNucleiEngine) ExecuteNucleiWithOpts(targets []string, opts ..
163163
return nil
164164
}
165165

166+
// ExecuteNucleiWithOpts is same as ExecuteNucleiWithOptsCtx but with default context
167+
// This is a placeholder and will be deprecated in future major release
168+
func (e *ThreadSafeNucleiEngine) ExecuteNucleiWithOpts(targets []string, opts ...NucleiSDKOptions) error {
169+
return e.ExecuteNucleiWithOptsCtx(context.Background(), targets, opts...)
170+
}
171+
166172
// Close all resources used by nuclei engine
167173
func (e *ThreadSafeNucleiEngine) Close() {
168174
e.eng.Close()

lib/sdk.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,9 @@ func (e *NucleiEngine) Close() {
219219
}
220220
}
221221

222-
// ExecuteWithCallback executes templates on targets and calls callback on each result(only if results are found)
223-
func (e *NucleiEngine) ExecuteWithCallback(callback ...func(event *output.ResultEvent)) error {
222+
// ExecuteCallbackWithCtx executes templates on targets and calls callback on each result(only if results are found)
223+
// enable matcher-status option if you expect this callback to be called for all results regardless if it matched or not
224+
func (e *NucleiEngine) ExecuteCallbackWithCtx(ctx context.Context, callback ...func(event *output.ResultEvent)) error {
224225
if !e.templatesLoaded {
225226
_ = e.LoadAllTemplates()
226227
}
@@ -244,10 +245,18 @@ func (e *NucleiEngine) ExecuteWithCallback(callback ...func(event *output.Result
244245
return nil
245246
}
246247

248+
// ExecuteWithCallback is same as ExecuteCallbackWithCtx but with default context
249+
// Note this is deprecated and will be removed in future major release
250+
func (e *NucleiEngine) ExecuteWithCallback(callback ...func(event *output.ResultEvent)) error {
251+
return e.ExecuteCallbackWithCtx(context.Background(), callback...)
252+
}
253+
254+
// Options return nuclei Type Options
247255
func (e *NucleiEngine) Options() *types.Options {
248256
return e.opts
249257
}
250258

259+
// Engine returns core Executer of nuclei
251260
func (e *NucleiEngine) Engine() *core.Engine {
252261
return e.engine
253262
}

pkg/catalog/config/constants.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const (
3131
CLIConfigFileName = "config.yaml"
3232
ReportingConfigFilename = "reporting-config.yaml"
3333
// Version is the current version of nuclei
34-
Version = `v3.2.6`
34+
Version = `v3.2.7`
3535
// Directory Names of custom templates
3636
CustomS3TemplatesDirName = "s3"
3737
CustomGitHubTemplatesDirName = "github"

pkg/core/executors.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ func (e *Engine) executeTemplatesOnTarget(ctx context.Context, alltemplates []*t
162162
// wp is workpool that contains different waitgroups for
163163
// headless and non-headless templates
164164
// global waitgroup should not be used here
165-
wp := e.WorkPool()
165+
wp := e.GetWorkPool()
166166

167167
for _, tpl := range alltemplates {
168168
select {

0 commit comments

Comments
 (0)