mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2026-11-08 02:08:33 -10:00
Compare commits
114
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fe24f8638b | ||
|
|
8b7cbf44e6 | ||
|
|
59ae4cac04 | ||
|
|
64965ba776 | ||
|
|
15271926ad | ||
|
|
46fbc92a76 | ||
|
|
36d0adba18 | ||
|
|
049e6b629e | ||
|
|
2c6b223bb4 | ||
|
|
0827b2779b | ||
|
|
0971fb83e2 | ||
|
|
62dae92b3d | ||
|
|
e44df6e947 | ||
|
|
25f50f1036 | ||
|
|
f9446e9290 | ||
|
|
faaeaf30b1 | ||
|
|
b7fe335285 | ||
|
|
7481b20d78 | ||
|
|
48600a24de | ||
|
|
ec4036147e | ||
|
|
9b04153a3b | ||
|
|
23f3407af7 | ||
|
|
be40690a29 | ||
|
|
64f94f3e66 | ||
|
|
b2b54a7ac4 | ||
|
|
22aedebe5d | ||
|
|
5896509c84 | ||
|
|
825dcfb10a | ||
|
|
d465cc82a4 | ||
|
|
48f36b4edc | ||
|
|
0e7a56b0d7 | ||
|
|
f8cf960022 | ||
|
|
cbd2cb3881 | ||
|
|
1fc87e6b02 | ||
|
|
7a08c714f9 | ||
|
|
6903f2d559 | ||
|
|
27edbd6a64 | ||
|
|
be678d9d7c | ||
|
|
515b22a35a | ||
|
|
cd0122aa85 | ||
|
|
b7d22eb52b | ||
|
|
c2cecb92a8 | ||
|
|
9206560d1d | ||
|
|
e94840ad56 | ||
|
|
aec0b6eebf | ||
|
|
b6dd16ffbf | ||
|
|
d510a9c2fb | ||
|
|
de382b5de3 | ||
|
|
7ed324680f | ||
|
|
684d55eeed | ||
|
|
4dcb37ad23 | ||
|
|
ab506a2bb6 | ||
|
|
7b44856ce8 | ||
|
|
288f657fca | ||
|
|
87a8c61932 | ||
|
|
9c26dc1d2a | ||
|
|
613e581542 | ||
|
|
5c9f02a4fc | ||
|
|
df57ae6d29 | ||
|
|
2a5392eaad | ||
|
|
bdf7e983c5 | ||
|
|
6a3300b13d | ||
|
|
266593d7a0 | ||
|
|
7b0ca00fdf | ||
|
|
2e258fc3f5 | ||
|
|
b3596ac64e | ||
|
|
ac52212d17 | ||
|
|
1f79f786da | ||
|
|
3ab77ec3e7 | ||
|
|
58354693e0 | ||
|
|
dc817c8dbd | ||
|
|
e55509d881 | ||
|
|
998641728c | ||
|
|
4e3f78c2c0 | ||
|
|
7a9ec9c8da | ||
|
|
5d876b88e5 | ||
|
|
7d143c989a | ||
|
|
aa45ef92f6 | ||
|
|
7f57e92074 | ||
|
|
3ae6ca8e3d | ||
|
|
6c615b76df | ||
|
|
681854444d | ||
|
|
449fdd2c37 | ||
|
|
9d7aa53226 | ||
|
|
3ee4f0f408 | ||
|
|
091191f518 | ||
|
|
827f4a9f88 | ||
|
|
bd1c4dd226 | ||
|
|
f990fe4d5d | ||
|
|
00ed0552da | ||
|
|
099a037928 | ||
|
|
12d6f03826 | ||
|
|
1644ba7e81 | ||
|
|
a113cf0db8 | ||
|
|
97337e2b4a | ||
|
|
8d29c12eef | ||
|
|
4fc17dc284 | ||
|
|
035fc270f9 | ||
|
|
3f341f0222 | ||
|
|
26ce6d2ef2 | ||
|
|
0f34b1b6b8 | ||
|
|
77ba7792f3 | ||
|
|
8caa65a839 | ||
|
|
a4afaa41b2 | ||
|
|
abcdcf19a4 | ||
|
|
9dc004926d | ||
|
|
3d2f411e1d | ||
|
|
763e490f42 | ||
|
|
421ec70686 | ||
|
|
1eeb2f3979 | ||
|
|
ea108ee04f | ||
|
|
aac1427cdc | ||
|
|
c4552c6011 | ||
|
|
4331cd0f7a |
No files matched your search
@@ -36,7 +36,7 @@ It also specifies a `WorkflowLoader` interface that is used during workflow load
|
||||
|
||||
```go
|
||||
type WorkflowLoader interface {
|
||||
GetTemplatePathsByTags(tags []string) []string
|
||||
GetTemplatePathsByTags(tags []string, noValidate bool) []string
|
||||
GetTemplatePaths(templatesList []string, noValidate bool) []string
|
||||
}
|
||||
```
|
||||
|
||||
@@ -23,7 +23,7 @@ endif
|
||||
|
||||
.PHONY: all build build-stats clean devtools-all devtools-bindgen devtools-scrapefuncs fuzz fuzz-ci fuzz-tools
|
||||
.PHONY: devtools-tsgen docs docgen dsl-docs functional go-build lint lint-strict fuzzplayground syntax-docs
|
||||
.PHONY: integration integration-debug regression jsupdate-all jsupdate-bindgen jsupdate-tsgen memogen scan-charts test test-with-lint test-sandbox-linux
|
||||
.PHONY: integration integration-debug regression jsupdate-all jsupdate-bindgen jsupdate-tsgen memogen scan-charts test test-with-lint
|
||||
.PHONY: tidy ts verify download vet template-validate build-fuzz discover-fuzz-packages
|
||||
|
||||
all: build
|
||||
@@ -99,11 +99,6 @@ integration:
|
||||
integration-debug:
|
||||
$(GOTEST) -tags=integration ./internal/tests/integration -v $(GO_TEST_ARGS) -args $(INTEGRATION_ARGS)
|
||||
|
||||
# Runs the Landlock sandbox tests inside Linux Docker (macOS/Windows hosts).
|
||||
test-sandbox-linux:
|
||||
docker run --rm -e GOTOOLCHAIN=auto -v "$(PWD):/src" -w /src golang:bookworm \
|
||||
go test ./pkg/protocols/common/sandbox/... ./pkg/protocols/code/... -count=1 -run "Landlock|Apply|Supported|DisableSandbox"
|
||||
|
||||
# Opt-in HTTP engine scale regression harness (not part of CI). Stands up many
|
||||
# loopback hosts and asserts finding parity across a diverse template set.
|
||||
# Override host count with NUCLEI_SCALE_HOSTS, e.g. NUCLEI_SCALE_HOSTS=500 make regression
|
||||
|
||||
@@ -145,12 +145,12 @@ TARGET:
|
||||
-eh, -exclude-hosts string[] hosts to exclude to scan from the input list (ip, cidr, hostname)
|
||||
-resume string resume scan from and save to specified file (clustering will be disabled)
|
||||
-sa, -scan-all-ips scan all the IP's associated with dns record
|
||||
-iv, -ip-version string[] IP version to scan of hostname (4,6) - (default 4)
|
||||
-iv, -ip-version string[] IP version to scan of hostname (4,6); default uses dialer fallback, -sa scans all addresses
|
||||
-dun, -disable-url-normalization keep targets exactly as supplied instead of collapsing urls that address the same resource
|
||||
-mup, -max-urls-per-pattern int scan at most this many urls sharing one structural shape, e.g. /user/1 and /user/2 (0 to scan all)
|
||||
|
||||
TARGET-FORMAT:
|
||||
-im, -input-mode string mode of input file (list, burp, jsonl, yaml, openapi, swagger, http) (default "list")
|
||||
-im, -input-mode string mode of input file (list, burp, har, jsonl, yaml, openapi, swagger, http) (default "list")
|
||||
-ro, -required-only use only required fields in input format when generating requests
|
||||
-sfv, -skip-format-validation skip format validation (like missing vars) when parsing input file
|
||||
-vtt, -vars-text-templating enable text templating for vars in input file (only for yaml input mode)
|
||||
@@ -177,7 +177,7 @@ TEMPLATES:
|
||||
-egm, -enable-global-matchers enable loading global matchers templates
|
||||
-file enable loading file templates
|
||||
-llm enable llm matchers and extractors (semantic matching)
|
||||
-llm-provider string llm provider for semantic matching (openai, ollama, llamacpp, vllm, lmstudio, groq, openrouter, together, orcarouter) (default "openai")
|
||||
-llm-provider string llm provider for semantic matching (openai, ollama, llamacpp, vllm, lmstudio, groq, openrouter, together, orcarouter, jev) (default "openai")
|
||||
-llm-base-url string openai-compatible endpoint for semantic matching (overrides -llm-provider, e.g. a local model)
|
||||
-llm-model string model used for semantic matching
|
||||
-llm-timeout int time in seconds to wait for a single llm call (default 30)
|
||||
@@ -221,6 +221,7 @@ OUTPUT:
|
||||
-jle, -jsonl-export string file to export results in JSONL(ine) format
|
||||
-pe, -pdf-export string file to export results in PDF format
|
||||
-rd, -redact string[] redact given list of keys from query parameter, request header and body
|
||||
-nrd, -no-redact disable the built-in redaction of credential headers (Authorization, Cookie, Set-Cookie, ...) in output; keys given with -redact are still redacted
|
||||
|
||||
CONFIGURATIONS:
|
||||
-config string path to the nuclei configuration file
|
||||
@@ -246,9 +247,7 @@ CONFIGURATIONS:
|
||||
-ztls use ztls library with autofallback to standard one for tls13 [Deprecated] autofallback to ztls is enabled by default
|
||||
-sni string tls sni hostname to use (default: input domain name)
|
||||
-dka, -dialer-keep-alive value keep-alive duration for network requests.
|
||||
-lfa, -allow-local-file-access allows local file access from additional allowed directories (cwd and --allowed-paths)
|
||||
-ap, -allowed-paths string[] additional filesystem roots allowed with -lfa (repeatable)
|
||||
-no-sandbox disable the OS-level filesystem sandbox and the code template sandbox
|
||||
-lfa, -allow-local-file-access allow all templates in the run to read any file on the system (not just payloads)
|
||||
-lna, -restrict-local-network-access blocks connections to the local / private network
|
||||
-i, -interface string network interface to use for network scan
|
||||
-at, -attack-type string type of payload combinations to perform (batteringram,pitchfork,clusterbomb)
|
||||
@@ -328,6 +327,7 @@ OPTIMIZATIONS:
|
||||
-nh, -no-httpx disable httpx probing for non-url input
|
||||
-preflight-portscan run preflight resolve + TCP portscan and filter targets before scanning (disabled by default)
|
||||
-no-stdin disable stdin processing
|
||||
-ac, -auto-calibrate drop HTTP matches on a host's catch-all page (answers missing paths with 2xx/3xx)
|
||||
|
||||
HEADLESS:
|
||||
-headless enable templates that require headless browser support (root user on Linux will disable sandbox)
|
||||
|
||||
+4
-5
@@ -148,7 +148,7 @@ TARGET:
|
||||
-iv, -ip-version string[] IP version to scan of hostname (4,6) - (default 4)
|
||||
|
||||
TARGET-FORMAT:
|
||||
-im, -input-mode string mode of input file (list, burp, jsonl, yaml, openapi, swagger, http) (default "list")
|
||||
-im, -input-mode string mode of input file (list, burp, har, jsonl, yaml, openapi, swagger, http) (default "list")
|
||||
-ro, -required-only use only required fields in input format when generating requests
|
||||
-sfv, -skip-format-validation skip format validation (like missing vars) when parsing input file
|
||||
-vtt, -vars-text-templating enable text templating for vars in input file (only for yaml input mode)
|
||||
@@ -175,7 +175,7 @@ TEMPLATES:
|
||||
-egm, -enable-global-matchers enable loading global matchers templates
|
||||
-file enable loading file templates
|
||||
-llm enable llm matchers and extractors (semantic matching)
|
||||
-llm-provider string llm provider for semantic matching (openai, ollama, llamacpp, vllm, lmstudio, groq, openrouter, together, orcarouter) (default "openai")
|
||||
-llm-provider string llm provider for semantic matching (openai, ollama, llamacpp, vllm, lmstudio, groq, openrouter, together, orcarouter, jev) (default "openai")
|
||||
-llm-base-url string openai-compatible endpoint for semantic matching (overrides -llm-provider, e.g. a local model)
|
||||
-llm-model string model used for semantic matching
|
||||
-llm-timeout int time in seconds to wait for a single llm call (default 30)
|
||||
@@ -219,6 +219,7 @@ OUTPUT:
|
||||
-jle, -jsonl-export string file to export results in JSONL(ine) format
|
||||
-pe, -pdf-export string file to export results in PDF format
|
||||
-rd, -redact string[] redact given list of keys from query parameter, request header and body
|
||||
-nrd, -no-redact disable the built-in redaction of credential headers (Authorization, Cookie, Set-Cookie, ...) in output; keys given with -redact are still redacted
|
||||
|
||||
CONFIGURATIONS:
|
||||
-config string path to the nuclei configuration file
|
||||
@@ -244,9 +245,7 @@ CONFIGURATIONS:
|
||||
-ztls use ztls library with autofallback to standard one for tls13 [Deprecated] autofallback to ztls is enabled by default
|
||||
-sni string tls sni hostname to use (default: input domain name)
|
||||
-dka, -dialer-keep-alive value keep-alive duration for network requests.
|
||||
-lfa, -allow-local-file-access allows local file access from additional allowed directories (cwd and --allowed-paths)
|
||||
-ap, -allowed-paths string[] additional filesystem roots allowed with -lfa (repeatable)
|
||||
-no-sandbox disable the OS-level filesystem sandbox and the code template sandbox
|
||||
-lfa, -allow-local-file-access allow all templates in the run to read any file on the system (not just payloads)
|
||||
-lna, -restrict-local-network-access blocks connections to the local / private network
|
||||
-i, -interface string network interface to use for network scan
|
||||
-at, -attack-type string type of payload combinations to perform (batteringram,pitchfork,clusterbomb)
|
||||
|
||||
+4
-5
@@ -148,7 +148,7 @@ TARGET:
|
||||
-iv, -ip-version string[] IP version to scan of hostname (4,6) - (default 4)
|
||||
|
||||
TARGET-FORMAT:
|
||||
-im, -input-mode string mode of input file (list, burp, jsonl, yaml, openapi, swagger, http) (default "list")
|
||||
-im, -input-mode string mode of input file (list, burp, har, jsonl, yaml, openapi, swagger, http) (default "list")
|
||||
-ro, -required-only use only required fields in input format when generating requests
|
||||
-sfv, -skip-format-validation skip format validation (like missing vars) when parsing input file
|
||||
-vtt, -vars-text-templating enable text templating for vars in input file (only for yaml input mode)
|
||||
@@ -175,7 +175,7 @@ TEMPLATES:
|
||||
-egm, -enable-global-matchers enable loading global matchers templates
|
||||
-file enable loading file templates
|
||||
-llm enable llm matchers and extractors (semantic matching)
|
||||
-llm-provider string llm provider for semantic matching (openai, ollama, llamacpp, vllm, lmstudio, groq, openrouter, together, orcarouter) (default "openai")
|
||||
-llm-provider string llm provider for semantic matching (openai, ollama, llamacpp, vllm, lmstudio, groq, openrouter, together, orcarouter, jev) (default "openai")
|
||||
-llm-base-url string openai-compatible endpoint for semantic matching (overrides -llm-provider, e.g. a local model)
|
||||
-llm-model string model used for semantic matching
|
||||
-llm-timeout int time in seconds to wait for a single llm call (default 30)
|
||||
@@ -219,6 +219,7 @@ OUTPUT:
|
||||
-jle, -jsonl-export string file to export results in JSONL(ine) format
|
||||
-pe, -pdf-export string file to export results in PDF format
|
||||
-rd, -redact string[] redact given list of keys from query parameter, request header and body
|
||||
-nrd, -no-redact disable the built-in redaction of credential headers (Authorization, Cookie, Set-Cookie, ...) in output; keys given with -redact are still redacted
|
||||
|
||||
CONFIGURATIONS:
|
||||
-config string path to the nuclei configuration file
|
||||
@@ -244,9 +245,7 @@ CONFIGURATIONS:
|
||||
-ztls use ztls library with autofallback to standard one for tls13 [Deprecated] autofallback to ztls is enabled by default
|
||||
-sni string tls sni hostname to use (default: input domain name)
|
||||
-dka, -dialer-keep-alive value keep-alive duration for network requests.
|
||||
-lfa, -allow-local-file-access allows local file access from additional allowed directories (cwd and --allowed-paths)
|
||||
-ap, -allowed-paths string[] additional filesystem roots allowed with -lfa (repeatable)
|
||||
-no-sandbox disable the OS-level filesystem sandbox and the code template sandbox
|
||||
-lfa, -allow-local-file-access allow all templates in the run to read any file on the system (not just payloads)
|
||||
-lna, -restrict-local-network-access blocks connections to the local / private network
|
||||
-i, -interface string network interface to use for network scan
|
||||
-at, -attack-type string type of payload combinations to perform (batteringram,pitchfork,clusterbomb)
|
||||
|
||||
+4
-5
@@ -165,7 +165,7 @@ TARGET:
|
||||
-mup, -max-urls-per-pattern int scan at most this many urls sharing one structural shape, e.g. /user/1 and /user/2 (0 to scan all)
|
||||
|
||||
TARGET-FORMAT:
|
||||
-im, -input-mode string mode of input file (list, burp, jsonl, yaml, openapi, swagger, http) (default "list")
|
||||
-im, -input-mode string mode of input file (list, burp, har, jsonl, yaml, openapi, swagger, http) (default "list")
|
||||
-ro, -required-only use only required fields in input format when generating requests
|
||||
-sfv, -skip-format-validation skip format validation (like missing vars) when parsing input file
|
||||
-vtt, -vars-text-templating enable text templating for vars in input file (only for yaml input mode)
|
||||
@@ -192,7 +192,7 @@ TEMPLATES:
|
||||
-egm, -enable-global-matchers enable loading global matchers templates
|
||||
-file enable loading file templates
|
||||
-llm enable llm matchers and extractors (semantic matching)
|
||||
-llm-provider string llm provider for semantic matching (openai, ollama, llamacpp, vllm, lmstudio, groq, openrouter, together, orcarouter) (default "openai")
|
||||
-llm-provider string llm provider for semantic matching (openai, ollama, llamacpp, vllm, lmstudio, groq, openrouter, together, orcarouter, jev) (default "openai")
|
||||
-llm-base-url string openai-compatible endpoint for semantic matching (overrides -llm-provider, e.g. a local model)
|
||||
-llm-model string model used for semantic matching
|
||||
-llm-timeout int time in seconds to wait for a single llm call (default 30)
|
||||
@@ -236,6 +236,7 @@ OUTPUT:
|
||||
-jle, -jsonl-export string file to export results in JSONL(ine) format
|
||||
-pe, -pdf-export string file to export results in PDF format
|
||||
-rd, -redact string[] redact given list of keys from query parameter, request header and body
|
||||
-nrd, -no-redact disable the built-in redaction of credential headers (Authorization, Cookie, Set-Cookie, ...) in output; keys given with -redact are still redacted
|
||||
|
||||
CONFIGURATIONS:
|
||||
-config string path to the nuclei configuration file
|
||||
@@ -261,9 +262,7 @@ CONFIGURATIONS:
|
||||
-ztls use ztls library with autofallback to standard one for tls13 [Deprecated] autofallback to ztls is enabled by default
|
||||
-sni string tls sni hostname to use (default: input domain name)
|
||||
-dka, -dialer-keep-alive value keep-alive duration for network requests.
|
||||
-lfa, -allow-local-file-access allows local file access from additional allowed directories (cwd and --allowed-paths)
|
||||
-ap, -allowed-paths string[] additional filesystem roots allowed with -lfa (repeatable)
|
||||
-no-sandbox disable the OS-level filesystem sandbox and the code template sandbox
|
||||
-lfa, -allow-local-file-access allow all templates in the run to read any file on the system (not just payloads)
|
||||
-lna, -restrict-local-network-access blocks connections to the local / private network
|
||||
-i, -interface string network interface to use for network scan
|
||||
-at, -attack-type string type of payload combinations to perform (batteringram,pitchfork,clusterbomb)
|
||||
|
||||
+4
-5
@@ -148,7 +148,7 @@ TARGET:
|
||||
-iv, -ip-version string[] IP version to scan of hostname (4,6) - (default 4)
|
||||
|
||||
TARGET-FORMAT:
|
||||
-im, -input-mode string mode of input file (list, burp, jsonl, yaml, openapi, swagger, http) (default "list")
|
||||
-im, -input-mode string mode of input file (list, burp, har, jsonl, yaml, openapi, swagger, http) (default "list")
|
||||
-ro, -required-only use only required fields in input format when generating requests
|
||||
-sfv, -skip-format-validation skip format validation (like missing vars) when parsing input file
|
||||
-vtt, -vars-text-templating enable text templating for vars in input file (only for yaml input mode)
|
||||
@@ -175,7 +175,7 @@ TEMPLATES:
|
||||
-egm, -enable-global-matchers enable loading global matchers templates
|
||||
-file enable loading file templates
|
||||
-llm enable llm matchers and extractors (semantic matching)
|
||||
-llm-provider string llm provider for semantic matching (openai, ollama, llamacpp, vllm, lmstudio, groq, openrouter, together, orcarouter) (default "openai")
|
||||
-llm-provider string llm provider for semantic matching (openai, ollama, llamacpp, vllm, lmstudio, groq, openrouter, together, orcarouter, jev) (default "openai")
|
||||
-llm-base-url string openai-compatible endpoint for semantic matching (overrides -llm-provider, e.g. a local model)
|
||||
-llm-model string model used for semantic matching
|
||||
-llm-timeout int time in seconds to wait for a single llm call (default 30)
|
||||
@@ -219,6 +219,7 @@ OUTPUT:
|
||||
-jle, -jsonl-export string file to export results in JSONL(ine) format
|
||||
-pe, -pdf-export string file to export results in PDF format
|
||||
-rd, -redact string[] redact given list of keys from query parameter, request header and body
|
||||
-nrd, -no-redact disable the built-in redaction of credential headers (Authorization, Cookie, Set-Cookie, ...) in output; keys given with -redact are still redacted
|
||||
|
||||
CONFIGURATIONS:
|
||||
-config string path to the nuclei configuration file
|
||||
@@ -244,9 +245,7 @@ CONFIGURATIONS:
|
||||
-ztls use ztls library with autofallback to standard one for tls13 [Deprecated] autofallback to ztls is enabled by default
|
||||
-sni string tls sni hostname to use (default: input domain name)
|
||||
-dka, -dialer-keep-alive value keep-alive duration for network requests.
|
||||
-lfa, -allow-local-file-access allows local file access from additional allowed directories (cwd and --allowed-paths)
|
||||
-ap, -allowed-paths string[] additional filesystem roots allowed with -lfa (repeatable)
|
||||
-no-sandbox disable the OS-level filesystem sandbox and the code template sandbox
|
||||
-lfa, -allow-local-file-access allow all templates in the run to read any file on the system (not just payloads)
|
||||
-lna, -restrict-local-network-access blocks connections to the local / private network
|
||||
-i, -interface string network interface to use for network scan
|
||||
-at, -attack-type string type of payload combinations to perform (batteringram,pitchfork,clusterbomb)
|
||||
|
||||
+4
-5
@@ -148,7 +148,7 @@ TARGET:
|
||||
-iv, -ip-version string[] IP version to scan of hostname (4,6) - (default 4)
|
||||
|
||||
TARGET-FORMAT:
|
||||
-im, -input-mode string mode of input file (list, burp, jsonl, yaml, openapi, swagger, http) (default "list")
|
||||
-im, -input-mode string mode of input file (list, burp, har, jsonl, yaml, openapi, swagger, http) (default "list")
|
||||
-ro, -required-only use only required fields in input format when generating requests
|
||||
-sfv, -skip-format-validation skip format validation (like missing vars) when parsing input file
|
||||
-vtt, -vars-text-templating enable text templating for vars in input file (only for yaml input mode)
|
||||
@@ -175,7 +175,7 @@ TEMPLATES:
|
||||
-egm, -enable-global-matchers enable loading global matchers templates
|
||||
-file enable loading file templates
|
||||
-llm enable llm matchers and extractors (semantic matching)
|
||||
-llm-provider string llm provider for semantic matching (openai, ollama, llamacpp, vllm, lmstudio, groq, openrouter, together, orcarouter) (default "openai")
|
||||
-llm-provider string llm provider for semantic matching (openai, ollama, llamacpp, vllm, lmstudio, groq, openrouter, together, orcarouter, jev) (default "openai")
|
||||
-llm-base-url string openai-compatible endpoint for semantic matching (overrides -llm-provider, e.g. a local model)
|
||||
-llm-model string model used for semantic matching
|
||||
-llm-timeout int time in seconds to wait for a single llm call (default 30)
|
||||
@@ -219,6 +219,7 @@ OUTPUT:
|
||||
-jle, -jsonl-export string file to export results in JSONL(ine) format
|
||||
-pe, -pdf-export string file to export results in PDF format
|
||||
-rd, -redact string[] redact given list of keys from query parameter, request header and body
|
||||
-nrd, -no-redact disable the built-in redaction of credential headers (Authorization, Cookie, Set-Cookie, ...) in output; keys given with -redact are still redacted
|
||||
|
||||
CONFIGURATIONS:
|
||||
-config string path to the nuclei configuration file
|
||||
@@ -244,9 +245,7 @@ CONFIGURATIONS:
|
||||
-ztls use ztls library with autofallback to standard one for tls13 [Deprecated] autofallback to ztls is enabled by default
|
||||
-sni string tls sni hostname to use (default: input domain name)
|
||||
-dka, -dialer-keep-alive value keep-alive duration for network requests.
|
||||
-lfa, -allow-local-file-access allows local file access from additional allowed directories (cwd and --allowed-paths)
|
||||
-ap, -allowed-paths string[] additional filesystem roots allowed with -lfa (repeatable)
|
||||
-no-sandbox disable the OS-level filesystem sandbox and the code template sandbox
|
||||
-lfa, -allow-local-file-access allow all templates in the run to read any file on the system (not just payloads)
|
||||
-lna, -restrict-local-network-access blocks connections to the local / private network
|
||||
-i, -interface string network interface to use for network scan
|
||||
-at, -attack-type string type of payload combinations to perform (batteringram,pitchfork,clusterbomb)
|
||||
|
||||
+4
-5
@@ -148,7 +148,7 @@ TARGET:
|
||||
-iv, -ip-version string[] IP version to scan of hostname (4,6) - (default 4)
|
||||
|
||||
TARGET-FORMAT:
|
||||
-im, -input-mode string mode of input file (list, burp, jsonl, yaml, openapi, swagger, http) (default "list")
|
||||
-im, -input-mode string mode of input file (list, burp, har, jsonl, yaml, openapi, swagger, http) (default "list")
|
||||
-ro, -required-only use only required fields in input format when generating requests
|
||||
-sfv, -skip-format-validation skip format validation (like missing vars) when parsing input file
|
||||
-vtt, -vars-text-templating enable text templating for vars in input file (only for yaml input mode)
|
||||
@@ -175,7 +175,7 @@ TEMPLATES:
|
||||
-egm, -enable-global-matchers enable loading global matchers templates
|
||||
-file enable loading file templates
|
||||
-llm enable llm matchers and extractors (semantic matching)
|
||||
-llm-provider string llm provider for semantic matching (openai, ollama, llamacpp, vllm, lmstudio, groq, openrouter, together, orcarouter) (default "openai")
|
||||
-llm-provider string llm provider for semantic matching (openai, ollama, llamacpp, vllm, lmstudio, groq, openrouter, together, orcarouter, jev) (default "openai")
|
||||
-llm-base-url string openai-compatible endpoint for semantic matching (overrides -llm-provider, e.g. a local model)
|
||||
-llm-model string model used for semantic matching
|
||||
-llm-timeout int time in seconds to wait for a single llm call (default 30)
|
||||
@@ -219,6 +219,7 @@ OUTPUT:
|
||||
-jle, -jsonl-export string file to export results in JSONL(ine) format
|
||||
-pe, -pdf-export string file to export results in PDF format
|
||||
-rd, -redact string[] redact given list of keys from query parameter, request header and body
|
||||
-nrd, -no-redact disable the built-in redaction of credential headers (Authorization, Cookie, Set-Cookie, ...) in output; keys given with -redact are still redacted
|
||||
|
||||
CONFIGURATIONS:
|
||||
-config string path to the nuclei configuration file
|
||||
@@ -244,9 +245,7 @@ CONFIGURATIONS:
|
||||
-ztls use ztls library with autofallback to standard one for tls13 [Deprecated] autofallback to ztls is enabled by default
|
||||
-sni string tls sni hostname to use (default: input domain name)
|
||||
-dka, -dialer-keep-alive value keep-alive duration for network requests.
|
||||
-lfa, -allow-local-file-access allows local file access from additional allowed directories (cwd and --allowed-paths)
|
||||
-ap, -allowed-paths string[] additional filesystem roots allowed with -lfa (repeatable)
|
||||
-no-sandbox disable the OS-level filesystem sandbox and the code template sandbox
|
||||
-lfa, -allow-local-file-access allow all templates in the run to read any file on the system (not just payloads)
|
||||
-lna, -restrict-local-network-access blocks connections to the local / private network
|
||||
-i, -interface string network interface to use for network scan
|
||||
-at, -attack-type string type of payload combinations to perform (batteringram,pitchfork,clusterbomb)
|
||||
|
||||
+4
-5
@@ -148,7 +148,7 @@ TARGET:
|
||||
-iv, -ip-version string[] IP version to scan of hostname (4,6) - (default 4)
|
||||
|
||||
TARGET-FORMAT:
|
||||
-im, -input-mode string mode of input file (list, burp, jsonl, yaml, openapi, swagger, http) (default "list")
|
||||
-im, -input-mode string mode of input file (list, burp, har, jsonl, yaml, openapi, swagger, http) (default "list")
|
||||
-ro, -required-only use only required fields in input format when generating requests
|
||||
-sfv, -skip-format-validation skip format validation (like missing vars) when parsing input file
|
||||
-vtt, -vars-text-templating enable text templating for vars in input file (only for yaml input mode)
|
||||
@@ -175,7 +175,7 @@ TEMPLATES:
|
||||
-egm, -enable-global-matchers enable loading global matchers templates
|
||||
-file enable loading file templates
|
||||
-llm enable llm matchers and extractors (semantic matching)
|
||||
-llm-provider string llm provider for semantic matching (openai, ollama, llamacpp, vllm, lmstudio, groq, openrouter, together, orcarouter) (default "openai")
|
||||
-llm-provider string llm provider for semantic matching (openai, ollama, llamacpp, vllm, lmstudio, groq, openrouter, together, orcarouter, jev) (default "openai")
|
||||
-llm-base-url string openai-compatible endpoint for semantic matching (overrides -llm-provider, e.g. a local model)
|
||||
-llm-model string model used for semantic matching
|
||||
-llm-timeout int time in seconds to wait for a single llm call (default 30)
|
||||
@@ -219,6 +219,7 @@ OUTPUT:
|
||||
-jle, -jsonl-export string file to export results in JSONL(ine) format
|
||||
-pe, -pdf-export string file to export results in PDF format
|
||||
-rd, -redact string[] redact given list of keys from query parameter, request header and body
|
||||
-nrd, -no-redact disable the built-in redaction of credential headers (Authorization, Cookie, Set-Cookie, ...) in output; keys given with -redact are still redacted
|
||||
|
||||
CONFIGURATIONS:
|
||||
-config string path to the nuclei configuration file
|
||||
@@ -244,9 +245,7 @@ CONFIGURATIONS:
|
||||
-ztls use ztls library with autofallback to standard one for tls13 [Deprecated] autofallback to ztls is enabled by default
|
||||
-sni string tls sni hostname to use (default: input domain name)
|
||||
-dka, -dialer-keep-alive value keep-alive duration for network requests.
|
||||
-lfa, -allow-local-file-access allows local file access from additional allowed directories (cwd and --allowed-paths)
|
||||
-ap, -allowed-paths string[] additional filesystem roots allowed with -lfa (repeatable)
|
||||
-no-sandbox disable the OS-level filesystem sandbox and the code template sandbox
|
||||
-lfa, -allow-local-file-access allow all templates in the run to read any file on the system (not just payloads)
|
||||
-lna, -restrict-local-network-access blocks connections to the local / private network
|
||||
-i, -interface string network interface to use for network scan
|
||||
-at, -attack-type string type of payload combinations to perform (batteringram,pitchfork,clusterbomb)
|
||||
|
||||
+4
-5
@@ -148,7 +148,7 @@ TARGET:
|
||||
-iv, -ip-version string[] IP version to scan of hostname (4,6) - (default 4)
|
||||
|
||||
TARGET-FORMAT:
|
||||
-im, -input-mode string mode of input file (list, burp, jsonl, yaml, openapi, swagger, http) (default "list")
|
||||
-im, -input-mode string mode of input file (list, burp, har, jsonl, yaml, openapi, swagger, http) (default "list")
|
||||
-ro, -required-only use only required fields in input format when generating requests
|
||||
-sfv, -skip-format-validation skip format validation (like missing vars) when parsing input file
|
||||
-vtt, -vars-text-templating enable text templating for vars in input file (only for yaml input mode)
|
||||
@@ -175,7 +175,7 @@ TEMPLATES:
|
||||
-egm, -enable-global-matchers enable loading global matchers templates
|
||||
-file enable loading file templates
|
||||
-llm enable llm matchers and extractors (semantic matching)
|
||||
-llm-provider string llm provider for semantic matching (openai, ollama, llamacpp, vllm, lmstudio, groq, openrouter, together, orcarouter) (default "openai")
|
||||
-llm-provider string llm provider for semantic matching (openai, ollama, llamacpp, vllm, lmstudio, groq, openrouter, together, orcarouter, jev) (default "openai")
|
||||
-llm-base-url string openai-compatible endpoint for semantic matching (overrides -llm-provider, e.g. a local model)
|
||||
-llm-model string model used for semantic matching
|
||||
-llm-timeout int time in seconds to wait for a single llm call (default 30)
|
||||
@@ -219,6 +219,7 @@ OUTPUT:
|
||||
-jle, -jsonl-export string file to export results in JSONL(ine) format
|
||||
-pe, -pdf-export string file to export results in PDF format
|
||||
-rd, -redact string[] redact given list of keys from query parameter, request header and body
|
||||
-nrd, -no-redact disable the built-in redaction of credential headers (Authorization, Cookie, Set-Cookie, ...) in output; keys given with -redact are still redacted
|
||||
|
||||
CONFIGURATIONS:
|
||||
-config string path to the nuclei configuration file
|
||||
@@ -244,9 +245,7 @@ CONFIGURATIONS:
|
||||
-ztls use ztls library with autofallback to standard one for tls13 [Deprecated] autofallback to ztls is enabled by default
|
||||
-sni string tls sni hostname to use (default: input domain name)
|
||||
-dka, -dialer-keep-alive value keep-alive duration for network requests.
|
||||
-lfa, -allow-local-file-access allows local file access from additional allowed directories (cwd and --allowed-paths)
|
||||
-ap, -allowed-paths string[] additional filesystem roots allowed with -lfa (repeatable)
|
||||
-no-sandbox disable the OS-level filesystem sandbox and the code template sandbox
|
||||
-lfa, -allow-local-file-access allow all templates in the run to read any file on the system (not just payloads)
|
||||
-lna, -restrict-local-network-access blocks connections to the local / private network
|
||||
-i, -interface string network interface to use for network scan
|
||||
-at, -attack-type string type of payload combinations to perform (batteringram,pitchfork,clusterbomb)
|
||||
|
||||
+103
-238
@@ -1,255 +1,120 @@
|
||||
<!-- Generated by securitycontext.dev. Source HEAD: 3e1e0e81f091c7817bbf7af64bb8eec6e8c2bac1. -->
|
||||
<!-- Generated by securitycontext.dev. Source HEAD: df57ae6d2955864fd92a1bd2565fe9e4e9a7592b. -->
|
||||
# Security Context: projectdiscovery/nuclei @ dev
|
||||
|
||||
> Reference context for editing projectdiscovery/nuclei. Before changing any component below, **preserve the listed guards and do not reintroduce these fixed issues**. Each fingerprint is a regression check, and each shared attack surface is a guard that must keep holding on every path.
|
||||
|
||||
_Generated 2026-09-01 16:22 UTC by secc_
|
||||
|
||||
_Analyzed commit: 3e1e0e81f091c7817bbf7af64bb8eec6e8c2bac1_
|
||||
|
||||
**Remediation coverage: 56.7%**
|
||||
_17 of 30 historical fixes have no remaining unguarded variant; 368 open remediation leads to verify. Measures fix consistency, not a vulnerability verdict._
|
||||
|
||||
- Commits analyzed: **4814**
|
||||
- Commits flagged for review: **235**
|
||||
- Confirmed historical security fixes: **32**
|
||||
- Known published CVEs: **0**
|
||||
|
||||
## Summary
|
||||
|
||||
Nuclei's historical security posture is dominated by sandbox escapes and code execution via unsigned or unverified templates, with recurring SSRF, path traversal, and auth bypass issues across JS libraries, loaders, and workflow paths. The most critical theme is inconsistent enforcement of signature verification and local-file-access (-lfa) guards across direct, workflow, DAST, and JS-sandbox entry points, enabling variant attacks. A second theme is network policy (host allowlist) gaps in LDAP dialing and proxy handling. The security context also includes dependency upgrades (Alpine, go-git) and output file permission hardening, but the highest-value focus is on template trust boundaries and sandbox enforcement parity.
|
||||
_Analyzed [df57ae6d29][c-df57ae6d29] on `dev` · 5174 commits, 548 security-relevant examined · generated 2026-11-02_
|
||||
|
||||
## Recurring Security Patterns
|
||||
|
||||
**15.6% of classified fixes repeat a previously fixed pattern** (5 recurring, 27 first-seen). A recurring pattern means this repository fixed a similar issue before — not that the code is currently vulnerable.
|
||||
|
||||
- **Code Execution:** [1c440e755a](https://github.com/projectdiscovery/nuclei/commit/1c440e755a97471c56fb0276ee8a8c4132974645) → [9de96e4dda](https://github.com/projectdiscovery/nuclei/commit/9de96e4dda5a03da963b9ae6582f03ea55791a76) — matched on `class:code execution`, `component:pkg/catalog/loader/loader.go`
|
||||
- **Code Execution via Unsigned Template:** [fa56800fcc](https://github.com/projectdiscovery/nuclei/commit/fa56800fcca3c8c8fe8e8dec28584210ca1527de) → [fac0b7196d](https://github.com/projectdiscovery/nuclei/commit/fac0b7196d2fbca56c8af8ff8e1899c111041a37) — matched on `class:code execution via unsigned template`, `CWE-347`, `sink:loadtemplates`
|
||||
- **SSRF:** [a167e6c57b](https://github.com/projectdiscovery/nuclei/commit/a167e6c57b80f5dc7be231231b62d7c594ee2770) → [9def9af7e3](https://github.com/projectdiscovery/nuclei/commit/9def9af7e3f7ebcf5cd561c37b623b9999ee7572) — matched on `class:ssrf`, `CWE-918`, `component:pkg/js/libs/ldap/ldap.go`
|
||||
- **Dependency Vulnerability:** [d93b4a01df](https://github.com/projectdiscovery/nuclei/commit/d93b4a01df9c218a36dd2fccfb1c2c1f96b181fe) → [fcd5c6b111](https://github.com/projectdiscovery/nuclei/commit/fcd5c6b111ddcb746525f88b7d0bf4b4abbc2529) — matched on `class:dependency vulnerability`, `CWE-1104`, `component:dockerfile`
|
||||
- **Sandbox Escape:** [96049a32fa](https://github.com/projectdiscovery/nuclei/commit/96049a32fa70aef0483d4180d386a57b3c2d973a) → [cf2a98b03d](https://github.com/projectdiscovery/nuclei/commit/cf2a98b03d76327c20fb0183b7f1c849eb692c91) — matched on `class:sandbox escape`, `CWE-284`, `component:v2/internal/runner/processor.go`, `sink:stdlib allmodulenames`, `sink:stdlib getmodulemap`
|
||||
**7.1% of classified fixes repeat a previously fixed pattern** (1 recurring, 13 first-seen). A recurring pattern means this repository fixed a similar issue before — not that the code is currently vulnerable.
|
||||
|
||||
## Top Risks
|
||||
|
||||
### 1. Sandbox Escape: `pkg/js/compiler/pool.go, v2/pkg/protocols/javascript/js.go, v2/pkg/protocols/headless/engine/engine.go, v2/internal/runner/processor.go` (high)
|
||||
Components with the strongest concentration of past fixes for one class.
|
||||
|
||||
Multiple sandbox escapes across JS require(), eval/ReadFile, headless browser flags, and tengo imports, indicating weak default sandbox boundaries that require consistent -lfa and safe-module enforcement.
|
||||
|
||||
Evidence: 6f2ade6a9b427c284c15a43445f9c7f055e60e5d, c35162c8ef061a96dd74b54c8f022c1a41cf5833, df55f7a2eb591a7949b5c66a9c54db54aa28f450, cf2a98b03d76327c20fb0183b7f1c849eb692c91, 96049a32fa70aef0483d4180d386a57b3c2d973a
|
||||
|
||||
### 2. Code Execution via Unsigned Template: `pkg/catalog/loader/loader.go, pkg/templates/workflows.go, pkg/templates/templates.go` (critical)
|
||||
|
||||
Unsigned templates can execute code through direct loading, workflows, and DAST branches; signature verification was bypassed via cache poisoning and missing guards on specific paths.
|
||||
|
||||
Evidence: 9de96e4dda5a03da963b9ae6582f03ea55791a76, 1c440e755a97471c56fb0276ee8a8c4132974645, fac0b7196d2fbca56c8af8ff8e1899c111041a37, e86f38299765b82ad724fdb701557e0eaff3884d, fa56800fcca3c8c8fe8e8dec28584210ca1527de
|
||||
|
||||
### 3. Auth Bypass: `pkg/templates/compile.go, pkg/templates/signer/tmpl_signer.go, pkg/catalog/loader/loader.go, pkg/protocols/http/request.go` (high)
|
||||
|
||||
Signature verification can be bypassed via cached metadata, improper signature extraction, or missing checks on specific load paths, and cookie jar bypass via disabled cookie handling.
|
||||
|
||||
Evidence: 4534e9cb3034ebe5cc7b0cecabe399b6fb9ce0e4, 0da993afe6d41b4b1b814e8fad23a2acba13c60a, 9bd4db3f74aedd067af568df4f9198a8a090f68b, a976ca8d3f6a18c9ca746c8ce73f28fdcd518642
|
||||
|
||||
### 4. SSRF: `pkg/js/libs/ldap/ldap.go, v2/internal/runner/proxy.go` (high)
|
||||
|
||||
SSRF via LDAP dialing to internal hosts and via proxy configuration; host allowlist checks were missing or applied to the wrong target (domain vs controller).
|
||||
|
||||
Evidence: 9def9af7e3f7ebcf5cd561c37b623b9999ee7572, a167e6c57b80f5dc7be231231b62d7c594ee2770, 0e46d3e0410f89e4af41099f5cd38fa7f54ae54f
|
||||
|
||||
### 5. Path Traversal: `pkg/catalog/config/nucleiconfig.go, v2/internal/runner/update.go, v2/pkg/protocols/common/protocolstate/headless.go` (high)
|
||||
|
||||
Path traversal via lexical prefix checks, zip-slip in template extraction, and file:// scheme in headless mode; canonicalization and containment checks are required.
|
||||
|
||||
Evidence: 20cbf0bd73893c1270582c9778b6b26a5cb11206, f9c214a66f37a00fc29fe64232b690e6285ec59c, d3928e080d819f25306bfbaecc399f03516db5aa
|
||||
|
||||
### 6. Code Execution: `pkg/catalog/loader/loader.go, pkg/templates/workflows.go` (high)
|
||||
|
||||
Code execution via cache poisoning and unverified code templates in workflows; requires -code flag and verified templates.
|
||||
|
||||
Evidence: 9de96e4dda5a03da963b9ae6582f03ea55791a76, e86f38299765b82ad724fdb701557e0eaff3884d
|
||||
|
||||
## Shared Attack Surfaces
|
||||
|
||||
Capabilities guarded by more than one past fix on different code paths. A guard enforced on one entry point is often missing on a sibling; verify each alternate path before assuming it's covered.
|
||||
|
||||
### 1. Template signature verification and unsigned-template opt-in enforcement across all load paths
|
||||
|
||||
- Guard that should hold everywhere: signature verification (template.Verified, Verify), DisableUnsignedTemplates flag, -code flag for code templates, cache invalidation on verification status/fingerprint/digest
|
||||
- Entry points: `pkg/catalog/loader/loader.go (LoadTemplatesWithTags, DAST branch)`, `pkg/templates/workflows.go (loadTemplates, workflowExecutor)`, `pkg/templates/templates.go (loadTemplates)`, `pkg/templates/compile.go (template.Verified)`, `pkg/templates/signer/tmpl_signer.go (Verify)`
|
||||
- Check: Inspect the DAST and workflow sub-loaders: they must enforce the same DisableUnsignedTemplates and -code checks as the direct loader, and must not rely on cached verification results without re-checking signatures.
|
||||
- Evidence: 9de96e4dda5a03da963b9ae6582f03ea55791a76, 1c440e755a97471c56fb0276ee8a8c4132974645, fac0b7196d2fbca56c8af8ff8e1899c111041a37, e86f38299765b82ad724fdb701557e0eaff3884d, fa56800fcca3c8c8fe8e8dec28584210ca1527de, 4534e9cb3034ebe5cc7b0cecabe399b6fb9ce0e4, 0da993afe6d41b4b1b814e8fad23a2acba13c60a, 9bd4db3f74aedd067af568df4f9198a8a090f68b
|
||||
|
||||
### 2. Local file access (read/write) outside the sandbox, gated by -lfa flag
|
||||
|
||||
- Guard that should hold everywhere: -lfa flag enforcement, path canonicalization and containment (sandbox directory), file:// scheme blocking, allowAllFiles stripping, require() registry rebuild
|
||||
- Entry points: `pkg/js/libs/krbforge/krbforge.go (CreateTicket)`, `pkg/js/libs/mysql/mysql_private.go (sql.Open)`, `pkg/js/compiler/pool.go (require)`, `v2/pkg/protocols/javascript/js.go (ReadFile, eval)`, `v2/pkg/protocols/common/protocolstate/headless.go (file:)`, `v2/pkg/protocols/common/generators/load.go (loadPayloadsFromFile)`
|
||||
- Check: Verify that every JS library and protocol helper (krbforge, mysql, require, headless file://, payload loaders) enforces the -lfa flag and path containment; a sibling path that skips the -lfa check is a sandbox escape.
|
||||
- Evidence: 3a8b65cb45f121fcdf418f60e5177ed9f250c122, 9611926a9a1ca99e8ed554d1b26fbeff60e06368, 6f2ade6a9b427c284c15a43445f9c7f055e60e5d, c35162c8ef061a96dd74b54c8f022c1a41cf5833, d3928e080d819f25306bfbaecc399f03516db5aa, e7fb40a41308f6c41267e858d1781eb67f7e0572
|
||||
|
||||
### 3. Network policy (host allowlist) enforcement before outbound connections
|
||||
|
||||
- Guard that should hold everywhere: IsHostAllowed check on the actual target host (controller, not domain), proxy validation and connectivity check, ProxyInternal gate for HTTP_PROXY env
|
||||
- Entry points: `pkg/js/libs/ldap/ldap.go (Dial, newLdapSession)`, `v2/internal/runner/proxy.go (loadProxyServers, os.Setenv HTTP_PROXY)`
|
||||
- Check: Inspect other dialing paths (e.g., HTTP, headless) to ensure they apply the same host allowlist check on the resolved IP/host, not just a user-supplied domain, and that proxy settings cannot redirect traffic to internal hosts.
|
||||
- Evidence: 9def9af7e3f7ebcf5cd561c37b623b9999ee7572, a167e6c57b80f5dc7be231231b62d7c594ee2770, 0e46d3e0410f89e4af41099f5cd38fa7f54ae54f, 3f5c055aca1499642caf4f40e8cf55ad32bd4da9
|
||||
|
||||
### 4. Path traversal in file extraction and template path trust boundaries
|
||||
|
||||
- Guard that should hold everywhere: canonical path containment check (filepath.Rel, prefix), zip-slip validation against template directory, sandbox path prefix validation
|
||||
- Entry points: `pkg/catalog/config/nucleiconfig.go (IsCustomTemplate)`, `v2/internal/runner/update.go (os.OpenFile)`, `v2/pkg/protocols/common/generators/load.go (loadPayloadsFromFile)`
|
||||
- Check: Audit all file-write and file-read paths that accept template-controlled paths (e.g., template extraction, payload loading) to ensure they use canonical containment, not lexical prefix checks, and apply the same sandbox directory restriction.
|
||||
- Evidence: 20cbf0bd73893c1270582c9778b6b26a5cb11206, f9c214a66f37a00fc29fe64232b690e6285ec59c, e7fb40a41308f6c41267e858d1781eb67f7e0572
|
||||
|
||||
## Historical Vulnerability Classes
|
||||
|
||||
| Class | Count |
|
||||
|---|---|
|
||||
| Sandbox Escape | 7 |
|
||||
| Auth Bypass | 4 |
|
||||
| Code Execution | 3 |
|
||||
| Dependency Vulnerability | 3 |
|
||||
| Path Traversal | 3 |
|
||||
| SSRF | 3 |
|
||||
| Code Execution via Unsigned Template | 2 |
|
||||
| Arbitrary File Read | 1 |
|
||||
| Cryptographic Weakness | 1 |
|
||||
| Deserialization of Untrusted Data | 1 |
|
||||
| Information Disclosure | 1 |
|
||||
| Insecure File Permissions | 1 |
|
||||
| Race Condition | 1 |
|
||||
| Security Misconfiguration | 1 |
|
||||
| # | Class | Component | Severity | Fixes | Evidence |
|
||||
|---|---|---|---|---|---|
|
||||
| 1 | SSRF | `pkg/protocols/common/protocolstate/headless.go` | high | 2 | [d43c1f547f][c-d43c1f547f], [d9dabbb4a1][c-d9dabbb4a1] |
|
||||
| 2 | Arbitrary File Access | `v2/pkg/protocols/common/generators/load.go` | high | 0 (1 component gone, not counted) | [e5154d362a][c-e5154d362a] |
|
||||
| 3 | Arbitrary File Access | `pkg/js/libs/mysql/mysql.go` | high | 1 | [634cecbb28][c-634cecbb28] |
|
||||
| 4 | Code Execution | `pkg/fuzz/execute.go` | high | 1 | [ccbfb12bd0][c-ccbfb12bd0] |
|
||||
| 5 | Code Execution | `pkg/protocols/common/expressions/expressions.go` | high | 1 | [d221732016][c-d221732016] |
|
||||
| 6 | Information Disclosure | `internal/httpapi/apiendpoint.go` | high | 1 | [a20aa26024][c-a20aa26024] |
|
||||
|
||||
## Fixed-Issue Fingerprints
|
||||
|
||||
These are real security fixes mined from git history. Use them as regression checks.
|
||||
Real security fixes mined from git history; use them as regression checks. `verified` fixes are linked to a published advisory, `inferred` fixes were confirmed from the diff evidence alone. Each is identified by its short commit SHA, which the variant-leads report uses to reference it back to this history.
|
||||
|
||||
- **Auth Bypass** (high) [CWE-287]: Honors disable-cookie by preventing the shared cookie jar from being applied when cookie handling is disabled, closing a path where cookies could be reused across requests.
|
||||
- sink: `SetCookieJar(input.CookieJar)`
|
||||
- fix: Adds !request.DisableCookie check before applying shared cookie jar
|
||||
- commit: https://github.com/projectdiscovery/nuclei/commit/a976ca8d3f6a18c9ca746c8ce73f28fdcd518642 (2026-08-25)
|
||||
- **Code Execution** (high) [CWE-347]: This commit fixes a cache poisoning vulnerability where unsigned templates could bypass signature verification and execute malicious code during compilation or request execution.
|
||||
- sink: `template compilation and execution of JavaScript`
|
||||
- fix: cache invalidation based on verification status, verifier fingerprint, and content digest
|
||||
- commit: https://github.com/projectdiscovery/nuclei/commit/9de96e4dda5a03da963b9ae6582f03ea55791a76 (2026-08-04)
|
||||
- **Code Execution via Unsigned Template** (high) [CWE-347]: Enforces signature verification on JavaScript templates, preventing execution of unsigned templates that could lead to arbitrary code execution.
|
||||
- sink: `loading unsigned javascript templates into execution paths`
|
||||
- fix: Require signature verification for javascript templates in direct loading and workflows when signing is enforced
|
||||
- commit: https://github.com/projectdiscovery/nuclei/commit/fac0b7196d2fbca56c8af8ff8e1899c111041a37 (2026-07-03)
|
||||
- **Sandbox Escape** (high) [CWE-22]: Enforces nuclei's local file access policy on krbforge output paths, preventing arbitrary file writes outside the sandbox.
|
||||
- sink: `gpkrb.CreateTicket(cfg) with cfg.OutputFile`
|
||||
- fix: Path normalization into sandbox and denial of outside paths unless -lfa
|
||||
- commit: https://github.com/projectdiscovery/nuclei/commit/3a8b65cb45f121fcdf418f60e5177ed9f250c122 (2026-06-24)
|
||||
- **SSRF** (high) [CWE-918]: Adds network policy host allowlist checks before LDAP dialing, preventing SSRF to restricted internal hosts.
|
||||
- sink: `dialers.Fastdialer.Dial`
|
||||
- fix: host allowlist check via IsHostAllowed before dialing
|
||||
- commit: https://github.com/projectdiscovery/nuclei/commit/9def9af7e3f7ebcf5cd561c37b623b9999ee7572 (2026-06-24)
|
||||
- **Arbitrary File Read** (high) [CWE-22]: Gates MySQL's allowAllFiles option behind the -lfa flag, preventing arbitrary local file reads via LOAD DATA LOCAL INFILE.
|
||||
- sink: `sql.Open("mysql", dsn) with AllowAllFiles=true`
|
||||
- fix: DSN sandbox that strips allowAllFiles unless -lfa is set
|
||||
- commit: https://github.com/projectdiscovery/nuclei/commit/9611926a9a1ca99e8ed554d1b26fbeff60e06368 (2026-06-19)
|
||||
- **Code Execution** (critical) [CWE-94]: Moves the unsigned code-template guard ahead of the DAST branch, preventing unsigned code templates from being loaded and executed under DAST, which previously bypassed the signature check.
|
||||
- sink: `Template loading and execution`
|
||||
- fix: Hoisting unsigned code-template guard before DAST branch to ensure it applies on all load paths
|
||||
- commit: https://github.com/projectdiscovery/nuclei/commit/1c440e755a97471c56fb0276ee8a8c4132974645 (2026-06-19)
|
||||
- **Path Traversal** (high) [CWE-22]: This commit replaces lexical prefix checks with canonical path containment checks across multiple filesystem trust boundaries, preventing path traversal where sibling paths were incorrectly treated as trusted.
|
||||
- sink: `IsCustomTemplate`
|
||||
- fix: path canonicalization and containment check
|
||||
- commit: https://github.com/projectdiscovery/nuclei/commit/20cbf0bd73893c1270582c9778b6b26a5cb11206 (2026-06-04)
|
||||
- **Information Disclosure** (medium) [CWE-200]: This commit fixes a data leakage issue in workflows where sibling state could leak across concurrent executions, and race requests ignored dynamic values, by syncing context and cloning inputs.
|
||||
- sink: `syncWorkflowInputToTemplateCtx`
|
||||
- fix: context synchronization and input cloning
|
||||
- commit: https://github.com/projectdiscovery/nuclei/commit/805bcfe76f3629dbe71021795d4ce865406c1555 (2026-05-08)
|
||||
- **Sandbox Escape** (high) [CWE-284]: Fixes sandbox escape where require() bypassed local file access restrictions and reused privileged module cache across executions.
|
||||
- sink: `require() using default host filesystem loader`
|
||||
- fix: Rebuild require registry per execution and enforce allow-local-file-access sandbox rules
|
||||
- commit: https://github.com/projectdiscovery/nuclei/commit/6f2ade6a9b427c284c15a43445f9c7f055e60e5d (2026-04-10)
|
||||
- **Cryptographic Weakness** (medium) [CWE-338]: Replaces predictable math/rand PRNG with cryptographically secure crypto/rand in JS helper functions.
|
||||
- sink: `rand.Intn(255) / rand.Int63()`
|
||||
- fix: Replace predictable math/rand with crypto/rand
|
||||
- commit: https://github.com/projectdiscovery/nuclei/commit/44ef9ce34ffcfdfca3a96626abc73d99dd0e83ab (2026-03-15)
|
||||
- **Auth Bypass** (high) [CWE-347]: Caching signature verification results without cryptographic re-check allows a metadata index compromise to bypass template signature verification.
|
||||
- sink: `template.Verified, template.TemplateVerifier`
|
||||
- fix: cached verification data reuse
|
||||
- commit: https://github.com/projectdiscovery/nuclei/commit/4534e9cb3034ebe5cc7b0cecabe399b6fb9ce0e4 (2026-01-21)
|
||||
- **Race Condition** (medium) [CWE-362]: Fixes a race condition in workflow execution caused by shared context callbacks, which could lead to data corruption or crashes; the primary impact is reliability, not a direct security breach.
|
||||
- sink: `shared context callbacks in workflow execution`
|
||||
- fix: fix race condition by making workflow execution sequential
|
||||
- commit: https://github.com/projectdiscovery/nuclei/commit/24d1f58682027e23cb21a299a170abd2bdf20dc2 (2025-12-05)
|
||||
- **Auth Bypass** (high) [CWE-347]: Fixes template signature verification by centralizing signature extraction and requiring the signature to be at the end of the template, preventing bypass.
|
||||
- sink: `Verify`
|
||||
- fix: signature extraction and verification
|
||||
- commit: https://github.com/projectdiscovery/nuclei/commit/0da993afe6d41b4b1b814e8fad23a2acba13c60a (2024-08-19)
|
||||
- **Dependency Vulnerability** (medium) [CWE-1104]: Upgrades Alpine base image from 3.18.5 to 3.18.6 to fix known security vulnerabilities in bundled packages.
|
||||
- sink: `FROM alpine:3.18.5`
|
||||
- fix: Upgrade base image to patched version
|
||||
- commit: https://github.com/projectdiscovery/nuclei/commit/fcd5c6b111ddcb746525f88b7d0bf4b4abbc2529 (2024-03-15)
|
||||
- **Dependency Vulnerability** (medium) [CWE-1104]: Upgrades Alpine base image from 3.18.2 to 3.18.5 to fix known security vulnerabilities in bundled packages.
|
||||
- sink: `FROM alpine:3.18.2`
|
||||
- fix: Upgrade base image to patched version
|
||||
- commit: https://github.com/projectdiscovery/nuclei/commit/d93b4a01df9c218a36dd2fccfb1c2c1f96b181fe (2024-03-15)
|
||||
- **Dependency Vulnerability** (high) [CWE-1035]: Updates go-git to fix known vulnerabilities (CVE-2023-49569, CVE-2023-49568), which could be exploited when processing untrusted git data.
|
||||
- sink: `go-git library usage`
|
||||
- fix: dependency upgrade to patched version
|
||||
- commit: https://github.com/projectdiscovery/nuclei/commit/1700cdf4e23128a358066364062246b58c1c013f (2024-03-14)
|
||||
- **Code Execution via Unsigned Template** (high) [CWE-347]: Introduces a flag to disable unsigned templates, preventing execution of unverified templates that could lead to arbitrary code execution.
|
||||
- sink: `loading unsigned templates when -dut flag is set`
|
||||
- fix: Adds -disable-unsigned-templates flag to skip unsigned templates and report them separately
|
||||
- commit: https://github.com/projectdiscovery/nuclei/commit/fa56800fcca3c8c8fe8e8dec28584210ca1527de (2024-03-14)
|
||||
- **Auth Bypass** (medium) [CWE-347]: This commit introduces a flag to skip unsigned templates, closing a path where an attacker could execute untrusted templates by bypassing signature verification.
|
||||
- sink: `parsed.Verified`
|
||||
- fix: skip unverified templates when DisableUnsignedTemplates is set
|
||||
- commit: https://github.com/projectdiscovery/nuclei/commit/9bd4db3f74aedd067af568df4f9198a8a090f68b (2024-03-10)
|
||||
- **Code Execution** (high) [CWE-94]: Prevents execution of unverified code templates in workflows, mitigating code execution risk.
|
||||
- sink: `template.RequestsCode`
|
||||
- fix: require -code flag and verified templates for code templates in workflows
|
||||
- commit: https://github.com/projectdiscovery/nuclei/commit/e86f38299765b82ad724fdb701557e0eaff3884d (2024-03-01)
|
||||
- **SSRF** (high) [CWE-918]: Fixes SSRF by validating the actual LDAP controller host against the network policy instead of the domain name.
|
||||
- sink: `newLdapSession`
|
||||
- fix: host allowlist check on controller instead of domain
|
||||
- commit: https://github.com/projectdiscovery/nuclei/commit/a167e6c57b80f5dc7be231231b62d7c594ee2770 (2024-01-20)
|
||||
- **Sandbox Escape** (high) [CWE-94]: Disables eval and tightens file read validation in the JavaScript sandbox, preventing template-driven code execution and file access outside the sandbox.
|
||||
- sink: `eval function and file read in sandbox mode`
|
||||
- fix: Disable eval function and rewrite file validation in sandbox mode
|
||||
- commit: https://github.com/projectdiscovery/nuclei/commit/c35162c8ef061a96dd74b54c8f022c1a41cf5833 (2023-10-13)
|
||||
- **Path Traversal** (high) [CWE-22]: Adds network policy and blocks file:// protocol in headless mode unless -lfa is set, preventing local file disclosure.
|
||||
- sink: `file:// protocol access in headless browser`
|
||||
- fix: Network policy validation and file:// scheme blocking when local file access is disabled
|
||||
- commit: https://github.com/projectdiscovery/nuclei/commit/d3928e080d819f25306bfbaecc399f03516db5aa (2023-08-25)
|
||||
- **Deserialization of Untrusted Data** (medium) [CWE-502]: Fixes JSON deserialization by adding explicit UnmarshalJSON methods and correcting tags, preventing type confusion and potential logic bypasses.
|
||||
- sink: `UnmarshalJSON on user-controlled fields like Type and Name`
|
||||
- fix: Adds proper UnmarshalJSON implementations and corrects json tags to prevent type confusion
|
||||
- commit: https://github.com/projectdiscovery/nuclei/commit/85090b75317977bb9301444c9dfd8e4c2dba667a (2023-02-07)
|
||||
- **Sandbox Escape** (medium) [CWE-22]: The commit adds sandbox mode that restricts payload file paths to the template directory, preventing arbitrary file reads when sandbox is enabled.
|
||||
- sink: `loadPayloadsFromFile`
|
||||
- fix: path prefix validation against template directory and template path directory
|
||||
- commit: https://github.com/projectdiscovery/nuclei/commit/e7fb40a41308f6c41267e858d1781eb67f7e0572 (2022-11-16)
|
||||
- **Insecure File Permissions** (low) [CWE-732]: Fixes overly permissive file permissions on debug output files by changing from os.ModePerm (0777) to 0644.
|
||||
- sink: `os.OpenFile`
|
||||
- fix: restrict file mode to 0644
|
||||
- commit: https://github.com/projectdiscovery/nuclei/commit/af4854f90de728bb08689d5cae3dec4acfdb6b9a (2022-06-20)
|
||||
- **Security Misconfiguration** (medium) [CWE-16]: Prevents setting HTTP_PROXY environment variable unless explicitly enabled, avoiding potential proxy hijacking.
|
||||
- sink: `os.Setenv(types.HTTP_PROXY_ENV, proxyURL.String())`
|
||||
- fix: Added check for options.ProxyInternal before setting HTTP_PROXY environment variable
|
||||
- commit: https://github.com/projectdiscovery/nuclei/commit/3f5c055aca1499642caf4f40e8cf55ad32bd4da9 (2022-03-09)
|
||||
- **Sandbox Escape** (high) [CWE-250]: The commit restricts the use of the --no-sandbox flag to Linux root users, preventing sandbox escape vulnerabilities in other environments.
|
||||
- sink: `NoSandbox(true)`
|
||||
- fix: Conditionally disable sandbox only on Linux as root
|
||||
- commit: https://github.com/projectdiscovery/nuclei/commit/df55f7a2eb591a7949b5c66a9c54db54aa28f450 (2021-12-05)
|
||||
- **Path Traversal** (high) [CWE-22]: This commit fixes a zip-slip path traversal vulnerability by validating the extracted file path against the configured template directory.
|
||||
- sink: `os.OpenFile`
|
||||
- fix: path canonicalization and prefix check
|
||||
- commit: https://github.com/projectdiscovery/nuclei/commit/f9c214a66f37a00fc29fe64232b690e6285ec59c (2021-11-25)
|
||||
- **SSRF** (high) [CWE-918]: Adds validation and connectivity checks for SOCKS5 proxies before launching a scan, preventing SSRF through proxy configuration.
|
||||
- sink: `Proxy connection validation and loading`
|
||||
- fix: Proxy server validation and connectivity check before scan launch
|
||||
- commit: https://github.com/projectdiscovery/nuclei/commit/0e46d3e0410f89e4af41099f5cd38fa7f54ae54f (2021-11-10)
|
||||
- **Sandbox Escape** (high) [CWE-284]: This commit adds a sandbox flag that, when enabled, restricts the tengo scripting engine to safe modules, preventing sandbox escape and arbitrary command execution.
|
||||
- sink: `stdlib.GetModuleMap(stdlib.AllModuleNames()...)`
|
||||
- fix: Added sandbox flag to restrict imports to safe modules when sandbox is enabled
|
||||
- commit: https://github.com/projectdiscovery/nuclei/commit/cf2a98b03d76327c20fb0183b7f1c849eb692c91 (2020-12-13)
|
||||
- **Sandbox Escape** (high) [CWE-284]: This commit restricts the tengo scripting engine to a safe module list, preventing sandbox escape and arbitrary command execution via workflow templates.
|
||||
- sink: `stdlib.GetModuleMap(stdlib.AllModuleNames()...)`
|
||||
- fix: Restricted tengo script imports to a safe module list
|
||||
- commit: https://github.com/projectdiscovery/nuclei/commit/96049a32fa70aef0483d4180d386a57b3c2d973a (2020-12-13)
|
||||
**By component** (directories with the most fixes):
|
||||
|
||||
- `pkg/protocols/common/protocolstate` — 2 fixes: SSRF (2)
|
||||
|
||||
- [1c0f77d28e][c-1c0f77d28e] **fix(js/net): enforce network policy on proxied target in JS net dial** — SSRF, high [CWE-918] · inferred · 2026-10-18
|
||||
`pkg/js/libs/net/net.go` · sink `dialHTTPProxy` · fix: input validation
|
||||
- [d43c1f547f][c-d43c1f547f] **fix(headless): canonicalize IPv4-mapped IPv6 literals and re-validate dial targets** — SSRF, high [CWE-918] · inferred · 2026-10-13
|
||||
`pkg/protocols/common/protocolstate/headless.go` · sink `net.DialTimeout` · fix: canonicalization before validation
|
||||
- [d9dabbb4a1][c-d9dabbb4a1] **fix(headless): enforce network policy on ws and wss schemes (#7867)** — SSRF, high [CWE-918] · inferred · 2026-10-12
|
||||
`pkg/protocols/common/protocolstate/headless.go` · sink `isValidHost` · fix: canonicalization before validation
|
||||
- [a20aa26024][c-a20aa26024] **Fix pprof/auth exposure on http-api-endpoint and harden file permissions** — Information Disclosure, high [CWE-200] · inferred · 2026-08-03
|
||||
`internal/httpapi/apiendpoint.go` · sink `http.ListenAndServe` · fix: authentication verification
|
||||
- [fac0b7196d][c-fac0b7196d] **feat(templates): require signatures for javascript templates (#7514)** — Signature Verification Bypass, high [CWE-347] · verified (CVE-2026-76819, GHSA-vxg7-f2jj-jmqm) · 2026-07-03
|
||||
`pkg/catalog/loader/loader.go` · sink `t.HasJavascriptRequest` · fix: cryptographic verification
|
||||
- [ccbfb12bd0][c-ccbfb12bd0] **refactor(protocols): template rendering boundary (#7499)** — Code Execution, high [CWE-94] · verified (CVE-2026-76805, GHSA-jpvm-9frm-hjcq) · 2026-06-30
|
||||
`pkg/fuzz/execute.go` · sink `expressions.Evaluate` · fix: sandbox isolation
|
||||
- [3a8b65cb45][c-3a8b65cb45] **fix(js): reject unsandboxed ccache writes in krbforge (#7482)** — Sandbox Escape, high [CWE-693] · inferred · 2026-06-24
|
||||
`pkg/js/libs/krbforge/krbforge.go` · sink `OutputFile` · fix: sandbox isolation
|
||||
- [68daef44a7][c-68daef44a7] **fix(js): escape dbname in lib/pq URL (#7479)** — SQL Injection, high [CWE-89] · inferred · 2026-06-23
|
||||
`pkg/js/libs/postgres/postgres.go` · sink `fmt.Sprintf` (library call — the operation around it is the sink) · fix: context-aware output escaping
|
||||
- [634cecbb28][c-634cecbb28] **gate mysql allowAllFiles behind -lfa** — Arbitrary File Access, high [CWE-22] · verified (CVE-2026-76803, GHSA-xhmx-w2j4-rw3q) · 2026-06-19
|
||||
`pkg/js/libs/mysql/mysql.go` · sink `sql.Open` · fix: sandbox isolation
|
||||
- [20cbf0bd73][c-20cbf0bd73] **refactor: use path-aware filesystem containment checks (#7420)** — Path Traversal, high [CWE-22] · inferred · 2026-06-04
|
||||
`pkg/installer/template.go` · sink `filepath.Join` · fix: canonicalization before validation
|
||||
- [6f2ade6a9b][c-6f2ade6a9b] **fix(js): respect \`allow-local-file-access\` in \`require\` (#7332)** — Sandbox Escape, high [CWE-693] · inferred · 2026-04-10
|
||||
`pkg/js/compiler/pool.go` · sink `require.DefaultSourceLoader` · fix: sandbox isolation
|
||||
- [d221732016][c-d221732016] **fix(expressions): only eval template-authored expressions (#7221)** — Code Execution, high [CWE-94] · verified (CVE-2026-76805, GHSA-jpvm-9frm-hjcq) · 2026-03-16
|
||||
`pkg/protocols/common/expressions/expressions.go` · sink `FindExpressions` · fix: allowlist enforcement
|
||||
- [0da993afe6][c-0da993afe6] **Merge commit from fork** — Signature Verification Bypass, medium [CWE-347] · verified (CVE-2024-43405, GHSA-7h5p-mmpp-hgmm) · 2024-08-19
|
||||
`pkg/templates/signer/tmpl_signer.go` · sink `os.ReadFile` · fix: cryptographic verification
|
||||
- [e5154d362a][c-e5154d362a] **fixing payload load (#3927)** — Arbitrary File Access, high [CWE-22] · verified (CVE-2023-37896, GHSA-2xx4-jj5v-6mff) · 2023-07-14
|
||||
`v2/pkg/protocols/common/generators/load.go` · sink `loadPayloads` · fix: sandbox isolation
|
||||
|
||||
## Historical Vulnerability Classes
|
||||
|
||||
| Class | Fixes | Verified | Most recent fix |
|
||||
|---|---|---|---|
|
||||
| SSRF | 3 | 0 | [2026-10-18][c-1c0f77d28e] 1c0f77d28e |
|
||||
| Arbitrary File Access | 1 (1 component gone, not counted) | 2 | [2026-06-19][c-634cecbb28] 634cecbb28 |
|
||||
| Code Execution | 2 | 2 | [2026-06-30][c-ccbfb12bd0] ccbfb12bd0 |
|
||||
| Sandbox Escape | 2 | 0 | [2026-06-24][c-3a8b65cb45] 3a8b65cb45 |
|
||||
| Signature Verification Bypass | 2 | 2 | [2026-07-03][c-fac0b7196d] fac0b7196d |
|
||||
| Information Disclosure | 1 | 0 | [2026-08-03][c-a20aa26024] a20aa26024 |
|
||||
| Path Traversal | 1 | 0 | [2026-06-04][c-20cbf0bd73] 20cbf0bd73 |
|
||||
| SQL Injection | 1 | 0 | [2026-06-23][c-68daef44a7] 68daef44a7 |
|
||||
|
||||
## Known Advisories
|
||||
|
||||
### Linked to a fix commit in this history (5)
|
||||
|
||||
- **CVE-2026-76805** / GHSA-jpvm-9frm-hjcq (medium 5.3) CWE-200 — fixed in [ccbfb12bd0][c-ccbfb12bd0], [d221732016][c-d221732016]
|
||||
- Environment Variable Disclosure via Response-Derived Data in DAST/Fuzz Mode. A vulnerability in Nuclei's DAST/fuzz expression evaluation path allows a malicious target server to trigger disclosure of ...
|
||||
- **CVE-2026-76803** / GHSA-xhmx-w2j4-rw3q (medium 5.3) CWE-284 — fixed in [634cecbb28][c-634cecbb28]
|
||||
- Local File Read via MySQL Client Sandbox Bypass. A vulnerability in Nuclei's JavaScript MySQL client library allows arbitrary local file reads that bypass the `-allow-local-file-access` (`-lfa`) sandb...
|
||||
- **CVE-2026-76819** / GHSA-vxg7-f2jj-jmqm (high 8.6) CWE-94,CWE-787 — fixed in [fac0b7196d][c-fac0b7196d]
|
||||
- Arbitrary Code Execution via Goja JavaScript Engine Vulnerability. A vulnerability in the Goja JavaScript engine used by Nuclei's `javascript:` protocol allows arbitrary native code execution on the s...
|
||||
- **CVE-2024-43405** / GHSA-7h5p-mmpp-hgmm (high 7.4) CWE-78 — fixed in [0da993afe6][c-0da993afe6]
|
||||
- Nuclei Template Signature Verification Bypass. ## Summary A vulnerability has been identified in Nuclei's template signature verification system that could allow an attacker to bypass the signature ch...
|
||||
- **CVE-2023-37896** / GHSA-2xx4-jj5v-6mff (medium 5.9) CWE-22 — fixed in [e5154d362a][c-e5154d362a]
|
||||
- Nuclei < 2.9.9 - Sandbox restriction bypass. ## Overview Affected: < 2.9.9 (patched 2.9.9).
|
||||
|
||||
### Without a linked fix commit (6)
|
||||
|
||||
Published elsewhere, fixed before the history window, or not yet linked; full descriptions are in the JSON context.
|
||||
|
||||
| Advisory | Severity | Published | CWE | Summary |
|
||||
|---|---|---|---|---|
|
||||
| CVE-2026-76804 / GHSA-qgw5-7j4f-fg97 | medium 5.5 | 2026-07-16 | CWE-284 | Local File Read via Workflow File-Protocol Gate Bypass. A vulnerability in Nuclei's workfl... |
|
||||
| CVE-2026-76802 / GHSA-jpf4-98qj-qr67 | medium 4.7 | 2026-07-16 | CWE-78 | Arbitrary Command Execution via DAST Code Signature Bypass. A vulnerability in Nuclei's DA... |
|
||||
| CVE-2026-41645 / GHSA-jm34-66cf-qpvr | medium 5.3 | 2026-04-18 | CWE-94 | Environment variable disclosure via Response-Derived DSL Expressions. A vulnerability in N... |
|
||||
| CVE-2026-41646 / GHSA-29rg-wmcw-hpf4 | medium 5.5 | 2026-04-18 | CWE-284 | Local File Read via require() Module Loader Bypass. A vulnerability in Nuclei's JavaScript... |
|
||||
| CVE-2024-40641 / GHSA-c3q9-c27p-cw9h | high 7.4 | 2024-07-17 | CWE-78 | Unsigned code template execution through workflows in projectdiscovery/nuclei. ### Summary... |
|
||||
| CVE-2024-27920 / GHSA-w5wx-6g2r-r78q | high 7.4 | 2024-03-15 | CWE-78 | Unsigned code template execution through workflows in projectdiscovery/nuclei. ### Overvie... |
|
||||
|
||||
[c-df57ae6d29]: https://github.com/projectdiscovery/nuclei/commit/df57ae6d2955864fd92a1bd2565fe9e4e9a7592b
|
||||
[c-d43c1f547f]: https://github.com/projectdiscovery/nuclei/commit/d43c1f547f98ac56654f4335ad20af0cca4c229c
|
||||
[c-d9dabbb4a1]: https://github.com/projectdiscovery/nuclei/commit/d9dabbb4a19e897a6bc12334a030a43035b27b73
|
||||
[c-e5154d362a]: https://github.com/projectdiscovery/nuclei/commit/e5154d362af900e83b30fb79028bfab1a7f0c648
|
||||
[c-634cecbb28]: https://github.com/projectdiscovery/nuclei/commit/634cecbb289db494247c04a9c4ec6a113aef3cc0
|
||||
[c-ccbfb12bd0]: https://github.com/projectdiscovery/nuclei/commit/ccbfb12bd01447ba25f6e755dfb2bee677736da6
|
||||
[c-d221732016]: https://github.com/projectdiscovery/nuclei/commit/d2217320162d5782ca7cb95bef9dda17063818f3
|
||||
[c-a20aa26024]: https://github.com/projectdiscovery/nuclei/commit/a20aa260245e5db889c5a421d4a65aeb2a64bf46
|
||||
[c-1c0f77d28e]: https://github.com/projectdiscovery/nuclei/commit/1c0f77d28ed639a34c2036fa23c7503ffac0bf27
|
||||
[c-fac0b7196d]: https://github.com/projectdiscovery/nuclei/commit/fac0b7196d2fbca56c8af8ff8e1899c111041a37
|
||||
[c-3a8b65cb45]: https://github.com/projectdiscovery/nuclei/commit/3a8b65cb45f121fcdf418f60e5177ed9f250c122
|
||||
[c-68daef44a7]: https://github.com/projectdiscovery/nuclei/commit/68daef44a7eafd41c39690924620e418762909ef
|
||||
[c-20cbf0bd73]: https://github.com/projectdiscovery/nuclei/commit/20cbf0bd73893c1270582c9778b6b26a5cb11206
|
||||
[c-6f2ade6a9b]: https://github.com/projectdiscovery/nuclei/commit/6f2ade6a9b427c284c15a43445f9c7f055e60e5d
|
||||
[c-0da993afe6]: https://github.com/projectdiscovery/nuclei/commit/0da993afe6d41b4b1b814e8fad23a2acba13c60a
|
||||
|
||||
---
|
||||
_Fixed-issue fingerprints and CVE matches are derived from real data; LLM-written prose is advisory and should be verified against the cited commits._
|
||||
_Fixed-issue fingerprints and advisory matches are derived from git history and published advisories; the risk tables and pattern descriptions above are derived from them and should be verified against the cited commits._
|
||||
@@ -530,6 +530,16 @@ Description of the template.
|
||||
|
||||
You can go in-depth here on what the template actually does.
|
||||
|
||||
Description, impact and remediation may hold {{placeholders}} filled for
|
||||
each finding: named extractors, payloads, variables and DSL helpers
|
||||
(network helpers excluded), and the result fields host, port, ip, url,
|
||||
scheme, path, matched-at, matcher-name and extractor-name, which win over
|
||||
values of the same name. Use join(", ", name) for an extractor with
|
||||
several values, and brackets for a hyphenated name inside a helper:
|
||||
to_upper([matcher-name]). Unknown placeholders stay as written, and so
|
||||
does a field whose expression fails. Global matcher templates match on
|
||||
other templates' responses, so only the result fields fill their text.
|
||||
|
||||
|
||||
|
||||
Examples:
|
||||
@@ -543,6 +553,10 @@ description: Bower is a package manager which stores package information in the
|
||||
description: Subversion ALM for the enterprise before 8.8.2 allows reflected XSS at multiple locations
|
||||
```
|
||||
|
||||
```yaml
|
||||
description: Redis {{version}} on {{host}}:{{port}} accepts the default password
|
||||
```
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
@@ -559,6 +573,8 @@ Impact of the template.
|
||||
|
||||
You can go in-depth here on impact of the template.
|
||||
|
||||
Supports the same placeholders as description.
|
||||
|
||||
|
||||
|
||||
Examples:
|
||||
@@ -665,6 +681,8 @@ Remediation steps for the template.
|
||||
|
||||
You can go in-depth here on how to mitigate the problem found by this template.
|
||||
|
||||
Supports the same placeholders as description.
|
||||
|
||||
|
||||
|
||||
Examples:
|
||||
@@ -3757,6 +3775,8 @@ Part Definitions:
|
||||
- <code>req</code> - Headless request made from the client
|
||||
- <code>duration</code> - Latest measured operation duration in seconds
|
||||
- <code>resp,body,data</code> - Headless response received from client (default)
|
||||
- <code>header,all_headers</code> - Headless response headers
|
||||
- <code>status_code</code> - Status code received from the server
|
||||
|
||||
<hr />
|
||||
|
||||
|
||||
@@ -20,6 +20,8 @@ extend-exclude = [
|
||||
"vendor/",
|
||||
# Go checksum file
|
||||
"go.sum",
|
||||
# Generated history. Commit SHAs are not words.
|
||||
"SECURITY_CONTEXT.md",
|
||||
]
|
||||
|
||||
[default.extend-identifiers]
|
||||
|
||||
@@ -57,7 +57,8 @@
|
||||
# severity: low
|
||||
# # duplicate-issue-check (optional) flag to enable duplicate tracking issue check
|
||||
# duplicate-issue-check: false
|
||||
# # duplicate-issue-page-size (optional) controls how many issues to fetch per page when searching for duplicates
|
||||
# # duplicate-issue-page-size (optional) sets the number of issues to request per page when searching for duplicates
|
||||
# # (GitLab returns at most 100 issues per page)
|
||||
# duplicate-issue-page-size: 100
|
||||
# # duplicate-issue-max-pages (optional) limits how many pages to fetch when searching for duplicates (0 = no limit)
|
||||
# duplicate-issue-max-pages: 0
|
||||
|
||||
+6
-11
@@ -271,10 +271,10 @@ on extensive configurability, massive extensibility and ease of use.`)
|
||||
flagSet.StringSliceVarP(&options.Targets, "target", "u", nil, "target URLs/hosts to scan", goflags.CommaSeparatedStringSliceOptions),
|
||||
flagSet.StringVarP(&options.TargetsFilePath, "list", "l", "", "path to file containing a list of target URLs/hosts to scan (one per line)"),
|
||||
flagSet.StringVarP(&options.InlineTargetsList, "targets-inline", "", "", "inline multiline target list (for use in template profiles)"),
|
||||
flagSet.StringSliceVarP(&options.ExcludeTargets, "exclude-hosts", "eh", nil, "hosts to exclude to scan from the input list (ip, cidr, hostname)", goflags.FileCommaSeparatedStringSliceOptions),
|
||||
flagSet.StringSliceVarP(&options.ExcludeTargets, "exclude-hosts", "eh", nil, "hosts to exclude to scan from the input list (ip, cidr, hostname)", goflags.FileNormalizedOriginalStringSliceOptions),
|
||||
flagSet.StringVar(&options.Resume, "resume", "", "resume scan from and save to specified file (clustering will be disabled)"),
|
||||
flagSet.BoolVarP(&options.ScanAllIPs, "scan-all-ips", "sa", false, "scan all the IP's associated with dns record"),
|
||||
flagSet.StringSliceVarP(&options.IPVersion, "ip-version", "iv", nil, "IP version to scan of hostname (4,6) - (default 4)", goflags.CommaSeparatedStringSliceOptions),
|
||||
flagSet.StringSliceVarP(&options.IPVersion, "ip-version", "iv", nil, "IP version to scan of hostname (4,6); default uses dialer fallback, -sa scans all addresses", goflags.CommaSeparatedStringSliceOptions),
|
||||
flagSet.BoolVarP(&options.DisableURLNormalization, "disable-url-normalization", "dun", false, "keep targets exactly as supplied instead of collapsing urls that address the same resource"),
|
||||
flagSet.IntVarP(&options.MaxURLsPerPattern, "max-urls-per-pattern", "mup", 0, "scan at most this many urls sharing one structural shape, e.g. /user/1 and /user/2 (0 to scan all)"),
|
||||
)
|
||||
@@ -309,7 +309,7 @@ on extensive configurability, massive extensibility and ease of use.`)
|
||||
flagSet.BoolVarP(&options.EnableGlobalMatchersTemplates, "enable-global-matchers", "egm", false, "enable loading global matchers templates"),
|
||||
flagSet.BoolVar(&options.EnableFileTemplates, "file", false, "enable loading file templates"),
|
||||
flagSet.BoolVar(&options.EnableLLM, "llm", false, "enable llm matchers and extractors (semantic matching)"),
|
||||
flagSet.StringVar(&options.LLMProvider, "llm-provider", "openai", "llm provider for semantic matching (openai, ollama, llamacpp, vllm, lmstudio, groq, openrouter, together, orcarouter)"),
|
||||
flagSet.StringVar(&options.LLMProvider, "llm-provider", "openai", "llm provider for semantic matching (openai, ollama, llamacpp, vllm, lmstudio, groq, openrouter, together, orcarouter, jev)"),
|
||||
flagSet.StringVar(&options.LLMBaseURL, "llm-base-url", "", "openai-compatible endpoint for semantic matching (overrides -llm-provider, e.g. a local model)"),
|
||||
flagSet.StringVar(&options.LLMModel, "llm-model", "", "model used for semantic matching"),
|
||||
flagSet.IntVar(&options.LLMTimeout, "llm-timeout", 30, "time in seconds to wait for a single llm call"),
|
||||
@@ -355,6 +355,7 @@ on extensive configurability, massive extensibility and ease of use.`)
|
||||
flagSet.StringVarP(&options.JSONLExport, "jsonl-export", "jle", "", "file to export results in JSONL(ine) format"),
|
||||
flagSet.StringVarP(&options.PDFExport, "pdf-export", "pe", "", "file to export results in PDF format"),
|
||||
flagSet.StringSliceVarP(&options.Redact, "redact", "rd", nil, "redact given list of keys from query parameter, request header and body", goflags.CommaSeparatedStringSliceOptions),
|
||||
flagSet.BoolVarP(&options.NoRedact, "no-redact", "nrd", false, "disable the built-in redaction of credential headers (Authorization, Cookie, Set-Cookie, ...) in output; keys given with -redact are still redacted"),
|
||||
)
|
||||
|
||||
flagSet.CreateGroup("configs", "Configurations",
|
||||
@@ -381,9 +382,7 @@ on extensive configurability, massive extensibility and ease of use.`)
|
||||
flagSet.BoolVar(&options.ZTLS, "ztls", false, "use ztls library with autofallback to standard one for tls13 [Deprecated] autofallback to ztls is enabled by default"), //nolint:all
|
||||
flagSet.StringVar(&options.SNI, "sni", "", "tls sni hostname to use (default: input domain name)"),
|
||||
flagSet.DurationVarP(&options.DialerKeepAlive, "dialer-keep-alive", "dka", 0, "keep-alive duration for network requests."),
|
||||
flagSet.BoolVarP(&options.AllowLocalFileAccess, "allow-local-file-access", "lfa", false, "allows local file access from additional allowed directories (cwd and --allowed-paths)"),
|
||||
flagSet.StringSliceVarP(&options.AllowedPaths, "allowed-paths", "ap", nil, "additional filesystem roots allowed with -lfa (repeatable)", goflags.CommaSeparatedStringSliceOptions),
|
||||
flagSet.BoolVar(&options.DisableSandbox, "no-sandbox", false, "disable the OS-level filesystem sandbox and the code template sandbox"),
|
||||
flagSet.BoolVarP(&options.AllowLocalFileAccess, "allow-local-file-access", "lfa", false, "allow all templates in the run to read any file on the system (not just payloads)"),
|
||||
flagSet.BoolVarP(&options.RestrictLocalNetworkAccess, "restrict-local-network-access", "lna", false, "blocks connections to the local / private network"),
|
||||
flagSet.StringVarP(&options.Interface, "interface", "i", "", "network interface to use for network scan"),
|
||||
flagSet.StringVarP(&options.AttackType, "attack-type", "at", "", "type of payload combinations to perform (batteringram,pitchfork,clusterbomb)"),
|
||||
@@ -472,6 +471,7 @@ on extensive configurability, massive extensibility and ease of use.`)
|
||||
flagSet.BoolVar(&options.PreflightPortScan, "preflight-portscan", false, "run preflight resolve + TCP portscan and filter targets before scanning (disabled by default)"),
|
||||
flagSet.BoolVar(&options.DisableStdin, "no-stdin", false, "disable stdin processing"),
|
||||
flagSet.BoolVar(&options.EnableHTTPCache, "http-cache", false, "enable HTTP cache (RFC 9111) for HTTP requests"),
|
||||
flagSet.BoolVarP(&options.AutoCalibrate, "auto-calibrate", "ac", false, "drop HTTP matches on a host's catch-all page (answers missing paths with 2xx/3xx)"),
|
||||
)
|
||||
|
||||
flagSet.CreateGroup("headless", "Headless",
|
||||
@@ -589,11 +589,6 @@ Additional documentation is available at: https://docs.nuclei.sh/getting-started
|
||||
resetCallback()
|
||||
}
|
||||
|
||||
// The CLI owns its process, so it applies the process-wide OS filesystem
|
||||
// sandbox by default. -no-sandbox (DisableSandbox) still turns it off. SDK
|
||||
// embedders do not get it unless they ask for it.
|
||||
options.EnableProcessSandbox = true
|
||||
|
||||
// when fuzz flag is enabled, set the dast flag to true
|
||||
if fuzzFlag {
|
||||
// backwards compatibility for fuzz flag
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/projectdiscovery/gologger"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/protocolinit"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/types"
|
||||
)
|
||||
|
||||
const processSandboxChildEnv = "NUCLEI_PROCESS_SANDBOX_CHILD"
|
||||
|
||||
// TestCLIProcessSandboxWiring checks that the CLI turns the process-wide
|
||||
// sandbox on by default and that -no-sandbox turns it off. readConfig parses
|
||||
// os.Args and touches config dirs, so it runs in an isolated child process.
|
||||
func TestCLIProcessSandboxWiring(t *testing.T) {
|
||||
if os.Getenv(processSandboxChildEnv) == "1" {
|
||||
options = &types.Options{Logger: gologger.DefaultLogger}
|
||||
os.Args = append([]string{os.Args[0], "-disable-update-check"}, strings.Fields(os.Getenv("NUCLEI_TEST_ARGS"))...)
|
||||
readConfig()
|
||||
fmt.Printf("process-sandbox=%v\n", protocolinit.ProcessSandboxEnabled(options))
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
args string
|
||||
want string
|
||||
}{
|
||||
{args: "", want: "process-sandbox=true"},
|
||||
{args: "-no-sandbox", want: "process-sandbox=false"},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run("args="+test.args, func(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
tempRoot := filepath.Join(root, "tmp")
|
||||
if err := os.Mkdir(tempRoot, 0o700); err != nil {
|
||||
t.Fatalf("create temporary root: %v", err)
|
||||
}
|
||||
cmd := exec.Command(os.Args[0], "-test.run=^TestCLIProcessSandboxWiring$", "-test.count=1")
|
||||
cmd.Env = isolatedNucleiStorageEnv(root, tempRoot,
|
||||
processSandboxChildEnv+"=1",
|
||||
"NUCLEI_TEST_ARGS="+test.args,
|
||||
)
|
||||
output, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
t.Fatalf("child failed: %v\n%s", err, output)
|
||||
}
|
||||
if !strings.Contains(string(output), test.want) {
|
||||
t.Fatalf("expected %q in child output:\n%s", test.want, output)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -18,10 +18,11 @@ require (
|
||||
github.com/alecthomas/chroma v0.10.0
|
||||
github.com/alexsnet/go-vnc v0.1.0
|
||||
github.com/alitto/pond v1.9.2
|
||||
github.com/andybalholm/brotli v1.2.0
|
||||
github.com/andygrunwald/go-jira v1.16.1
|
||||
github.com/antchfx/htmlquery v1.3.5
|
||||
github.com/antchfx/htmlquery v1.3.7
|
||||
github.com/antchfx/xmlquery v1.4.4
|
||||
github.com/antchfx/xpath v1.3.6
|
||||
github.com/antchfx/xpath v1.3.9
|
||||
github.com/aws/aws-sdk-go-v2 v1.41.5
|
||||
github.com/aws/aws-sdk-go-v2/config v1.31.16
|
||||
github.com/aws/aws-sdk-go-v2/credentials v1.18.20
|
||||
@@ -33,10 +34,11 @@ require (
|
||||
github.com/clbanning/mxj/v2 v2.7.0
|
||||
github.com/ditashi/jsbeautifier-go v0.0.0-20141206144643-2520a8026a9c
|
||||
github.com/docker/go-units v0.5.0
|
||||
github.com/dsnet/compress v0.0.2-0.20230904184137-39efe44ab707
|
||||
github.com/elazarl/goproxy v1.7.2
|
||||
github.com/fatih/structs v1.1.0
|
||||
github.com/fullstorydev/grpcurl v1.9.3
|
||||
github.com/getkin/kin-openapi v0.144.0
|
||||
github.com/getkin/kin-openapi v0.149.0
|
||||
github.com/getsops/sops/v3 v3.9.2
|
||||
github.com/go-echarts/go-echarts/v2 v2.6.0
|
||||
github.com/go-git/go-git/v5 v5.19.2
|
||||
@@ -61,7 +63,7 @@ require (
|
||||
github.com/jhump/protoreflect v1.17.0
|
||||
github.com/julienschmidt/httprouter v1.3.0
|
||||
github.com/kitabisa/go-ci v1.0.3
|
||||
github.com/landlock-lsm/go-landlock v0.9.0
|
||||
github.com/klauspost/compress v1.18.7
|
||||
github.com/leslie-qiwa/flat v0.0.0-20230424180412-f9d1cf014baa
|
||||
github.com/lib/pq v1.12.3
|
||||
github.com/logrusorgru/aurora/v4 v4.0.0
|
||||
@@ -76,7 +78,7 @@ require (
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/praetorian-inc/fingerprintx v1.1.15
|
||||
github.com/projectdiscovery/clistats v0.1.7
|
||||
github.com/projectdiscovery/dsl v0.8.24
|
||||
github.com/projectdiscovery/dsl v0.9.0
|
||||
github.com/projectdiscovery/fastdialer v0.6.0
|
||||
github.com/projectdiscovery/fasttemplate v0.0.2
|
||||
github.com/projectdiscovery/gcache v0.0.0-20241015120333-12546c6e3f4c
|
||||
@@ -86,8 +88,8 @@ require (
|
||||
github.com/projectdiscovery/goja_nodejs v0.0.0-20260618132410-8519f75f703d
|
||||
github.com/projectdiscovery/gologger v1.1.73
|
||||
github.com/projectdiscovery/gostruct v0.0.2
|
||||
github.com/projectdiscovery/govaluate v0.0.0-20260615100919-5ee2581bbf7e
|
||||
github.com/projectdiscovery/gozero v0.1.1-0.20261026122302-786e195b6314
|
||||
github.com/projectdiscovery/govaluate v0.0.0-20261102102118-9294133b15a2
|
||||
github.com/projectdiscovery/gozero v0.1.1-0.20260530071156-fa1dad563d76
|
||||
github.com/projectdiscovery/hmap v0.0.102
|
||||
github.com/projectdiscovery/httpx v1.12.0
|
||||
github.com/projectdiscovery/interactsh v1.4.1
|
||||
@@ -103,8 +105,8 @@ require (
|
||||
github.com/projectdiscovery/tlsx v1.4.3-0.20261020052910-acb80c2c7c75
|
||||
github.com/projectdiscovery/uncover v1.2.1
|
||||
github.com/projectdiscovery/useragent v0.0.109
|
||||
github.com/projectdiscovery/utils v0.11.12-0.20261025172519-64b3c221cfe5
|
||||
github.com/projectdiscovery/wappalyzergo v0.3.5
|
||||
github.com/projectdiscovery/utils v0.11.13-0.20261103094816-5c0b20e35350
|
||||
github.com/projectdiscovery/wappalyzergo v0.3.6
|
||||
github.com/projectdiscovery/yamldoc-go v1.0.7
|
||||
github.com/redis/go-redis/v9 v9.19.0
|
||||
github.com/remeh/sizedwaitgroup v1.0.0
|
||||
@@ -114,6 +116,7 @@ require (
|
||||
github.com/segmentio/ksuid v1.0.4
|
||||
github.com/shurcooL/graphql v0.0.0-20230722043721-ed46e5a46466
|
||||
github.com/sijms/go-ora/v2 v2.9.0
|
||||
github.com/spaolacci/murmur3 v1.1.0
|
||||
github.com/spf13/cast v1.10.0
|
||||
github.com/stretchr/testify v1.12.1
|
||||
github.com/syndtr/goleveldb v1.0.0
|
||||
@@ -176,7 +179,6 @@ require (
|
||||
github.com/alecthomas/kingpin/v2 v2.4.0 // indirect
|
||||
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
|
||||
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect
|
||||
github.com/andybalholm/brotli v1.2.0 // indirect
|
||||
github.com/andybalholm/cascadia v1.3.4 // indirect
|
||||
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.8 // indirect
|
||||
@@ -240,7 +242,6 @@ require (
|
||||
github.com/docker/cli v29.2.0+incompatible // indirect
|
||||
github.com/docker/go-connections v0.7.0 // indirect
|
||||
github.com/dop251/goja v0.0.0-20260311135729-065cd970411c // indirect
|
||||
github.com/dsnet/compress v0.0.2-0.20230904184137-39efe44ab707 // indirect
|
||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||
github.com/ebitengine/purego v0.10.0 // indirect
|
||||
github.com/emersion/go-sasl v0.0.0-20241020182733-b788ff22d5a6 // indirect
|
||||
@@ -324,7 +325,6 @@ require (
|
||||
github.com/kaiakz/ubuffer v0.0.0-20200803053910-dd1083087166 // indirect
|
||||
github.com/kataras/jwt v0.1.10 // indirect
|
||||
github.com/kevinburke/ssh_config v1.2.0 // indirect
|
||||
github.com/klauspost/compress v1.18.7 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
|
||||
github.com/klauspost/pgzip v1.2.6 // indirect
|
||||
github.com/kylelemons/godebug v1.1.0 // indirect
|
||||
@@ -386,14 +386,13 @@ require (
|
||||
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
||||
github.com/ryanuber/go-glob v1.0.0 // indirect
|
||||
github.com/saintfish/chardet v0.0.0-20230101081208-5e3ef4b5456d // indirect
|
||||
github.com/santhosh-tekuri/jsonschema/v6 v6.0.2 // indirect
|
||||
github.com/santhosh-tekuri/jsonschema/v6 v6.0.3 // indirect
|
||||
github.com/sergi/go-diff v1.4.0 // indirect
|
||||
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
|
||||
github.com/shirou/gopsutil/v4 v4.26.3 // indirect
|
||||
github.com/sirupsen/logrus v1.10.2 // indirect
|
||||
github.com/skeema/knownhosts v1.3.1 // indirect
|
||||
github.com/sorairolake/lzip-go v0.3.8 // indirect
|
||||
github.com/spaolacci/murmur3 v1.1.0 // indirect
|
||||
github.com/spf13/afero v1.15.0 // indirect
|
||||
github.com/spf13/pflag v1.0.10 // indirect
|
||||
github.com/spiffe/go-spiffe/v2 v2.7.0 // indirect
|
||||
@@ -468,7 +467,6 @@ require (
|
||||
gopkg.in/corvus-ch/zbase32.v1 v1.0.0 // indirect
|
||||
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||
gopkg.in/warnings.v0 v0.1.2 // indirect
|
||||
kernel.org/pub/linux/libs/security/libcap/psx v1.2.77 // indirect
|
||||
mellium.im/sasl v0.3.2 // indirect
|
||||
software.sslmate.com/src/go-pkcs12 v0.7.2 // indirect
|
||||
)
|
||||
|
||||
@@ -180,14 +180,13 @@ github.com/andygrunwald/go-jira v1.16.1 h1:WoQEar5XoDRAibOgKzTFELlPNlKAtnfWr296R
|
||||
github.com/andygrunwald/go-jira v1.16.1/go.mod h1:UQH4IBVxIYWbgagc0LF/k9FRs9xjIiQ8hIcC6HfLwFU=
|
||||
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8=
|
||||
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4=
|
||||
github.com/antchfx/htmlquery v1.3.5 h1:aYthDDClnG2a2xePf6tys/UyyM/kRcsFRm+ifhFKoU0=
|
||||
github.com/antchfx/htmlquery v1.3.5/go.mod h1:5oyIPIa3ovYGtLqMPNjBF2Uf25NPCKsMjCnQ8lvjaoA=
|
||||
github.com/antchfx/htmlquery v1.3.7 h1:KCUklE1EO/xm6iS3CWx6iatFlcnENBk4I4UYa2pBmLU=
|
||||
github.com/antchfx/htmlquery v1.3.7/go.mod h1:/uBTMnFEl6LaBlIgw3KZ+c061tAQdlfbCXObZoxwQf4=
|
||||
github.com/antchfx/xmlquery v1.4.4 h1:mxMEkdYP3pjKSftxss4nUHfjBhnMk4imGoR96FRY2dg=
|
||||
github.com/antchfx/xmlquery v1.4.4/go.mod h1:AEPEEPYE9GnA2mj5Ur2L5Q5/2PycJ0N9Fusrx9b12fc=
|
||||
github.com/antchfx/xpath v1.3.3/go.mod h1:i54GszH55fYfBmoZXapTHN8T8tkcHfRgLyVwwqzXNcs=
|
||||
github.com/antchfx/xpath v1.3.5/go.mod h1:i54GszH55fYfBmoZXapTHN8T8tkcHfRgLyVwwqzXNcs=
|
||||
github.com/antchfx/xpath v1.3.6 h1:s0y+ElRRtTQdfHP609qFu0+c6bglDv20pqOViQjjdPI=
|
||||
github.com/antchfx/xpath v1.3.6/go.mod h1:i54GszH55fYfBmoZXapTHN8T8tkcHfRgLyVwwqzXNcs=
|
||||
github.com/antchfx/xpath v1.3.9 h1:muXJSod6jRzhsiUjvduNSxsRSptFZ2GOJ1oMD1QkPSA=
|
||||
github.com/antchfx/xpath v1.3.9/go.mod h1:i54GszH55fYfBmoZXapTHN8T8tkcHfRgLyVwwqzXNcs=
|
||||
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
|
||||
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
|
||||
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3dyBCFEj5IhUbnKptjxatkF07cF2ak3yi77so=
|
||||
@@ -427,8 +426,8 @@ github.com/gaissmai/bart v0.30.0 h1:K1oTSQ6Nf76bhrgxeTqzZa4hE0M9x4xDfL6n6UG67Sc=
|
||||
github.com/gaissmai/bart v0.30.0/go.mod h1:GREWQfTLRWz/c5FTOsIw+KkscuFkIV5t8Rp7Nd1Td5c=
|
||||
github.com/geoffgarside/ber v1.2.0 h1:/loowoRcs/MWLYmGX9QtIAbA+V/FrnVLsMMPhwiRm64=
|
||||
github.com/geoffgarside/ber v1.2.0/go.mod h1:jVPKeCbj6MvQZhwLYsGwaGI52oUorHoHKNecGT85ZCc=
|
||||
github.com/getkin/kin-openapi v0.144.0 h1:hIRcTH+KjLfkLpYU6bSSfdFpi0fZi1fp+hSPi4aQu9Y=
|
||||
github.com/getkin/kin-openapi v0.144.0/go.mod h1:3BH9M9XDe/y9M5DSvEocVYAYq1w0qrhJHjC/vZi0AaY=
|
||||
github.com/getkin/kin-openapi v0.149.0 h1:ZbhmVJ4yq5RZDUsyP8lcBcGMsjsaTqXEFt6isdtMDfA=
|
||||
github.com/getkin/kin-openapi v0.149.0/go.mod h1:1+BHDzstro+P5CKtPy1X4PfofnFgmRe6uvMy9+r9fKY=
|
||||
github.com/getsops/gopgagent v0.0.0-20240527072608-0c14999532fe h1:QKe/kmAYbndxwu91TcjHERsnMh5SgOB1x/qicvOdUJ8=
|
||||
github.com/getsops/gopgagent v0.0.0-20240527072608-0c14999532fe/go.mod h1:awFzISqLJoZLm+i9QQ4SgMNHDqljH6jWV0B36V5MrUM=
|
||||
github.com/getsops/sops/v3 v3.9.2 h1:Cuuahc/UGu7W3+NXd+mrl+2oXGxxj/jIPsw6Ah2CbxA=
|
||||
@@ -773,8 +772,6 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
|
||||
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
|
||||
github.com/landlock-lsm/go-landlock v0.9.0 h1:2q8G8yx9Hsd5bV+R6PJfgQl0zszNxC8KO+SIqGwfxlw=
|
||||
github.com/landlock-lsm/go-landlock v0.9.0/go.mod h1:mn5GSi81Jf7yMs5WSi+SUi4sUeNLUGVdbT4Id6wXNQw=
|
||||
github.com/ledongthuc/pdf v0.0.0-20220302134840-0c2507a12d80/go.mod h1:imJHygn/1yfhB7XSJJKlFZKl/J+dCPAknuiaGOshXAs=
|
||||
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
|
||||
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
|
||||
@@ -937,8 +934,8 @@ github.com/projectdiscovery/cdncheck v1.3.2 h1:I453ZWNBeG0WWIy3wi9412l4PTzorLgeb
|
||||
github.com/projectdiscovery/cdncheck v1.3.2/go.mod h1:5IkUMMlcGaeg1DWW5oJVd3r9X3EpJ88j5HxBeF4Me9M=
|
||||
github.com/projectdiscovery/clistats v0.1.7 h1:NXf4lUzx1QcbJd6QycNwwYHTv2FsW9MchQ2LsgSL6C0=
|
||||
github.com/projectdiscovery/clistats v0.1.7/go.mod h1:RxRGxhMzkT344VTTvZWIrojurUXdQQRN1yfwgg/88I8=
|
||||
github.com/projectdiscovery/dsl v0.8.24 h1:rN2w6LSIjA16qKGRjyj70oxdwXGaspe6sAjEkP7F2fk=
|
||||
github.com/projectdiscovery/dsl v0.8.24/go.mod h1:V+EludvS5PS19UNMlM3CuBwZ+sFnMaQhCFGxysDUanQ=
|
||||
github.com/projectdiscovery/dsl v0.9.0 h1:i1KyCbKJyKfHkgdbfh0JkWdd14APUjpEYf+GaYANlCg=
|
||||
github.com/projectdiscovery/dsl v0.9.0/go.mod h1:ntNFkkiYCTEosGFTbApA61RMrvJTCjnakPxnWj56MyY=
|
||||
github.com/projectdiscovery/fastdialer v0.6.0 h1:4ZeFQ6LyRH4D8e3qO/yzqIP4Cf9Fr0DduaVpJD6ENnE=
|
||||
github.com/projectdiscovery/fastdialer v0.6.0/go.mod h1:FpHwa9S5PUgfPbh+irOm+cdU6AO631XidxkhPwPv7yY=
|
||||
github.com/projectdiscovery/fasttemplate v0.0.2 h1:h2cISk5xDhlJEinlBQS6RRx0vOlOirB2y3Yu4PJzpiA=
|
||||
@@ -959,10 +956,10 @@ github.com/projectdiscovery/gologger v1.1.73 h1:WX2nzq29cL7HdvOHqIttacoid/5lMwap
|
||||
github.com/projectdiscovery/gologger v1.1.73/go.mod h1:mJwODZcFDg70ihINpOvZevmBtgvpP8H9/l8Y+OPhZPY=
|
||||
github.com/projectdiscovery/gostruct v0.0.2 h1:s8gP8ApugGM4go1pA+sVlPDXaWqNP5BBDDSv7VEdG1M=
|
||||
github.com/projectdiscovery/gostruct v0.0.2/go.mod h1:H86peL4HKwMXcQQtEa6lmC8FuD9XFt6gkNR0B/Mu5PE=
|
||||
github.com/projectdiscovery/govaluate v0.0.0-20260615100919-5ee2581bbf7e h1:vxzgQlz2Cy/YvizYDQx9OhucBcmBotfDhbQ4yCY2vfA=
|
||||
github.com/projectdiscovery/govaluate v0.0.0-20260615100919-5ee2581bbf7e/go.mod h1:xH7bPwHxUlz1yx9UlVeTF+UVCUaKhTnZgaxHb5z362E=
|
||||
github.com/projectdiscovery/gozero v0.1.1-0.20261026122302-786e195b6314 h1:LxsDXTuF19qS90pVc1/iLY0BNL9ZEyZjBU6g/K0RB/M=
|
||||
github.com/projectdiscovery/gozero v0.1.1-0.20261026122302-786e195b6314/go.mod h1:RFHYWR70/YBV74h/0P2l0Crht6lHq8zhJfAluVg97OI=
|
||||
github.com/projectdiscovery/govaluate v0.0.0-20261102102118-9294133b15a2 h1:aSLbDvrJQPlp4HvojU+bTU5XV8xdAVCjoc5gX1Wfbw4=
|
||||
github.com/projectdiscovery/govaluate v0.0.0-20261102102118-9294133b15a2/go.mod h1:Z3VjpUJV1pnXDwvAddA8aZ4e839SoeftB7CSdZntAVI=
|
||||
github.com/projectdiscovery/gozero v0.1.1-0.20260530071156-fa1dad563d76 h1:AN70bbi6BBs7KpIM9w0LxygUN7uzT/oH+owDIQ+Fz/k=
|
||||
github.com/projectdiscovery/gozero v0.1.1-0.20260530071156-fa1dad563d76/go.mod h1:cWHYnRXoYWHtTpOYyAp5laGYX8GH8ITUhgQaP8G/8FA=
|
||||
github.com/projectdiscovery/hmap v0.0.102 h1:ybPuf7UQvuOLiHLOUbVMvd+PSlItQU5iQpP1Erl8kaU=
|
||||
github.com/projectdiscovery/hmap v0.0.102/go.mod h1:IZ92wXFmxYpdn0euZ7VFmypzOBNDwq8c3yRyIIol6XE=
|
||||
github.com/projectdiscovery/httpx v1.12.0 h1:NN5iDrw7NjPBDlACdjac4lePTQmZ5aOmgOzptMpP44c=
|
||||
@@ -1001,10 +998,10 @@ github.com/projectdiscovery/uncover v1.2.1 h1:8U46T/96CLT7BPoXBgkTvWqB06lOyeTSLv
|
||||
github.com/projectdiscovery/uncover v1.2.1/go.mod h1:0p8onrWxfpXQEYs90ZDzTSpu1107gWmodX1NWqu/+z4=
|
||||
github.com/projectdiscovery/useragent v0.0.109 h1:b86BPdZvmgbJousa04jAugDRY4Y+rAvEamE0TFCPmeE=
|
||||
github.com/projectdiscovery/useragent v0.0.109/go.mod h1:sRyBqDAcD31RKYrO8fyXGowLd36fNwY1g0MNW9mp7zk=
|
||||
github.com/projectdiscovery/utils v0.11.12-0.20261025172519-64b3c221cfe5 h1:AOspf7ScbwZr8A2YnjCFd4ZJAMSFqzfEaIJIbJPuu10=
|
||||
github.com/projectdiscovery/utils v0.11.12-0.20261025172519-64b3c221cfe5/go.mod h1:TJgsyVjB02CavwZVFzUzPg6YOSJXQxLhL808JCiQKlU=
|
||||
github.com/projectdiscovery/wappalyzergo v0.3.5 h1:UZradYF1GIcruSIV5wwo/Coph9/VnM17oajLD9eXR2U=
|
||||
github.com/projectdiscovery/wappalyzergo v0.3.5/go.mod h1:4E6+fh/ckaY3wo5tlM7lNYSkhuTYRHzu2YmGIRraXP0=
|
||||
github.com/projectdiscovery/utils v0.11.13-0.20261103094816-5c0b20e35350 h1:uXqpYa6XKV9dCvoti9PbSgIWIsBKPu5YKMywB9G4q0Q=
|
||||
github.com/projectdiscovery/utils v0.11.13-0.20261103094816-5c0b20e35350/go.mod h1:TJgsyVjB02CavwZVFzUzPg6YOSJXQxLhL808JCiQKlU=
|
||||
github.com/projectdiscovery/wappalyzergo v0.3.6 h1:1FXCMeCa1xVu2zaW+eeBcbVxtlMStqGOlKcMLyh2pzI=
|
||||
github.com/projectdiscovery/wappalyzergo v0.3.6/go.mod h1:4E6+fh/ckaY3wo5tlM7lNYSkhuTYRHzu2YmGIRraXP0=
|
||||
github.com/projectdiscovery/yamldoc-go v1.0.7 h1:Odmjd1o4EkMff2F6QHi1dIYPIQPZUFy24YqmQCprmTk=
|
||||
github.com/projectdiscovery/yamldoc-go v1.0.7/go.mod h1:nqD1iPMcofpRA1DbXavPByJhWURrshT+l8WN9XjyQag=
|
||||
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
|
||||
@@ -1057,8 +1054,8 @@ github.com/saintfish/chardet v0.0.0-20230101081208-5e3ef4b5456d h1:hrujxIzL1woJ7
|
||||
github.com/saintfish/chardet v0.0.0-20230101081208-5e3ef4b5456d/go.mod h1:uugorj2VCxiV1x+LzaIdVa9b4S4qGAcH6cbhh4qVxOU=
|
||||
github.com/sandrolain/httpcache v1.4.0 h1:Jf4Vx62X2ybvNPSpPvI1kT3xvMdDG1AsApQjOQKO9E0=
|
||||
github.com/sandrolain/httpcache v1.4.0/go.mod h1:kHBuXveitSn39SNPBhdf/ybG272X706HJ2RJqOQ+Em0=
|
||||
github.com/santhosh-tekuri/jsonschema/v6 v6.0.2 h1:KRzFb2m7YtdldCEkzs6KqmJw4nqEVZGK7IN2kJkjTuQ=
|
||||
github.com/santhosh-tekuri/jsonschema/v6 v6.0.2/go.mod h1:JXeL+ps8p7/KNMjDQk3TCwPpBy0wYklyWTfbkIzdIFU=
|
||||
github.com/santhosh-tekuri/jsonschema/v6 v6.0.3 h1:1EYB5IzjZawrrnELUi78f9fPu57HuXjmddZPjrls/28=
|
||||
github.com/santhosh-tekuri/jsonschema/v6 v6.0.3/go.mod h1:JXeL+ps8p7/KNMjDQk3TCwPpBy0wYklyWTfbkIzdIFU=
|
||||
github.com/segmentio/ksuid v1.0.4 h1:sBo2BdShXjmcugAMwjugoGUdUV0pcxY5mW4xKRn3v4c=
|
||||
github.com/segmentio/ksuid v1.0.4/go.mod h1:/XUiZBD3kVx5SmUOl55voK5yeAbBNNIed+2O73XgrPE=
|
||||
github.com/sergi/go-diff v1.4.0 h1:n/SP9D5ad1fORl+llWyN+D6qoUETXNZARKjyY2/KVCw=
|
||||
@@ -1745,8 +1742,6 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh
|
||||
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
||||
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
|
||||
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
|
||||
kernel.org/pub/linux/libs/security/libcap/psx v1.2.77 h1:Z06sMOzc0GNCwp6efaVrIrz4ywGJ1v+DP0pjVkOfDuA=
|
||||
kernel.org/pub/linux/libs/security/libcap/psx v1.2.77/go.mod h1:+l6Ee2F59XiJ2I6WR5ObpC1utCQJZ/VLsEbQCD8RG24=
|
||||
mellium.im/sasl v0.3.2 h1:PT6Xp7ccn9XaXAnJ03FcEjmAn7kK1x7aoXV6F+Vmrl0=
|
||||
mellium.im/sasl v0.3.2/go.mod h1:NKXDi1zkr+BlMHLQjY3ofYuU4KSPFxknb8mfEu6SveY=
|
||||
moul.io/http2curl v1.0.0 h1:6XwpyZOYsgZJrU8exnG87ncVkU1FVCcTRpwzOkTDUi8=
|
||||
|
||||
@@ -39,6 +39,9 @@ func (r *Runner) initializeTemplatesHTTPInput() (*hybrid.HybridMap, error) {
|
||||
}
|
||||
httpxOptions.RetryMax = r.options.Retries
|
||||
httpxOptions.Timeout = time.Duration(r.options.Timeout) * time.Second
|
||||
if len(r.options.InternalResolversList) > 0 {
|
||||
httpxOptions.Resolvers = r.options.InternalResolversList
|
||||
}
|
||||
|
||||
dialers := protocolstate.GetDialersWithId(r.options.ExecutionId)
|
||||
if dialers == nil {
|
||||
|
||||
+35
-1
@@ -2,8 +2,12 @@ package runner
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/projectdiscovery/gologger"
|
||||
|
||||
llmclient "github.com/projectdiscovery/nuclei/v3/pkg/operators/common/llm"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/types"
|
||||
utilsllm "github.com/projectdiscovery/utils/llm"
|
||||
@@ -28,6 +32,32 @@ func (a *llmMatcherClient) Complete(ctx context.Context, prompt string, asJSON b
|
||||
})
|
||||
}
|
||||
|
||||
// llmJudgeClient is an llmMatcherClient whose provider classifies natively, so
|
||||
// llm matchers ask it through Judge instead of Complete.
|
||||
type llmJudgeClient struct {
|
||||
*llmMatcherClient
|
||||
warnComplete sync.Once
|
||||
}
|
||||
|
||||
func (a *llmJudgeClient) Judge(ctx context.Context, question string, labels, inputs []string) (llmclient.Verdict, error) {
|
||||
verdict, err := a.client.Judge(ctx, utilsllm.JudgeRequest{Question: question, Labels: labels, Inputs: inputs})
|
||||
if err != nil {
|
||||
return llmclient.Verdict{}, err
|
||||
}
|
||||
return llmclient.Verdict{Label: verdict.Label, Confidence: verdict.Confidence, Model: verdict.Model}, nil
|
||||
}
|
||||
|
||||
// Complete is only reached by llm extractors, which need free text a
|
||||
// classifier cannot produce. Returning here spends no call budget and
|
||||
// makes no provider request. Extractors turn the error into an empty
|
||||
// result, and the warning says why.
|
||||
func (a *llmJudgeClient) Complete(context.Context, string, bool) (string, error) {
|
||||
a.warnComplete.Do(func() {
|
||||
gologger.Warning().Msgf("llm provider %q cannot run llm extractors, they return nothing", utilsllm.ProviderJev)
|
||||
})
|
||||
return "", errors.New("llm provider cannot run extractors")
|
||||
}
|
||||
|
||||
// configureLLM builds the scan's llm client from options. It returns nil unless
|
||||
// -llm is set, so nothing reaches a model until the user opts in. The API key is
|
||||
// read from the environment by the provider layer, never from options.
|
||||
@@ -52,5 +82,9 @@ func configureLLM(options *types.Options) (llmclient.Client, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &llmMatcherClient{client: client, model: options.LLMModel}, nil
|
||||
matcherClient := &llmMatcherClient{client: client, model: options.LLMModel}
|
||||
if client.CanJudge() {
|
||||
return &llmJudgeClient{llmMatcherClient: matcherClient}, nil
|
||||
}
|
||||
return matcherClient, nil
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package runner
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
|
||||
llmclient "github.com/projectdiscovery/nuclei/v3/pkg/operators/common/llm"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/types"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestConfigureLLMExposesJudgeOnlyForClassifiers(t *testing.T) {
|
||||
t.Setenv("LLM_API_KEY", "key")
|
||||
|
||||
client, err := configureLLM(&types.Options{EnableLLM: true, LLMProvider: "jev", LLMModel: "jev-latest"})
|
||||
require.NoError(t, err)
|
||||
require.Implements(t, (*llmclient.Judge)(nil), client)
|
||||
|
||||
client, err = configureLLM(&types.Options{EnableLLM: true, LLMProvider: "ollama", LLMModel: "llama3.2"})
|
||||
require.NoError(t, err)
|
||||
_, isJudge := client.(llmclient.Judge)
|
||||
require.False(t, isJudge, "chat providers keep the Complete path")
|
||||
}
|
||||
|
||||
func TestJevExtractorDoesNotSpendCallBudget(t *testing.T) {
|
||||
t.Setenv("LLM_API_KEY", "key")
|
||||
// ProxyFromEnvironment caches the first request in the process. Match the
|
||||
// proxy the interactsh client test expects, and keep the local server direct.
|
||||
for _, key := range []string{"HTTP_PROXY", "http_proxy", "ALL_PROXY", "all_proxy", "https_proxy", "no_proxy"} {
|
||||
t.Setenv(key, "")
|
||||
}
|
||||
t.Setenv("HTTPS_PROXY", "http://127.0.0.1:9")
|
||||
t.Setenv("NO_PROXY", "127.0.0.1,localhost")
|
||||
|
||||
var calls atomic.Int32
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
calls.Add(1)
|
||||
_, _ = w.Write([]byte(`{"model":"jev-1.14.0","answers":{"q":{"type":"noul","noul":0.9}}}`))
|
||||
}))
|
||||
t.Cleanup(server.Close)
|
||||
|
||||
client, err := configureLLM(&types.Options{
|
||||
EnableLLM: true,
|
||||
LLMProvider: "jev",
|
||||
LLMBaseURL: server.URL + "/v1",
|
||||
LLMModel: "jev-latest",
|
||||
LLMMaxCalls: 1,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = client.Complete(context.Background(), "extract the title", true)
|
||||
require.ErrorContains(t, err, "cannot run extractors")
|
||||
_, err = client.Complete(context.Background(), "extract another", true)
|
||||
require.Error(t, err)
|
||||
require.Zero(t, calls.Load())
|
||||
|
||||
judge := client.(llmclient.Judge)
|
||||
verdict, err := judge.Judge(context.Background(), "login page?", nil, []string{"<form>"})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "yes", verdict.Label)
|
||||
require.EqualValues(t, 1, calls.Load())
|
||||
}
|
||||
@@ -228,25 +228,14 @@ func ValidateOptions(options *types.Options) error {
|
||||
}
|
||||
}
|
||||
|
||||
// verify that a valid ip version type was selected (4, 6)
|
||||
if len(options.IPVersion) == 0 {
|
||||
// add ipv4 as default
|
||||
options.IPVersion = append(options.IPVersion, "4")
|
||||
}
|
||||
var useIPV4, useIPV6 bool
|
||||
// An empty -iv leaves one unpinned target so the dialer can fall back
|
||||
// between address families. -sa resolves and scans every selected address.
|
||||
// Explicit -iv 4, -iv 6 and -iv 4,6 retain their usual selection semantics.
|
||||
for _, ipv := range options.IPVersion {
|
||||
switch ipv {
|
||||
case "4":
|
||||
useIPV4 = true
|
||||
case "6":
|
||||
useIPV6 = true
|
||||
default:
|
||||
if ipv != "4" && ipv != "6" {
|
||||
return fmt.Errorf("unsupported ip version: %s", ipv)
|
||||
}
|
||||
}
|
||||
if !useIPV4 && !useIPV6 {
|
||||
return errors.New("ipv4 and/or ipv6 must be selected")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -90,3 +90,15 @@ func TestReadsTargetsFromStdin(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// The default must remain empty so the provider can distinguish automatic
|
||||
// IPv6 preference from explicit user-supplied -iv selections.
|
||||
func TestValidateOptionsIPVersionPreference(t *testing.T) {
|
||||
automatic := &types.Options{}
|
||||
require.NoError(t, ValidateOptions(automatic))
|
||||
require.Empty(t, automatic.IPVersion)
|
||||
for _, versions := range []goflags.StringSlice{{"4"}, {"6"}, {"4", "6"}} {
|
||||
require.NoError(t, ValidateOptions(&types.Options{IPVersion: versions}))
|
||||
}
|
||||
require.ErrorContains(t, ValidateOptions(&types.Options{IPVersion: goflags.StringSlice{"7"}}), "unsupported ip version")
|
||||
}
|
||||
@@ -67,6 +67,7 @@ import (
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/utils/excludematchers"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/protocols/headless/engine"
|
||||
httpProtocol "github.com/projectdiscovery/nuclei/v3/pkg/protocols/http"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/protocols/http/catchall"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/protocols/http/httpclientpool"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/reporting"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/templates"
|
||||
@@ -294,8 +295,6 @@ func New(options *types.Options) (*Runner, error) {
|
||||
return nil, errors.Wrap(err, "could not create temporary directory")
|
||||
}
|
||||
runner.tmpDir = tmpDir
|
||||
// The per-scan temp dir is the only temp location templates may access.
|
||||
protocolstate.SetTemporaryDirectory(options.ExecutionId, tmpDir)
|
||||
|
||||
// Cleanup tmpDir only if initialization fails
|
||||
// On successful initialization, Close() method will handle cleanup
|
||||
@@ -539,7 +538,6 @@ func (r *Runner) Close() {
|
||||
}
|
||||
if r.tmpDir != "" {
|
||||
_ = os.RemoveAll(r.tmpDir)
|
||||
protocolstate.SetTemporaryDirectory(r.options.ExecutionId, "")
|
||||
}
|
||||
|
||||
//this is no-op unless nuclei is built with stats build tag
|
||||
@@ -737,6 +735,9 @@ func (r *Runner) RunEnumeration() error {
|
||||
if r.options.HostBackoff {
|
||||
executorOpts.HostBackoff = hostbackoff.New(hostbackoff.Config{Max: r.options.HostBackoffMax})
|
||||
}
|
||||
if r.options.AutoCalibrate {
|
||||
executorOpts.CatchAll = catchall.New(0)
|
||||
}
|
||||
|
||||
executorEngine := core.New(r.options)
|
||||
executorEngine.SetExecuterOptions(executorOpts)
|
||||
@@ -1075,6 +1076,7 @@ func (r *Runner) displayExecutionInfo(store *loader.Store) {
|
||||
stats.DisplayAsWarning(httpProtocol.SetThreadToCountZero)
|
||||
stats.ForceDisplayWarning(templates.SkippedUnverifiedTemplateStats)
|
||||
stats.ForceDisplayWarning(templates.SkippedRequestSignatureTemplateStats)
|
||||
stats.ForceDisplayWarning(templates.SkippedWorkflowStepStats)
|
||||
|
||||
cfg := config.DefaultConfig
|
||||
|
||||
|
||||
@@ -6,11 +6,17 @@ import (
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
"github.com/projectdiscovery/gologger"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/input"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/input/provider"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/model/types/severity"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/protocolstate"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/types"
|
||||
@@ -197,3 +203,63 @@ func TestNewInteractshHTTPClient(t *testing.T) {
|
||||
require.NotNil(t, proxyURL)
|
||||
require.Equal(t, "http://127.0.0.1:9", proxyURL.String())
|
||||
}
|
||||
|
||||
func TestInitializeTemplatesHTTPInputUsesResolvers(t *testing.T) {
|
||||
for _, key := range []string{"HTTP_PROXY", "http_proxy", "HTTPS_PROXY", "https_proxy"} {
|
||||
t.Setenv(key, "")
|
||||
}
|
||||
|
||||
listener, err := net.ListenPacket("udp", "127.0.0.1:0")
|
||||
require.NoError(t, err)
|
||||
queries := new(atomic.Int32)
|
||||
server := &dns.Server{PacketConn: listener, Handler: dns.HandlerFunc(func(writer dns.ResponseWriter, request *dns.Msg) {
|
||||
queries.Add(1)
|
||||
response := new(dns.Msg).SetReply(request)
|
||||
for _, question := range request.Question {
|
||||
if question.Qtype == dns.TypeA {
|
||||
response.Answer = append(response.Answer, &dns.A{Hdr: dns.RR_Header{Name: question.Name, Rrtype: dns.TypeA, Class: dns.ClassINET}, A: net.ParseIP("127.0.0.1")})
|
||||
}
|
||||
}
|
||||
_ = writer.WriteMsg(response)
|
||||
})}
|
||||
started := make(chan struct{})
|
||||
server.NotifyStartedFunc = func() { close(started) }
|
||||
done := make(chan error, 1)
|
||||
go func() { done <- server.ActivateAndServe() }()
|
||||
<-started
|
||||
t.Cleanup(func() { require.NoError(t, server.Shutdown()); require.NoError(t, <-done) })
|
||||
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}))
|
||||
t.Cleanup(srv.Close)
|
||||
|
||||
resolverFile := filepath.Join(t.TempDir(), "resolv.conf")
|
||||
require.NoError(t, os.WriteFile(resolverFile, nil, 0o600))
|
||||
t.Setenv("RESOLVERS_PATH", resolverFile)
|
||||
|
||||
options := &types.Options{
|
||||
ExecutionId: t.Name(),
|
||||
Timeout: 5,
|
||||
BulkSize: 1,
|
||||
InternalResolversList: []string{listener.LocalAddr().String()},
|
||||
}
|
||||
require.NoError(t, protocolstate.Init(options))
|
||||
t.Cleanup(func() { protocolstate.Close(options.ExecutionId) })
|
||||
|
||||
target := "probe.nuclei.test:" + strconv.Itoa(srv.Listener.Addr().(*net.TCPAddr).Port)
|
||||
r := &Runner{
|
||||
options: options,
|
||||
inputProvider: provider.NewSimpleInputProviderWithUrls(options.ExecutionId, target),
|
||||
Logger: &gologger.Logger{},
|
||||
}
|
||||
|
||||
hm, err := r.initializeTemplatesHTTPInput()
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() { _ = hm.Close() })
|
||||
|
||||
probed, ok := hm.Get(input.ProbeKey(target, ""))
|
||||
require.True(t, ok, "the probe should resolve the target through the -r resolver")
|
||||
require.Equal(t, "http://"+target, string(probed))
|
||||
require.Positive(t, queries.Load())
|
||||
}
|
||||
@@ -10,9 +10,11 @@ import (
|
||||
"github.com/logrusorgru/aurora/v4"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/catalog/config"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/catalog/loader"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/model"
|
||||
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/templates"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/types"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/utils"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/utils/json"
|
||||
)
|
||||
|
||||
@@ -38,12 +40,17 @@ func (r *Runner) verboseTemplate(tpl *templates.Template) {
|
||||
tpl.Info.SeverityHolder.Severity))
|
||||
}
|
||||
|
||||
// listedTemplate names its fields like a result event, so a -jsonl listing
|
||||
// joins with scan results on the same keys.
|
||||
type listedTemplate struct {
|
||||
Template string `json:"template,omitempty"`
|
||||
TemplateID string `json:"template-id"`
|
||||
TemplatePath string `json:"template-path"`
|
||||
Info model.Info `json:"info"`
|
||||
}
|
||||
|
||||
func (r *Runner) listAvailableStoreTemplates(store *loader.Store) {
|
||||
r.Logger.Print().Msgf(
|
||||
"\nListing available %v nuclei templates for %v",
|
||||
config.DefaultConfig.TemplateVersion,
|
||||
config.DefaultConfig.TemplatesDirectory,
|
||||
)
|
||||
r.listingHeader("templates")
|
||||
// order templates alphabetically by path
|
||||
templates := store.Templates()
|
||||
sort.Slice(templates, func(i, j int) bool {
|
||||
@@ -51,6 +58,10 @@ func (r *Runner) listAvailableStoreTemplates(store *loader.Store) {
|
||||
})
|
||||
|
||||
for _, tpl := range templates {
|
||||
if r.options.JSONL && !r.options.TemplateDisplay {
|
||||
r.listTemplateJSON(tpl)
|
||||
continue
|
||||
}
|
||||
if hasExtraFlags(r.options) {
|
||||
if r.options.TemplateDisplay {
|
||||
colorize := !r.options.NoColor
|
||||
@@ -78,12 +89,36 @@ func (r *Runner) listAvailableStoreTemplates(store *loader.Store) {
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Runner) listAvailableTags(tagsMap map[string]int) {
|
||||
func (r *Runner) listTemplateJSON(tpl *templates.Template) {
|
||||
path, _ := utils.TemplatePathURL(tpl.Path, tpl.ID, "")
|
||||
marshalled, err := json.Marshal(listedTemplate{
|
||||
Template: path,
|
||||
TemplateID: tpl.ID,
|
||||
TemplatePath: tpl.Path,
|
||||
Info: tpl.Info,
|
||||
})
|
||||
if err != nil {
|
||||
r.Logger.Error().Msgf("Could not marshal the template %s: %s", tpl.Path, err)
|
||||
return
|
||||
}
|
||||
r.Logger.Print().Msgf("%s", marshalled)
|
||||
}
|
||||
|
||||
// listingHeader is skipped for -jsonl, where every line must parse as JSON.
|
||||
func (r *Runner) listingHeader(what string) {
|
||||
if r.options.JSONL {
|
||||
return
|
||||
}
|
||||
r.Logger.Print().Msgf(
|
||||
"\nListing available %v nuclei tags for %v",
|
||||
"\nListing available %v nuclei %s for %v",
|
||||
config.DefaultConfig.TemplateVersion,
|
||||
what,
|
||||
config.DefaultConfig.TemplatesDirectory,
|
||||
)
|
||||
}
|
||||
|
||||
func (r *Runner) listAvailableTags(tagsMap map[string]int) {
|
||||
r.listingHeader("tags")
|
||||
|
||||
type kv struct {
|
||||
Key string `json:"tag"`
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
package runner
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/projectdiscovery/gologger"
|
||||
"github.com/projectdiscovery/gologger/formatter"
|
||||
"github.com/projectdiscovery/gologger/levels"
|
||||
"github.com/projectdiscovery/nuclei/v3/internal/tests/testutils"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/catalog/config"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/catalog/disk"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/catalog/loader"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/templates"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/utils/json"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const listedTemplateYAML = `id: listed-template
|
||||
info:
|
||||
name: Listed Template
|
||||
author: pdteam
|
||||
severity: info
|
||||
tags: listing
|
||||
http:
|
||||
- method: GET
|
||||
path:
|
||||
- "{{BaseURL}}"
|
||||
`
|
||||
|
||||
func TestTemplateListWritesJSONLines(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
cfg := config.DefaultConfig
|
||||
oldRoot := cfg.TemplatesDirectory
|
||||
t.Cleanup(func() { cfg.SetTemplatesDir(oldRoot) })
|
||||
cfg.SetTemplatesDir(root)
|
||||
|
||||
path := filepath.Join(root, "http", "listed-template.yaml")
|
||||
require.NoError(t, os.MkdirAll(filepath.Dir(path), 0o755))
|
||||
require.NoError(t, os.WriteFile(path, []byte(listedTemplateYAML), 0o600))
|
||||
|
||||
writer := &ignoreFileLogWriter{}
|
||||
logger := &gologger.Logger{}
|
||||
logger.SetFormatter(formatter.NewCLI(true))
|
||||
logger.SetWriter(writer)
|
||||
logger.SetMaxLevel(levels.LevelInfo)
|
||||
|
||||
options := testutils.DefaultOptions.Copy()
|
||||
options.ExecutionId = t.Name()
|
||||
options.Logger = logger
|
||||
options.Templates = []string{path}
|
||||
options.TemplateList = true
|
||||
options.JSONL = true
|
||||
testutils.Init(options)
|
||||
t.Cleanup(func() { testutils.Cleanup(options) })
|
||||
|
||||
executerOpts := testutils.NewMockExecuterOptions(options, nil)
|
||||
executerOpts.Parser = templates.NewParser()
|
||||
store, err := loader.New(loader.NewConfig(options, disk.NewCatalog(root), executerOpts))
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, store.LoadTemplatesOnlyMetadata())
|
||||
|
||||
require.Len(t, store.Templates(), 1)
|
||||
|
||||
r := &Runner{options: options, Logger: logger}
|
||||
r.listAvailableStoreTemplates(store)
|
||||
|
||||
require.Len(t, writer.records, 1, "JSONL output carries no banner line")
|
||||
var listed map[string]any
|
||||
require.NoError(t, json.Unmarshal([]byte(strings.TrimSpace(writer.records[0].message)), &listed))
|
||||
require.Equal(t, "listed-template", listed["template-id"])
|
||||
require.Equal(t, filepath.Join("http", "listed-template.yaml"), listed["template"])
|
||||
require.Equal(t, "Listed Template", listed["info"].(map[string]any)["name"])
|
||||
}
|
||||
@@ -33,6 +33,7 @@ import (
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/interactsh"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/utils/excludematchers"
|
||||
browserEngine "github.com/projectdiscovery/nuclei/v3/pkg/protocols/headless/engine"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/protocols/http/catchall"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/reporting"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/templates"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/types"
|
||||
@@ -110,6 +111,9 @@ func newNucleiExecutor(opts *NucleiExecutorOptions) (*nucleiExecutor, error) {
|
||||
if opts.Options.HostBackoff {
|
||||
executorOpts.HostBackoff = hostbackoff.New(hostbackoff.Config{Max: opts.Options.HostBackoffMax})
|
||||
}
|
||||
if opts.Options.AutoCalibrate {
|
||||
executorOpts.CatchAll = catchall.New(0)
|
||||
}
|
||||
|
||||
executorEngine := core.New(opts.Options)
|
||||
executorEngine.SetExecuterOptions(executorOpts)
|
||||
|
||||
@@ -39,8 +39,8 @@ var codeTestCases = []integrationCase{
|
||||
{Path: "protocols/code/py-interactsh.yaml", TestCase: &codeSnippet{}, DisableOn: isCodeDisabled},
|
||||
{Path: "protocols/code/ps1-snippet.yaml", TestCase: &codeSnippet{}, DisableOn: func() bool { return !osutils.IsWindows() || isCodeDisabled() }},
|
||||
{Path: "protocols/code/pre-condition.yaml", TestCase: &codePreCondition{}, DisableOn: isCodeDisabled},
|
||||
{Path: "protocols/code/sh-virtual.yaml", TestCase: &codeVirtualSnippet{}, DisableOn: func() bool { return !osutils.IsLinux() || isCodeDisabled() || !hasAnyExecutable("docker", "podman") }, Serial: true},
|
||||
{Path: "protocols/code/py-virtual.yaml", TestCase: &codeVirtualSnippet{}, DisableOn: func() bool { return !osutils.IsLinux() || isCodeDisabled() || !hasAnyExecutable("docker", "podman") }, Serial: true},
|
||||
{Path: "protocols/code/sh-virtual.yaml", TestCase: &codeSnippet{}, DisableOn: func() bool { return !osutils.IsLinux() || isCodeDisabled() || !hasAnyExecutable("docker", "podman") }, Serial: true},
|
||||
{Path: "protocols/code/py-virtual.yaml", TestCase: &codeSnippet{}, DisableOn: func() bool { return !osutils.IsLinux() || isCodeDisabled() || !hasAnyExecutable("docker", "podman") }, Serial: true},
|
||||
{Path: "protocols/code/pwsh-echo.yaml", TestCase: &codeSnippet{}, DisableOn: func() bool { return isCodeDisabled() || !hasAnyExecutable("pwsh", "powershell", "powershell.exe") }},
|
||||
}
|
||||
|
||||
@@ -108,12 +108,6 @@ func ensureSignedIntegrationTemplates() error {
|
||||
}
|
||||
templatesToSign = append(templatesToSign, v.Path)
|
||||
}
|
||||
for _, v := range securityHardeningTestcases {
|
||||
if v.DisableOn != nil && v.DisableOn() {
|
||||
continue
|
||||
}
|
||||
templatesToSign = append(templatesToSign, v.Path)
|
||||
}
|
||||
for _, templatePath := range templatesToSign {
|
||||
if err := templates.SignTemplate(tsigner, fixturePath(templatePath)); err != nil {
|
||||
signedIntegrationTemplatesErr = err
|
||||
@@ -143,16 +137,6 @@ type codeSnippet struct{}
|
||||
|
||||
// Execute executes a test case and returns an error if occurred
|
||||
func (h *codeSnippet) Execute(filePath string) error {
|
||||
results, err := testutils.RunNucleiArgsWithEnvAndGetResults(debug, getEnvValues(), "-t", filePath, "-u", "input", "-code", "-no-sandbox")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return expectResultsCount(results, 1)
|
||||
}
|
||||
|
||||
type codeVirtualSnippet struct{}
|
||||
|
||||
func (h *codeVirtualSnippet) Execute(filePath string) error {
|
||||
results, err := testutils.RunNucleiArgsWithEnvAndGetResults(debug, getEnvValues(), "-t", filePath, "-u", "input", "-code")
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -164,7 +148,7 @@ type codePreCondition struct{}
|
||||
|
||||
// Execute executes a test case and returns an error if occurred
|
||||
func (h *codePreCondition) Execute(filePath string) error {
|
||||
results, err := testutils.RunNucleiArgsWithEnvAndGetResults(debug, getEnvValues(), "-t", filePath, "-u", "input", "-code", "-no-sandbox", "-esc")
|
||||
results, err := testutils.RunNucleiArgsWithEnvAndGetResults(debug, getEnvValues(), "-t", filePath, "-u", "input", "-code", "-esc")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -180,7 +164,7 @@ type codeFile struct{}
|
||||
|
||||
// Execute executes a test case and returns an error if occurred
|
||||
func (h *codeFile) Execute(filePath string) error {
|
||||
results, err := testutils.RunNucleiArgsWithEnvAndGetResults(debug, getEnvValues(), "-t", filePath, "-u", "input", "-code", "-no-sandbox")
|
||||
results, err := testutils.RunNucleiArgsWithEnvAndGetResults(debug, getEnvValues(), "-t", filePath, "-u", "input", "-code")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -191,7 +175,7 @@ type codeEnvVar struct{}
|
||||
|
||||
// Execute executes a test case and returns an error if occurred
|
||||
func (h *codeEnvVar) Execute(filePath string) error {
|
||||
results, err := testutils.RunNucleiArgsWithEnvAndGetResults(debug, getEnvValues(), "-t", filePath, "-u", "input", "-V", "baz=baz", "-code", "-no-sandbox")
|
||||
results, err := testutils.RunNucleiArgsWithEnvAndGetResults(debug, getEnvValues(), "-t", filePath, "-u", "input", "-V", "baz=baz", "-code")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -102,6 +102,7 @@ var httpTestcases = []integrationCase{
|
||||
{Path: "protocols/http/raw-unsafe-path-single-slash.yaml", TestCase: &httpRawUnsafePathSingleSlash{}},
|
||||
{Path: "protocols/http/disable-http-cache.yaml", TestCase: &httpDisableCache{}},
|
||||
{Path: "protocols/http/http-cache.yaml", TestCase: &httpCache{}},
|
||||
{Path: "protocols/http/get.yaml", TestCase: &httpExcludeHostsFileComments{}},
|
||||
}
|
||||
|
||||
type httpMultiVarSharing struct{}
|
||||
@@ -1983,3 +1984,59 @@ func (h *httpDisableCache) Execute(filePath string) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ensure that comments in an -exclude-hosts file are ignored
|
||||
type httpExcludeHostsFileComments struct{}
|
||||
|
||||
// Execute executes a test case and returns an error if occurred
|
||||
func (h *httpExcludeHostsFileComments) Execute(filePath string) error {
|
||||
router := httprouter.New()
|
||||
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
||||
_, _ = fmt.Fprintf(w, "This is test matcher text")
|
||||
})
|
||||
ts := httptest.NewServer(router)
|
||||
defer ts.Close()
|
||||
|
||||
excludeHosts := func(content string) ([]string, error) {
|
||||
file, err := os.CreateTemp("", "exclude-hosts-*.txt")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer func() { _ = os.Remove(file.Name()) }()
|
||||
_, err = file.WriteString(content)
|
||||
_ = file.Close()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL, debug, "-eh", file.Name())
|
||||
}
|
||||
|
||||
// a comment line is not a host, even when it reads as an invalid regex
|
||||
results, err := excludeHosts("# hosts out of scope (see ticket\n203.0.113.10\n")
|
||||
if err != nil {
|
||||
return fmt.Errorf("comment line: %w", err)
|
||||
}
|
||||
if err := expectResultsCount(results, 1); err != nil {
|
||||
return fmt.Errorf("comment line: %w", err)
|
||||
}
|
||||
|
||||
// a trailing comment does not stop the host from being excluded
|
||||
results, err = excludeHosts("127.0.0.1 # test server\n")
|
||||
if err != nil {
|
||||
return fmt.Errorf("trailing comment: %w", err)
|
||||
}
|
||||
if err := expectResultsCount(results, 0); err != nil {
|
||||
return fmt.Errorf("trailing comment: %w", err)
|
||||
}
|
||||
|
||||
// comma separated hosts are still split when passed on the command line
|
||||
results, err = testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL, debug, "-eh", "203.0.113.10, 127.0.0.1")
|
||||
if err != nil {
|
||||
return fmt.Errorf("comma separated: %w", err)
|
||||
}
|
||||
if err := expectResultsCount(results, 0); err != nil {
|
||||
return fmt.Errorf("comma separated: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -113,7 +113,6 @@ func integrationFamilies() []integrationFamily {
|
||||
{Name: "generic", Cases: genericTestcases},
|
||||
{Name: "dsl", Cases: dslTestcases},
|
||||
{Name: "javascript", Cases: jsTestcases},
|
||||
{Name: "security-hardening", Cases: securityHardeningTestcases},
|
||||
{Name: "matcher-status", Cases: matcherStatusTestcases},
|
||||
{Name: "exporters", Cases: exportersTestCases},
|
||||
{Name: "profile-loader", Cases: profileLoaderTestcases},
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
//go:build integration
|
||||
// +build integration
|
||||
|
||||
package integration_test
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
var securityHardeningTestcases = []integrationCase{
|
||||
{Path: "protocols/javascript/fs-read-deny.yaml", TestCase: &javascriptFSReadDeny{}},
|
||||
{Path: "protocols/javascript/fs-read-deny-lfa.yaml", TestCase: &javascriptFSReadDenyWithLFA{}},
|
||||
{Path: "protocols/javascript/net-deny-excluded.yaml", TestCase: &javascriptNetDenyExcluded{}},
|
||||
{Path: "protocols/javascript/fs-read-allowed-paths.yaml", TestCase: &javascriptFSReadAllowedPaths{}},
|
||||
}
|
||||
|
||||
type javascriptFSReadDeny struct{}
|
||||
|
||||
func (j *javascriptFSReadDeny) Execute(filePath string) error {
|
||||
results, err := runSignedNucleiTemplateAndGetResults(filePath, "127.0.0.1", debug)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return expectResultsCount(results, 1)
|
||||
}
|
||||
|
||||
type javascriptFSReadDenyWithLFA struct{}
|
||||
|
||||
func (j *javascriptFSReadDenyWithLFA) Execute(filePath string) error {
|
||||
denied := "/etc/passwd"
|
||||
if runtime.GOOS == "windows" {
|
||||
sys := os.Getenv("SystemRoot")
|
||||
if sys == "" {
|
||||
sys = `C:\Windows`
|
||||
}
|
||||
denied = filepath.Join(sys, "win.ini")
|
||||
}
|
||||
results, err := runSignedNucleiTemplateAndGetResults(
|
||||
filePath,
|
||||
"127.0.0.1",
|
||||
debug,
|
||||
"-allow-local-file-access",
|
||||
"-var", "DeniedPath="+denied,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return expectResultsCount(results, 1)
|
||||
}
|
||||
|
||||
type javascriptNetDenyExcluded struct{}
|
||||
|
||||
func (j *javascriptNetDenyExcluded) Execute(filePath string) error {
|
||||
results, err := runSignedNucleiTemplateAndGetResults(filePath, "127.0.0.1", debug, "-eh", "203.0.113.10")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return expectResultsCount(results, 1)
|
||||
}
|
||||
|
||||
type javascriptFSReadAllowedPaths struct{}
|
||||
|
||||
func (j *javascriptFSReadAllowedPaths) Execute(filePath string) error {
|
||||
grantedDir, err := os.MkdirTemp("", "nuclei-allowed-paths-*")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer os.RemoveAll(grantedDir)
|
||||
|
||||
secretPath := filepath.Join(grantedDir, "secret.txt")
|
||||
if err := os.WriteFile(secretPath, []byte("granted-secret"), 0o600); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
results, err := runSignedNucleiTemplateAndGetResults(
|
||||
filePath,
|
||||
"127.0.0.1",
|
||||
debug,
|
||||
"-allow-local-file-access",
|
||||
"-ap", grantedDir,
|
||||
"-var", "ReadPath="+secretPath,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return expectResultsCount(results, 1)
|
||||
}
|
||||
@@ -10,12 +10,15 @@ info:
|
||||
|
||||
code:
|
||||
- engine:
|
||||
- py
|
||||
- python3
|
||||
- python
|
||||
- sh
|
||||
- bash
|
||||
sandbox:
|
||||
working-dir: /tmp
|
||||
image: python:3.14
|
||||
source: |
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
print("hello from python virtual code")
|
||||
|
||||
matchers:
|
||||
|
||||
-34
@@ -1,34 +0,0 @@
|
||||
id: javascript-fs-read-allowed-paths
|
||||
|
||||
info:
|
||||
name: JavaScript FS Read Allowed Paths
|
||||
author: pdteam
|
||||
severity: info
|
||||
description: reads a file granted via --allowed-paths
|
||||
|
||||
javascript:
|
||||
- code: |
|
||||
const fs = require('nuclei/fs');
|
||||
let ok = false;
|
||||
let content = "";
|
||||
try {
|
||||
content = fs.ReadFileAsString(ReadPath);
|
||||
ok = content === "granted-secret";
|
||||
} catch (e) {
|
||||
ok = false;
|
||||
}
|
||||
Export(to_json({ ok: ok, content: content }));
|
||||
args:
|
||||
Host: "{{Host}}"
|
||||
ReadPath: "{{ReadPath}}"
|
||||
matchers-condition: and
|
||||
matchers:
|
||||
- type: dsl
|
||||
dsl:
|
||||
- success == true
|
||||
- type: word
|
||||
part: response
|
||||
condition: and
|
||||
words:
|
||||
- '"ok": true'
|
||||
- "granted-secret"
|
||||
-34
@@ -1,34 +0,0 @@
|
||||
id: javascript-fs-read-deny-lfa
|
||||
|
||||
info:
|
||||
name: JavaScript FS Read Deny With LFA
|
||||
author: pdteam
|
||||
severity: info
|
||||
description: confirms -lfa does not bypass absolute paths outside the allowlist
|
||||
|
||||
javascript:
|
||||
- code: |
|
||||
const fs = require('nuclei/fs');
|
||||
let ok = true;
|
||||
let errMsg = "";
|
||||
try {
|
||||
fs.ReadFileAsString(DeniedPath);
|
||||
} catch (e) {
|
||||
ok = false;
|
||||
errMsg = String(e);
|
||||
}
|
||||
Export(to_json({ ok: ok, err: errMsg }));
|
||||
args:
|
||||
Host: "{{Host}}"
|
||||
DeniedPath: "{{DeniedPath}}"
|
||||
matchers-condition: and
|
||||
matchers:
|
||||
- type: dsl
|
||||
dsl:
|
||||
- success == true
|
||||
- type: word
|
||||
part: response
|
||||
condition: and
|
||||
words:
|
||||
- '"ok": false'
|
||||
- "outside allowed directories"
|
||||
@@ -1,31 +0,0 @@
|
||||
id: javascript-fs-read-deny
|
||||
|
||||
info:
|
||||
name: JavaScript FS Read Deny
|
||||
author: pdteam
|
||||
severity: info
|
||||
description: attempts to read a file outside the sandbox allowlist
|
||||
|
||||
javascript:
|
||||
- code: |
|
||||
const fs = require('nuclei/fs');
|
||||
let ok = true;
|
||||
let errMsg = "";
|
||||
try {
|
||||
fs.ReadFileAsString('/etc/passwd');
|
||||
} catch (e) {
|
||||
ok = false;
|
||||
errMsg = String(e);
|
||||
}
|
||||
Export(to_json({ ok: ok, err: errMsg }));
|
||||
args:
|
||||
Host: "{{Host}}"
|
||||
matchers-condition: and
|
||||
matchers:
|
||||
- type: dsl
|
||||
dsl:
|
||||
- success == true
|
||||
- type: word
|
||||
part: response
|
||||
words:
|
||||
- '"ok": false'
|
||||
-33
@@ -1,33 +0,0 @@
|
||||
id: javascript-net-deny-excluded
|
||||
|
||||
info:
|
||||
name: JavaScript Net Deny Excluded Host
|
||||
author: pdteam
|
||||
severity: info
|
||||
description: attempts to dial a host blocked by network policy
|
||||
|
||||
javascript:
|
||||
- code: |
|
||||
const net = require('nuclei/net');
|
||||
let ok = true;
|
||||
let errMsg = "";
|
||||
try {
|
||||
net.Open('tcp', '203.0.113.10:445');
|
||||
} catch (e) {
|
||||
ok = false;
|
||||
errMsg = String(e);
|
||||
}
|
||||
Export(to_json({ ok: ok, err: errMsg }));
|
||||
args:
|
||||
Host: "{{Host}}"
|
||||
matchers-condition: and
|
||||
matchers:
|
||||
- type: dsl
|
||||
dsl:
|
||||
- success == true
|
||||
- type: word
|
||||
part: response
|
||||
condition: and
|
||||
words:
|
||||
- '"ok": false'
|
||||
- "denied address found"
|
||||
@@ -208,7 +208,7 @@ func (h *workflowCodeKeyValueShare) Execute(filePath string) error {
|
||||
// provide the Certificate File that the code templates are signed with
|
||||
certEnvVar := signer.CertEnvVarName + "=" + testCertFile
|
||||
|
||||
results, err := testutils.RunNucleiArgsWithEnvAndGetResults(debug, []string{certEnvVar}, "-workflows", filePath, "-target", "input", "-code", "-no-sandbox")
|
||||
results, err := testutils.RunNucleiArgsWithEnvAndGetResults(debug, []string{certEnvVar}, "-workflows", filePath, "-target", "input", "-code")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -111,12 +111,6 @@ func WithExtraArgs(args ...string) RunnerOption {
|
||||
}
|
||||
}
|
||||
|
||||
func WithAllowLocalFileAccess(allow bool) RunnerOption {
|
||||
return func(r *Runner) {
|
||||
r.AllowLocalFileAccess = allow
|
||||
}
|
||||
}
|
||||
|
||||
var defaultRunner = NewRunner()
|
||||
|
||||
func DefaultRunner() *Runner {
|
||||
|
||||
@@ -73,18 +73,6 @@ For Various use cases like batching etc. you might want to run nuclei in gorouti
|
||||
defer ne.Close()
|
||||
```
|
||||
|
||||
## Filesystem Sandbox
|
||||
|
||||
The nuclei CLI applies an OS-level filesystem sandbox (landlock on Linux) to its whole process. The CLI turns it off with `-no-sandbox`.
|
||||
|
||||
The SDK does not apply it by default. Landlock confines the whole process and cannot be undone, so it would also confine your program. To apply it, pass `nuclei.EnableProcessSandbox()`:
|
||||
|
||||
```go
|
||||
ne, err := nuclei.NewNucleiEngineCtx(ctx, nuclei.EnableProcessSandbox())
|
||||
```
|
||||
|
||||
After the engine starts, your process can only use the nuclei roots (templates, config, cache, temp, outputs, the working directory and allowed paths) and the read-only system paths. Use it only when your process does nothing else on the filesystem. The option has no effect on platforms without landlock. Setting `DisableSandbox` in the engine options turns it off.
|
||||
|
||||
## More Documentation
|
||||
|
||||
For complete documentation of nuclei library, please refer to [godoc](https://pkg.go.dev/github.com/projectdiscovery/nuclei/v3/lib) which contains all available options and methods.
|
||||
|
||||
@@ -411,22 +411,6 @@ func WithSandboxOptions(allowLocalFileAccess bool, restrictLocalNetworkAccess bo
|
||||
}
|
||||
}
|
||||
|
||||
// EnableProcessSandbox applies the OS-level filesystem sandbox (landlock on
|
||||
// Linux) to the whole host process when the engine initializes, the same way
|
||||
// the nuclei CLI does by default. It is off for SDK users because the sandbox
|
||||
// is process-wide and irreversible: after it is applied, the host program can
|
||||
// only reach the nuclei allowlisted roots (templates, config, cache, temp,
|
||||
// outputs, cwd and allowed paths) and the read-only runtime paths, for the
|
||||
// rest of its life. Enable it only when the host process does nothing else
|
||||
// on the filesystem. It has no effect on platforms without landlock, and
|
||||
// DisableSandbox in the engine options still turns it off.
|
||||
func EnableProcessSandbox() NucleiSDKOptions {
|
||||
return func(e *NucleiEngine) error {
|
||||
e.opts.EnableProcessSandbox = true
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// EnableCodeTemplates allows loading/executing code protocol templates
|
||||
func EnableCodeTemplates() NucleiSDKOptions {
|
||||
return func(e *NucleiEngine) error {
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
package nuclei
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/protocolinit"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/types"
|
||||
)
|
||||
|
||||
func TestProcessSandboxIsOptInForSDK(t *testing.T) {
|
||||
e := &NucleiEngine{opts: types.DefaultOptions()}
|
||||
if protocolinit.ProcessSandboxEnabled(e.opts) {
|
||||
t.Fatal("SDK default options enable the process-wide sandbox")
|
||||
}
|
||||
|
||||
if err := EnableProcessSandbox()(e); err != nil {
|
||||
t.Fatalf("EnableProcessSandbox: %v", err)
|
||||
}
|
||||
if !protocolinit.ProcessSandboxEnabled(e.opts) {
|
||||
t.Fatal("EnableProcessSandbox did not enable the process-wide sandbox")
|
||||
}
|
||||
|
||||
e.opts.DisableSandbox = true
|
||||
if protocolinit.ProcessSandboxEnabled(e.opts) {
|
||||
t.Fatal("DisableSandbox did not override EnableProcessSandbox")
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,6 @@ import (
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/hosterrorscache"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/interactsh"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/protocolinit"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/protocolstate"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/protocols/headless/engine"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/reporting"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/templates"
|
||||
@@ -280,9 +279,6 @@ func (e *NucleiEngine) closeInternal() {
|
||||
}
|
||||
if e.tmpDir != "" {
|
||||
_ = os.RemoveAll(e.tmpDir)
|
||||
if e.opts != nil {
|
||||
protocolstate.SetTemporaryDirectory(e.opts.ExecutionId, "")
|
||||
}
|
||||
}
|
||||
if e.opts != nil {
|
||||
generators.ClearOptionsPayloadMap(e.opts)
|
||||
|
||||
+3
-2
@@ -271,8 +271,6 @@ func (e *NucleiEngine) init(ctx context.Context) error {
|
||||
}
|
||||
e.tmpDir = tmpDir
|
||||
}
|
||||
// The per-scan temp dir is the only temp location templates may access.
|
||||
protocolstate.SetTemporaryDirectory(e.opts.ExecutionId, e.tmpDir)
|
||||
|
||||
e.executerOpts = &protocols.ExecutorOptions{
|
||||
Output: e.customWriter,
|
||||
@@ -360,6 +358,9 @@ func (e *NucleiEngine) init(ctx context.Context) error {
|
||||
|
||||
httpxOptions := httpx.DefaultOptions
|
||||
httpxOptions.Timeout = 5 * time.Second
|
||||
if len(e.opts.InternalResolversList) > 0 {
|
||||
httpxOptions.Resolvers = e.opts.InternalResolversList
|
||||
}
|
||||
if client, err := httpx.New(&httpxOptions); err != nil {
|
||||
return err
|
||||
} else {
|
||||
|
||||
@@ -631,10 +631,10 @@ func (store *Store) noteMissingCapabilities(templatePath string, missingCaps []t
|
||||
// erroring out on discovering any faulty templates.
|
||||
func (store *Store) ValidateTemplates() error {
|
||||
templatePaths, errs := store.config.Catalog.GetTemplatesPath(store.finalTemplates)
|
||||
store.logErroredTemplates(errs)
|
||||
notFound := store.logErroredTemplates(errs)
|
||||
|
||||
workflowPaths, errs := store.config.Catalog.GetTemplatesPath(store.finalWorkflows)
|
||||
store.logErroredTemplates(errs)
|
||||
notFound += store.logErroredTemplates(errs)
|
||||
|
||||
templatePathsMap := make(map[string]struct{}, len(templatePaths))
|
||||
for _, path := range templatePaths {
|
||||
@@ -646,7 +646,8 @@ func (store *Store) ValidateTemplates() error {
|
||||
workflowPathsMap[path] = struct{}{}
|
||||
}
|
||||
|
||||
if store.areTemplatesValid(templatePathsMap) && store.areWorkflowsValid(workflowPathsMap) {
|
||||
// a path that can't be resolved is not validated, so it can't count as valid
|
||||
if store.areTemplatesValid(templatePathsMap) && store.areWorkflowsValid(workflowPathsMap) && notFound == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1056,10 +1057,15 @@ func workflowContainsProtocol(workflow []*workflows.WorkflowTemplate) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (s *Store) logErroredTemplates(erred map[string]error) {
|
||||
// logErroredTemplates logs the templates that could not be found and returns
|
||||
// how many of them were not handled by the NotFoundCallback.
|
||||
func (s *Store) logErroredTemplates(erred map[string]error) int {
|
||||
notFound := 0
|
||||
for template, err := range erred {
|
||||
if s.NotFoundCallback == nil || !s.NotFoundCallback(template) {
|
||||
s.logger.Error().Msgf("Could not find template '%s': %s", template, err)
|
||||
notFound++
|
||||
}
|
||||
}
|
||||
return notFound
|
||||
}
|
||||
@@ -176,25 +176,8 @@ func TestLoadTemplatesOnlyMetadataLogsCachedTemplateParseErrors(t *testing.T) {
|
||||
require.Contains(t, output.String(), "Could not load template")
|
||||
}
|
||||
|
||||
func TestValidateTemplatesRejectsRuntimeCompilationError(t *testing.T) {
|
||||
templatePath := filepath.Join(t.TempDir(), "invalid-regex-group.yaml")
|
||||
require.NoError(t, os.WriteFile(templatePath, []byte(`id: invalid-regex-group
|
||||
|
||||
info:
|
||||
name: Invalid Regex Group
|
||||
author: pdteam
|
||||
severity: info
|
||||
|
||||
http:
|
||||
- method: GET
|
||||
path:
|
||||
- "{{BaseURL}}"
|
||||
extractors:
|
||||
- type: regex
|
||||
group: -1
|
||||
regex:
|
||||
- "(a)(b)"
|
||||
`), 0o600))
|
||||
func newValidateStore(t *testing.T, executionID, templatePath string) (*Store, *bytes.Buffer) {
|
||||
t.Helper()
|
||||
|
||||
options := testutils.DefaultOptions.Copy()
|
||||
var output bytes.Buffer
|
||||
@@ -203,7 +186,7 @@ http:
|
||||
logger.SetWriter(&utils.CaptureWriter{Buffer: &output})
|
||||
logger.SetMaxLevel(levels.LevelDebug)
|
||||
options.Logger = logger
|
||||
options.ExecutionId = "loader-invalid-regex-group"
|
||||
options.ExecutionId = executionID
|
||||
options.Templates = []string{templatePath}
|
||||
options.Validate = true
|
||||
options.TemplateLoadingConcurrency = 1
|
||||
@@ -226,10 +209,50 @@ http:
|
||||
|
||||
store, err := New(NewConfig(options, catalog, executerOpts))
|
||||
require.NoError(t, err)
|
||||
return store, &output
|
||||
}
|
||||
|
||||
func TestValidateTemplatesRejectsRuntimeCompilationError(t *testing.T) {
|
||||
templatePath := filepath.Join(t.TempDir(), "invalid-regex-group.yaml")
|
||||
require.NoError(t, os.WriteFile(templatePath, []byte(`id: invalid-regex-group
|
||||
|
||||
info:
|
||||
name: Invalid Regex Group
|
||||
author: pdteam
|
||||
severity: info
|
||||
|
||||
http:
|
||||
- method: GET
|
||||
path:
|
||||
- "{{BaseURL}}"
|
||||
extractors:
|
||||
- type: regex
|
||||
group: -1
|
||||
regex:
|
||||
- "(a)(b)"
|
||||
`), 0o600))
|
||||
|
||||
store, output := newValidateStore(t, "loader-invalid-regex-group", templatePath)
|
||||
require.Error(t, store.ValidateTemplates())
|
||||
require.Contains(t, output.String(), "regex extractor group must be >= 0")
|
||||
}
|
||||
|
||||
func TestValidateTemplatesRejectsMissingTemplatePath(t *testing.T) {
|
||||
templatePath := filepath.Join(t.TempDir(), "no-such-templates")
|
||||
|
||||
store, output := newValidateStore(t, "loader-missing-template-path", templatePath)
|
||||
require.Error(t, store.ValidateTemplates())
|
||||
require.Contains(t, output.String(), "Could not find template")
|
||||
}
|
||||
|
||||
func TestValidateTemplatesAcceptsMissingPathHandledByCallback(t *testing.T) {
|
||||
templatePath := filepath.Join(t.TempDir(), "no-such-templates")
|
||||
|
||||
store, _ := newValidateStore(t, "loader-missing-path-callback", templatePath)
|
||||
store.NotFoundCallback = func(string) bool { return true }
|
||||
require.NoError(t, store.ValidateTemplates())
|
||||
}
|
||||
|
||||
func TestRemoteTemplates(t *testing.T) {
|
||||
catalog := disk.NewCatalog("")
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ Formats implements support for passing a number of request source as input provi
|
||||
Currently the following formats are implemented -
|
||||
|
||||
- Burp Suite XML Request/Response file
|
||||
- HAR (HTTP Archive) file exported by browsers and proxies
|
||||
- Proxify JSONL output file
|
||||
- OpenAPI Specification file
|
||||
- Postman Collection file
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
package har
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"io"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/projectdiscovery/gologger"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/input/formats"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/input/types"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/utils/json"
|
||||
)
|
||||
|
||||
// HARFormat is an HTTP Archive (HAR 1.2) parser, the format browsers and
|
||||
// proxies export captured traffic in.
|
||||
type HARFormat struct {
|
||||
opts formats.InputFormatOptions
|
||||
}
|
||||
|
||||
// New creates a new HAR parser
|
||||
func New() *HARFormat {
|
||||
return &HARFormat{}
|
||||
}
|
||||
|
||||
var _ formats.Format = &HARFormat{}
|
||||
|
||||
type archive struct {
|
||||
Log struct {
|
||||
Entries []entry `json:"entries"`
|
||||
} `json:"log"`
|
||||
}
|
||||
|
||||
type entry struct {
|
||||
Request struct {
|
||||
Method string `json:"method"`
|
||||
URL string `json:"url"`
|
||||
Headers []header `json:"headers"`
|
||||
PostData *struct {
|
||||
Text string `json:"text"`
|
||||
} `json:"postData"`
|
||||
} `json:"request"`
|
||||
Response struct {
|
||||
Status int `json:"status"`
|
||||
StatusText string `json:"statusText"`
|
||||
Headers []header `json:"headers"`
|
||||
Content struct {
|
||||
Text string `json:"text"`
|
||||
Encoding string `json:"encoding"`
|
||||
} `json:"content"`
|
||||
} `json:"response"`
|
||||
}
|
||||
|
||||
type header struct {
|
||||
Name string `json:"name"`
|
||||
Value string `json:"value"`
|
||||
}
|
||||
|
||||
// Name returns the name of the format
|
||||
func (h *HARFormat) Name() string {
|
||||
return "har"
|
||||
}
|
||||
|
||||
func (h *HARFormat) SetOptions(options formats.InputFormatOptions) {
|
||||
h.opts = options
|
||||
}
|
||||
|
||||
// Parse parses the input and calls the provided callback
|
||||
// function for each RawRequest it discovers.
|
||||
func (h *HARFormat) Parse(input io.Reader, resultsCb formats.ParseReqRespCallback, filePath string) error {
|
||||
var har archive
|
||||
if err := json.NewDecoder(input).Decode(&har); err != nil {
|
||||
return errors.Wrap(err, "could not decode har file")
|
||||
}
|
||||
|
||||
for _, e := range har.Log.Entries {
|
||||
// Browsers also log data:, blob: and extension URLs, which have no
|
||||
// host to send a request to.
|
||||
if !strings.HasPrefix(e.Request.URL, "http://") && !strings.HasPrefix(e.Request.URL, "https://") {
|
||||
continue
|
||||
}
|
||||
rawRequest, err := types.ParseRawRequestWithURL(rawRequestOf(e), e.Request.URL)
|
||||
if err != nil {
|
||||
gologger.Warning().Msgf("har: Could not parse request %s: %s\n", e.Request.URL, err)
|
||||
continue
|
||||
}
|
||||
// Status 0 is a request that was blocked or never answered.
|
||||
if e.Response.Status != 0 {
|
||||
rawRequest.Response = &types.HttpResponse{Raw: rawResponseOf(e)}
|
||||
}
|
||||
resultsCb(rawRequest)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// rawRequestOf rebuilds the request as HTTP/1.1 with an absolute target, which
|
||||
// carries the authority that HTTP/2 captures only keep in pseudo-headers.
|
||||
func rawRequestOf(e entry) string {
|
||||
var b strings.Builder
|
||||
b.WriteString(e.Request.Method + " " + e.Request.URL + " HTTP/1.1\r\n")
|
||||
writeHeaders(&b, e.Request.Headers)
|
||||
if e.Request.PostData != nil {
|
||||
b.WriteString(e.Request.PostData.Text)
|
||||
}
|
||||
return b.String()
|
||||
}
|
||||
|
||||
func rawResponseOf(e entry) string {
|
||||
statusText := e.Response.StatusText
|
||||
if statusText == "" {
|
||||
statusText = http.StatusText(e.Response.Status)
|
||||
}
|
||||
var b strings.Builder
|
||||
b.WriteString("HTTP/1.1 " + strconv.Itoa(e.Response.Status) + " " + statusText + "\r\n")
|
||||
writeHeaders(&b, e.Response.Headers)
|
||||
body := e.Response.Content.Text
|
||||
if e.Response.Content.Encoding == "base64" {
|
||||
if decoded, err := base64.StdEncoding.DecodeString(body); err == nil {
|
||||
body = string(decoded)
|
||||
}
|
||||
}
|
||||
b.WriteString(body)
|
||||
return b.String()
|
||||
}
|
||||
|
||||
func writeHeaders(b *strings.Builder, headers []header) {
|
||||
for _, h := range headers {
|
||||
// HTTP/2 pseudo-headers (:authority, :path, ...) are not headers.
|
||||
if strings.HasPrefix(h.Name, ":") {
|
||||
continue
|
||||
}
|
||||
b.WriteString(h.Name + ": " + h.Value + "\r\n")
|
||||
}
|
||||
b.WriteString("\r\n")
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package har
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/input/types"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const chromeHAR = "../testdata/chrome.har"
|
||||
|
||||
func parse(t *testing.T, input string) []*types.RequestResponse {
|
||||
t.Helper()
|
||||
file, err := os.Open(input)
|
||||
require.NoError(t, err)
|
||||
defer func() { _ = file.Close() }()
|
||||
|
||||
var got []*types.RequestResponse
|
||||
require.NoError(t, New().Parse(file, func(rr *types.RequestResponse) bool {
|
||||
got = append(got, rr)
|
||||
return false
|
||||
}, input))
|
||||
return got
|
||||
}
|
||||
|
||||
func TestHARParse(t *testing.T) {
|
||||
got := parse(t, chromeHAR)
|
||||
|
||||
urls := make([]string, 0, len(got))
|
||||
for _, rr := range got {
|
||||
urls = append(urls, rr.URL.String())
|
||||
}
|
||||
require.Equal(t, []string{
|
||||
"https://ginandjuice.shop/catalog?category=Juice",
|
||||
"https://ginandjuice.shop/login",
|
||||
"https://ginandjuice.shop/blocked.js",
|
||||
}, urls, "non-http entries such as data: URLs are skipped")
|
||||
}
|
||||
|
||||
func TestHARParseHTTP2Request(t *testing.T) {
|
||||
rr := parse(t, chromeHAR)[0]
|
||||
|
||||
require.Equal(t, "GET", rr.Request.Method)
|
||||
cookie, _ := rr.Request.Headers.Get("cookie")
|
||||
require.Equal(t, "session=abc123", cookie)
|
||||
for _, name := range rr.Request.Headers.GetKeys() {
|
||||
require.False(t, strings.HasPrefix(name, ":"), "pseudo-header %s is not a real header", name)
|
||||
}
|
||||
|
||||
req, err := rr.BuildRequest()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "ginandjuice.shop", req.Host)
|
||||
}
|
||||
|
||||
func TestHARParseBodyAndResponse(t *testing.T) {
|
||||
got := parse(t, chromeHAR)
|
||||
|
||||
login := got[1]
|
||||
require.Equal(t, "POST", login.Request.Method)
|
||||
require.Equal(t, "username=carlos&password=hunter2", login.Request.Body)
|
||||
require.NotNil(t, login.Response)
|
||||
require.Contains(t, login.Response.Raw, "302 Found")
|
||||
require.Contains(t, login.Response.Raw, "Location: /my-account")
|
||||
|
||||
require.NotNil(t, got[0].Response)
|
||||
require.Contains(t, got[0].Response.Raw, "<h1>Juice</h1>", "base64 content is decoded")
|
||||
|
||||
require.Nil(t, got[2].Response, "a request that never got an answer has no response")
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
//go:build gofuzz
|
||||
// +build gofuzz
|
||||
|
||||
package openapi
|
||||
|
||||
// Fuzz exercises OpenAPI 3.0 schema parsing and request generation. The input
|
||||
// bytes are treated as a raw schema document (YAML or JSON) and fed through the
|
||||
// format's Parse, which loads the schema and generates requests from it.
|
||||
func Fuzz(data []byte) int {
|
||||
if len(data) == 0 {
|
||||
return 0
|
||||
}
|
||||
if len(data) > fuzzMaxInputSize {
|
||||
return -1
|
||||
}
|
||||
if !fuzzOpenAPIParsing(data) {
|
||||
return 0
|
||||
}
|
||||
return 1
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package openapi
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/input/formats"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/input/types"
|
||||
)
|
||||
|
||||
const fuzzMaxInputSize = 64 << 10
|
||||
|
||||
// fuzzOpenAPIParsing feeds data to the OpenAPI format parser as a raw schema
|
||||
// document and drives request generation. It must never panic for any input;
|
||||
// it returns true when the schema parsed and at least one request was produced.
|
||||
func fuzzOpenAPIParsing(data []byte) bool {
|
||||
if len(data) == 0 || len(data) > fuzzMaxInputSize {
|
||||
return false
|
||||
}
|
||||
|
||||
format := New()
|
||||
format.SetOptions(formats.InputFormatOptions{})
|
||||
|
||||
produced := false
|
||||
cb := func(rr *types.RequestResponse) bool {
|
||||
produced = true
|
||||
return true
|
||||
}
|
||||
if err := format.Parse(bytes.NewReader(data), cb, "fuzz.openapi"); err != nil {
|
||||
return false
|
||||
}
|
||||
return produced
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package openapi
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/input/types"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestFuzzOpenAPIParsingSeedCorpus(t *testing.T) {
|
||||
entries, err := os.ReadDir("testdata/gofuzz-corpus")
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, entries)
|
||||
|
||||
for _, entry := range entries {
|
||||
if entry.IsDir() {
|
||||
continue
|
||||
}
|
||||
|
||||
data, err := os.ReadFile(filepath.Join("testdata/gofuzz-corpus", entry.Name()))
|
||||
require.NoError(t, err)
|
||||
require.Truef(t, fuzzOpenAPIParsing(data), "seed %s should produce at least one request", entry.Name())
|
||||
}
|
||||
}
|
||||
|
||||
func TestFuzzOpenAPIParsingRejectsOversizeInput(t *testing.T) {
|
||||
require.False(t, fuzzOpenAPIParsing(make([]byte, fuzzMaxInputSize+1)))
|
||||
}
|
||||
|
||||
// Null entries decode to nil pointers and used to panic during request
|
||||
// generation. The remaining valid entries must still produce requests.
|
||||
func TestFuzzOpenAPIParsingNullEntries(t *testing.T) {
|
||||
specs := map[string]string{
|
||||
"null server": `
|
||||
openapi: 3.0.0
|
||||
info: {title: t, version: "1"}
|
||||
servers:
|
||||
-
|
||||
- {url: "http://example.com"}
|
||||
paths:
|
||||
/users:
|
||||
get:
|
||||
responses: {"200": {description: ok}}
|
||||
`,
|
||||
"null media type": `
|
||||
openapi: 3.0.0
|
||||
info: {title: t, version: "1"}
|
||||
servers: [{url: "http://example.com"}]
|
||||
paths:
|
||||
/users:
|
||||
post:
|
||||
requestBody:
|
||||
content:
|
||||
application/xml:
|
||||
application/json:
|
||||
schema: {type: object, properties: {name: {type: string}}}
|
||||
responses: {"200": {description: ok}}
|
||||
`,
|
||||
}
|
||||
|
||||
for name, spec := range specs {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
require.True(t, fuzzOpenAPIParsing([]byte(spec)))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGenerateRequestsOnlyNullServers(t *testing.T) {
|
||||
spec := `
|
||||
openapi: 3.0.0
|
||||
info: {title: t, version: "1"}
|
||||
servers:
|
||||
-
|
||||
paths:
|
||||
/users:
|
||||
get:
|
||||
responses: {"200": {description: ok}}
|
||||
`
|
||||
err := New().Parse(strings.NewReader(spec), func(*types.RequestResponse) bool { return false }, "spec.yaml")
|
||||
require.ErrorContains(t, err, "no servers found in openapi schema")
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"net/http/httputil"
|
||||
"net/url"
|
||||
"os"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/clbanning/mxj/v2"
|
||||
@@ -33,7 +34,9 @@ const (
|
||||
|
||||
// GenerateRequestsFromSchema generates http requests from an OpenAPI 3.0 document object
|
||||
func GenerateRequestsFromSchema(schema *openapi3.T, opts formats.InputFormatOptions, callback formats.ParseReqRespCallback) error {
|
||||
if len(schema.Servers) == 0 {
|
||||
// Null entries in `servers:` are skipped below, so a list of only null
|
||||
// entries has no usable server, the same as an empty list.
|
||||
if !slices.ContainsFunc(schema.Servers, func(s *openapi3.Server) bool { return s != nil }) {
|
||||
return errors.New("no servers found in openapi schema")
|
||||
}
|
||||
globalParams, globalSecurityErr := selectSecurityParameters(schema, &schema.Security, opts.Variables)
|
||||
@@ -49,6 +52,11 @@ func GenerateRequestsFromSchema(schema *openapi3.T, opts formats.InputFormatOpti
|
||||
}
|
||||
|
||||
for _, serverURL := range schema.Servers {
|
||||
// A null entry in the `servers:` list decodes to a nil *Server, so skip
|
||||
// it rather than dereferencing it.
|
||||
if serverURL == nil {
|
||||
continue
|
||||
}
|
||||
pathURL := serverURL.URL
|
||||
// Split the server URL into baseURL and serverPath
|
||||
u, err := url.Parse(pathURL)
|
||||
@@ -268,6 +276,11 @@ func generateRequestsFromOp(opts *generateReqOptions) error {
|
||||
|
||||
if opts.op.RequestBody != nil {
|
||||
for content, value := range opts.op.RequestBody.Value.Content {
|
||||
// A null media-type entry (e.g. `content: {application/json: }`)
|
||||
// decodes to a nil *MediaType, so skip it before dereferencing.
|
||||
if value == nil {
|
||||
continue
|
||||
}
|
||||
cloned := req.Clone(req.Context())
|
||||
|
||||
var val interface{}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
{"openapi":"3.0.0","info":{"title":"t","version":"1"},"servers":[{"url":"http://example.com"}],"paths":{"/a":{"post":{"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"k":{"type":"string"}}}}}},"responses":{"200":{"description":"ok"}}}}}}
|
||||
@@ -0,0 +1,7 @@
|
||||
openapi: 3.0.0
|
||||
info: {title: t, version: "1"}
|
||||
servers: [{url: "http://example.com"}]
|
||||
paths:
|
||||
/users:
|
||||
get:
|
||||
responses: {"200": {description: ok}}
|
||||
@@ -0,0 +1,12 @@
|
||||
openapi: 3.0.0
|
||||
info: {title: t, version: "1"}
|
||||
servers: [{url: "http://example.com"}]
|
||||
paths:
|
||||
/users:
|
||||
post:
|
||||
requestBody:
|
||||
content:
|
||||
application/xml:
|
||||
application/json:
|
||||
schema: {type: object, properties: {name: {type: string}}}
|
||||
responses: {"200": {description: ok}}
|
||||
@@ -0,0 +1,9 @@
|
||||
openapi: 3.0.0
|
||||
info: {title: t, version: "1"}
|
||||
servers:
|
||||
-
|
||||
- {url: "http://example.com"}
|
||||
paths:
|
||||
/users:
|
||||
get:
|
||||
responses: {"200": {description: ok}}
|
||||
@@ -3,7 +3,9 @@ package swagger
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"maps"
|
||||
"path"
|
||||
"slices"
|
||||
|
||||
"github.com/getkin/kin-openapi/openapi2"
|
||||
"github.com/getkin/kin-openapi/openapi2conv"
|
||||
@@ -55,6 +57,7 @@ func (j *SwaggerFormat) Parse(input io.Reader, resultsCb formats.ParseReqRespCal
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not decode openapi 2.0 schema")
|
||||
}
|
||||
dropNullEntries(schemav2)
|
||||
schema, err := openapi2conv.ToV3(schemav2)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not convert openapi 2.0 schema to 3.0")
|
||||
@@ -67,6 +70,32 @@ func (j *SwaggerFormat) Parse(input io.Reader, resultsCb formats.ParseReqRespCal
|
||||
return openapi.GenerateRequestsFromSchema(schema, j.opts, resultsCb)
|
||||
}
|
||||
|
||||
// dropNullEntries removes null entries from the maps and lists of a decoded
|
||||
// OpenAPI 2.0 document. A null value such as `paths: {/x: }` or an empty list
|
||||
// item under `parameters:` decodes to a nil pointer, which openapi2conv.ToV3
|
||||
// dereferences without checking.
|
||||
func dropNullEntries(doc *openapi2.T) {
|
||||
maps.DeleteFunc(doc.Paths, func(_ string, v *openapi2.PathItem) bool { return v == nil })
|
||||
maps.DeleteFunc(doc.Parameters, func(_ string, v *openapi2.Parameter) bool { return v == nil })
|
||||
dropNullResponses(doc.Responses)
|
||||
for _, pathItem := range doc.Paths {
|
||||
pathItem.Parameters = slices.DeleteFunc(pathItem.Parameters, func(v *openapi2.Parameter) bool { return v == nil })
|
||||
for _, op := range pathItem.Operations() {
|
||||
op.Parameters = slices.DeleteFunc(op.Parameters, func(v *openapi2.Parameter) bool { return v == nil })
|
||||
dropNullResponses(op.Responses)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// dropNullResponses removes null responses, and null headers of the remaining
|
||||
// responses, which openapi2conv.ToV3Response also dereferences.
|
||||
func dropNullResponses(responses map[string]*openapi2.Response) {
|
||||
maps.DeleteFunc(responses, func(_ string, v *openapi2.Response) bool { return v == nil })
|
||||
for _, response := range responses {
|
||||
maps.DeleteFunc(response.Headers, func(_ string, v *openapi2.Header) bool { return v == nil })
|
||||
}
|
||||
}
|
||||
|
||||
func decodeYAML(data []byte, target interface{}) error {
|
||||
var value interface{}
|
||||
if err := yaml.Unmarshal(data, &value); err != nil {
|
||||
|
||||
@@ -2,6 +2,7 @@ package swagger
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/input/types"
|
||||
@@ -39,3 +40,69 @@ func TestSwaggerAPIParser(t *testing.T) {
|
||||
}
|
||||
require.ElementsMatch(t, gotMethodsToURLs, expectedURLs, "could not get swagger urls")
|
||||
}
|
||||
|
||||
func TestSwaggerParseNullEntries(t *testing.T) {
|
||||
// Each spec has a null map value or list item that decodes to a nil
|
||||
// pointer and used to panic inside openapi2conv.ToV3.
|
||||
specs := map[string]string{
|
||||
"null-path-item": `
|
||||
swagger: "2.0"
|
||||
info: {title: t, version: "1"}
|
||||
host: localhost
|
||||
paths:
|
||||
/x:
|
||||
`,
|
||||
"null-parameter": `
|
||||
swagger: "2.0"
|
||||
info: {title: t, version: "1"}
|
||||
host: localhost
|
||||
paths:
|
||||
/x:
|
||||
get:
|
||||
parameters:
|
||||
-
|
||||
responses: {"200": {description: ok}}
|
||||
`,
|
||||
"null-response": `
|
||||
swagger: "2.0"
|
||||
info: {title: t, version: "1"}
|
||||
host: localhost
|
||||
paths:
|
||||
/x:
|
||||
get:
|
||||
responses: {"200": }
|
||||
`,
|
||||
"null-response-header": `
|
||||
swagger: "2.0"
|
||||
info: {title: t, version: "1"}
|
||||
host: localhost
|
||||
responses:
|
||||
Shared:
|
||||
description: ok
|
||||
headers:
|
||||
X-Shared:
|
||||
paths:
|
||||
/x:
|
||||
get:
|
||||
responses:
|
||||
"200":
|
||||
description: ok
|
||||
headers:
|
||||
X-Rate-Limit:
|
||||
`,
|
||||
}
|
||||
|
||||
for name, spec := range specs {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
var count int
|
||||
err := New().Parse(strings.NewReader(spec), func(request *types.RequestResponse) bool {
|
||||
count++
|
||||
return false
|
||||
}, "spec.yaml")
|
||||
require.NoError(t, err)
|
||||
if name != "null-path-item" {
|
||||
require.Equal(t, 1, count, "the operation should still produce a request")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
{
|
||||
"log": {
|
||||
"version": "1.2",
|
||||
"creator": { "name": "WebInspector", "version": "537.36" },
|
||||
"entries": [
|
||||
{
|
||||
"request": {
|
||||
"method": "GET",
|
||||
"url": "https://ginandjuice.shop/catalog?category=Juice",
|
||||
"httpVersion": "http/2.0",
|
||||
"headers": [
|
||||
{ "name": ":authority", "value": "ginandjuice.shop" },
|
||||
{ "name": ":method", "value": "GET" },
|
||||
{ "name": ":path", "value": "/catalog?category=Juice" },
|
||||
{ "name": ":scheme", "value": "https" },
|
||||
{ "name": "accept", "value": "text/html" },
|
||||
{ "name": "cookie", "value": "session=abc123" }
|
||||
],
|
||||
"queryString": [{ "name": "category", "value": "Juice" }],
|
||||
"cookies": [],
|
||||
"headersSize": -1,
|
||||
"bodySize": 0
|
||||
},
|
||||
"response": {
|
||||
"status": 200,
|
||||
"statusText": "",
|
||||
"httpVersion": "http/2.0",
|
||||
"headers": [{ "name": "content-type", "value": "text/html; charset=utf-8" }],
|
||||
"content": { "size": 19, "mimeType": "text/html", "text": "PGgxPkp1aWNlPC9oMT4=", "encoding": "base64" }
|
||||
}
|
||||
},
|
||||
{
|
||||
"request": {
|
||||
"method": "POST",
|
||||
"url": "https://ginandjuice.shop/login",
|
||||
"httpVersion": "HTTP/1.1",
|
||||
"headers": [
|
||||
{ "name": "Host", "value": "ginandjuice.shop" },
|
||||
{ "name": "Content-Type", "value": "application/x-www-form-urlencoded" }
|
||||
],
|
||||
"postData": { "mimeType": "application/x-www-form-urlencoded", "text": "username=carlos&password=hunter2" }
|
||||
},
|
||||
"response": {
|
||||
"status": 302,
|
||||
"statusText": "Found",
|
||||
"httpVersion": "HTTP/1.1",
|
||||
"headers": [{ "name": "Location", "value": "/my-account" }],
|
||||
"content": { "size": 0, "mimeType": "" }
|
||||
}
|
||||
},
|
||||
{
|
||||
"request": {
|
||||
"method": "GET",
|
||||
"url": "data:image/png;base64,iVBORw0KGgo=",
|
||||
"httpVersion": "",
|
||||
"headers": []
|
||||
},
|
||||
"response": { "status": 200, "statusText": "", "httpVersion": "", "headers": [], "content": { "size": 0 } }
|
||||
},
|
||||
{
|
||||
"request": {
|
||||
"method": "GET",
|
||||
"url": "https://ginandjuice.shop/blocked.js",
|
||||
"httpVersion": "",
|
||||
"headers": []
|
||||
},
|
||||
"response": { "status": 0, "statusText": "", "httpVersion": "", "headers": [], "content": { "size": 0 } }
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/projectdiscovery/gologger"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/input/formats"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/input/formats/burp"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/input/formats/har"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/input/formats/json"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/input/formats/openapi"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/input/formats/raw"
|
||||
@@ -142,6 +143,7 @@ func (i *HttpInputProvider) Close() {}
|
||||
// Supported Providers
|
||||
var providersList = []formats.Format{
|
||||
burp.New(),
|
||||
har.New(),
|
||||
json.New(),
|
||||
yaml.New(),
|
||||
openapi.New(),
|
||||
|
||||
+66
-138
@@ -89,8 +89,9 @@ func New(opts *Options) (*ListInputProvider, error) {
|
||||
patterns: normalize.NewFingerprinter(options.MaxURLsPerPattern),
|
||||
ipOptions: &ipOptions{
|
||||
ScanAllIPs: options.ScanAllIPs,
|
||||
IPV4: sliceutil.Contains(options.IPVersion, "4"),
|
||||
IPV6: sliceutil.Contains(options.IPVersion, "6"),
|
||||
IPV4: len(options.IPVersion) == 0 || sliceutil.Contains(options.IPVersion, "4"),
|
||||
IPV6: len(options.IPVersion) == 0 || sliceutil.Contains(options.IPVersion, "6"),
|
||||
Auto: len(options.IPVersion) == 0,
|
||||
},
|
||||
excludedHosts: make(map[string]struct{}),
|
||||
profiles: targetprofile.NewRegistry(configuration.TemplatesDirectory(options, config.DefaultConfig)),
|
||||
@@ -168,6 +169,61 @@ func (i *ListInputProvider) TargetProfiles() *targetprofile.Registry {
|
||||
return i.profiles
|
||||
}
|
||||
|
||||
// selectedIPs returns address pins for a hostname. An empty pin delegates
|
||||
// DNS and connection fallback to fastdialer, which races IPv4 and IPv6.
|
||||
// Set and Del share this selection. With -iv omitted and without -sa, one
|
||||
// unpinned target is returned. -sa returns every selected address.
|
||||
func (i *ListInputProvider) selectedIPs(executionId, hostname string) []string {
|
||||
if i.ipOptions == nil || (!i.ipOptions.ScanAllIPs && (i.ipOptions.Auto || !i.ipOptions.IPV6)) {
|
||||
return []string{""}
|
||||
}
|
||||
dialers := protocolstate.GetDialersWithId(executionId)
|
||||
if dialers == nil {
|
||||
gologger.Warning().Msgf("cannot resolve %s: dialer %s not found", hostname, executionId)
|
||||
return nil
|
||||
}
|
||||
dnsData, err := dialers.Fastdialer.GetDNSData(hostname)
|
||||
if err != nil {
|
||||
gologger.Warning().Msgf("DNS resolution failed for %s: %v", hostname, err)
|
||||
if i.ipOptions.IPV4 {
|
||||
return []string{""}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if len(dnsData.A) == 0 && len(dnsData.AAAA) == 0 {
|
||||
gologger.Warning().Msgf("DNS resolution returned no IP addresses for %s", hostname)
|
||||
if i.ipOptions.IPV4 {
|
||||
return []string{""}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if i.ipOptions.ScanAllIPs {
|
||||
var ips []string
|
||||
if i.ipOptions.IPV6 {
|
||||
ips = append(ips, dnsData.AAAA...)
|
||||
}
|
||||
if i.ipOptions.IPV4 {
|
||||
ips = append(ips, dnsData.A...)
|
||||
}
|
||||
if len(ips) == 0 {
|
||||
gologger.Warning().Msgf("no DNS addresses matching -iv selection for %s", hostname)
|
||||
}
|
||||
return ips
|
||||
}
|
||||
var ips []string
|
||||
if i.ipOptions.IPV6 && len(dnsData.AAAA) > 0 {
|
||||
ips = append(ips, dnsData.AAAA[0])
|
||||
}
|
||||
// Explicit -iv 4,6 scans the first IPv6 address and one unpinned target.
|
||||
if i.ipOptions.IPV4 {
|
||||
ips = append(ips, "")
|
||||
}
|
||||
if len(ips) == 0 {
|
||||
gologger.Warning().Msgf("no IPv6 DNS address found for %s", hostname)
|
||||
}
|
||||
return ips
|
||||
}
|
||||
|
||||
// Set normalizes and stores passed input values
|
||||
func (i *ListInputProvider) Set(executionId string, value string) {
|
||||
i.set(executionId, value, nil)
|
||||
@@ -202,75 +258,11 @@ func (i *ListInputProvider) set(executionId string, value string, selection *tar
|
||||
return
|
||||
}
|
||||
|
||||
if i.ipOptions.ScanAllIPs {
|
||||
// scan all ips
|
||||
dialers := protocolstate.GetDialersWithId(executionId)
|
||||
if dialers == nil {
|
||||
gologger.Error().Msgf("dialers with executionId %s not found", executionId)
|
||||
return
|
||||
}
|
||||
|
||||
dnsData, err := dialers.Fastdialer.GetDNSData(urlx.Hostname())
|
||||
if err == nil {
|
||||
if (len(dnsData.A) + len(dnsData.AAAA)) > 0 {
|
||||
var ips []string
|
||||
if i.ipOptions.IPV4 {
|
||||
ips = append(ips, dnsData.A...)
|
||||
}
|
||||
if i.ipOptions.IPV6 {
|
||||
ips = append(ips, dnsData.AAAA...)
|
||||
}
|
||||
for _, ip := range ips {
|
||||
if ip == "" {
|
||||
continue
|
||||
}
|
||||
metaInput := contextargs.NewMetaInput()
|
||||
metaInput.Input = URL
|
||||
metaInput.CustomIP = ip
|
||||
i.setItem(metaInput, selection)
|
||||
}
|
||||
return
|
||||
} else {
|
||||
gologger.Debug().Msgf("scanAllIps: no ip's found reverting to default")
|
||||
}
|
||||
} else {
|
||||
// failed to scanallips falling back to defaults
|
||||
gologger.Debug().Msgf("scanAllIps: dns resolution failed: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
ips := []string{}
|
||||
// only scan the target but ipv6 if it has one
|
||||
if i.ipOptions.IPV6 {
|
||||
dialers := protocolstate.GetDialersWithId(executionId)
|
||||
if dialers == nil {
|
||||
gologger.Error().Msgf("dialers with executionId %s not found", executionId)
|
||||
return
|
||||
}
|
||||
|
||||
dnsData, err := dialers.Fastdialer.GetDNSData(urlx.Hostname())
|
||||
if err == nil && len(dnsData.AAAA) > 0 {
|
||||
// pick/ prefer 1st
|
||||
ips = append(ips, dnsData.AAAA[0])
|
||||
} else {
|
||||
gologger.Warning().Msgf("target does not have ipv6 address falling back to ipv4 %v\n", err)
|
||||
}
|
||||
}
|
||||
if i.ipOptions.IPV4 {
|
||||
// if IPV4 is enabled do not specify ip let dialer handle it
|
||||
ips = append(ips, "")
|
||||
}
|
||||
|
||||
for _, ip := range ips {
|
||||
for _, ip := range i.selectedIPs(executionId, urlx.Hostname()) {
|
||||
metaInput := contextargs.NewMetaInput()
|
||||
if ip != "" {
|
||||
metaInput.Input = URL
|
||||
metaInput.CustomIP = ip
|
||||
i.setItem(metaInput, selection)
|
||||
} else {
|
||||
metaInput.Input = URL
|
||||
i.setItem(metaInput, selection)
|
||||
}
|
||||
metaInput.Input = URL
|
||||
metaInput.CustomIP = ip
|
||||
i.setItem(metaInput, selection)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -493,75 +485,11 @@ func (i *ListInputProvider) Del(executionId string, value string) {
|
||||
return
|
||||
}
|
||||
|
||||
if i.ipOptions.ScanAllIPs {
|
||||
// scan all ips
|
||||
dialers := protocolstate.GetDialersWithId(executionId)
|
||||
if dialers == nil {
|
||||
gologger.Error().Msgf("dialers with executionId %s not found", executionId)
|
||||
return
|
||||
}
|
||||
|
||||
dnsData, err := dialers.Fastdialer.GetDNSData(urlx.Hostname())
|
||||
if err == nil {
|
||||
if (len(dnsData.A) + len(dnsData.AAAA)) > 0 {
|
||||
var ips []string
|
||||
if i.ipOptions.IPV4 {
|
||||
ips = append(ips, dnsData.A...)
|
||||
}
|
||||
if i.ipOptions.IPV6 {
|
||||
ips = append(ips, dnsData.AAAA...)
|
||||
}
|
||||
for _, ip := range ips {
|
||||
if ip == "" {
|
||||
continue
|
||||
}
|
||||
metaInput := contextargs.NewMetaInput()
|
||||
metaInput.Input = value
|
||||
metaInput.CustomIP = ip
|
||||
i.delItem(metaInput)
|
||||
}
|
||||
return
|
||||
} else {
|
||||
gologger.Debug().Msgf("scanAllIps: no ip's found reverting to default")
|
||||
}
|
||||
} else {
|
||||
// failed to scanallips falling back to defaults
|
||||
gologger.Debug().Msgf("scanAllIps: dns resolution failed: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
ips := []string{}
|
||||
// only scan the target but ipv6 if it has one
|
||||
if i.ipOptions.IPV6 {
|
||||
dialers := protocolstate.GetDialersWithId(executionId)
|
||||
if dialers == nil {
|
||||
gologger.Error().Msgf("dialers with executionId %s not found", executionId)
|
||||
return
|
||||
}
|
||||
|
||||
dnsData, err := dialers.Fastdialer.GetDNSData(urlx.Hostname())
|
||||
if err == nil && len(dnsData.AAAA) > 0 {
|
||||
// pick/ prefer 1st
|
||||
ips = append(ips, dnsData.AAAA[0])
|
||||
} else {
|
||||
gologger.Warning().Msgf("target does not have ipv6 address falling back to ipv4 %v\n", err)
|
||||
}
|
||||
}
|
||||
if i.ipOptions.IPV4 {
|
||||
// if IPV4 is enabled do not specify ip let dialer handle it
|
||||
ips = append(ips, "")
|
||||
}
|
||||
|
||||
for _, ip := range ips {
|
||||
for _, ip := range i.selectedIPs(executionId, urlx.Hostname()) {
|
||||
metaInput := contextargs.NewMetaInput()
|
||||
if ip != "" {
|
||||
metaInput.Input = URL
|
||||
metaInput.CustomIP = ip
|
||||
i.delItem(metaInput)
|
||||
} else {
|
||||
metaInput.Input = URL
|
||||
i.delItem(metaInput)
|
||||
}
|
||||
metaInput.Input = URL
|
||||
metaInput.CustomIP = ip
|
||||
i.delItem(metaInput)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
package list
|
||||
|
||||
import (
|
||||
"net"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
"github.com/projectdiscovery/hmap/store/hybrid"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/contextargs"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/protocolstate"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/types"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// A local deterministic DNS responder for dual-stack, A-only and AAAA-only hosts.
|
||||
type ipVersionDNSHandler struct{}
|
||||
|
||||
func (ipVersionDNSHandler) ServeDNS(w dns.ResponseWriter, r *dns.Msg) {
|
||||
reply := new(dns.Msg)
|
||||
reply.SetReply(r)
|
||||
if len(r.Question) == 0 {
|
||||
_ = w.WriteMsg(reply)
|
||||
return
|
||||
}
|
||||
question := r.Question[0]
|
||||
// Some resolvers try search suffixes before the absolute name. Match the
|
||||
// test host prefix rather than answering unrelated names as dual-stack.
|
||||
host := strings.ToLower(question.Name)
|
||||
if strings.HasPrefix(host, "empty.") {
|
||||
_ = w.WriteMsg(reply)
|
||||
return
|
||||
}
|
||||
isDual := strings.HasPrefix(host, "dual.")
|
||||
isV4 := strings.HasPrefix(host, "v4only.")
|
||||
isV6 := strings.HasPrefix(host, "v6only.")
|
||||
if question.Qtype == dns.TypeA && (isDual || isV4) {
|
||||
reply.Answer = append(reply.Answer, &dns.A{Hdr: dns.RR_Header{Name: question.Name, Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: 60}, A: net.ParseIP("192.0.2.10")})
|
||||
}
|
||||
if question.Qtype == dns.TypeAAAA && (isDual || isV6) {
|
||||
reply.Answer = append(reply.Answer, &dns.AAAA{Hdr: dns.RR_Header{Name: question.Name, Rrtype: dns.TypeAAAA, Class: dns.ClassINET, Ttl: 60}, AAAA: net.ParseIP("2001:db8::10")})
|
||||
}
|
||||
_ = w.WriteMsg(reply)
|
||||
}
|
||||
|
||||
func TestIPVersionsDefaultAndExplicitSelection(t *testing.T) {
|
||||
conn, err := net.ListenPacket("udp", "127.0.0.1:0")
|
||||
require.NoError(t, err)
|
||||
started := make(chan struct{})
|
||||
server := &dns.Server{PacketConn: conn, Handler: ipVersionDNSHandler{}, NotifyStartedFunc: func() { close(started) }}
|
||||
go func() { _ = server.ActivateAndServe() }()
|
||||
t.Cleanup(func() { _ = server.Shutdown() })
|
||||
select {
|
||||
case <-started:
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Fatal("DNS test resolver did not start")
|
||||
}
|
||||
opts := types.DefaultOptions()
|
||||
opts.ExecutionId = "ip-version-regression"
|
||||
opts.InternalResolversList = []string{conn.LocalAddr().String()}
|
||||
require.NoError(t, protocolstate.Init(opts))
|
||||
t.Cleanup(func() { protocolstate.Close(opts.ExecutionId) })
|
||||
for _, tc := range []struct {
|
||||
name, hostname string
|
||||
scanAll, ipv4, ipv6, auto bool
|
||||
want []string
|
||||
}{
|
||||
{"automatic dual-stack keeps dialer fallback", "dual.test", false, true, true, true, []string{""}},
|
||||
{"automatic IPv6-only keeps dialer fallback", "v6only.test", false, true, true, true, []string{""}},
|
||||
{"auto IPv4 fallback", "v4only.test", false, true, true, true, []string{""}},
|
||||
{"auto empty DNS response fallback", "empty.test", false, true, true, true, []string{""}},
|
||||
{"all empty DNS response fallback", "empty.test", true, true, true, true, []string{""}},
|
||||
{"all dual", "dual.test", true, true, true, true, []string{"192.0.2.10", "2001:db8::10"}},
|
||||
{"all IPv6 only", "v6only.test", true, true, true, true, []string{"2001:db8::10"}},
|
||||
{"all IPv4 only", "v4only.test", true, true, true, true, []string{"192.0.2.10"}},
|
||||
{"explicit IPv4 only", "dual.test", false, true, false, false, []string{""}},
|
||||
{"explicit IPv6 only", "dual.test", false, false, true, false, []string{"2001:db8::10"}},
|
||||
{"explicit both", "dual.test", false, true, true, false, []string{"2001:db8::10", ""}},
|
||||
{"all explicit IPv6", "dual.test", true, false, true, false, []string{"2001:db8::10"}},
|
||||
{"all explicit IPv4", "dual.test", true, true, false, false, []string{"192.0.2.10"}},
|
||||
{"IPv6 restricted on IPv4-only", "v4only.test", true, false, true, false, nil},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
hm, err := hybrid.New(hybrid.DefaultDiskOptions)
|
||||
require.NoError(t, err)
|
||||
input := &ListInputProvider{
|
||||
hostMap: hm,
|
||||
excludedHosts: make(map[string]struct{}),
|
||||
ipOptions: &ipOptions{ScanAllIPs: tc.scanAll, IPV4: tc.ipv4, IPV6: tc.ipv6, Auto: tc.auto},
|
||||
}
|
||||
t.Cleanup(input.Close)
|
||||
input.Set(opts.ExecutionId, "https://"+tc.hostname)
|
||||
var got []string
|
||||
input.Iterate(func(value *contextargs.MetaInput) bool {
|
||||
got = append(got, value.CustomIP)
|
||||
return true
|
||||
})
|
||||
require.ElementsMatch(t, tc.want, got)
|
||||
if tc.scanAll && len(tc.want) > 0 {
|
||||
input.Del(opts.ExecutionId, "https://"+tc.hostname)
|
||||
require.EqualValues(t, 0, input.Count(), "Del must remove the same IPs added by Set")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -4,4 +4,5 @@ type ipOptions struct {
|
||||
ScanAllIPs bool
|
||||
IPV4 bool
|
||||
IPV6 bool
|
||||
Auto bool // -iv omitted: one unpinned target unless -sa scans every address
|
||||
}
|
||||
@@ -46,27 +46,13 @@ func TestNewCompilerConsoleDebug(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func outsideModulePath(t *testing.T, name string) string {
|
||||
t.Helper()
|
||||
// os.UserHomeDir (not os.Getenv("HOME")) so this resolves to an absolute,
|
||||
// writable location outside the templates allowlist on every OS. HOME is
|
||||
// unset on GitHub Actions windows-latest, which would otherwise collapse to
|
||||
// a relative path resolved under the templates dir and void the denial test.
|
||||
home, err := os.UserHomeDir()
|
||||
require.NoError(t, err)
|
||||
outsideDir := filepath.Join(home, ".nuclei-test-outside-"+t.Name())
|
||||
require.NoError(t, os.MkdirAll(outsideDir, 0o700))
|
||||
t.Cleanup(func() { _ = os.RemoveAll(outsideDir) })
|
||||
return writeModuleFile(t, outsideDir, name, `module.exports = { value: "outside-secret" };`)
|
||||
}
|
||||
|
||||
func TestRequireLocalFileAccessDenied(t *testing.T) {
|
||||
modulePath := outsideModulePath(t, "outside.js")
|
||||
modulePath := writeModuleFile(t, t.TempDir(), "outside.js", `module.exports = { value: "outside-secret" };`)
|
||||
script := fmt.Sprintf(`var helper = require(%q); ExportAs("value", helper.value); true;`, modulePath)
|
||||
|
||||
result, err := executeScript(t, t.Name(), false, script)
|
||||
require.Error(t, err)
|
||||
require.Contains(t, err.Error(), "outside")
|
||||
require.Contains(t, err.Error(), "-lfa is not enabled")
|
||||
require.Equal(t, err.Error(), result["error"])
|
||||
}
|
||||
|
||||
@@ -88,13 +74,7 @@ func TestRequireTemplateModuleAllowedWithoutLFA(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRequireLocalFileAccessAllowed(t *testing.T) {
|
||||
// -lfa grants the working directory; the system temp dir is never granted.
|
||||
cwd, err := os.Getwd()
|
||||
require.NoError(t, err)
|
||||
moduleDir := filepath.Join(cwd, ".nuclei-module-lfa-test-"+t.Name())
|
||||
require.NoError(t, os.MkdirAll(moduleDir, 0o700))
|
||||
t.Cleanup(func() { _ = os.RemoveAll(moduleDir) })
|
||||
modulePath := writeModuleFile(t, moduleDir, "outside.js", `module.exports = { value: "outside-ok" };`)
|
||||
modulePath := writeModuleFile(t, t.TempDir(), "outside.js", `module.exports = { value: "outside-ok" };`)
|
||||
script := fmt.Sprintf(`var helper = require(%q); ExportAs("value", helper.value); true;`, modulePath)
|
||||
|
||||
result, err := executeScript(t, t.Name(), true, script)
|
||||
@@ -103,12 +83,7 @@ func TestRequireLocalFileAccessAllowed(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRequireDoesNotReusePrivilegedModuleCacheAcrossExecutions(t *testing.T) {
|
||||
cwd, err := os.Getwd()
|
||||
require.NoError(t, err)
|
||||
moduleDir := filepath.Join(cwd, ".nuclei-module-cache-test-"+t.Name())
|
||||
require.NoError(t, os.MkdirAll(moduleDir, 0o700))
|
||||
t.Cleanup(func() { _ = os.RemoveAll(moduleDir) })
|
||||
modulePath := writeModuleFile(t, moduleDir, "outside.js", `module.exports = { value: "outside-ok" };`)
|
||||
modulePath := writeModuleFile(t, t.TempDir(), "outside.js", `module.exports = { value: "outside-ok" };`)
|
||||
program, err := goja.Compile("", fmt.Sprintf(`require(%q).value`, modulePath), false)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -128,7 +103,7 @@ func TestRequireDoesNotReusePrivilegedModuleCacheAcrossExecutions(t *testing.T)
|
||||
ExecutionId: denyExecutionID,
|
||||
}, nil)
|
||||
require.Error(t, err)
|
||||
require.Contains(t, err.Error(), "outside")
|
||||
require.Contains(t, err.Error(), "-lfa is not enabled")
|
||||
}
|
||||
|
||||
func TestExecuteWithRuntimeCleansUpAfterCallbackPanic(t *testing.T) {
|
||||
|
||||
@@ -16,10 +16,12 @@ import (
|
||||
syncutil "github.com/projectdiscovery/utils/sync"
|
||||
|
||||
_ "github.com/projectdiscovery/nuclei/v3/pkg/js/generated/go/libbytes"
|
||||
_ "github.com/projectdiscovery/nuclei/v3/pkg/js/generated/go/libcompress"
|
||||
_ "github.com/projectdiscovery/nuclei/v3/pkg/js/generated/go/libdcerpc"
|
||||
_ "github.com/projectdiscovery/nuclei/v3/pkg/js/generated/go/libdcom"
|
||||
_ "github.com/projectdiscovery/nuclei/v3/pkg/js/generated/go/libfs"
|
||||
_ "github.com/projectdiscovery/nuclei/v3/pkg/js/generated/go/libgrpc"
|
||||
_ "github.com/projectdiscovery/nuclei/v3/pkg/js/generated/go/libhash"
|
||||
_ "github.com/projectdiscovery/nuclei/v3/pkg/js/generated/go/libhttp"
|
||||
_ "github.com/projectdiscovery/nuclei/v3/pkg/js/generated/go/libikev2"
|
||||
_ "github.com/projectdiscovery/nuclei/v3/pkg/js/generated/go/libkerberos"
|
||||
|
||||
@@ -0,0 +1,158 @@
|
||||
package compiler
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/andybalholm/brotli"
|
||||
"github.com/klauspost/compress/gzip"
|
||||
"github.com/klauspost/compress/zlib"
|
||||
"github.com/klauspost/compress/zstd"
|
||||
"github.com/projectdiscovery/dsl"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/protocolstate"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/types"
|
||||
httputil "github.com/projectdiscovery/utils/http"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const streamHashScript = `
|
||||
const net = require('nuclei/net');
|
||||
const compress = require('nuclei/compress');
|
||||
const hash = require('nuclei/hash');
|
||||
|
||||
const conn = net.Open('tcp', %q);
|
||||
conn.Send('GET / HTTP/1.1\r\nHost: test\r\nAccept-Encoding: gzip, deflate, br, zstd\r\n\r\n');
|
||||
let head = '';
|
||||
while (!head.endsWith('\r\n\r\n')) head += conn.RecvString(1);
|
||||
const header = (name) => (head.match(new RegExp('\r\n' + name + ': ([^\r]+)', 'i')) || [])[1];
|
||||
const length = header('Content-Length');
|
||||
const coding = [header('Content-Encoding'), header('Transfer-Encoding')].filter(Boolean).join(', ');
|
||||
|
||||
const d = compress.NewDecoder(coding);
|
||||
const sha = hash.New('sha256'), mmh3 = hash.New('mmh3');
|
||||
const take = (out) => { sha.Write(out); mmh3.Write(out); };
|
||||
if (length !== undefined) {
|
||||
for (let read = 0; read < parseInt(length); ) {
|
||||
const chunk = conn.Recv(65536);
|
||||
read += chunk.length;
|
||||
for (let out = d.Write(chunk); out.length > 0; out = d.Read()) take(out);
|
||||
}
|
||||
for (let out = d.Close(); out.length > 0; out = d.Read()) take(out);
|
||||
} else {
|
||||
while (!d.Finished()) {
|
||||
for (let out = d.Write(conn.Recv(65536)); out.length > 0; out = d.Read()) take(out);
|
||||
}
|
||||
}
|
||||
ExportAs('sha256', sha.Sum());
|
||||
ExportAs('mmh3', mmh3.Sum());
|
||||
true;
|
||||
`
|
||||
|
||||
func encodeBody(t *testing.T, encoding string, data []byte) []byte {
|
||||
t.Helper()
|
||||
var buf bytes.Buffer
|
||||
var w io.WriteCloser
|
||||
switch encoding {
|
||||
case "gzip":
|
||||
w = gzip.NewWriter(&buf)
|
||||
case "deflate":
|
||||
w = zlib.NewWriter(&buf)
|
||||
case "br":
|
||||
w = brotli.NewWriter(&buf)
|
||||
case "zstd":
|
||||
zw, err := zstd.NewWriter(&buf)
|
||||
require.NoError(t, err)
|
||||
w = zw
|
||||
case "":
|
||||
return data
|
||||
}
|
||||
_, err := w.Write(data)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, w.Close())
|
||||
return buf.Bytes()
|
||||
}
|
||||
|
||||
func TestStreamingHashMatchesHTTPEngine(t *testing.T) {
|
||||
rng := rand.New(rand.NewSource(1))
|
||||
var body []byte
|
||||
for len(body) < 6<<20 {
|
||||
body = append(body, "large compressed response body "...)
|
||||
body = append(body, byte(rng.Intn(256)))
|
||||
}
|
||||
|
||||
executionID := t.Name()
|
||||
require.NoError(t, protocolstate.Init(&types.Options{ExecutionId: executionID}))
|
||||
t.Cleanup(func() { protocolstate.Close(executionID) })
|
||||
|
||||
for _, tc := range []struct {
|
||||
encoding string
|
||||
chunked bool
|
||||
}{
|
||||
{"gzip", false},
|
||||
{"gzip", true},
|
||||
{"deflate", false},
|
||||
{"br", true},
|
||||
{"zstd", true},
|
||||
{"", true},
|
||||
} {
|
||||
t.Run(fmt.Sprintf("%s chunked=%v", tc.encoding, tc.chunked), func(t *testing.T) {
|
||||
encoded := encodeBody(t, tc.encoding, body)
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if tc.encoding != "" {
|
||||
w.Header().Set("Content-Encoding", tc.encoding)
|
||||
}
|
||||
if !tc.chunked {
|
||||
w.Header().Set("Content-Length", strconv.Itoa(len(encoded)))
|
||||
_, _ = w.Write(encoded)
|
||||
return
|
||||
}
|
||||
// Flushing before the handler returns makes the body chunked.
|
||||
for rest := encoded; len(rest) > 0; {
|
||||
n := min(len(rest), 50000)
|
||||
_, _ = w.Write(rest[:n])
|
||||
w.(http.Flusher).Flush()
|
||||
rest = rest[n:]
|
||||
}
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
client := &http.Client{Transport: &http.Transport{DisableCompression: true}}
|
||||
resp, err := client.Get(server.URL)
|
||||
require.NoError(t, err)
|
||||
if tc.chunked {
|
||||
require.Equal(t, []string{"chunked"}, resp.TransferEncoding)
|
||||
}
|
||||
chain := httputil.NewResponseChain(resp, 64<<20)
|
||||
defer chain.Close()
|
||||
require.NoError(t, chain.Fill())
|
||||
require.Equal(t, len(body), chain.Body().Len(), "the engine must decode the whole body")
|
||||
engineBody := map[string]interface{}{"body": chain.BodyString()}
|
||||
wantSha, err := dsl.EvalExpr("sha256(body)", engineBody)
|
||||
require.NoError(t, err)
|
||||
wantMmh3, err := dsl.EvalExpr("mmh3(body)", engineBody)
|
||||
require.NoError(t, err)
|
||||
|
||||
serverURL, err := url.Parse(server.URL)
|
||||
require.NoError(t, err)
|
||||
script := fmt.Sprintf(streamHashScript, serverURL.Host)
|
||||
compiled, err := SourceAutoMode(script, false)
|
||||
require.NoError(t, err)
|
||||
result, err := New().ExecuteWithOptions(t.Context(), compiled, NewExecuteArgs(), &ExecuteOptions{
|
||||
ExecutionId: executionID,
|
||||
Source: &script,
|
||||
TimeoutVariants: &types.Timeouts{JsCompilerExecutionTimeout: 20 * time.Second},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, fmt.Sprint(wantSha), result["sha256"])
|
||||
require.Equal(t, fmt.Sprint(wantMmh3), result["mmh3"])
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package compress
|
||||
|
||||
import (
|
||||
lib_compress "github.com/projectdiscovery/nuclei/v3/pkg/js/libs/compress"
|
||||
|
||||
"github.com/projectdiscovery/goja"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/js/gojs"
|
||||
)
|
||||
|
||||
var (
|
||||
module = gojs.NewGojaModule("nuclei/compress")
|
||||
)
|
||||
|
||||
func init() {
|
||||
module.Set(
|
||||
gojs.Objects{
|
||||
// Functions
|
||||
"NewDecoder": lib_compress.NewDecoder,
|
||||
|
||||
// Var and consts
|
||||
|
||||
// Objects / Classes
|
||||
"Decoder": gojs.GetClassConstructor[lib_compress.Decoder](&lib_compress.Decoder{}),
|
||||
},
|
||||
).Register()
|
||||
}
|
||||
|
||||
func Enable(runtime *goja.Runtime) {
|
||||
module.Enable(runtime)
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package hash
|
||||
|
||||
import (
|
||||
lib_hash "github.com/projectdiscovery/nuclei/v3/pkg/js/libs/hash"
|
||||
|
||||
"github.com/projectdiscovery/goja"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/js/gojs"
|
||||
)
|
||||
|
||||
var (
|
||||
module = gojs.NewGojaModule("nuclei/hash")
|
||||
)
|
||||
|
||||
func init() {
|
||||
module.Set(
|
||||
gojs.Objects{
|
||||
// Functions
|
||||
"New": lib_hash.New,
|
||||
|
||||
// Var and consts
|
||||
|
||||
// Objects / Classes
|
||||
"Hash": gojs.GetClassConstructor[lib_hash.Hash](&lib_hash.Hash{}),
|
||||
},
|
||||
).Register()
|
||||
}
|
||||
|
||||
func Enable(runtime *goja.Runtime) {
|
||||
module.Enable(runtime)
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
|
||||
|
||||
/**
|
||||
* NewDecoder returns a decoder for gzip, deflate, br, zstd, chunked or
|
||||
* identity. List several comma-separated, in the order they were applied.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const compress = require('nuclei/compress');
|
||||
* const d = compress.NewDecoder('br');
|
||||
* // Content-Encoding: gzip sent with Transfer-Encoding: chunked
|
||||
* const c = compress.NewDecoder('gzip, chunked');
|
||||
* ```
|
||||
*/
|
||||
export function NewDecoder(encoding: string): Decoder | null {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Decoder decodes a compressed stream written to it in chunks. Each call
|
||||
* returns up to about 1 MB; call Read until it returns nothing before the
|
||||
* next Write.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const compress = require('nuclei/compress');
|
||||
* const hash = require('nuclei/hash');
|
||||
* const d = compress.NewDecoder('gzip');
|
||||
* const h = hash.New('sha256');
|
||||
* for (const chunk of chunks) {
|
||||
* for (let out = d.Write(chunk); out.length > 0; out = d.Read()) h.Write(out);
|
||||
* }
|
||||
* for (let out = d.Close(); out.length > 0; out = d.Read()) h.Write(out);
|
||||
* log(h.Sum());
|
||||
* ```
|
||||
*/
|
||||
export class Decoder {
|
||||
|
||||
|
||||
// Constructor of Decoder
|
||||
constructor() {}
|
||||
/**
|
||||
* Write decodes the next chunk and returns up to about 1 MB of output.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const compress = require('nuclei/compress');
|
||||
* const d = compress.NewDecoder('gzip');
|
||||
* const out = d.Write(chunk);
|
||||
* ```
|
||||
*/
|
||||
public Write(chunk: Uint8Array): Uint8Array | null {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Read returns more decoded bytes, or none once the decoder needs input.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const compress = require('nuclei/compress');
|
||||
* const d = compress.NewDecoder('gzip');
|
||||
* for (let out = d.Write(chunk); out.length > 0; out = d.Read()) log(out.length);
|
||||
* ```
|
||||
*/
|
||||
public Read(): Uint8Array | null {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Close ends the input and returns the last decoded bytes. A truncated
|
||||
* stream errors once the bytes before the cut have been returned.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const compress = require('nuclei/compress');
|
||||
* const d = compress.NewDecoder('gzip');
|
||||
* d.Write(chunk);
|
||||
* for (let out = d.Close(); out.length > 0; out = d.Read()) log(out.length);
|
||||
* ```
|
||||
*/
|
||||
public Close(): Uint8Array | null {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Finished reports whether a stream that marks its own end, such as a
|
||||
* chunked body, has ended and all its output was read.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const compress = require('nuclei/compress');
|
||||
* const d = compress.NewDecoder('gzip, chunked');
|
||||
* while (!d.Finished()) for (let out = d.Write(conn.Recv(65536)); out.length > 0; out = d.Read()) log(out.length);
|
||||
* ```
|
||||
*/
|
||||
public Finished(): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Executable
+77
@@ -0,0 +1,77 @@
|
||||
|
||||
|
||||
/**
|
||||
* New returns a running hash for md5, sha1, sha256, sha512 or mmh3. Sum
|
||||
* matches the DSL function of the same name.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const hash = require('nuclei/hash');
|
||||
* const h = hash.New('sha256');
|
||||
* ```
|
||||
*/
|
||||
export function New(algorithm: string): Hash | null {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Hash is a running hash.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const hash = require('nuclei/hash');
|
||||
* const h = hash.New('sha256');
|
||||
* h.WriteString('hello');
|
||||
* log(h.Sum());
|
||||
* ```
|
||||
*/
|
||||
export class Hash {
|
||||
|
||||
|
||||
// Constructor of Hash
|
||||
constructor() {}
|
||||
/**
|
||||
* Write adds data to the hash.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const hash = require('nuclei/hash');
|
||||
* const h = hash.New('sha256');
|
||||
* h.Write([104, 105]);
|
||||
* ```
|
||||
*/
|
||||
public Write(data: Uint8Array): void {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* WriteString adds the string data to the hash.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const hash = require('nuclei/hash');
|
||||
* const h = hash.New('sha256');
|
||||
* h.WriteString('hi');
|
||||
* ```
|
||||
*/
|
||||
public WriteString(data: string): void {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sum returns the hash of the data written so far, formatted as the DSL does.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const hash = require('nuclei/hash');
|
||||
* const h = hash.New('mmh3');
|
||||
* h.WriteString('hello');
|
||||
* log(h.Sum());
|
||||
* ```
|
||||
*/
|
||||
public Sum(): string | null {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
export * as bytes from './bytes';
|
||||
export * as compress from './compress';
|
||||
export * as dcom from './dcom';
|
||||
export * as dcerpc from './dcerpc';
|
||||
export * as fs from './fs';
|
||||
export * as goconsole from './goconsole';
|
||||
export * as grpc from './grpc';
|
||||
export * as hash from './hash';
|
||||
export * as http from './http';
|
||||
export * as ikev2 from './ikev2';
|
||||
export * as kerberos from './kerberos';
|
||||
|
||||
@@ -0,0 +1,303 @@
|
||||
// Package compress exposes streaming decompression to nuclei JavaScript templates.
|
||||
package compress
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http/httputil"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/dsnet/compress/brotli"
|
||||
"github.com/klauspost/compress/gzip"
|
||||
"github.com/klauspost/compress/zlib"
|
||||
"github.com/klauspost/compress/zstd"
|
||||
)
|
||||
|
||||
// maxDecodedChunk caps the decoded bytes one call hands back.
|
||||
const maxDecodedChunk = 1 << 20
|
||||
|
||||
type pauseReason int
|
||||
|
||||
const (
|
||||
needInput pauseReason = iota
|
||||
outputFull
|
||||
finished
|
||||
)
|
||||
|
||||
type (
|
||||
// Decoder decodes a compressed stream written to it in chunks. Each call
|
||||
// returns up to about 1 MB; call Read until it returns nothing before the
|
||||
// next Write.
|
||||
// @example
|
||||
// ```javascript
|
||||
// const compress = require('nuclei/compress');
|
||||
// const hash = require('nuclei/hash');
|
||||
// const d = compress.NewDecoder('gzip');
|
||||
// const h = hash.New('sha256');
|
||||
// for (const chunk of chunks) {
|
||||
// for (let out = d.Write(chunk); out.length > 0; out = d.Read()) h.Write(out);
|
||||
// }
|
||||
// for (let out = d.Close(); out.length > 0; out = d.Read()) h.Write(out);
|
||||
// log(h.Sum());
|
||||
// ```
|
||||
Decoder struct {
|
||||
ctx context.Context
|
||||
// The decode goroutine and the template's calls take turns over these
|
||||
// channels, so no field is accessed by both at once.
|
||||
resume chan []byte
|
||||
paused chan pauseReason
|
||||
done chan struct{}
|
||||
out []byte
|
||||
|
||||
state pauseReason
|
||||
inputEnded bool
|
||||
|
||||
pending []byte
|
||||
eof bool
|
||||
err error
|
||||
}
|
||||
)
|
||||
|
||||
// NewDecoder returns a decoder for gzip, deflate, br, zstd, chunked or
|
||||
// identity. List several comma-separated, in the order they were applied.
|
||||
// @example
|
||||
// ```javascript
|
||||
// const compress = require('nuclei/compress');
|
||||
// const d = compress.NewDecoder('br');
|
||||
// // Content-Encoding: gzip sent with Transfer-Encoding: chunked
|
||||
// const c = compress.NewDecoder('gzip, chunked');
|
||||
// ```
|
||||
func NewDecoder(ctx context.Context, encoding string) (*Decoder, error) {
|
||||
var opens []func(io.Reader) (io.Reader, func(), error)
|
||||
for name := range strings.SplitSeq(encoding, ",") {
|
||||
switch name = strings.ToLower(strings.TrimSpace(name)); name {
|
||||
case "gzip":
|
||||
opens = append(opens, func(r io.Reader) (io.Reader, func(), error) {
|
||||
zr, err := gzip.NewReader(r)
|
||||
return zr, func() {}, err
|
||||
})
|
||||
case "deflate":
|
||||
opens = append(opens, func(r io.Reader) (io.Reader, func(), error) {
|
||||
zr, err := zlib.NewReader(r)
|
||||
return zr, func() {}, err
|
||||
})
|
||||
case "br":
|
||||
opens = append(opens, func(r io.Reader) (io.Reader, func(), error) {
|
||||
br, err := brotli.NewReader(r, nil)
|
||||
return br, func() {}, err
|
||||
})
|
||||
case "zstd":
|
||||
opens = append(opens, func(r io.Reader) (io.Reader, func(), error) {
|
||||
// One goroutine so no background workers outlive the stream.
|
||||
zr, err := zstd.NewReader(r, zstd.WithDecoderConcurrency(1))
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
return zr, zr.Close, nil
|
||||
})
|
||||
case "chunked":
|
||||
opens = append(opens, func(r io.Reader) (io.Reader, func(), error) {
|
||||
return httputil.NewChunkedReader(r), func() {}, nil
|
||||
})
|
||||
case "", "identity":
|
||||
default:
|
||||
return nil, fmt.Errorf("unsupported encoding %q, expected gzip, deflate, br, zstd, chunked or identity", name)
|
||||
}
|
||||
}
|
||||
slices.Reverse(opens)
|
||||
open := func(r io.Reader) (io.Reader, func(), error) {
|
||||
var closers []func()
|
||||
closeAll := func() {
|
||||
for _, c := range slices.Backward(closers) {
|
||||
c()
|
||||
}
|
||||
}
|
||||
for _, o := range opens {
|
||||
next, c, err := o(r)
|
||||
if err != nil {
|
||||
closeAll()
|
||||
return nil, nil, err
|
||||
}
|
||||
r = next
|
||||
closers = append(closers, c)
|
||||
}
|
||||
return r, closeAll, nil
|
||||
}
|
||||
d := &Decoder{
|
||||
ctx: ctx,
|
||||
resume: make(chan []byte),
|
||||
paused: make(chan pauseReason),
|
||||
done: make(chan struct{}),
|
||||
}
|
||||
go d.run(open)
|
||||
d.wait()
|
||||
return d, nil
|
||||
}
|
||||
|
||||
// Write decodes the next chunk and returns up to about 1 MB of output.
|
||||
// @example
|
||||
// ```javascript
|
||||
// const compress = require('nuclei/compress');
|
||||
// const d = compress.NewDecoder('gzip');
|
||||
// const out = d.Write(chunk);
|
||||
// ```
|
||||
func (d *Decoder) Write(chunk []byte) ([]byte, error) {
|
||||
if d.done == nil {
|
||||
return nil, errNotCreatedByNewDecoder
|
||||
}
|
||||
if d.inputEnded {
|
||||
return nil, errors.New("decoder is closed")
|
||||
}
|
||||
if d.state == outputFull {
|
||||
return nil, errors.New("decoded bytes are waiting: call Read until it returns no bytes before writing more")
|
||||
}
|
||||
if d.state == needInput && len(chunk) > 0 {
|
||||
// The decode goroutine may still hold the chunk after Write returns.
|
||||
d.resumeWith(bytes.Clone(chunk))
|
||||
}
|
||||
return d.result()
|
||||
}
|
||||
|
||||
// Read returns more decoded bytes, or none once the decoder needs input.
|
||||
// @example
|
||||
// ```javascript
|
||||
// const compress = require('nuclei/compress');
|
||||
// const d = compress.NewDecoder('gzip');
|
||||
// for (let out = d.Write(chunk); out.length > 0; out = d.Read()) log(out.length);
|
||||
// ```
|
||||
func (d *Decoder) Read() ([]byte, error) {
|
||||
if d.done == nil {
|
||||
return nil, errNotCreatedByNewDecoder
|
||||
}
|
||||
d.advance()
|
||||
return d.result()
|
||||
}
|
||||
|
||||
// Close ends the input and returns the last decoded bytes. A truncated
|
||||
// stream errors once the bytes before the cut have been returned.
|
||||
// @example
|
||||
// ```javascript
|
||||
// const compress = require('nuclei/compress');
|
||||
// const d = compress.NewDecoder('gzip');
|
||||
// d.Write(chunk);
|
||||
// for (let out = d.Close(); out.length > 0; out = d.Read()) log(out.length);
|
||||
// ```
|
||||
func (d *Decoder) Close() ([]byte, error) {
|
||||
if d.done == nil {
|
||||
return nil, errNotCreatedByNewDecoder
|
||||
}
|
||||
d.inputEnded = true
|
||||
d.advance()
|
||||
return d.result()
|
||||
}
|
||||
|
||||
// Finished reports whether a stream that marks its own end, such as a
|
||||
// chunked body, has ended and all its output was read.
|
||||
// @example
|
||||
// ```javascript
|
||||
// const compress = require('nuclei/compress');
|
||||
// const d = compress.NewDecoder('gzip, chunked');
|
||||
// while (!d.Finished()) for (let out = d.Write(conn.Recv(65536)); out.length > 0; out = d.Read()) log(out.length);
|
||||
// ```
|
||||
func (d *Decoder) Finished() bool {
|
||||
return d.state == finished && len(d.out) == 0
|
||||
}
|
||||
|
||||
var errNotCreatedByNewDecoder = errors.New("decoder was not created with compress.NewDecoder")
|
||||
|
||||
func (d *Decoder) advance() {
|
||||
for len(d.out) == 0 && (d.state == outputFull || d.state == needInput && d.inputEnded) {
|
||||
d.resumeWith(nil)
|
||||
}
|
||||
}
|
||||
|
||||
func (d *Decoder) result() ([]byte, error) {
|
||||
out := d.out
|
||||
d.out = nil
|
||||
if len(out) == 0 && d.state == finished {
|
||||
return nil, d.err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (d *Decoder) resumeWith(chunk []byte) {
|
||||
select {
|
||||
case d.resume <- chunk:
|
||||
d.wait()
|
||||
case <-d.done:
|
||||
d.state = finished
|
||||
}
|
||||
}
|
||||
|
||||
func (d *Decoder) wait() {
|
||||
select {
|
||||
case d.state = <-d.paused:
|
||||
case <-d.done:
|
||||
d.state = finished
|
||||
}
|
||||
}
|
||||
|
||||
func (d *Decoder) run(open func(io.Reader) (io.Reader, func(), error)) {
|
||||
defer close(d.done)
|
||||
r, closeReader, err := open(decoderInput{d})
|
||||
if err != nil {
|
||||
d.err = err
|
||||
return
|
||||
}
|
||||
defer closeReader()
|
||||
_, err = io.Copy(decoderOutput{d}, r)
|
||||
d.err = err
|
||||
}
|
||||
|
||||
func (d *Decoder) pause(reason pauseReason) ([]byte, error) {
|
||||
select {
|
||||
case d.paused <- reason:
|
||||
case <-d.ctx.Done():
|
||||
return nil, context.Cause(d.ctx)
|
||||
}
|
||||
select {
|
||||
case chunk := <-d.resume:
|
||||
return chunk, nil
|
||||
case <-d.ctx.Done():
|
||||
return nil, context.Cause(d.ctx)
|
||||
}
|
||||
}
|
||||
|
||||
type decoderInput struct{ d *Decoder }
|
||||
|
||||
func (in decoderInput) Read(p []byte) (int, error) {
|
||||
d := in.d
|
||||
for len(d.pending) == 0 {
|
||||
if d.eof {
|
||||
return 0, io.EOF
|
||||
}
|
||||
chunk, err := d.pause(needInput)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if chunk == nil {
|
||||
d.eof = true
|
||||
}
|
||||
d.pending = chunk
|
||||
}
|
||||
n := copy(p, d.pending)
|
||||
d.pending = d.pending[n:]
|
||||
return n, nil
|
||||
}
|
||||
|
||||
type decoderOutput struct{ d *Decoder }
|
||||
|
||||
func (out decoderOutput) Write(p []byte) (int, error) {
|
||||
d := out.d
|
||||
d.out = append(d.out, p...)
|
||||
if len(d.out) >= maxDecodedChunk {
|
||||
if _, err := d.pause(outputFull); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
return len(p), nil
|
||||
}
|
||||
@@ -0,0 +1,192 @@
|
||||
package compress
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"io"
|
||||
"math/rand"
|
||||
"net/http/httputil"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/andybalholm/brotli"
|
||||
"github.com/klauspost/compress/gzip"
|
||||
"github.com/klauspost/compress/zlib"
|
||||
"github.com/klauspost/compress/zstd"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func compressed(t *testing.T, encoding string, data []byte) []byte {
|
||||
t.Helper()
|
||||
var buf bytes.Buffer
|
||||
var w io.WriteCloser
|
||||
switch encoding {
|
||||
case "gzip":
|
||||
w = gzip.NewWriter(&buf)
|
||||
case "deflate":
|
||||
w = zlib.NewWriter(&buf)
|
||||
case "br":
|
||||
w = brotli.NewWriter(&buf)
|
||||
case "zstd":
|
||||
zw, err := zstd.NewWriter(&buf)
|
||||
require.NoError(t, err)
|
||||
w = zw
|
||||
case "identity":
|
||||
return data
|
||||
}
|
||||
_, err := w.Write(data)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, w.Close())
|
||||
return buf.Bytes()
|
||||
}
|
||||
|
||||
func decodeInChunks(t *testing.T, d *Decoder, input []byte) ([]byte, error) {
|
||||
t.Helper()
|
||||
rng := rand.New(rand.NewSource(1))
|
||||
var decoded []byte
|
||||
collect := func(out []byte, err error) bool {
|
||||
require.LessOrEqual(t, len(out), maxDecodedChunk+64<<10)
|
||||
decoded = append(decoded, out...)
|
||||
return err == nil && len(out) > 0
|
||||
}
|
||||
drain := func(out []byte, err error) error {
|
||||
for collect(out, err) {
|
||||
out, err = d.Read()
|
||||
}
|
||||
return err
|
||||
}
|
||||
for len(input) > 0 {
|
||||
n := min(len(input), 1+rng.Intn(70000))
|
||||
out, err := d.Write(input[:n])
|
||||
if err := drain(out, err); err != nil {
|
||||
return decoded, err
|
||||
}
|
||||
input = input[n:]
|
||||
}
|
||||
out, err := d.Close()
|
||||
return decoded, drain(out, err)
|
||||
}
|
||||
|
||||
func TestDecoderMatchesWholeBodyDecode(t *testing.T) {
|
||||
data := bytes.Repeat([]byte("nuclei streaming decoder "), 400000)
|
||||
for _, encoding := range []string{"gzip", "deflate", "br", "zstd", "identity"} {
|
||||
t.Run(encoding, func(t *testing.T) {
|
||||
d, err := NewDecoder(t.Context(), encoding)
|
||||
require.NoError(t, err)
|
||||
decoded, err := decodeInChunks(t, d, compressed(t, encoding, data))
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, data, decoded)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func chunked(t *testing.T, data []byte) []byte {
|
||||
t.Helper()
|
||||
var buf bytes.Buffer
|
||||
w := httputil.NewChunkedWriter(&buf)
|
||||
for len(data) > 0 {
|
||||
n := min(len(data), 8000)
|
||||
_, err := w.Write(data[:n])
|
||||
require.NoError(t, err)
|
||||
data = data[n:]
|
||||
}
|
||||
require.NoError(t, w.Close())
|
||||
buf.WriteString("\r\n")
|
||||
return buf.Bytes()
|
||||
}
|
||||
|
||||
func TestDecoderDecodesChunkedTransfer(t *testing.T) {
|
||||
data := bytes.Repeat([]byte("nuclei chunked decoder "), 400000)
|
||||
for _, encoding := range []string{"gzip", "deflate", "br", "zstd", "identity"} {
|
||||
t.Run(encoding, func(t *testing.T) {
|
||||
d, err := NewDecoder(t.Context(), encoding+", chunked")
|
||||
require.NoError(t, err)
|
||||
decoded, err := decodeInChunks(t, d, chunked(t, compressed(t, encoding, data)))
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, data, decoded)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecoderFinishesAtLastChunk(t *testing.T) {
|
||||
data := bytes.Repeat([]byte("finished "), 1000)
|
||||
d, err := NewDecoder(t.Context(), "gzip, chunked")
|
||||
require.NoError(t, err)
|
||||
input := chunked(t, compressed(t, "gzip", data))
|
||||
|
||||
half := len(input) / 2
|
||||
_, err = d.Write(input[:half])
|
||||
require.NoError(t, err)
|
||||
require.False(t, d.Finished())
|
||||
|
||||
out, err := d.Write(input[half:])
|
||||
require.NoError(t, err)
|
||||
var decoded []byte
|
||||
for ; len(out) > 0; out, err = d.Read() {
|
||||
decoded = append(decoded, out...)
|
||||
}
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, data, decoded)
|
||||
require.True(t, d.Finished(), "decoder must finish without Close once the last chunk arrives")
|
||||
}
|
||||
|
||||
func TestDecoderAppliesCodingsInReverse(t *testing.T) {
|
||||
data := bytes.Repeat([]byte("two codings "), 100000)
|
||||
input := compressed(t, "br", compressed(t, "gzip", data))
|
||||
d, err := NewDecoder(t.Context(), "gzip, br")
|
||||
require.NoError(t, err)
|
||||
decoded, err := decodeInChunks(t, d, input)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, data, decoded)
|
||||
}
|
||||
|
||||
func TestDecoderReportsTruncatedStream(t *testing.T) {
|
||||
data := bytes.Repeat([]byte("truncated "), 200000)
|
||||
for _, encoding := range []string{"gzip", "deflate", "br", "zstd", "identity, chunked"} {
|
||||
t.Run(encoding, func(t *testing.T) {
|
||||
var input []byte
|
||||
if encoding == "identity, chunked" {
|
||||
input = chunked(t, data)
|
||||
} else {
|
||||
input = compressed(t, encoding, data)
|
||||
}
|
||||
d, err := NewDecoder(t.Context(), encoding)
|
||||
require.NoError(t, err)
|
||||
decoded, err := decodeInChunks(t, d, input[:len(input)/2])
|
||||
require.Error(t, err)
|
||||
require.True(t, bytes.HasPrefix(data, decoded), "bytes before the cut must still be handed back")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecoderStopsWhenContextEnds(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(t.Context())
|
||||
d, err := NewDecoder(ctx, "gzip")
|
||||
require.NoError(t, err)
|
||||
_, err = d.Write(compressed(t, "gzip", []byte("abandoned"))[:5])
|
||||
require.NoError(t, err)
|
||||
|
||||
cancel()
|
||||
select {
|
||||
case <-d.done:
|
||||
case <-time.After(time.Second):
|
||||
t.Fatal("decode goroutine outlived its context")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewDecoderRejectsUnknownEncoding(t *testing.T) {
|
||||
_, err := NewDecoder(t.Context(), "compress")
|
||||
require.Error(t, err)
|
||||
_, err = NewDecoder(t.Context(), "gzip, compress")
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
||||
func TestDecoderNotCreatedByNewDecoderErrors(t *testing.T) {
|
||||
var d Decoder
|
||||
_, err := d.Write([]byte("x"))
|
||||
require.ErrorIs(t, err, errNotCreatedByNewDecoder)
|
||||
_, err = d.Read()
|
||||
require.ErrorIs(t, err, errNotCreatedByNewDecoder)
|
||||
_, err = d.Close()
|
||||
require.ErrorIs(t, err, errNotCreatedByNewDecoder)
|
||||
}
|
||||
@@ -211,7 +211,7 @@ func (c *Client) RpcDump(ctx context.Context) ([]Endpoint, error) {
|
||||
if dialer == nil {
|
||||
return nil, fmt.Errorf("dialers not initialized for execution %s", c.nj.ExecutionId())
|
||||
}
|
||||
conn, err := protocolstate.DialAllowedWithExecutionID(ctx, c.nj.ExecutionId(), "tcp", net.JoinHostPort(c.Host, strconv.Itoa(135)))
|
||||
conn, err := dialer.Fastdialer.Dial(ctx, "tcp", net.JoinHostPort(c.Host, strconv.Itoa(135)))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("dial epmapper: %w", err)
|
||||
}
|
||||
|
||||
+7
-10
@@ -2,11 +2,9 @@ package fs
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/protocolstate"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/types"
|
||||
)
|
||||
|
||||
// ListDir lists itemType values within a directory
|
||||
@@ -31,10 +29,7 @@ import (
|
||||
// const items = fs.ListDir('/tmp');
|
||||
// ```
|
||||
func ListDir(ctx context.Context, path string, itemType string) ([]string, error) {
|
||||
executionId := protocolstate.ExecutionIDFromContext(ctx)
|
||||
if executionId == "" {
|
||||
return nil, fmt.Errorf("fs: missing executionId")
|
||||
}
|
||||
executionId := ctx.Value("executionId").(string)
|
||||
finalPath, err := protocolstate.NormalizePathWithExecutionId(executionId, path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -65,11 +60,13 @@ func ListDir(ctx context.Context, path string, itemType string) ([]string, error
|
||||
// const content = fs.ReadFile('helpers/usernames.txt');
|
||||
// ```
|
||||
func ReadFile(ctx context.Context, path string) ([]byte, error) {
|
||||
executionId := protocolstate.ExecutionIDFromContext(ctx)
|
||||
if executionId == "" {
|
||||
return nil, fmt.Errorf("fs: missing executionId")
|
||||
executionId := ctx.Value("executionId").(string)
|
||||
finalPath, err := protocolstate.NormalizePathWithExecutionId(executionId, path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return protocolstate.ReadFileAllowed(&types.Options{ExecutionId: executionId}, path)
|
||||
bin, err := os.ReadFile(finalPath)
|
||||
return bin, err
|
||||
}
|
||||
|
||||
// ReadFileAsString reads file contents within permitted paths
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
package fs
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/projectdiscovery/gologger"
|
||||
"github.com/projectdiscovery/gologger/levels"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/catalog/config"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/protocolstate"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/types"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestReadFileAllowsTemplatesPath(t *testing.T) {
|
||||
gologger.DefaultLogger.SetMaxLevel(levels.LevelSilent)
|
||||
templatesDir := t.TempDir()
|
||||
secret := []byte("fs-module-secret")
|
||||
path := filepath.Join(templatesDir, "allowed.txt")
|
||||
require.NoError(t, os.WriteFile(path, secret, 0o600))
|
||||
|
||||
old := config.DefaultConfig.TemplatesDirectory
|
||||
config.DefaultConfig.SetTemplatesDir(templatesDir)
|
||||
t.Cleanup(func() { config.DefaultConfig.SetTemplatesDir(old) })
|
||||
|
||||
executionID := t.Name()
|
||||
protocolstate.SetLfaAllowed(&types.Options{ExecutionId: executionID, AllowLocalFileAccess: false})
|
||||
ctx := context.WithValue(context.Background(), "executionId", executionID) //nolint:staticcheck
|
||||
|
||||
got, err := ReadFile(ctx, path)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, secret, got)
|
||||
}
|
||||
|
||||
func TestReadFileRejectsPathOutsideAllowlist(t *testing.T) {
|
||||
gologger.DefaultLogger.SetMaxLevel(levels.LevelSilent)
|
||||
templatesDir := t.TempDir()
|
||||
old := config.DefaultConfig.TemplatesDirectory
|
||||
config.DefaultConfig.SetTemplatesDir(templatesDir)
|
||||
t.Cleanup(func() { config.DefaultConfig.SetTemplatesDir(old) })
|
||||
|
||||
home, err := os.UserHomeDir()
|
||||
require.NoError(t, err)
|
||||
outside := filepath.Join(home, ".nuclei-fs-module-"+t.Name(), "secret.txt")
|
||||
require.NoError(t, os.MkdirAll(filepath.Dir(outside), 0o700))
|
||||
require.NoError(t, os.WriteFile(outside, []byte("x"), 0o600))
|
||||
t.Cleanup(func() { _ = os.RemoveAll(filepath.Dir(outside)) })
|
||||
|
||||
executionID := t.Name()
|
||||
protocolstate.SetLfaAllowed(&types.Options{ExecutionId: executionID, AllowLocalFileAccess: false})
|
||||
ctx := context.WithValue(context.Background(), "executionId", executionID) //nolint:staticcheck
|
||||
|
||||
_, err = ReadFile(ctx, outside)
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
||||
func TestListDirRejectsOutsideAllowlist(t *testing.T) {
|
||||
gologger.DefaultLogger.SetMaxLevel(levels.LevelSilent)
|
||||
templatesDir := t.TempDir()
|
||||
old := config.DefaultConfig.TemplatesDirectory
|
||||
config.DefaultConfig.SetTemplatesDir(templatesDir)
|
||||
t.Cleanup(func() { config.DefaultConfig.SetTemplatesDir(old) })
|
||||
|
||||
executionID := t.Name()
|
||||
protocolstate.SetLfaAllowed(&types.Options{ExecutionId: executionID, AllowLocalFileAccess: false})
|
||||
ctx := context.WithValue(context.Background(), "executionId", executionID) //nolint:staticcheck
|
||||
|
||||
_, err := ListDir(ctx, "/etc", "file")
|
||||
require.Error(t, err)
|
||||
}
|
||||
@@ -41,8 +41,7 @@ func NewExecDialer(execID string) *gptr.Dialer {
|
||||
}
|
||||
}
|
||||
|
||||
// DialWithExec performs the fastdialer dial after enforcing host policy via the
|
||||
// centralized dial broker (fail-closed when dialers are missing).
|
||||
// DialWithExec performs the fastdialer dial after enforcing host policy.
|
||||
func DialWithExec(ctx context.Context, execID, network, address string) (net.Conn, error) {
|
||||
host, _, err := net.SplitHostPort(address)
|
||||
if err != nil {
|
||||
@@ -51,7 +50,11 @@ func DialWithExec(ctx context.Context, execID, network, address string) (net.Con
|
||||
if !protocolstate.IsHostAllowed(execID, host) {
|
||||
return nil, protocolstate.ErrHostDenied.Msgf(host)
|
||||
}
|
||||
return protocolstate.DialAllowedWithExecutionID(ctx, execID, network, address)
|
||||
dialer := protocolstate.GetDialersWithId(execID)
|
||||
if dialer == nil || dialer.Fastdialer == nil {
|
||||
return nil, fmt.Errorf("goimpacket: no fastdialer registered for executionId %q", execID)
|
||||
}
|
||||
return dialer.Fastdialer.Dial(ctx, network, address)
|
||||
}
|
||||
|
||||
// ExecutionIDFromCtx pulls the executionId set by nuclei on its goja runtime
|
||||
|
||||
@@ -193,25 +193,11 @@ func TestProtosetOutsideTemplatesDirDenied(t *testing.T) {
|
||||
setTemplateDir(t)
|
||||
executionID := initExec(t, &types.Options{AllowLocalFileAccess: false})
|
||||
|
||||
// t.TempDir() lives under os.TempDir(), which is always in the filesystem
|
||||
// allowlist. Create a unique directory under $HOME and skip if HOME itself
|
||||
// is inside that allowlist.
|
||||
home, err := os.UserHomeDir()
|
||||
require.NoError(t, err)
|
||||
absHome, err := filepath.Abs(home)
|
||||
require.NoError(t, err)
|
||||
absTemp, err := filepath.Abs(os.TempDir())
|
||||
require.NoError(t, err)
|
||||
if strings.HasPrefix(absHome+string(os.PathSeparator), absTemp+string(os.PathSeparator)) || absHome == absTemp {
|
||||
t.Skip("$HOME is under the temp root, so it is already allowlisted")
|
||||
}
|
||||
outsideDir, err := os.MkdirTemp(home, "nuclei-grpc-outside-*")
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() { _ = os.RemoveAll(outsideDir) })
|
||||
outside := filepath.Join(outsideDir, "health.protoset")
|
||||
// write the protoset outside the templates directory
|
||||
outside := filepath.Join(t.TempDir(), "health.protoset")
|
||||
require.NoError(t, os.WriteFile(outside, healthProtoset(t), 0o600))
|
||||
|
||||
_, _, err = descriptorSource(context.Background(), executionID, nil, outside)
|
||||
_, _, err := descriptorSource(context.Background(), executionID, nil, outside)
|
||||
require.Error(t, err)
|
||||
require.Contains(t, err.Error(), "protoset path denied")
|
||||
}
|
||||
|
||||
+14
-11
@@ -4,10 +4,10 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/fullstorydev/grpcurl"
|
||||
@@ -20,7 +20,6 @@ import (
|
||||
"google.golang.org/protobuf/types/descriptorpb"
|
||||
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/protocolstate"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/types"
|
||||
)
|
||||
|
||||
// connConfig holds the low level knobs used to build a gRPC client connection.
|
||||
@@ -35,7 +34,7 @@ type connConfig struct {
|
||||
|
||||
// dialTarget builds a *grpc.ClientConn whose every connection is routed through
|
||||
// nuclei's network policy. The host is validated up front and the actual dial
|
||||
// is delegated to the execution's fastdialer via DialAllowedWithExecutionID, so
|
||||
// is delegated to the execution's fastdialer via a custom context dialer, so
|
||||
// IP/host denylists and RestrictLocalNetworkAccess are always enforced. The
|
||||
// passthrough scheme guarantees the target is handed verbatim to our dialer
|
||||
// (instead of gRPC's built in DNS resolver), keeping resolution and policy
|
||||
@@ -54,9 +53,13 @@ func dialTarget(ctx context.Context, executionID, target string, cfg connConfig)
|
||||
if !protocolstate.IsHostAllowed(executionID, host) {
|
||||
return nil, protocolstate.ErrHostDenied.Msgf(host)
|
||||
}
|
||||
dialers := protocolstate.GetDialersWithId(executionID)
|
||||
if dialers == nil || dialers.Fastdialer == nil {
|
||||
return nil, fmt.Errorf("grpc: dialers not initialized for executionId %q", executionID)
|
||||
}
|
||||
|
||||
contextDialer := func(dialCtx context.Context, addr string) (net.Conn, error) {
|
||||
return protocolstate.DialAllowedWithExecutionID(dialCtx, executionID, "tcp", addr)
|
||||
return dialers.Fastdialer.Dial(dialCtx, "tcp", addr)
|
||||
}
|
||||
|
||||
var creds credentials.TransportCredentials
|
||||
@@ -92,14 +95,14 @@ func dialTarget(ctx context.Context, executionID, target string, cfg connConfig)
|
||||
func descriptorSource(ctx context.Context, executionID string, cc *grpc.ClientConn, protosetFile string) (grpcurl.DescriptorSource, func(), error) {
|
||||
noop := func() {}
|
||||
if strings.TrimSpace(protosetFile) != "" {
|
||||
// resolve + read through the filesystem allowlist: unless -lfa /
|
||||
// --allowed-paths expand it, only templates/config/temp roots are
|
||||
// permitted.
|
||||
data, err := protocolstate.ReadFileAllowed(&types.Options{ExecutionId: executionID}, protosetFile)
|
||||
// resolve through the local-file-access allowlist: unless -lfa is set,
|
||||
// only files inside the nuclei-templates directory are permitted.
|
||||
normalized, err := protocolstate.NormalizePathWithExecutionId(executionID, protosetFile)
|
||||
if err != nil {
|
||||
return nil, noop, fmt.Errorf("protoset path denied: %w", err)
|
||||
}
|
||||
data, err := os.ReadFile(normalized)
|
||||
if err != nil {
|
||||
if errors.Is(err, protocolstate.ErrPathDenied) {
|
||||
return nil, noop, fmt.Errorf("protoset path denied: %w", err)
|
||||
}
|
||||
return nil, noop, fmt.Errorf("failed to read protoset file: %w", err)
|
||||
}
|
||||
fds := &descriptorpb.FileDescriptorSet{}
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
package jslibs
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestJSLibsDoNotDialFastdialerDirectly(t *testing.T) {
|
||||
root := ".."
|
||||
var offenders []string
|
||||
err := filepath.WalkDir(root, func(path string, d os.DirEntry, walkErr error) error {
|
||||
if walkErr != nil {
|
||||
return walkErr
|
||||
}
|
||||
if d.IsDir() {
|
||||
if path != root && d.Name() == "guard" {
|
||||
return filepath.SkipDir
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if !strings.HasSuffix(path, ".go") || strings.HasSuffix(path, "_test.go") {
|
||||
return nil
|
||||
}
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
content := string(data)
|
||||
if strings.Contains(content, "Fastdialer.Dial") || strings.Contains(content, "Fastdialer.DialTLS") {
|
||||
offenders = append(offenders, path)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
requireNoError(t, err)
|
||||
if len(offenders) > 0 {
|
||||
t.Fatalf("js libs must dial via protocolstate.DialAllowed, offenders: %v", offenders)
|
||||
}
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
package jslibs
|
||||
|
||||
import (
|
||||
"go/ast"
|
||||
"go/parser"
|
||||
"go/token"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// forbiddenSelectors is keyed by the package *identifier* used at the call
|
||||
// site, not the import path. `import "os/exec"` binds the identifier `exec`, so
|
||||
// a direct `exec.Command(...)` yields the selector key "exec.Command" — the
|
||||
// import path form "os/exec.Command" would never match.
|
||||
var forbiddenSelectors = map[string]struct{}{
|
||||
"net.Dial": {},
|
||||
"net.Dialer": {},
|
||||
"exec.Command": {},
|
||||
"os.Open": {},
|
||||
"os.ReadFile": {},
|
||||
"os.WriteFile": {},
|
||||
}
|
||||
|
||||
func TestJSLibsDoNotUseForbiddenSyscalls(t *testing.T) {
|
||||
root := ".."
|
||||
err := filepath.WalkDir(root, func(path string, d os.DirEntry, walkErr error) error {
|
||||
if walkErr != nil {
|
||||
return walkErr
|
||||
}
|
||||
if d.IsDir() {
|
||||
if path != root && d.Name() == "guard" {
|
||||
return filepath.SkipDir
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if !strings.HasSuffix(path, ".go") || strings.HasSuffix(path, "_test.go") {
|
||||
return nil
|
||||
}
|
||||
|
||||
fset := token.NewFileSet()
|
||||
file, err := parser.ParseFile(fset, path, nil, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Inspect every selector expression (pkg.Name), not just call
|
||||
// expressions: this catches type references such as net.Dialer and
|
||||
// composite literals like net.Dialer{}, not only direct calls.
|
||||
ast.Inspect(file, func(n ast.Node) bool {
|
||||
sel, ok := n.(*ast.SelectorExpr)
|
||||
if !ok {
|
||||
return true
|
||||
}
|
||||
pkg, ok := sel.X.(*ast.Ident)
|
||||
if !ok {
|
||||
return true
|
||||
}
|
||||
key := pkg.Name + "." + sel.Sel.Name
|
||||
if _, blocked := forbiddenSelectors[key]; blocked {
|
||||
t.Fatalf("%s uses forbidden selector %s", path, key)
|
||||
}
|
||||
return true
|
||||
})
|
||||
return nil
|
||||
})
|
||||
requireNoError(t, err)
|
||||
}
|
||||
|
||||
func requireNoError(t *testing.T, err error) {
|
||||
t.Helper()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
// Package hash exposes incremental hashes to nuclei JavaScript templates.
|
||||
package hash
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"crypto/sha1"
|
||||
"crypto/sha256"
|
||||
"crypto/sha512"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"hash"
|
||||
"strings"
|
||||
|
||||
"github.com/spaolacci/murmur3"
|
||||
)
|
||||
|
||||
type (
|
||||
// Hash is a running hash.
|
||||
// @example
|
||||
// ```javascript
|
||||
// const hash = require('nuclei/hash');
|
||||
// const h = hash.New('sha256');
|
||||
// h.WriteString('hello');
|
||||
// log(h.Sum());
|
||||
// ```
|
||||
Hash struct {
|
||||
h hash.Hash
|
||||
mmh3 bool
|
||||
}
|
||||
)
|
||||
|
||||
// New returns a running hash for md5, sha1, sha256, sha512 or mmh3. Sum
|
||||
// matches the DSL function of the same name.
|
||||
// @example
|
||||
// ```javascript
|
||||
// const hash = require('nuclei/hash');
|
||||
// const h = hash.New('sha256');
|
||||
// ```
|
||||
func New(algorithm string) (*Hash, error) {
|
||||
switch strings.ToLower(algorithm) {
|
||||
case "md5":
|
||||
return &Hash{h: md5.New()}, nil
|
||||
case "sha1":
|
||||
return &Hash{h: sha1.New()}, nil
|
||||
case "sha256":
|
||||
return &Hash{h: sha256.New()}, nil
|
||||
case "sha512":
|
||||
return &Hash{h: sha512.New()}, nil
|
||||
case "mmh3":
|
||||
return &Hash{h: murmur3.New32WithSeed(0), mmh3: true}, nil
|
||||
}
|
||||
return nil, fmt.Errorf("unsupported hash algorithm %q, expected md5, sha1, sha256, sha512 or mmh3", algorithm)
|
||||
}
|
||||
|
||||
// Write adds data to the hash.
|
||||
// @example
|
||||
// ```javascript
|
||||
// const hash = require('nuclei/hash');
|
||||
// const h = hash.New('sha256');
|
||||
// h.Write([104, 105]);
|
||||
// ```
|
||||
func (h *Hash) Write(data []byte) error {
|
||||
if h.h == nil {
|
||||
return errNotCreatedByNew
|
||||
}
|
||||
_, _ = h.h.Write(data)
|
||||
return nil
|
||||
}
|
||||
|
||||
// WriteString adds the string data to the hash.
|
||||
// @example
|
||||
// ```javascript
|
||||
// const hash = require('nuclei/hash');
|
||||
// const h = hash.New('sha256');
|
||||
// h.WriteString('hi');
|
||||
// ```
|
||||
func (h *Hash) WriteString(data string) error {
|
||||
return h.Write([]byte(data))
|
||||
}
|
||||
|
||||
// Sum returns the hash of the data written so far, formatted as the DSL does.
|
||||
// @example
|
||||
// ```javascript
|
||||
// const hash = require('nuclei/hash');
|
||||
// const h = hash.New('mmh3');
|
||||
// h.WriteString('hello');
|
||||
// log(h.Sum());
|
||||
// ```
|
||||
func (h *Hash) Sum() (string, error) {
|
||||
if h.h == nil {
|
||||
return "", errNotCreatedByNew
|
||||
}
|
||||
if h.mmh3 {
|
||||
return fmt.Sprintf("%d", int32(h.h.(hash.Hash32).Sum32())), nil
|
||||
}
|
||||
return hex.EncodeToString(h.h.Sum(nil)), nil
|
||||
}
|
||||
|
||||
var errNotCreatedByNew = errors.New("hash was not created with hash.New")
|
||||
@@ -0,0 +1,43 @@
|
||||
package hash
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/projectdiscovery/dsl"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestSumMatchesDSLAcrossChunks(t *testing.T) {
|
||||
data := make([]byte, 3<<20+7)
|
||||
for i := range data {
|
||||
data[i] = byte(i * 31)
|
||||
}
|
||||
for _, algorithm := range []string{"md5", "sha1", "sha256", "sha512", "mmh3"} {
|
||||
t.Run(algorithm, func(t *testing.T) {
|
||||
h, err := New(algorithm)
|
||||
require.NoError(t, err)
|
||||
for chunk := data; len(chunk) > 0; {
|
||||
n := min(len(chunk), 65521)
|
||||
require.NoError(t, h.Write(chunk[:n]))
|
||||
chunk = chunk[n:]
|
||||
}
|
||||
want, err := dsl.EvalExpr(algorithm+"(body)", map[string]interface{}{"body": string(data)})
|
||||
require.NoError(t, err)
|
||||
sum, err := h.Sum()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, want, sum)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewRejectsUnknownAlgorithm(t *testing.T) {
|
||||
_, err := New("crc32")
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
||||
func TestHashNotCreatedByNewErrors(t *testing.T) {
|
||||
var h Hash
|
||||
require.ErrorIs(t, h.WriteString("x"), errNotCreatedByNew)
|
||||
_, err := h.Sum()
|
||||
require.ErrorIs(t, err, errNotCreatedByNew)
|
||||
}
|
||||
@@ -269,6 +269,11 @@ func (c *Client) do(ctx context.Context, method, rawURL, body string) (*Response
|
||||
return nil, protocolstate.ErrHostDenied.Msgf(host)
|
||||
}
|
||||
|
||||
dialers := protocolstate.GetDialersWithId(executionID)
|
||||
if dialers == nil {
|
||||
return nil, fmt.Errorf("dialers not initialized for %s", executionID)
|
||||
}
|
||||
|
||||
tlsConfig := &tls.Config{
|
||||
InsecureSkipVerify: true,
|
||||
MinVersion: tls.VersionTLS10,
|
||||
@@ -285,14 +290,10 @@ func (c *Client) do(ctx context.Context, method, rawURL, body string) (*Response
|
||||
transport := &http.Transport{
|
||||
Proxy: proxy,
|
||||
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
|
||||
return protocolstate.DialAllowedWithExecutionID(ctx, executionID, network, addr)
|
||||
return dialers.Fastdialer.Dial(ctx, network, addr)
|
||||
},
|
||||
DialTLSContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
|
||||
cfg := tlsConfig.Clone()
|
||||
if h, _, err := net.SplitHostPort(addr); err == nil && h != "" && net.ParseIP(h) == nil {
|
||||
cfg.ServerName = h
|
||||
}
|
||||
return protocolstate.DialTLSAllowedWithExecutionID(ctx, executionID, network, addr, cfg)
|
||||
return dialers.Fastdialer.DialTLSWithConfig(ctx, network, addr, tlsConfig)
|
||||
},
|
||||
TLSClientConfig: tlsConfig,
|
||||
ForceAttemptHTTP2: true,
|
||||
|
||||
@@ -81,7 +81,7 @@ func sendToKDCTcp(kclient *Client, msg string) ([]byte, error) {
|
||||
// use that ip address instead of realm/domain for resolving
|
||||
host = kclient.config.ip
|
||||
}
|
||||
tcpConn, err := protocolstate.DialAllowedWithExecutionID(dialCtx, executionId, "tcp", net.JoinHostPort(host, port))
|
||||
tcpConn, err := dialers.Fastdialer.Dial(dialCtx, "tcp", net.JoinHostPort(host, port))
|
||||
if err != nil {
|
||||
errs = append(errs, fmt.Sprintf("error establishing connection to %s: %v", kdcs[i], err))
|
||||
continue
|
||||
@@ -122,7 +122,7 @@ func sendToKDCUdp(kclient *Client, msg string) ([]byte, error) {
|
||||
// use that ip address instead of realm/domain for resolving
|
||||
host = kclient.config.ip
|
||||
}
|
||||
udpConn, err := protocolstate.DialAllowedWithExecutionID(dialCtx, executionId, "udp", net.JoinHostPort(host, port))
|
||||
udpConn, err := dialers.Fastdialer.Dial(dialCtx, "udp", net.JoinHostPort(host, port))
|
||||
if err != nil {
|
||||
errs = append(errs, fmt.Sprintf("error establishing connection to %s: %v", kdcs[i], err))
|
||||
continue
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/projectdiscovery/goja"
|
||||
@@ -20,10 +19,7 @@ func TestCreateTicketDefaultOutput(t *testing.T) {
|
||||
t.Run(fmt.Sprintf("golden=%v/%s", golden, location), func(t *testing.T) {
|
||||
templatesDir := setTemplateDir(t)
|
||||
cwd := templatesDir
|
||||
switch location {
|
||||
case "outside denied":
|
||||
cwd = outsideAllowedDir(t)
|
||||
case "outside allowed":
|
||||
if location != "sandbox" {
|
||||
cwd = t.TempDir()
|
||||
}
|
||||
t.Chdir(cwd)
|
||||
@@ -111,7 +107,7 @@ func TestCreateTicketRejectsDefaultOutputSymlink(t *testing.T) {
|
||||
t.Chdir(cwd)
|
||||
executionID := t.Name()
|
||||
setLocalFileAccess(executionID, false)
|
||||
outside := filepath.Join(outsideAllowedDir(t), "ticket.ccache")
|
||||
outside := filepath.Join(t.TempDir(), "ticket.ccache")
|
||||
require.NoError(t, os.WriteFile(outside, []byte("unchanged"), 0600))
|
||||
if err := os.Symlink(outside, filepath.Join(cwd, "Administrator.ccache")); err != nil {
|
||||
t.Skipf("symlink unavailable: %v", err)
|
||||
@@ -146,7 +142,7 @@ func TestCreateTicketRejectsDefaultOutputHardLink(t *testing.T) {
|
||||
|
||||
func TestCreateGoldenTicketDeniesDefaultOutputFromRuntime(t *testing.T) {
|
||||
setTemplateDir(t)
|
||||
cwd := outsideAllowedDir(t)
|
||||
cwd := t.TempDir()
|
||||
t.Chdir(cwd)
|
||||
executionID := t.Name()
|
||||
setLocalFileAccess(executionID, false)
|
||||
@@ -181,27 +177,6 @@ func TestBuildConfigPreservesIdentity(t *testing.T) {
|
||||
require.Equal(t, req.Domain, cfg.Domain)
|
||||
}
|
||||
|
||||
// outsideAllowedDir returns a new directory outside the file allowlist. The
|
||||
// temp dir is always allowlisted, so t.TempDir() cannot be used for this.
|
||||
func outsideAllowedDir(t *testing.T) string {
|
||||
t.Helper()
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil || home == "" {
|
||||
t.Skip("no home directory to create a path outside the allowlist")
|
||||
}
|
||||
absHome, err := filepath.Abs(home)
|
||||
require.NoError(t, err)
|
||||
absTemp, err := filepath.Abs(os.TempDir())
|
||||
require.NoError(t, err)
|
||||
if absHome == absTemp || strings.HasPrefix(absHome+string(os.PathSeparator), absTemp+string(os.PathSeparator)) {
|
||||
t.Skip("$HOME is under the temp root, so it is already allowlisted")
|
||||
}
|
||||
dir, err := os.MkdirTemp(home, "nuclei-krbforge-outside-*")
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() { _ = os.RemoveAll(dir) })
|
||||
return dir
|
||||
}
|
||||
|
||||
func setTemplateDir(t *testing.T) string {
|
||||
t.Helper()
|
||||
templatesDir := t.TempDir()
|
||||
|
||||
@@ -110,7 +110,7 @@ func NewClient(call goja.ConstructorCall, runtime *goja.Runtime) *goja.Object {
|
||||
if u.Path == "" || u.Path == "/" {
|
||||
u.Path = "/var/run/slapd/ldapi"
|
||||
}
|
||||
conn, err = protocolstate.DialAllowedWithExecutionID(dialCtx, executionId, "unix", u.Path)
|
||||
conn, err = dialers.Fastdialer.Dial(dialCtx, "unix", u.Path)
|
||||
c.nj.HandleError(err, "failed to connect to ldap server")
|
||||
} else {
|
||||
switch u.Scheme {
|
||||
@@ -124,12 +124,12 @@ func NewClient(call goja.ConstructorCall, runtime *goja.Runtime) *goja.Object {
|
||||
if port == "" {
|
||||
port = ldap.DefaultLdapPort
|
||||
}
|
||||
conn, err = protocolstate.DialAllowedWithExecutionID(dialCtx, executionId, "udp", net.JoinHostPort(host, port))
|
||||
conn, err = dialers.Fastdialer.Dial(dialCtx, "udp", net.JoinHostPort(host, port))
|
||||
case "ldap":
|
||||
if port == "" {
|
||||
port = ldap.DefaultLdapPort
|
||||
}
|
||||
conn, err = protocolstate.DialAllowedWithExecutionID(dialCtx, executionId, "tcp", net.JoinHostPort(host, port))
|
||||
conn, err = dialers.Fastdialer.Dial(dialCtx, "tcp", net.JoinHostPort(host, port))
|
||||
case "ldaps":
|
||||
if port == "" {
|
||||
port = ldap.DefaultLdapsPort
|
||||
@@ -138,7 +138,7 @@ func NewClient(call goja.ConstructorCall, runtime *goja.Runtime) *goja.Object {
|
||||
if c.cfg.ServerName != "" {
|
||||
serverName = c.cfg.ServerName
|
||||
}
|
||||
conn, err = protocolstate.DialTLSAllowedWithExecutionID(dialCtx, executionId, "tcp", net.JoinHostPort(host, port),
|
||||
conn, err = dialers.Fastdialer.DialTLSWithConfig(dialCtx, "tcp", net.JoinHostPort(host, port),
|
||||
&tls.Config{InsecureSkipVerify: true, MinVersion: tls.VersionTLS10, ServerName: serverName})
|
||||
}
|
||||
default:
|
||||
|
||||
@@ -91,10 +91,7 @@ type (
|
||||
// log(to_json(info));
|
||||
// ```
|
||||
func (c *MSSQLClient) FingerprintMssql(ctx context.Context, host string, port int) (MSSQLInfo, error) {
|
||||
executionId := protocolstate.ExecutionIDFromContext(ctx)
|
||||
if executionId == "" {
|
||||
return MSSQLInfo{}, fmt.Errorf("mssql: missing executionId")
|
||||
}
|
||||
executionId := ctx.Value("executionId").(string)
|
||||
return memoizedfingerprintMssql(ctx, executionId, host, port)
|
||||
}
|
||||
|
||||
@@ -112,8 +109,12 @@ func fingerprintMssql(ctx context.Context, executionId string, host string, port
|
||||
if !protocolstate.IsHostAllowed(executionId, host) {
|
||||
return info, protocolstate.ErrHostDenied.Msgf(host)
|
||||
}
|
||||
dialer := protocolstate.GetDialersWithId(executionId)
|
||||
if dialer == nil {
|
||||
return info, fmt.Errorf("dialers not initialized for %s", executionId)
|
||||
}
|
||||
|
||||
conn, err := protocolstate.DialAllowedWithExecutionID(ctx, executionId, "tcp", net.JoinHostPort(host, fmt.Sprintf("%d", port)))
|
||||
conn, err := dialer.Fastdialer.Dial(ctx, "tcp", net.JoinHostPort(host, fmt.Sprintf("%d", port)))
|
||||
if err != nil {
|
||||
return info, err
|
||||
}
|
||||
|
||||
@@ -189,5 +189,5 @@ func mssqlConnString(target, username, password, dbName string) string {
|
||||
url.PathEscape(username),
|
||||
url.PathEscape(password),
|
||||
target,
|
||||
protocolstate.SanitizeMSSQLDatabaseName(dbName))
|
||||
url.QueryEscape(dbName))
|
||||
}
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
"github.com/go-sql-driver/mysql"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/js/utils"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/protocolstate"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/types"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -132,7 +131,12 @@ func fingerprintMySQL(ctx context.Context, executionId string, host string, port
|
||||
// host is not valid according to network policy
|
||||
return info, protocolstate.ErrHostDenied.Msgf(host)
|
||||
}
|
||||
conn, err := protocolstate.DialAllowedWithExecutionID(ctx, executionId, "tcp", net.JoinHostPort(host, fmt.Sprintf("%d", port)))
|
||||
dialer := protocolstate.GetDialersWithId(executionId)
|
||||
if dialer == nil {
|
||||
return MySQLInfo{}, fmt.Errorf("dialers not initialized for %s", executionId)
|
||||
}
|
||||
|
||||
conn, err := dialer.Fastdialer.Dial(ctx, "tcp", net.JoinHostPort(host, fmt.Sprintf("%d", port)))
|
||||
if err != nil {
|
||||
return info, err
|
||||
}
|
||||
@@ -216,14 +220,6 @@ func (c *MySQLClient) ExecuteQueryWithOpts(ctx context.Context, opts MySQLOption
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// allowAllFiles is always stripped from the DSN; LOAD DATA LOCAL INFILE
|
||||
// only works for allowlisted files the query names.
|
||||
release, err := protocolstate.RegisterMySQLLocalInfiles(&types.Options{ExecutionId: executionId}, dsn, query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer release()
|
||||
|
||||
db, err := openDB(executionId, dsn)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -2,7 +2,11 @@ package mysql
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
@@ -169,6 +173,84 @@ func TestFingerprintMySQLDeniedByNetworkPolicy(t *testing.T) {
|
||||
require.Contains(t, err.Error(), "127.0.0.1")
|
||||
}
|
||||
|
||||
func TestConnectWithDSNDeniedByNetworkPolicy(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
executionID := "mysql-dsn-deny-" + strings.NewReplacer("/", "-", " ", "-").Replace(t.Name())
|
||||
require.NoError(t, protocolstate.Init(&types.Options{
|
||||
ExecutionId: executionID,
|
||||
RestrictLocalNetworkAccess: true,
|
||||
}))
|
||||
t.Cleanup(func() { protocolstate.Close(executionID) })
|
||||
ctx := context.WithValue(context.Background(), "executionId", executionID) //nolint:staticcheck
|
||||
|
||||
var accepted atomic.Int32
|
||||
ln, err := net.Listen("tcp", "127.0.0.1:0")
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() { _ = ln.Close() })
|
||||
go func() {
|
||||
for {
|
||||
conn, err := ln.Accept()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
accepted.Add(1)
|
||||
_ = conn.Close()
|
||||
}
|
||||
}()
|
||||
|
||||
port := ln.Addr().(*net.TCPAddr).Port
|
||||
dsn := fmt.Sprintf("vuser:vpass@tcp(127.0.0.1:%d)/vdb", port)
|
||||
ok, err := (&MySQLClient{}).ConnectWithDSN(ctx, dsn)
|
||||
require.Error(t, err)
|
||||
require.False(t, ok)
|
||||
require.Contains(t, err.Error(), "127.0.0.1")
|
||||
require.Zero(t, accepted.Load())
|
||||
}
|
||||
|
||||
func TestConnectWithDSNUnixDeniedByNetworkPolicy(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
executionID := "mysql-dsn-unix-deny-" + strings.NewReplacer("/", "-", " ", "-").Replace(t.Name())
|
||||
require.NoError(t, protocolstate.Init(&types.Options{
|
||||
ExecutionId: executionID,
|
||||
RestrictLocalNetworkAccess: true,
|
||||
}))
|
||||
t.Cleanup(func() { protocolstate.Close(executionID) })
|
||||
ctx := context.WithValue(context.Background(), "executionId", executionID) //nolint:staticcheck
|
||||
|
||||
// t.TempDir can exceed the unix socket path limit on macOS, so use a short dir.
|
||||
dir, err := os.MkdirTemp("", "nuclei-mysql")
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() { _ = os.RemoveAll(dir) })
|
||||
sock := filepath.Join(dir, "lna.sock")
|
||||
ln, err := net.Listen("unix", sock)
|
||||
if err != nil && runtime.GOOS == "windows" {
|
||||
t.Skipf("unix sockets not available: %v", err)
|
||||
}
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() { _ = ln.Close() })
|
||||
|
||||
var accepted atomic.Int32
|
||||
go func() {
|
||||
for {
|
||||
conn, err := ln.Accept()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
accepted.Add(1)
|
||||
_ = conn.Close()
|
||||
}
|
||||
}()
|
||||
|
||||
dsn := fmt.Sprintf("vuser:vpass@unix(%s)/vdb", sock)
|
||||
ok, err := (&MySQLClient{}).ConnectWithDSN(ctx, dsn)
|
||||
require.Error(t, err)
|
||||
require.False(t, ok)
|
||||
require.Contains(t, err.Error(), "127.0.0.1")
|
||||
require.Zero(t, accepted.Load())
|
||||
}
|
||||
|
||||
func TestFingerprintMySQLVersionNeverEmptyOnHandshakeFixtures(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/go-sql-driver/mysql"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/protocolstate"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/types"
|
||||
)
|
||||
@@ -76,9 +76,57 @@ func BuildDSN(opts MySQLOptions) (string, error) {
|
||||
return dsn.String(), nil
|
||||
}
|
||||
|
||||
func openDB(executionId, dsn string) (*sql.DB, error) {
|
||||
// sandboxDSN enforces local file and network policy on a MySQL DSN.
|
||||
// allowAllFiles is only honored when -lfa is enabled. tcp, tcp4 and tcp6
|
||||
// DSNs are rewritten to nucleitcp so the driver uses the fastdialer
|
||||
// registered in protocolstate. Unix sockets are treated as loopback for -lna.
|
||||
// Other networks are rejected.
|
||||
func sandboxDSN(executionId, dsn string) (string, error) {
|
||||
cfg, err := mysql.ParseDSN(dsn)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
opts := &types.Options{ExecutionId: executionId}
|
||||
dsn, err := protocolstate.SanitizeMySQLDSN(dsn, opts)
|
||||
if cfg.AllowAllFiles && !protocolstate.IsLfaAllowed(opts) {
|
||||
cfg.AllowAllFiles = false
|
||||
}
|
||||
|
||||
netName := cfg.Net
|
||||
if netName == "" {
|
||||
netName = "tcp"
|
||||
}
|
||||
switch netName {
|
||||
case "unix":
|
||||
// IP-based policy never sees a socket path; gate on loopback like ldapi.
|
||||
const unixPolicyHost = "127.0.0.1"
|
||||
if !protocolstate.IsHostAllowed(executionId, unixPolicyHost) {
|
||||
return "", protocolstate.ErrHostDenied.Msgf(unixPolicyHost)
|
||||
}
|
||||
case "tcp", "tcp4", "tcp6", "nucleitcp":
|
||||
// Only nucleitcp has a registered dialer; the others would use the
|
||||
// driver's plain net.Dialer and skip the dial-time policy check.
|
||||
cfg.Net = "nucleitcp"
|
||||
host := dsnPolicyHost(cfg.Addr)
|
||||
if !protocolstate.IsHostAllowed(executionId, host) {
|
||||
return "", protocolstate.ErrHostDenied.Msgf(host)
|
||||
}
|
||||
default:
|
||||
return "", fmt.Errorf("unsupported mysql network %q", netName)
|
||||
}
|
||||
return cfg.FormatDSN(), nil
|
||||
}
|
||||
|
||||
func dsnPolicyHost(addr string) string {
|
||||
host, _, err := net.SplitHostPort(addr)
|
||||
if err == nil && host != "" {
|
||||
return host
|
||||
}
|
||||
return addr
|
||||
}
|
||||
|
||||
// openDB opens a sandboxed MySQL connection from dsn.
|
||||
func openDB(executionId, dsn string) (*sql.DB, error) {
|
||||
dsn, err := sandboxDSN(executionId, dsn)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -4,14 +4,15 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/go-sql-driver/mysql"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/protocolstate"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/types"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestSandboxDSN(t *testing.T) {
|
||||
t.Run("strips allowAllFiles when lfa disabled", func(t *testing.T) {
|
||||
got, err := protocolstate.SanitizeMySQLDSN("root:x@nucleitcp(127.0.0.1:3306)/?allowAllFiles=true", &types.Options{})
|
||||
got, err := sandboxDSN("", "root:x@nucleitcp(127.0.0.1:3306)/?allowAllFiles=true")
|
||||
require.NoError(t, err)
|
||||
|
||||
cfg, err := mysql.ParseDSN(got)
|
||||
@@ -19,17 +20,24 @@ func TestSandboxDSN(t *testing.T) {
|
||||
require.False(t, cfg.AllowAllFiles)
|
||||
})
|
||||
|
||||
t.Run("strips allowAllFiles when lfa enabled", func(t *testing.T) {
|
||||
got, err := protocolstate.SanitizeMySQLDSN("root:x@nucleitcp(127.0.0.1:3306)/?allowAllFiles=true", &types.Options{AllowLocalFileAccess: true})
|
||||
t.Run("keeps allowAllFiles when lfa enabled", func(t *testing.T) {
|
||||
executionID := "mysql-lfa-" + t.Name()
|
||||
require.NoError(t, protocolstate.Init(&types.Options{
|
||||
ExecutionId: executionID,
|
||||
AllowLocalFileAccess: true,
|
||||
}))
|
||||
t.Cleanup(func() { protocolstate.Close(executionID) })
|
||||
|
||||
got, err := sandboxDSN(executionID, "root:x@nucleitcp(127.0.0.1:3306)/?allowAllFiles=true")
|
||||
require.NoError(t, err)
|
||||
|
||||
cfg, err := mysql.ParseDSN(got)
|
||||
require.NoError(t, err)
|
||||
require.False(t, cfg.AllowAllFiles, "-lfa must never disable the allowlist")
|
||||
require.True(t, cfg.AllowAllFiles)
|
||||
})
|
||||
|
||||
t.Run("leaves dsn without allowAllFiles untouched", func(t *testing.T) {
|
||||
got, err := protocolstate.SanitizeMySQLDSN("root:x@nucleitcp(127.0.0.1:3306)/", &types.Options{})
|
||||
got, err := sandboxDSN("", "root:x@nucleitcp(127.0.0.1:3306)/")
|
||||
require.NoError(t, err)
|
||||
|
||||
cfg, err := mysql.ParseDSN(got)
|
||||
@@ -37,8 +45,80 @@ func TestSandboxDSN(t *testing.T) {
|
||||
require.False(t, cfg.AllowAllFiles)
|
||||
})
|
||||
|
||||
t.Run("rewrites tcp to nucleitcp", func(t *testing.T) {
|
||||
got, err := sandboxDSN("", "root:x@tcp(acme.com:3306)/")
|
||||
require.NoError(t, err)
|
||||
|
||||
cfg, err := mysql.ParseDSN(got)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "nucleitcp", cfg.Net)
|
||||
require.Equal(t, "acme.com:3306", cfg.Addr)
|
||||
})
|
||||
|
||||
t.Run("rewrites tcp4 and tcp6 to nucleitcp", func(t *testing.T) {
|
||||
for _, netName := range []string{"tcp4", "tcp6"} {
|
||||
got, err := sandboxDSN("", "root:x@"+netName+"(acme.com:3306)/")
|
||||
require.NoError(t, err)
|
||||
|
||||
cfg, err := mysql.ParseDSN(got)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "nucleitcp", cfg.Net)
|
||||
require.Equal(t, "acme.com:3306", cfg.Addr)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("rejects unsupported network", func(t *testing.T) {
|
||||
_, err := sandboxDSN("", "root:x@udp(acme.com:3306)/")
|
||||
require.Error(t, err)
|
||||
require.Contains(t, err.Error(), "udp")
|
||||
})
|
||||
|
||||
t.Run("errors on invalid dsn", func(t *testing.T) {
|
||||
_, err := protocolstate.SanitizeMySQLDSN("::not-a-dsn::", &types.Options{})
|
||||
_, err := sandboxDSN("", "::not-a-dsn::")
|
||||
require.Error(t, err)
|
||||
})
|
||||
|
||||
t.Run("denies loopback tcp when lna enabled", func(t *testing.T) {
|
||||
executionID := "mysql-lna-tcp-" + t.Name()
|
||||
require.NoError(t, protocolstate.Init(&types.Options{
|
||||
ExecutionId: executionID,
|
||||
RestrictLocalNetworkAccess: true,
|
||||
}))
|
||||
t.Cleanup(func() { protocolstate.Close(executionID) })
|
||||
|
||||
_, err := sandboxDSN(executionID, "vuser:vpass@tcp(127.0.0.1:3306)/vdb")
|
||||
require.Error(t, err)
|
||||
require.Contains(t, err.Error(), "127.0.0.1")
|
||||
})
|
||||
|
||||
t.Run("denies loopback variants when lna enabled", func(t *testing.T) {
|
||||
executionID := "mysql-lna-variants-" + t.Name()
|
||||
require.NoError(t, protocolstate.Init(&types.Options{
|
||||
ExecutionId: executionID,
|
||||
RestrictLocalNetworkAccess: true,
|
||||
}))
|
||||
t.Cleanup(func() { protocolstate.Close(executionID) })
|
||||
|
||||
for _, dsn := range []string{
|
||||
"vuser:vpass@tcp4(127.0.0.1:3306)/vdb",
|
||||
"vuser:vpass@tcp6([::1]:3306)/vdb",
|
||||
"vuser:vpass@tcp([::ffff:127.0.0.1]:3306)/vdb",
|
||||
} {
|
||||
_, err := sandboxDSN(executionID, dsn)
|
||||
require.Error(t, err, dsn)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("denies unix socket when lna enabled", func(t *testing.T) {
|
||||
executionID := "mysql-lna-unix-" + t.Name()
|
||||
require.NoError(t, protocolstate.Init(&types.Options{
|
||||
ExecutionId: executionID,
|
||||
RestrictLocalNetworkAccess: true,
|
||||
}))
|
||||
t.Cleanup(func() { protocolstate.Close(executionID) })
|
||||
|
||||
_, err := sandboxDSN(executionID, "vuser:vpass@unix(/tmp/nuclei-mysql-lna.sock)/vdb")
|
||||
require.Error(t, err)
|
||||
require.Contains(t, err.Error(), "127.0.0.1")
|
||||
})
|
||||
}
|
||||
+12
-3
@@ -192,13 +192,13 @@ func Dial(ctx context.Context, protocol, address string) (net.Conn, error) {
|
||||
if !protocolstate.IsHostAllowed(executionId, dialTargetHost(address)) {
|
||||
return nil, fmt.Errorf("host %s is not allowed by network policy", address)
|
||||
}
|
||||
return dialHTTPProxy(ctx, protocolstate.DialAllowed, proxyURL, address, getTimeoutFromContext(ctx))
|
||||
return dialHTTPProxy(ctx, dialer.Fastdialer.Dial, proxyURL, address, getTimeoutFromContext(ctx))
|
||||
default:
|
||||
return nil, fmt.Errorf("unsupported proxy scheme %q in %s (expected http or https)", parsed.Scheme, redactProxyURL(proxyURL))
|
||||
}
|
||||
}
|
||||
|
||||
return protocolstate.DialAllowed(ctx, protocol, address)
|
||||
return dialer.Fastdialer.Dial(ctx, protocol, address)
|
||||
}
|
||||
|
||||
// Open opens a new connection to the address with a timeout.
|
||||
@@ -233,6 +233,7 @@ func OpenTLS(ctx context.Context, protocol, address string) (*NetConn, error) {
|
||||
c.ServerName = host
|
||||
config = c
|
||||
}
|
||||
|
||||
if proxyURLFromContext(ctx) != "" {
|
||||
conn, err := Dial(ctx, protocol, address)
|
||||
if err != nil {
|
||||
@@ -246,7 +247,15 @@ func OpenTLS(ctx context.Context, protocol, address string) (*NetConn, error) {
|
||||
return &NetConn{conn: tlsConn, timeout: timeout}, nil
|
||||
}
|
||||
|
||||
conn, err := protocolstate.DialTLSAllowed(ctx, protocol, address, config)
|
||||
executionId, err := executionIDFromContext(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dialer := protocolstate.GetDialersWithId(executionId)
|
||||
if dialer == nil {
|
||||
return nil, fmt.Errorf("dialers not initialized for %s", executionId)
|
||||
}
|
||||
conn, err := dialer.Fastdialer.DialTLSWithConfig(ctx, protocol, address, config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -5,14 +5,15 @@ import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/praetorian-inc/fingerprintx/pkg/plugins"
|
||||
"github.com/praetorian-inc/fingerprintx/pkg/plugins/services/oracledb"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/js/utils"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/protocolstate"
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/types"
|
||||
goora "github.com/sijms/go-ora/v2"
|
||||
)
|
||||
|
||||
@@ -55,9 +56,14 @@ func (c *OracleClient) IsOracle(ctx context.Context, host string, port int) (IsO
|
||||
// @memo
|
||||
func isOracle(ctx context.Context, executionId string, host string, port int) (IsOracleResponse, error) {
|
||||
resp := IsOracleResponse{}
|
||||
timeout := 5 * time.Second
|
||||
|
||||
conn, err := protocolstate.DialAllowedWithExecutionID(ctx, executionId, "tcp", net.JoinHostPort(host, strconv.Itoa(port)))
|
||||
dialer := protocolstate.GetDialersWithId(executionId)
|
||||
if dialer == nil {
|
||||
return IsOracleResponse{}, fmt.Errorf("dialers not initialized for %s", executionId)
|
||||
}
|
||||
|
||||
timeout := 5 * time.Second
|
||||
conn, err := dialer.Fastdialer.Dial(ctx, "tcp", net.JoinHostPort(host, strconv.Itoa(port)))
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -80,8 +86,7 @@ func isOracle(ctx context.Context, executionId string, host string, port int) (I
|
||||
}
|
||||
|
||||
func (c *OracleClient) oracleDbInstance(ctx context.Context, connStr string, executionId string) (*goora.OracleConnector, error) {
|
||||
opts := &types.Options{ExecutionId: executionId}
|
||||
connStr, err := protocolstate.SanitizeOracleDSN(executionId, connStr, opts)
|
||||
connStr, err := sandboxDSN(executionId, connStr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -102,6 +107,48 @@ func (c *OracleClient) oracleDbInstance(ctx context.Context, connStr string, exe
|
||||
return c.connector, nil
|
||||
}
|
||||
|
||||
func sandboxDSN(executionId string, dsn string) (string, error) {
|
||||
parsed, err := url.Parse(dsn)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
query := parsed.Query()
|
||||
changed := false
|
||||
for key, values := range query {
|
||||
if !isOracleTracePathOption(key) {
|
||||
continue
|
||||
}
|
||||
for i, value := range values {
|
||||
if value == "" {
|
||||
continue
|
||||
}
|
||||
normalized, err := protocolstate.NormalizePathWithExecutionId(executionId, value)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("oracle %s %q: %w", key, value, err)
|
||||
}
|
||||
values[i] = normalized
|
||||
}
|
||||
query[key] = values
|
||||
changed = true
|
||||
}
|
||||
if !changed {
|
||||
return dsn, nil
|
||||
}
|
||||
|
||||
parsed.RawQuery = query.Encode()
|
||||
return parsed.String(), nil
|
||||
}
|
||||
|
||||
func isOracleTracePathOption(key string) bool {
|
||||
switch strings.ToUpper(strings.TrimSpace(key)) {
|
||||
case "TRACE FILE", "TRACE DIR", "TRACE FOLDER", "TRACE DIRECTORY":
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// Connect connects to an Oracle database
|
||||
// @example
|
||||
// ```javascript
|
||||
|
||||
@@ -2,7 +2,6 @@ package oracle
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
@@ -13,17 +12,6 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// outsideTemplatesPath returns an absolute path that is guaranteed to sit
|
||||
// outside the sandbox allowlist on every OS. A Unix-style "/etc/..." literal is
|
||||
// not absolute on Windows, so it would be resolved relative to the templates
|
||||
// dir and fail with a "does not exist" error before the allowlist check ever
|
||||
// runs. Rooting at the temp volume keeps it drive-qualified on Windows yet
|
||||
// never inside the templates/temp/cwd roots.
|
||||
func outsideTemplatesPath(name string) string {
|
||||
root := filepath.VolumeName(os.TempDir()) + string(os.PathSeparator)
|
||||
return filepath.Join(root, "nuclei-denied", name)
|
||||
}
|
||||
|
||||
func TestSandboxDSNRejectsTraceFileOutsideTemplatesWithoutLFA(t *testing.T) {
|
||||
templatesDir := t.TempDir()
|
||||
restoreOracleTemplatesDir(t, templatesDir)
|
||||
@@ -31,14 +19,14 @@ func TestSandboxDSNRejectsTraceFileOutsideTemplatesWithoutLFA(t *testing.T) {
|
||||
executionID := t.Name()
|
||||
protocolstate.SetLfaAllowed(&types.Options{ExecutionId: executionID, AllowLocalFileAccess: false})
|
||||
|
||||
traceFile := outsideTemplatesPath("nuclei-oracle-trace-test.log")
|
||||
traceFile := filepath.Join(t.TempDir(), "trace.log")
|
||||
dsn := go_ora.BuildUrl("127.0.0.1", 1521, "XE", "user", "pass", map[string]string{
|
||||
"TRACE FILE": traceFile,
|
||||
})
|
||||
|
||||
_, err := protocolstate.SanitizeOracleDSN(executionID, dsn, &types.Options{ExecutionId: executionID, AllowLocalFileAccess: false})
|
||||
_, err := sandboxDSN(executionID, dsn)
|
||||
require.Error(t, err)
|
||||
require.Contains(t, err.Error(), "outside")
|
||||
require.Contains(t, err.Error(), "-lfa is not enabled")
|
||||
}
|
||||
|
||||
func TestConnectWithDSNRejectsTraceFileBeforeOracleOpen(t *testing.T) {
|
||||
@@ -48,7 +36,7 @@ func TestConnectWithDSNRejectsTraceFileBeforeOracleOpen(t *testing.T) {
|
||||
executionID := t.Name()
|
||||
protocolstate.SetLfaAllowed(&types.Options{ExecutionId: executionID, AllowLocalFileAccess: false})
|
||||
|
||||
traceFile := outsideTemplatesPath("nuclei-oracle-connect-trace-test.log")
|
||||
traceFile := filepath.Join(t.TempDir(), "trace.log")
|
||||
dsn := go_ora.BuildUrl("127.0.0.1", 1521, "XE", "user", "pass", map[string]string{
|
||||
"TRACE FILE": traceFile,
|
||||
})
|
||||
@@ -56,7 +44,8 @@ func TestConnectWithDSNRejectsTraceFileBeforeOracleOpen(t *testing.T) {
|
||||
ctx := context.WithValue(context.Background(), "executionId", executionID) // nolint:staticcheck
|
||||
_, err := (&OracleClient{}).ConnectWithDSN(ctx, dsn)
|
||||
require.Error(t, err)
|
||||
require.Contains(t, err.Error(), "outside")
|
||||
require.Contains(t, err.Error(), "-lfa is not enabled")
|
||||
require.NoFileExists(t, traceFile)
|
||||
}
|
||||
|
||||
func TestSandboxDSNNormalizesTraceOptionsWithinTemplatesWithoutLFA(t *testing.T) {
|
||||
@@ -73,7 +62,7 @@ func TestSandboxDSNNormalizesTraceOptionsWithinTemplatesWithoutLFA(t *testing.T)
|
||||
"TRACE DIRECTORY": traceDir,
|
||||
})
|
||||
|
||||
got, err := protocolstate.SanitizeOracleDSN(executionID, dsn, &types.Options{ExecutionId: executionID, AllowLocalFileAccess: false})
|
||||
got, err := sandboxDSN(executionID, dsn)
|
||||
require.NoError(t, err)
|
||||
|
||||
cfg, err := go_ora.ParseConfig(got)
|
||||
@@ -82,19 +71,19 @@ func TestSandboxDSNNormalizesTraceOptionsWithinTemplatesWithoutLFA(t *testing.T)
|
||||
require.Equal(t, traceDir, cfg.TraceDir)
|
||||
}
|
||||
|
||||
func TestSandboxDSNAllowsTraceFileWithinAllowedPathsWithLFA(t *testing.T) {
|
||||
func TestSandboxDSNAllowsTraceFileOutsideTemplatesWithLFA(t *testing.T) {
|
||||
templatesDir := t.TempDir()
|
||||
restoreOracleTemplatesDir(t, templatesDir)
|
||||
|
||||
executionID := t.Name()
|
||||
protocolstate.SetLfaAllowed(&types.Options{ExecutionId: executionID, AllowLocalFileAccess: true})
|
||||
|
||||
traceFile := filepath.Join(templatesDir, "trace.log")
|
||||
traceFile := filepath.Join(t.TempDir(), "trace.log")
|
||||
dsn := go_ora.BuildUrl("127.0.0.1", 1521, "XE", "user", "pass", map[string]string{
|
||||
"TRACE FILE": traceFile,
|
||||
})
|
||||
|
||||
got, err := protocolstate.SanitizeOracleDSN(executionID, dsn, &types.Options{ExecutionId: executionID, AllowLocalFileAccess: true})
|
||||
got, err := sandboxDSN(executionID, dsn)
|
||||
require.NoError(t, err)
|
||||
|
||||
cfg, err := go_ora.ParseConfig(got)
|
||||
|
||||
@@ -2,6 +2,7 @@ package oracle
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
@@ -21,7 +22,15 @@ func (o *oracleCustomDialer) dialWithCtx(ctx context.Context, network, address s
|
||||
if ctx == nil {
|
||||
ctx = context.Background()
|
||||
}
|
||||
return protocolstate.DialAllowedWithExecutionID(ctx, o.executionId, network, address)
|
||||
dialers := protocolstate.GetDialersWithId(o.executionId)
|
||||
if dialers == nil {
|
||||
return nil, fmt.Errorf("dialers not initialized for %s", o.executionId)
|
||||
}
|
||||
if !protocolstate.IsHostAllowed(o.executionId, address) {
|
||||
// host is not valid according to network policy
|
||||
return nil, protocolstate.ErrHostDenied.Msgf(address)
|
||||
}
|
||||
return dialers.Fastdialer.Dial(ctx, network, address)
|
||||
}
|
||||
|
||||
func (o *oracleCustomDialer) Dial(network, address string) (net.Conn, error) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package pop3
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
"strconv"
|
||||
"time"
|
||||
@@ -41,13 +42,14 @@ func IsPOP3(ctx context.Context, host string, port int) (IsPOP3Response, error)
|
||||
// @memo
|
||||
func isPoP3(ctx context.Context, executionId string, host string, port int) (IsPOP3Response, error) {
|
||||
resp := IsPOP3Response{}
|
||||
if !protocolstate.IsHostAllowed(executionId, host) {
|
||||
// host is not valid according to network policy
|
||||
return resp, protocolstate.ErrHostDenied.Msgf(host)
|
||||
|
||||
dialer := protocolstate.GetDialersWithId(executionId)
|
||||
if dialer == nil {
|
||||
return IsPOP3Response{}, fmt.Errorf("dialers not initialized for %s", executionId)
|
||||
}
|
||||
|
||||
timeout := 5 * time.Second
|
||||
conn, err := protocolstate.DialAllowedWithExecutionID(ctx, executionId, "tcp", net.JoinHostPort(host, strconv.Itoa(port)))
|
||||
conn, err := dialer.Fastdialer.Dial(ctx, "tcp", net.JoinHostPort(host, strconv.Itoa(port)))
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
|
||||
Loaded 100 of 214 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user