feat(modules): implement batteringram and a scan-wide fuzz budget - #387
feat(modules): implement batteringram and a scan-wide fuzz budget#387TBX3D wants to merge 17 commits into
Conversation
pr summary16 files changed (+1552 -169)
|
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #387 +/- ##
=======================================
Coverage ? 69.23%
=======================================
Files ? 90
Lines ? 9153
Branches ? 0
=======================================
Hits ? 6337
Misses ? 2402
Partials ? 414 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
batteringram and the shared budget both look right. this is the tip of the #384 → #386 stack though so it can't move til those do. one thing for the rebase: Reserve() bumps the counter even on the failed reservation, so the budget's off by one per module - tidy that up. Generated by Claude Code |
add the dsl matcher type with a curated helper allowlist and load-time compile validation (bad syntax, non-allowlisted functions, empty or over-length expressions all rejected before scan time). evaluation lands in a follow-up; a loaded dsl matcher currently misses at match time.
drives a live httptest server through ExecuteHTTPModule with a dsl matcher bound to status_code and body, mirroring the existing favicon integration test, and asserts exactly one finding.
parse the request url and expose host[:port] so a nuclei-style host == "..." expression matches; dedupe the header serialization.
covers the bound variables, the helper allowlist and the load-time compile, so a module author does not have to read dsl.go to know what an expression can touch.
overload the payloads field with a custom unmarshaler: a yaml sequence is the
legacy single set named "payload", a mapping is ordered named sets injectable
at {{name}}. generation moves to a lazy iter.Seq that never materializes the
product, and substitution now reaches header values. file-backed sets parse but
are rejected until the loader lands.
a named set whose yaml value is a scalar string is a local wordlist path, loaded via the existing loadWordlist at resolve time. resolveSets is the single point set resolution can fail.
per fuzzing-module-per-target request cap, default 25000, 0 = unlimited. threaded into modules.Options; enforced by the executor in a follow-up.
ExecuteHTTPModule consumes streamRequests directly instead of materializing the full product and sizing the results channel to it. a fixed worker pool pulls from an unbuffered feed, a single collector owns the findings slice (dropping the mutex), and the producer enforces -fuzz-max-requests with a one-shot truncation log.
the existing cancel test only ever passes an already-cancelled context, so the producer returns at its up-front ctx.Err() check and never reaches the send-select guarding reqCh. add a regression test that cancels while a large payload set is mid-flight against a blocking server, so the producer's and workers' send-selects both get exercised, and assert ExecuteHTTPModule still returns promptly with no goroutine leak.
substitute header values on the no-payload path too, matching the payload and chain paths; warn when a resolved payload set is empty so a misconfigured wordlist is not mistaken for a clean no-findings run. harden the mid-stream cancel test to poll for goroutine drain instead of a fixed sleep.
the payloads field grew two shapes (named sets, file-backed sets) and a scan-wide cap; none of that was discoverable without reading yaml.go.
the yaml shape rejections and the clusterbomb empty-set short-circuit were unexercised; removing either left the suite green.
each fuzzing module's producer already caps its own requests via -fuzz-max-requests, but a scan running many fuzz-capable modules against one target had no overall ceiling on total fuzz traffic. FuzzBudget is a shared atomic counter passed through Options and reserved per request by every module's producer; -fuzz-global-max-requests (default 100000, 0 = unlimited) sizes it once per scan run and it's reused across every concurrently scanned target. exhaustion truncates each affected module's producer cleanly and logs once scan-wide, not once per module.
validateAttack previously rejected batteringram alongside sniper as not-yet-implemented. match nuclei's semantics: every payload position in a request gets the same value simultaneously, drawn from the first declared set, crossed with paths and stopping at that set's length (not clusterbomb's cross-product). integrates with the existing lazy streamRequests iterator, so nothing is materialized.
Reserve incremented the shared counter before comparing it to the ceiling, so every producer that hit the cap left the count one higher than the number of requests actually issued. swap it for a compare-and-swap loop that only increments when the request fits.
3f5b1a9 to
794bc69
Compare
There was a problem hiding this comment.
Pull request overview
Extends HTTP module fuzzing with batteringram attack mode and a scan-wide request budget, plus adds DSL matcher support.
Changes:
- Adds batteringram generation and named/file-backed payload handling.
- Adds per-module and global fuzz request limits.
- Adds DSL compilation, evaluation, validation, tests, and documentation.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| sif.go | Updated as part of this pull request. |
| internal/modules/yaml.go | Updated as part of this pull request. |
| internal/modules/module.go | Updated as part of this pull request. |
| internal/modules/matchers_test.go | Updated as part of this pull request. |
| internal/modules/fuzz_test.go | Updated as part of this pull request. |
| internal/modules/favicon.go | Updated as part of this pull request. |
| internal/modules/favicon_test.go | Updated as part of this pull request. |
| internal/modules/executor.go | Updated as part of this pull request. |
| internal/modules/executor_test.go | Updated as part of this pull request. |
| internal/modules/dsl.go | Updated as part of this pull request. |
| internal/modules/dsl_test.go | Updated as part of this pull request. |
| internal/modules/attack_modes_test.go | Updated as part of this pull request. |
| internal/config/config.go | Updated as part of this pull request. |
| go.mod | Updated as part of this pull request. |
| docs/usage.md | Updated as part of this pull request. |
| docs/modules.md | Updated as part of this pull request. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| budget := opts.FuzzMaxRequests | ||
| for req := range streamRequests(target, cfg, paths, sets) { | ||
| if ctx.Err() != nil { | ||
| return | ||
| } | ||
| if budget > 0 && sent >= budget { | ||
| log.Warnf("fuzz: module %s hit the %d-request budget on %s (further combinations skipped)", def.ID, budget, target) | ||
| return | ||
| } | ||
| if !opts.FuzzGlobalBudget.Reserve() { | ||
| opts.FuzzGlobalBudget.warnOnce(def.ID, target) | ||
| return | ||
| } |
| set := PayloadSet{Name: name} | ||
| switch v.Kind { | ||
| case yaml.ScalarNode: | ||
| set.File = v.Value |
| "to_lower", "to_upper", "trim", "trim_left", "trim_right", "trim_space", | ||
| "trim_prefix", "trim_suffix", "split", "join", "replace", "replace_regex", | ||
| "concat", "reverse", |
| // DSL holds one or more boolean expressions evaluated against the response | ||
| // (dsl matchers only). Compiled and validated at module load. | ||
| DSL []string `yaml:"dsl,omitempty"` |
stacked on #386, so only the commits above it are this pr's.
validateAttack rejected batteringram alongside sniper as not implemented. it is the simple one: every payload position in a request takes the same value at once, drawn from the first declared set, crossed with paths and stopping at that set's length rather than clusterbomb's product. it rides the existing lazy iterator, so nothing is materialized. the second commit adds the ceiling the per-module cap does not give: FuzzBudget is a shared atomic reserved per request by every producer, sized once per run by -fuzz-global-max-requests and reused across concurrently scanned targets, so exhaustion logs once for the scan instead of once per module.