Skip to content

Commit 5957381

Browse files
committed
Merge remote-tracking branch 'origin'
2 parents 3f82fc6 + 673404a commit 5957381

File tree

45 files changed

+596
-203
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+596
-203
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ TEMPLATES:
137137
-nss, -no-strict-syntax disable strict syntax check on templates
138138
-td, -template-display displays the templates content
139139
-tl list all available templates
140+
-tgl list all available tags
140141
-sign signs the templates with the private key defined in NUCLEI_SIGNATURE_PRIVATE_KEY env variable
141142
-code enable loading code protocol-based templates
142143
-dut, -disable-unsigned-templates disable running unsigned templates or templates with mismatched signature

cmd/integration-test/integration-test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ var (
3737
"dns": dnsTestCases,
3838
"workflow": workflowTestcases,
3939
"loader": loaderTestcases,
40+
"profile-loader": profileLoaderTestcases,
4041
"websocket": websocketTestCases,
4142
"headless": headlessTestcases,
4243
"whois": whoisTestCases,
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/projectdiscovery/nuclei/v3/pkg/testutils"
7+
errorutil "github.com/projectdiscovery/utils/errors"
8+
)
9+
10+
var profileLoaderTestcases = []TestCaseInfo{
11+
{Path: "profile-loader/load-with-filename", TestCase: &profileLoaderByRelFile{}},
12+
{Path: "profile-loader/load-with-id", TestCase: &profileLoaderById{}},
13+
{Path: "profile-loader/basic.yml", TestCase: &customProfileLoader{}},
14+
}
15+
16+
type profileLoaderByRelFile struct{}
17+
18+
func (h *profileLoaderByRelFile) Execute(testName string) error {
19+
results, err := testutils.RunNucleiWithArgsAndGetResults(false, "-tl", "-tp", "kev.yml")
20+
if err != nil {
21+
return errorutil.NewWithErr(err).Msgf("failed to load template with id")
22+
}
23+
if len(results) < 267 {
24+
return fmt.Errorf("incorrect result: expected more results than %d, got %v", 267, len(results))
25+
}
26+
return nil
27+
}
28+
29+
type profileLoaderById struct{}
30+
31+
func (h *profileLoaderById) Execute(testName string) error {
32+
results, err := testutils.RunNucleiWithArgsAndGetResults(false, "-tl", "-tp", "kev")
33+
if err != nil {
34+
return errorutil.NewWithErr(err).Msgf("failed to load template with id")
35+
}
36+
if len(results) < 267 {
37+
return fmt.Errorf("incorrect result: expected more results than %d, got %v", 267, len(results))
38+
}
39+
return nil
40+
}
41+
42+
type customProfileLoader struct{}
43+
44+
func (h *customProfileLoader) Execute(filepath string) error {
45+
results, err := testutils.RunNucleiWithArgsAndGetResults(false, "-tl", "-tp", filepath)
46+
if err != nil {
47+
return errorutil.NewWithErr(err).Msgf("failed to load template with id")
48+
}
49+
if len(results) < 267 {
50+
return fmt.Errorf("incorrect result: expected more results than %d, got %v", 267, len(results))
51+
}
52+
return nil
53+
}

cmd/nuclei/main.go

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ import (
4242
)
4343

4444
var (
45-
cfgFile string
46-
memProfile string // optional profile file path
47-
options = &types.Options{}
45+
cfgFile string
46+
templateProfile string
47+
memProfile string // optional profile file path
48+
options = &types.Options{}
4849
)
4950

5051
func main() {
@@ -225,6 +226,7 @@ on extensive configurability, massive extensibility and ease of use.`)
225226
flagSet.BoolVarP(&options.NoStrictSyntax, "no-strict-syntax", "nss", false, "disable strict syntax check on templates"),
226227
flagSet.BoolVarP(&options.TemplateDisplay, "template-display", "td", false, "displays the templates content"),
227228
flagSet.BoolVar(&options.TemplateList, "tl", false, "list all available templates"),
229+
flagSet.BoolVar(&options.TagList, "tgl", false, "list all available tags"),
228230
flagSet.StringSliceVarConfigOnly(&options.RemoteTemplateDomainList, "remote-template-domain", []string{"cloud.projectdiscovery.io"}, "allowed domain list to load remote templates from"),
229231
flagSet.BoolVar(&options.SignTemplates, "sign", false, "signs the templates with the private key defined in NUCLEI_SIGNATURE_PRIVATE_KEY env variable"),
230232
flagSet.BoolVar(&options.EnableCodeTemplates, "code", false, "enable loading code protocol-based templates"),
@@ -270,6 +272,8 @@ on extensive configurability, massive extensibility and ease of use.`)
270272

271273
flagSet.CreateGroup("configs", "Configurations",
272274
flagSet.StringVar(&cfgFile, "config", "", "path to the nuclei configuration file"),
275+
flagSet.StringVarP(&templateProfile, "profile", "tp", "", "template profile config file to run"),
276+
flagSet.BoolVarP(&options.ListTemplateProfiles, "profile-list", "tpl", false, "list community template profiles"),
273277
flagSet.BoolVarP(&options.FollowRedirects, "follow-redirects", "fr", false, "enable following redirects for http templates"),
274278
flagSet.BoolVarP(&options.FollowHostRedirects, "follow-host-redirects", "fhr", false, "follow redirects on the same host"),
275279
flagSet.IntVarP(&options.MaxRedirects, "max-redirects", "mr", 10, "max number of redirects to follow for http templates"),
@@ -497,6 +501,34 @@ Additional documentation is available at: https://docs.nuclei.sh/getting-started
497501
config.DefaultConfig.SetTemplatesDir(options.NewTemplatesDirectory)
498502
}
499503

504+
defaultProfilesPath := filepath.Join(config.DefaultConfig.GetTemplateDir(), "profiles")
505+
if templateProfile != "" {
506+
if filepath.Ext(templateProfile) == "" {
507+
if tp := findProfilePathById(templateProfile, defaultProfilesPath); tp != "" {
508+
templateProfile = tp
509+
} else {
510+
gologger.Fatal().Msgf("'%s' is not a profile-id or profile path", templateProfile)
511+
}
512+
}
513+
if !filepath.IsAbs(templateProfile) {
514+
if filepath.Dir(templateProfile) == "profiles" {
515+
defaultProfilesPath = filepath.Join(config.DefaultConfig.GetTemplateDir())
516+
}
517+
currentDir, err := os.Getwd()
518+
if err == nil && fileutil.FileExists(filepath.Join(currentDir, templateProfile)) {
519+
templateProfile = filepath.Join(currentDir, templateProfile)
520+
} else {
521+
templateProfile = filepath.Join(defaultProfilesPath, templateProfile)
522+
}
523+
}
524+
if !fileutil.FileExists(templateProfile) {
525+
gologger.Fatal().Msgf("given template profile file '%s' does not exist", templateProfile)
526+
}
527+
if err := flagSet.MergeConfigFile(templateProfile); err != nil {
528+
gologger.Fatal().Msgf("Could not read template profile: %s\n", err)
529+
}
530+
}
531+
500532
if len(options.SecretsFile) > 0 {
501533
for _, secretFile := range options.SecretsFile {
502534
if !fileutil.FileExists(secretFile) {
@@ -622,6 +654,27 @@ Note: Make sure you have backup of your custom nuclei-templates before proceedin
622654
os.Exit(0)
623655
}
624656

657+
func findProfilePathById(profileId, templatesDir string) string {
658+
var profilePath string
659+
err := filepath.WalkDir(templatesDir, func(iterItem string, d fs.DirEntry, err error) error {
660+
ext := filepath.Ext(iterItem)
661+
isYaml := ext == extensions.YAML || ext == extensions.YML
662+
if err != nil || d.IsDir() || !isYaml {
663+
// skip non yaml files
664+
return nil
665+
}
666+
if strings.TrimSuffix(filepath.Base(iterItem), ext) == profileId {
667+
profilePath = iterItem
668+
return fmt.Errorf("FOUND")
669+
}
670+
return nil
671+
})
672+
if err != nil && err.Error() != "FOUND" {
673+
gologger.Error().Msgf("%s\n", err)
674+
}
675+
return profilePath
676+
}
677+
625678
func init() {
626679
// print stacktrace of errors in debug mode
627680
if strings.EqualFold(os.Getenv("DEBUG"), "true") {

go.mod

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ require (
2020
github.com/olekukonko/tablewriter v0.0.5
2121
github.com/pkg/errors v0.9.1
2222
github.com/projectdiscovery/clistats v0.0.20
23-
github.com/projectdiscovery/fastdialer v0.0.68
23+
github.com/projectdiscovery/fastdialer v0.0.69
2424
github.com/projectdiscovery/hmap v0.0.41
2525
github.com/projectdiscovery/interactsh v1.1.9
26-
github.com/projectdiscovery/rawhttp v0.1.45
26+
github.com/projectdiscovery/rawhttp v0.1.47
2727
github.com/projectdiscovery/retryabledns v1.0.58
28-
github.com/projectdiscovery/retryablehttp-go v1.0.57
28+
github.com/projectdiscovery/retryablehttp-go v1.0.58
2929
github.com/projectdiscovery/yamldoc-go v1.0.4
3030
github.com/remeh/sizedwaitgroup v1.0.0
3131
github.com/rs/xid v1.5.0
@@ -81,24 +81,25 @@ require (
8181
github.com/projectdiscovery/dsl v0.0.52
8282
github.com/projectdiscovery/fasttemplate v0.0.2
8383
github.com/projectdiscovery/go-smb2 v0.0.0-20240129202741-052cc450c6cb
84-
github.com/projectdiscovery/goflags v0.1.49
84+
github.com/projectdiscovery/goflags v0.1.50
8585
github.com/projectdiscovery/gologger v1.1.12
8686
github.com/projectdiscovery/gostruct v0.0.2
8787
github.com/projectdiscovery/gozero v0.0.2
8888
github.com/projectdiscovery/httpx v1.6.0
8989
github.com/projectdiscovery/mapcidr v1.1.34
9090
github.com/projectdiscovery/n3iwf v0.0.0-20230523120440-b8cd232ff1f5
91-
github.com/projectdiscovery/ratelimit v0.0.38
91+
github.com/projectdiscovery/ratelimit v0.0.39
9292
github.com/projectdiscovery/rdap v0.9.1-0.20221108103045-9865884d1917
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.47
97-
github.com/projectdiscovery/utils v0.0.91
98-
github.com/projectdiscovery/wappalyzergo v0.0.116
96+
github.com/projectdiscovery/useragent v0.0.48
97+
github.com/projectdiscovery/utils v0.0.92
98+
github.com/projectdiscovery/wappalyzergo v0.0.120
9999
github.com/redis/go-redis/v9 v9.1.0
100100
github.com/seh-msft/burpxml v1.0.1
101101
github.com/stretchr/testify v1.9.0
102+
github.com/tarunKoyalwar/goleak v0.0.0-20240426214851-746d64600adc
102103
github.com/zmap/zgrab2 v0.1.8-0.20230806160807-97ba87c0e706
103104
golang.org/x/term v0.19.0
104105
gopkg.in/yaml.v3 v3.0.1
@@ -142,8 +143,6 @@ require (
142143
github.com/docker/cli v24.0.5+incompatible // indirect
143144
github.com/docker/docker v24.0.9+incompatible // indirect
144145
github.com/docker/go-connections v0.4.0 // indirect
145-
github.com/eapache/channels v1.1.0 // indirect
146-
github.com/eapache/queue v1.1.0 // indirect
147146
github.com/fatih/color v1.15.0 // indirect
148147
github.com/free5gc/util v1.0.5-0.20230511064842-2e120956883b // indirect
149148
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
@@ -179,6 +178,7 @@ require (
179178
github.com/klauspost/compress v1.17.6 // indirect
180179
github.com/klauspost/pgzip v1.2.6 // indirect
181180
github.com/kylelemons/godebug v1.1.0 // indirect
181+
github.com/logrusorgru/aurora/v4 v4.0.0 // indirect
182182
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
183183
github.com/mackerelio/go-osstat v0.2.4 // indirect
184184
github.com/mailru/easyjson v0.7.7 // indirect
@@ -232,6 +232,7 @@ require (
232232
github.com/yuin/goldmark-emoji v1.0.1 // indirect
233233
github.com/zcalusic/sysinfo v1.0.2 // indirect
234234
github.com/zeebo/blake3 v0.2.3 // indirect
235+
go.uber.org/goleak v1.3.0 // indirect
235236
golang.org/x/arch v0.3.0 // indirect
236237
golang.org/x/sync v0.6.0 // indirect
237238
gopkg.in/djherbis/times.v1 v1.3.0 // indirect

0 commit comments

Comments
 (0)