Add deterministic WAF-evasion payload mutation tool - #41
Merged
Conversation
New mutate_payload(payload, context) tool -- distinct from attempt_bypass(): that handles a whole REQUEST getting blocked regardless of payload content (Tiers 1-4, header/path/method/HTTP- version), this handles a PAYLOAD itself getting pattern-matched by a WAF/filter once the request already reaches the backend. Operationalizes .claude/skills/waf-evasion-encoding-playbook/SKILL.md's manual technique list as deterministic string transforms: percent encoding, double percent encoding, HTML entity encoding (hex/decimal), overlong UTF-8 for the well-documented characters (/ . < >), whitespace substitution (tab/newline/vertical-tab/form-feed/NBSP/SQL comment), SQL keyword case-mixing, SQL inline-comment splitting, and JS hex-escaping. Auto-detects SQL vs XSS vs both vs generic context from the payload. Deliberately NOT an LLM call to a named model -- these are fixed-formula transforms with no benefit from non-determinism, and hardcoding a specific provider would conflict with model_gateway.py's whole no-lock-in design. Pure string transformation, no live request sent, so not scope-gated or budget-counted (same reasoning as oob-mcp's generate_payload_url()). Caught and fixed a real bug before landing: the first draft matched SQL keywords with re.escape(kw) and no \b word boundaries, so "OR" matched inside "FORMULA" and "AND" inside "SANDBOX", corrupting unrelated text instead of only mutating the actual keyword. Fixed with \b boundaries and added regression tests for it. 19 new tests, all passing; full suite (136 tests) still green.
…alse positives
Independent fresh-eyes review of mutate_payload() found two real bugs:
1. _js_hex_escape emitted \uXXXXX (5 hex digits) for codepoints above
0xFFFF (e.g. an emoji) via {:04x}'s minimum-width formatting -- not
valid JS syntax, which requires exactly 4 hex digits per \u escape or
the \u{...} codepoint form for astral characters. Fixed to use
\u{...} above the BMP.
2. _detect_context's XSS-marker check used plain substring matching
(marker.lower() in payload.lower()) while its SQL-keyword check used
\b-bounded regex. Several _XSS_MARKERS entries ("onload", "onclick")
are short common word fragments, so the substring check false-
positived on SQL-only payloads containing them embedded in an
unrelated word (e.g. "onload" inside "salonload", "onclick" inside
"econclick") -- misclassifying pure-SQL payloads as context="both"
and adding a spurious JS hex-escape variant to the output. Fixed with
a boundary-aware matcher (_has_xss_marker) that adds \b only on a
side where the marker itself starts/ends with a word character --
punctuation-anchored markers like "<script"/"alert(" don't need it
and a literal \b there wouldn't be meaningful.
Note: a LIKE '%onload%' style payload still detects as XSS-adjacent --
that's correct, not a bug, since '%' isn't a word character and "onload"
genuinely is a bounded standalone word there, not an embedded substring.
4 new regression tests (2 for each fix); full suite (138 tests) green.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
mutate_payload()to waf-bypass-mcp: deterministic (non-LLM) WAF-evasion techniques — percent-encoding, double-percent-encoding, HTML entity encoding, overlong UTF-8, whitespace substitution, SQL keyword case-mixing, SQL comment splitting, JS hex-escaping.Test plan
pytest tests/), including new regression tests for both audit fixespython -m py_compileclean