Skip to content

Commit bf01be1

Browse files
authored
Merge pull request #5870 from projectdiscovery/dev
v3.3.7
2 parents 419f08f + 2549592 commit bf01be1

File tree

15 files changed

+381
-101
lines changed

15 files changed

+381
-101
lines changed

.gitignore

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,32 @@
22
**/*-cache
33
**/*-config
44
**/.cache
5-
*.DS_Store
6-
*.exe
5+
**/*.DS_Store
6+
**/*.exe
77
.devcontainer
88
.gitignore
99
.idea
1010
.vscode
1111

1212
# Binaries
1313
/bin/*
14-
**/bindgen
15-
**/debug-*
16-
**/docgen
17-
**/functional-test
18-
**/fuzzplayground
19-
**/integration-test
20-
**/jsdocgen
21-
**/main
22-
**/memogen
23-
**/nuclei
24-
**/nuclei-stats*
25-
**/nuclei_dev
26-
**/nuclei_main
27-
**/scan-charts
28-
**/scrapefunc
29-
**/scrapefuncs
30-
**/tsgen
14+
/bindgen
15+
/debug-*
16+
/docgen
17+
/functional-test
18+
/fuzzplayground
19+
/integration-test
20+
/jsdocgen
21+
/main
22+
/memogen
23+
/nuclei
24+
/nuclei-stats*
25+
/nuclei_dev
26+
/nuclei_main
27+
/scan-charts
28+
/scrapefunc
29+
/scrapefuncs
30+
/tsgen
3131

3232
# Templates
3333
/*.yaml

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ scan-charts: GOBUILD_OUTPUT = ./bin/scan-charts
4242
scan-charts: GOBUILD_PACKAGES = cmd/scan-charts/main.go
4343
scan-charts: go-build
4444

45+
template-signer: GOBUILD_OUTPUT = ./bin/template-signer
46+
template-signer: GOBUILD_PACKAGES = cmd/tools/signer/main.go
47+
template-signer: go-build
48+
4549
docgen: GOBUILD_OUTPUT = ./bin/docgen
4650
docgen: GOBUILD_PACKAGES = cmd/docgen/docgen.go
4751
docgen: bin = dstdocgen

README.md

Lines changed: 131 additions & 26 deletions
Large diffs are not rendered by default.

cmd/nuclei/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ on extensive configurability, massive extensibility and ease of use.`)
264264
flagSet.BoolVar(&options.EnableCodeTemplates, "code", false, "enable loading code protocol-based templates"),
265265
flagSet.BoolVarP(&options.DisableUnsignedTemplates, "disable-unsigned-templates", "dut", false, "disable running unsigned templates or templates with mismatched signature"),
266266
flagSet.BoolVarP(&options.EnableSelfContainedTemplates, "enable-self-contained", "esc", false, "enable loading self-contained templates"),
267+
flagSet.BoolVarP(&options.EnableGlobalMatchersTemplates, "enable-global-matchers", "egm", false, "enable loading global matchers templates"),
267268
flagSet.BoolVar(&options.EnableFileTemplates, "file", false, "enable loading file templates"),
268269
)
269270

cmd/tools/signer/main.go

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
package main
2+
3+
import (
4+
"crypto/sha256"
5+
"encoding/hex"
6+
"flag"
7+
"os"
8+
"path/filepath"
9+
10+
"github.com/projectdiscovery/gologger"
11+
"github.com/projectdiscovery/gologger/levels"
12+
"github.com/projectdiscovery/nuclei/v3/pkg/catalog/config"
13+
"github.com/projectdiscovery/nuclei/v3/pkg/catalog/disk"
14+
"github.com/projectdiscovery/nuclei/v3/pkg/protocols"
15+
"github.com/projectdiscovery/nuclei/v3/pkg/templates"
16+
"github.com/projectdiscovery/nuclei/v3/pkg/templates/signer"
17+
"github.com/projectdiscovery/nuclei/v3/pkg/types"
18+
fileutil "github.com/projectdiscovery/utils/file"
19+
folderutil "github.com/projectdiscovery/utils/folder"
20+
)
21+
22+
var (
23+
appConfigDir = folderutil.AppConfigDirOrDefault(".config", "nuclei")
24+
defaultCertFile = filepath.Join(appConfigDir, "keys", "nuclei-user.crt")
25+
defaultPrivKey = filepath.Join(appConfigDir, "keys", "nuclei-user-private-key.pem")
26+
)
27+
28+
var (
29+
template string
30+
cert string
31+
privKey string
32+
)
33+
34+
func main() {
35+
flag.StringVar(&template, "template", "", "template to sign (file only)")
36+
flag.StringVar(&cert, "cert", defaultCertFile, "certificate file")
37+
flag.StringVar(&privKey, "priv-key", defaultPrivKey, "private key file")
38+
flag.Parse()
39+
40+
config.DefaultConfig.LogAllEvents = true
41+
gologger.DefaultLogger.SetMaxLevel(levels.LevelVerbose)
42+
43+
if template == "" {
44+
gologger.Fatal().Msg("template is required")
45+
}
46+
if !fileutil.FileExists(template) {
47+
gologger.Fatal().Msgf("template file %s does not exist or not a file", template)
48+
}
49+
50+
// get signer
51+
tmplSigner, err := signer.NewTemplateSignerFromFiles(cert, privKey)
52+
if err != nil {
53+
gologger.Fatal().Msgf("failed to create signer: %s", err)
54+
}
55+
gologger.Info().Msgf("Template Signer: %v\n", tmplSigner.Identifier())
56+
57+
// read file
58+
bin, err := os.ReadFile(template)
59+
if err != nil {
60+
gologger.Fatal().Msgf("failed to read template file %s: %s", template, err)
61+
}
62+
63+
// extract signature and content
64+
sig, content := signer.ExtractSignatureAndContent(bin)
65+
hash := sha256.Sum256(content)
66+
67+
gologger.Info().Msgf("Signature Details:")
68+
gologger.Info().Msgf("----------------")
69+
gologger.Info().Msgf("Signature: %s", sig)
70+
gologger.Info().Msgf("Content Hash (SHA256): %s\n", hex.EncodeToString(hash[:]))
71+
72+
execOpts := defaultExecutorOpts(template)
73+
74+
tmpl, err := templates.Parse(template, nil, execOpts)
75+
if err != nil {
76+
gologger.Fatal().Msgf("failed to parse template: %s", err)
77+
}
78+
gologger.Info().Msgf("Template Verified: %v\n", tmpl.Verified)
79+
80+
if !tmpl.Verified {
81+
gologger.Info().Msgf("------------------------")
82+
gologger.Info().Msg("Template is not verified, signing template")
83+
if err := templates.SignTemplate(tmplSigner, template); err != nil {
84+
gologger.Fatal().Msgf("Failed to sign template: %s", err)
85+
}
86+
// verify again by reading file what the new signature and hash is
87+
bin2, err := os.ReadFile(template)
88+
if err != nil {
89+
gologger.Fatal().Msgf("failed to read signed template file %s: %s", template, err)
90+
}
91+
sig2, content2 := signer.ExtractSignatureAndContent(bin2)
92+
hash2 := sha256.Sum256(content2)
93+
94+
gologger.Info().Msgf("Updated Signature Details:")
95+
gologger.Info().Msgf("------------------------")
96+
gologger.Info().Msgf("Signature: %s", sig2)
97+
gologger.Info().Msgf("Content Hash (SHA256): %s\n", hex.EncodeToString(hash2[:]))
98+
}
99+
gologger.Info().Msgf("✓ Template signed & verified successfully")
100+
}
101+
102+
func defaultExecutorOpts(templatePath string) protocols.ExecutorOptions {
103+
// use parsed options when initializing signer instead of default options
104+
options := types.DefaultOptions()
105+
templates.UseOptionsForSigner(options)
106+
catalog := disk.NewCatalog(filepath.Dir(templatePath))
107+
executerOpts := protocols.ExecutorOptions{
108+
Catalog: catalog,
109+
Options: options,
110+
TemplatePath: templatePath,
111+
Parser: templates.NewParser(),
112+
}
113+
return executerOpts
114+
}

go.mod

Lines changed: 17 additions & 16 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.1.1
23-
github.com/projectdiscovery/fastdialer v0.2.9
24-
github.com/projectdiscovery/hmap v0.0.67
23+
github.com/projectdiscovery/fastdialer v0.2.10
24+
github.com/projectdiscovery/hmap v0.0.69
2525
github.com/projectdiscovery/interactsh v1.2.0
26-
github.com/projectdiscovery/rawhttp v0.1.74
27-
github.com/projectdiscovery/retryabledns v1.0.85
28-
github.com/projectdiscovery/retryablehttp-go v1.0.86
26+
github.com/projectdiscovery/rawhttp v0.1.76
27+
github.com/projectdiscovery/retryabledns v1.0.86
28+
github.com/projectdiscovery/retryablehttp-go v1.0.88
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
@@ -38,9 +38,9 @@ require (
3838
github.com/weppos/publicsuffix-go v0.30.2
3939
github.com/xanzy/go-gitlab v0.107.0
4040
go.uber.org/multierr v1.11.0
41-
golang.org/x/net v0.30.0
41+
golang.org/x/net v0.31.0
4242
golang.org/x/oauth2 v0.22.0
43-
golang.org/x/text v0.19.0
43+
golang.org/x/text v0.20.0
4444
gopkg.in/yaml.v2 v2.4.0
4545
)
4646

@@ -85,29 +85,29 @@ require (
8585
github.com/projectdiscovery/fasttemplate v0.0.2
8686
github.com/projectdiscovery/go-smb2 v0.0.0-20240129202741-052cc450c6cb
8787
github.com/projectdiscovery/goflags v0.1.65
88-
github.com/projectdiscovery/gologger v1.1.31
88+
github.com/projectdiscovery/gologger v1.1.33
8989
github.com/projectdiscovery/gostruct v0.0.2
9090
github.com/projectdiscovery/gozero v0.0.3
9191
github.com/projectdiscovery/httpx v1.6.9
9292
github.com/projectdiscovery/mapcidr v1.1.34
9393
github.com/projectdiscovery/n3iwf v0.0.0-20230523120440-b8cd232ff1f5
94-
github.com/projectdiscovery/ratelimit v0.0.61
94+
github.com/projectdiscovery/ratelimit v0.0.64
9595
github.com/projectdiscovery/rdap v0.9.1-0.20221108103045-9865884d1917
9696
github.com/projectdiscovery/sarif v0.0.1
9797
github.com/projectdiscovery/tlsx v1.1.8
9898
github.com/projectdiscovery/uncover v1.0.9
9999
github.com/projectdiscovery/useragent v0.0.78
100-
github.com/projectdiscovery/utils v0.2.18
101-
github.com/projectdiscovery/wappalyzergo v0.2.2
100+
github.com/projectdiscovery/utils v0.3.0
101+
github.com/projectdiscovery/wappalyzergo v0.2.5
102102
github.com/redis/go-redis/v9 v9.1.0
103103
github.com/seh-msft/burpxml v1.0.1
104104
github.com/shurcooL/graphql v0.0.0-20230722043721-ed46e5a46466
105-
github.com/stretchr/testify v1.9.0
105+
github.com/stretchr/testify v1.10.0
106106
github.com/tarunKoyalwar/goleak v0.0.0-20240429141123-0efa90dbdcf9
107107
github.com/yassinebenaid/godump v0.10.0
108108
github.com/zmap/zgrab2 v0.1.8-0.20230806160807-97ba87c0e706
109109
go.mongodb.org/mongo-driver v1.17.0
110-
golang.org/x/term v0.25.0
110+
golang.org/x/term v0.26.0
111111
gopkg.in/yaml.v3 v3.0.1
112112
moul.io/http2curl v1.0.0
113113
)
@@ -152,6 +152,7 @@ require (
152152
github.com/docker/docker v24.0.9+incompatible // indirect
153153
github.com/docker/go-connections v0.4.0 // indirect
154154
github.com/fatih/color v1.16.0 // indirect
155+
github.com/felixge/fgprof v0.9.5 // indirect
155156
github.com/free5gc/util v1.0.5-0.20230511064842-2e120956883b // indirect
156157
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
157158
github.com/gaissmai/bart v0.9.5 // indirect
@@ -246,7 +247,7 @@ require (
246247
github.com/zeebo/blake3 v0.2.3 // indirect
247248
go.uber.org/goleak v1.3.0 // indirect
248249
golang.org/x/arch v0.3.0 // indirect
249-
golang.org/x/sync v0.8.0 // indirect
250+
golang.org/x/sync v0.9.0 // indirect
250251
gopkg.in/djherbis/times.v1 v1.3.0 // indirect
251252
mellium.im/sasl v0.3.1 // indirect
252253
)
@@ -313,10 +314,10 @@ require (
313314
go.etcd.io/bbolt v1.3.10 // indirect
314315
go.uber.org/zap v1.25.0 // indirect
315316
goftp.io/server/v2 v2.0.1 // indirect
316-
golang.org/x/crypto v0.28.0 // indirect
317+
golang.org/x/crypto v0.29.0 // indirect
317318
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842
318319
golang.org/x/mod v0.17.0 // indirect
319-
golang.org/x/sys v0.26.0 // indirect
320+
golang.org/x/sys v0.27.0 // indirect
320321
golang.org/x/time v0.6.0 // indirect
321322
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d
322323
google.golang.org/protobuf v1.34.2 // indirect

0 commit comments

Comments
 (0)