Bypassing Web Application Firewalls with SQLMap Tamper Scripts

http://websec.ca/blog/view/Bypassing_WAFs_with_SQLMap

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 https://svn.sqlmap.org/sqlmap/trunk/sqlmap 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 tohttps://svn.sqlmap.org/sqlmap/trunk/sqlmap/tamper/

The first scripts I’ll demonstrate are space2hash.py and space2morehash.py 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 (space2morehash.py) 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:

./sqlmap.py -u http://192.168.0.107/test.php?id=1 -v 3 --dbms "MySQL" --technique U -p id --batch --tamper "space2morehash.py"

Figure 1: space2morehash.py 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 inIGNORE_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 space2mssqlblank.py and space2mysqlblank.py. MySQL allows characters 090A-0DA0 to be used as whitespaces while MSSQL allows a much wider range, from 01-1F.

Figure 2: space2mssqlblank.py using different characters as whitespaces


Next up we have a few scripts that mess around with the encoding: charencode.py andchardoubleencode.py. 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: charencode.py can be used to evade keyword detection


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

Figure 4: chardoubleencode.py can be used when the application decodes the request


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

Figure 5: charunicodeencode.py 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.

References: 
SQLMap 
SQL Injection Pocket Reference


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值