Bypassing Web Application Firewalls with SQLMap Tamper Scripts

Bypassing Web Application Firewalls with SQLMap Tamper Scripts

Posted on August 26, 2011 by Roberto Salgado

Web Application Firewalls have become the new security solution for several businesses. Many companies often ignore the actual vulnerabilities and merely rely on the firewall for protection. Regrettably, most, if not all firewalls can be bypassed. In saying this, my post will demonstrate how to use some of SQLMap's new features to bypass WAFs/IDSs.

I have recently had the pleasure of working on a few tamper scripts for SQLMap, which can be found in the latest development version from the subversion repository.

svn checkout sqlmap-dev

The focus of the tamper scripts is to modify the request in a way that will evade the detection of the WAF (Web Application Firewall) rules. In some cases, you might need to combine a few tamper scripts together in order to fool the WAF. For a complete list of the tamper scripts, you can refer to

The first scripts I’ll demonstrate are and which work with MySQL (still haven't gotten around to the MSSQL one). These scripts will convert all spaces to block comments with random text. The extended version of the script ( will also add the comments in between certain function names and the parenthesis.

To get started using the tamper scripts, you use the --tamper switch followed by the script name. In my example I'm using the following command:

./ -u -v 3 --dbms "MySQL" --technique U -p id --batch --tamper ""

Figure 1: tamper script in action

As shown in figure 1, the tamper script replaces the spaces in the injection with %23randomText%0A, which is of course URL encoded. The function's CHAR(), USER(), CONCAT() get changed to FUNCTION%23randomText%0A() since they aren't blacklisted in IGNORE_SPACE_AFFECTED_KEYWORDS. This is because of MySQL's Function Name Parsing and Resolution and how it treats function calls and identifiers.

Another two scripts that transform spaces are and MySQL allows characters 09, 0A-0D, A0 to be used as whitespaces while MSSQL allows a much wider range, from 01-1F.

Figure 2: using different characters as whitespaces

Next up we have a few scripts that mess around with the encoding: and These are useful to bypass different keyword filters, for example when table_name is being detected and there is no way around it.

Figure 3: can be used to evade keyword detection

If the application URL decodes the request for some reason (some do), the script can come in handy.

Figure 4: can be used when the application decodes the request

Additionally, if the application is programmed in ASP/ASP.NET, the and scripts can be used to hide the true payload.

Figure 5: obfuscating the injection with Unicode encoding

An interesting characteristic of ASP is the ability to add as many percentage signs as you want in between characters. For example, AND 1=%%%%%%%%1 is completely valid!

Figure 6: Percent signs in between each character is valid in ASP

In conclusion, I've shown just a few of many tamper scripts. I highly recommend testing them out as each one can be used in different situations. I will be working on a few more this month, so be sure to stay tuned.

SQL Injection Pocket Reference

Latest Blog Entries

New publication: Mastering the Nmap Scripting Engine
We invite you to learn more about the latest publication from our team, "Mastering the Nmap Scripting Engine".

Presentation on Optimization and Obfuscation Techniques for SQL Injections
A couple years ago Roberto Salgado had the honor of presenting his research on SQL Injections at several conferences. Just recently, Blackhat released the video of his presentation. This post contains the link to Roberto's slides and video.

Backdoors in Zhone GPON 2520 and Alcatel Lucent I240Q
While examining the "dropbear" binary for the Zhone GPON 2520 and Alcatel Lucent I240Q, we found that both routers have backdoors that allow users with SSH access to connect to these devices with maximum privileges.

Latest News

BSides Vancouver 2015
Websec is proud to announce that we will be attending the 3rd annual edition of BSides Vancouver, a local non-profit information security conference held in the heart of Vancouver, BC on March 16 and 17.

Websec present at Campus Party 2014
Websec will be participating with four conferences at the largest Campus Party ever held, which will take place from the 24-29 of June in Guadalajara, Mexico.