Welcome back. In our previous lesson, you successfully completed a full SQL injection attack chain, culminating in the exfiltration of sensitive user credentials from an unprotected database. This represents a best-case scenario for an attacker but is often not the reality you'll face in the field.
This lesson addresses a crucial obstacle in penetration testing: defensive countermeasures. Most modern web applications are shielded by Web Application Firewalls (WAFs) or other input filters designed to detect and block malicious payloads like the ones sqlmap generates. We will explore how to use sqlmap's built-in tamper scripts to obfuscate your attack payloads, allowing them to slip past these defenses. You'll learn not just how to use these scripts, but the logic behind why they work and how to choose the right one for the job.
By the end of this lesson, you will be able to select and apply appropriate sqlmap tamper scripts to bypass basic security filters, making your automated injection attacks far more effective against real-world targets.
The Challenge: Web Application Firewalls (WAFs)
A WAF acts as a reverse proxy, inspecting incoming HTTP requests for malicious patterns before they reach the web server. If it sees a request containing ... OR '1'='1', UNION SELECT, or other common SQL injection signatures, it will block the request, often returning a "Forbidden" or "Access Denied" error.
This is where standard sqlmap scans fail. The WAF recognizes the attack payloads and stops them cold. To succeed, we must modify our payloads to be unrecognizable to the WAF, yet still be correctly interpreted by the backend database. This process is called evasion, and sqlmap's primary tool for this is the tamper script.
WAF Bypass Masterclass: SQLMap + Proxychains + Tamper Scripts(Cloudflare/Modsecurity)
To see this in action, the video "WAF Bypass Masterclass" by 𝙇𝙤𝙨𝙩𝙨𝙚𝙘 begins by showing how leading WAFs, Cloudflare and ModSecurity, effectively block standard attack payloads.
Watch the first part of the video from the demonstration where the presenter attempts basic XSS and SQL injection attacks. Notice how both WAFs immediately identify the malicious input and block the requests. This sets the stage for why evasion techniques are necessary.
Introducing Tamper Scripts
Tamper scripts are Python scripts that programmatically alter sqlmap's payloads before they are sent to the target. They apply various obfuscation techniques, from simple character replacement to complex encoding schemes.
The --tamper switch is used to specify which script (or scripts) to apply. To see the extensive list of built-in scripts, you can use the command sqlmap --list-tampers.

Let's watch a brief introduction to the fundamental concept.
#2.7 Bypass Web Application Firewall (WAFs) using Tamper Script via SQLMap
The video "#2.7 Bypass Web Application Firewall (WAFs) using Tamper Script" from Techno Science provides a quick, foundational overview of tamper scripts.
Watch the following segments: Introduction to the --tamper switch: This explains the purpose of tamper scripts. Listing tamper scripts: This shows the --list-tampers command. A simple example: This demonstrates the use of charencode.py, which URL-encodes the payload. Notice how the -v 4 (verbosity) flag is used to see the modified payload sqlmap is sending.
A Practical Guide to Evasion Techniques
With dozens of scripts available, knowing which one to use is key. The choice depends on the specific WAF and its rules. A WAF might block spaces, single quotes, or specific keywords like SELECT. Tamper scripts provide ways around each of these.
The article "Mastering SQLMap Tamper Scripts" by Trix Cyrus on dev.to is an excellent field guide. It organizes the scripts by functionality and the WAFs they are known to be effective against.
Mastering SQLMap Tamper Scripts: The Ultimate Guide to Evading ...
This guide is an essential reference for selecting the right evasion technique. We will focus on the core reference table and the syntax for using the scripts.
First, carefully study the table under the heading The Complete Tamper Script Table. You don't need to memorize it, but understand the different categories of evasion: Whitespace Manipulation: Scripts like space2comment.py replace spaces (e.g., SELECT * FROM users becomes SELECT/**/FROM/**/users). Keyword Obfuscation: Scripts like randomcase.py change SQL keywords (e.g., SELECT becomes sElEcT) to bypass simple, case-sensitive filters. Encoding: Scripts like base64encode.py and charunicodeencode.py encode parts or all of the payload, making it unreadable to a WAF that doesn't decode it first. Next, read the section How to Use Tamper Scripts to understand the command-line syntax. Note that you can chain multiple scripts for more complex obfuscation.
For instance, if you suspect a WAF is blocking spaces and is also case-sensitive, you could chain two scripts like this:
sqlmap -u "http://target.com/vuln.php?id=1" --tamper=space2comment,randomcase --dump
sqlmap will first apply space2comment and then apply randomcase to the result before sending the payload.
Advanced Evasion: Beyond Simple Scripts
Modern WAFs like Cloudflare are sophisticated. They don't just use simple signature matching; they employ rate-limiting, IP reputation analysis, and behavioral detection. Bypassing them often requires more than a single tamper script.
The 𝙇𝙤𝙨𝙩𝙨𝙚𝙘 video demonstrates a professional approach combining sqlmap with ProxyChains, a tool that routes traffic through multiple proxy servers. This helps evade IP-based blocking and rate limits, allowing your tampered payloads to reach the application.
WAF Bypass Masterclass: SQLMap + Proxychains + Tamper Scripts(Cloudflare/Modsecurity)
This video showcases a multi-layered evasion strategy, which is highly relevant for a security analyst's toolkit.
Watch these clips to see how the pieces fit together: Configuring ProxyChains: This section explains how to route traffic through multiple residential proxies to hide the attacker's true IP and rotate it to avoid blocking. Bypassing Cloudflare: Here, the presenter combines ProxyChains with sqlmap and tamper scripts to successfully bypass the WAF and dump table names. Bypassing ModSecurity: The same technique is shown to be effective against another popular WAF.
This demonstrates that effective evasion is a methodological process, not a magic bullet. It often involves reconnaissance of the WAF, IP rotation, and carefully selected payload obfuscation.
From Using to Creating: Custom Tamper Scripts
What happens when no built-in script works? This is where your coding skills become a significant advantage. Sometimes, a WAF has a unique rule, or the application handles data in an unusual way, requiring a custom-built evasion technique.
The article "Bypassing WAFs with JSON Unicode Escape Sequences" is a superb case study in the methodology of creating a custom tamper script.

Bypassing WAFs with JSON Unicode Escape Sequences
This article details the real-world process of a penetration tester who defeated a WAF by writing a custom script. It perfectly illustrates the analytical mindset required in your role.
Read through the article, focusing on the author's thought process: In WAF Analysis, see how the author methodically tests parts of the payload to determine that the WAF is specifically blocking the keyword SUBSTRING. In Bypass Identification, observe the creative leap. Instead of focusing only on SQL, the author considers the entire data path and realizes the JSON parser can be abused. By using JSON Unicode escapes (\u0053...), the keyword SUBSTRING becomes invisible to the WAF but is correctly reconstructed by the application before hitting the database. Finally, in the Tamper Script section, examine the Python code. The author first builds a script to replace a single keyword, then evolves it into a more robust script that encodes the entire payload, making it immune to further keyword-based blocking.
This case study is invaluable. It shows that bypassing a WAF is not just about running tools, but about systematic analysis, understanding how an application stack works, and applying that knowledge to create a novel solution.
Conclusion
You have now moved beyond attacking unprotected systems and have learned the principles of evading common defenses. While we couldn't practice this on our WAF-less DVWA setup, you now have the conceptual framework and practical references needed to approach a defended target.
Key Takeaways:
- Web Application Firewalls (WAFs) block SQL injection attacks by matching known malicious patterns.
sqlmap's--tamperflag allows you to use Python scripts to obfuscate payloads and bypass these filters.- Tamper scripts use various techniques, including whitespace manipulation, character encoding, and keyword replacement.
- Choosing the right tamper script (or chain of scripts) requires understanding the WAF's rules.
- Advanced evasion may require combining tamper scripts with other tools like ProxyChains to defeat IP-based blocking and rate limiting.
- For unique or highly configured WAFs, you may need to analyze the target and write your own custom tamper script.
In our journey, we have gone from writing basic SELECT statements to automating a full database takeover and even bypassing the guards at the gate. You now have a comprehensive view of the offensive application of SQL. In the final module of this course, we will switch roles from attacker to defender. You will learn the critical coding practices and defensive strategies, such as parameterized queries and input validation, used to prevent SQL injection vulnerabilities from ever existing.