Detector trait and uses pattern matching to identify specific WAF vendors.
The Detector trait
All detectors implement theDetector trait defined in src/detectors/mod.rs:3:
name()- Returns the human-readable name of the WAF (e.g., “Cloudflare”, “ArvanCloud”)detect()- Analyzes anHttpResponseand returnstrueif the WAF is detected
How detectors work
When whatwaf scans a target URL, it:- Sends multiple probe requests with different payloads (plain, XSS, SQL injection, LFI)
- Collects HTTP responses containing status codes, headers, and body content
- Passes each response through all registered detectors via
run_detectors()insrc/detector.rs:6 - Returns the names of all detectors that returned
true
Pattern matching capabilities
Detectors use helper methods fromHttpResponse to match patterns:
Header matching:
has_header()- Check if specific headers existheader_has()- Check if a header contains specific textheader_matches()- Match headers against regex patterns
body_has()- Check if body contains specific textbody_matches()- Match body against regex patterns
is_forbidden()- Returns true if status is 403is_not_found()- Returns true if status is 404is_error()- Returns true if status is 4xx or 5xx
MatchMode::Any- At least one pattern must matchMatchMode::All- All patterns must match
Extensibility
The detector system is designed for easy extension:- Create a new detector - Add a new
.rsfile insrc/detectors/ - Implement the trait - Define the
Detectortrait for your struct - Register with inventory - Use
inventory::submit!to auto-register - Add the module - Declare the module in
src/detectors/mod.rs
inventory crate automatically collects all registered detectors at compile time, eliminating the need for manual registration or configuration.
list_detectors() function
The library exposes alist_detectors() function in src/lib.rs:61 that returns all registered detector names: