Bypassing Web Application Firewalls with SQLMap Tamper Scripts

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介: http://websec.ca/blog/view/Bypassing_WAFs_with_SQLMapWeb Application Firewalls have become the new security solution for several businesses.

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


相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
5月前
|
Web App开发 缓存 前端开发
Angular 应用支持 PWA(Progressive Web Application) 特性的开发步骤分享
Angular 应用支持 PWA(Progressive Web Application) 特性的开发步骤分享
46 0
|
5月前
|
SQL 安全 JavaScript
什么是 WAF - Web Application Firewall
什么是 WAF - Web Application Firewall
68 0
|
5月前
|
Cloud Native Java 应用服务中间件
带你读《Apache Tomcat的云原生演进》——GraalVM static compilation in web container application(2)
带你读《Apache Tomcat的云原生演进》——GraalVM static compilation in web container application(2)
143 1
带你读《Apache Tomcat的云原生演进》——GraalVM static compilation in web container application(2)
|
5月前
|
Cloud Native Java 应用服务中间件
带你读《Apache Tomcat的云原生演进》——GraalVM static compilation in web container application(3)
带你读《Apache Tomcat的云原生演进》——GraalVM static compilation in web container application(3)
106 1
带你读《Apache Tomcat的云原生演进》——GraalVM static compilation in web container application(3)
|
9月前
|
域名解析 SQL 监控
Web Web Application Firewall
阿里云Web应用防火墙(Web Application Firewall,简称WAF)是一种网络安全服务,用于保护Web应用程序免受常见的Web攻击,如SQL注入、跨站脚本(XSS)和跨站请求伪造(CSRF)等。它可以通过配置规则和策略,识别和拦截恶意流量,从而保护Web应用程序的安全。
92 1
|
10月前
|
Java 应用服务中间件 Maven
Error configuring application listener of class org.springframework.web.context.ContextLoaderListene
Error configuring application listener of class org.springframework.web.context.ContextLoaderListene
76 0
|
缓存 Java Maven
严重: Error configuring application listener of class org.springframework.web.context.ContextLoaderLis
严重: Error configuring application listener of class org.springframework.web.context.ContextLoaderLis
103 0
严重: Error configuring application listener of class org.springframework.web.context.ContextLoaderLis
|
20天前
|
监控 JavaScript 前端开发
《理解 WebSocket:Java Web 开发的实时通信技术》
【4月更文挑战第4天】WebSocket是Java Web实时通信的关键技术,提供双向持久连接,实现低延迟、高效率的实时交互。适用于聊天应用、在线游戏、数据监控和即时通知。开发涉及服务器端实现、客户端连接及数据协议定义,注意安全、错误处理、性能和兼容性。随着实时应用需求增加,WebSocket在Java Web开发中的地位将更加重要。
|
1月前
|
Web App开发 前端开发 开发工具
介绍Web开发的基础知识
介绍Web开发的基础知识
29 7
|
6天前
|
JSON Java fastjson
Spring Boot 底层级探索系列 04 - Web 开发(2)
Spring Boot 底层级探索系列 04 - Web 开发(2)
15 0