SQL Tamper Framework
The SQL Tamper Framework is a context-aware SQL transformation framework for WAF (Web Application Firewall) bypass, built for authorized penetration testing and bug bounty work. Unlike naive string-replacement tamper scripts, it tokenizes SQL with a real lexer, tracks which clause each token belongs to, and applies transformations that are deterministic, SQL-validity-preserving, and safe to reapply. It ships as a Python framework plus a set of SQLMap-compatible tamper scripts targeting specific 2025/2026-era WAFs (Cloudflare, AWS WAF v2, Azure WAF, ModSecurity CRS, Imperva, Akamai Kona). It is GPL v2, authored by Regaan (Rot Hackers), and published on PyPI as sqlmap-tamper-framework (current version 2.1.0).
Overview
The framework’s core idea is that correct SQL tampering is a parsing problem, not a find-and-replace problem. A naive tamper script that URL-encodes >= character by character produces %3E= (broken), and a position-based tracker breaks the moment a token like SELECT is wrapped into /*!50000SELECT*/ and every downstream position shifts. The SQL Tamper Framework solves both by lexing into tokens, giving each token a UUID that survives value changes, and tracking SQL clause context so transformations only fire where they are valid (for example, encoding operators only inside WHERE/HAVING). On top of that engine sit composable transformation rules and ready-made WAF-specific tamper scripts.
Features
- Token-based transformation: full SQL lexer with UUID tracking, multi-character operator support (
>=,<=,<>,!=), context-aware transforms, and string-literal/comment preservation. - AST-based transformation: hierarchical SQL structure, nested subquery handling, depth-aware transforms, and function-call detection.
- Safety guarantees: deterministic output (same input yields same output), reapplication protection, SQL-validity preservation, and no random mutations.
- Core transformations: keyword wrapping (MySQL version comments), space-to-
/**/replacement, alternating case, and operator URL encoding. - Advanced transformations (v2.1.0+): Unicode homoglyphs, IF()/CASE function wrapping, numeric obfuscation (hex/float/math), comment chaos, logical-operator swaps (AND/OR to
&&/||), string-to-hex encoding, and variable MySQL version comments. - Seven WAF-specific tamper scripts plus a
meta_tamper.pyauto-chain combiner. - SQLMap integration: drop a script into SQLMap’s tamper directory and run with
--tamper=.
Architecture Summary
The framework has four core components. The Lexer (tamper_framework/lexer.py) tokenizes SQL queries, assigns each token a UUID, and correctly handles multi-character operators. The Context Tracker (tamper_framework/context.py) tracks the current SQL clause (SELECT vs FROM vs WHERE) and nesting depth. The Transformer (tamper_framework/transformer.py) applies context-aware transformation rules with reapplication protection and deterministic output. The AST Builder (tamper_framework/ast_builder.py) constructs a hierarchical SQL structure for subquery detection and function-call handling, used for the more complex/nested cases. Transformation logic is modular: each transformation is its own module and is composed onto a transformer as a rule. WAF-specific tamper scripts are pre-built chains of these transformations tuned per firewall.
Technology Stack
- Language: Python (99.6% of the repo), with a Dockerfile.
- Runtime: Python 3.8+ (README/PyPI badge) / 3.7+ (PyPI metadata field) — see discrepancy note.
- Target DB syntax: MySQL 5.7+ / MariaDB 10.x.
- Integration: SQLMap tamper scripts.
- Dev tooling:
pytest(>=7.0.0),black(>=22.0.0) as optional dev dependencies. - Distribution: PyPI (
sqlmap-tamper-framework2.1.0), GitHub, GPL v2. - Packaging: installable via
pip install -e .; tamper scripts copied into SQLMap’stamper/directory.
Problem Statement
WAFs block SQL injection payloads by pattern-matching on recognizable SQL. Tamper scripts exist to transform a payload so it still executes on the database but no longer matches the WAF’s signatures. The trouble is that most tamper scripts are naive string manipulators, and SQL is not a string, it is a structured language. Two failure modes dominate: character-level encoding that corrupts multi-character operators (turning >= into the broken %3E=), and position-based token tracking that desynchronizes as soon as a transformation changes a token’s length. Both produce invalid SQL that the database rejects, defeating the point. The SQL Tamper Framework addresses this by treating tampering as a lex-transform-reassemble pipeline with stable token identity and clause awareness, so transformed payloads stay valid SQL.
Why This Project Exists
The framework exists to bring engineering discipline to SQLMap tamper scripting: deterministic, testable, context-aware transformations instead of fragile regex hacks, packaged as reusable WAF-specific scripts. The author frames it explicitly as maintained for authorized red-team and bug-bounty use, with deterministic (non-randomized) output by design so that outputs are reproducible for research and verification rather than for generating unpredictable malicious variants.
Sub-Articles (this knowledge base)
- Case Study: Building a Context-Aware SQL Tamper Framework (§2)
- Engineering Notes: Research Notes 1-10 (§3)
- Technical Article: The Lexer and UUID Token Tracking (§4.1)
- Technical Article: Context Tracking and Clause-Aware Transformation (§4.2)
- Technical Article: The Transformation Module System (§4.3)
- Technical Article: WAF-Specific Tamper Scripts and the Meta-Combiner (§4.4)
- Technical Article: Token-Based vs AST-Based Transformation (§4.5)
- FAQ for penetration testers and researchers (§5)
- Diagrams (§8)
Related Projects
- ProtoCrash — coverage-guided protocol fuzzer by the same lab; the network-protocol counterpart to this web-layer tool.
- PoCSmith — AI exploit/shellcode generator by the same author; pairs in an offensive workflow.
- Rothalyx, Basilisk, Keikaku — the author’s other Rot Hackers projects.
REGAAN R