sqlmap之tamper脚本

进行注入时,往往会遇到服务端主机装有 WAF(Web Application Firewall)对 Payload 进行过滤的情况,这使得注入攻击无法成功实施。但 WAF 往往是通过规则对攻击的 Payload 进行检测然后过滤,只要我们能绕过 WAF 的检测规则就能完成攻击。那么绕过的方法一般有哪些呢?我们可以透过 SQLMAP 中的绕过技术学习一二。

SQLMAP 中有一个 Tamper 模块专为绕过 WAF 制定特殊的 Payload,–-tamper选项可以使用加载模块的不同绕过方法将Payload后进行注入。

一、使用方法

–tamer “xxxxx,xxxx.py” 或者–tamper = xxx,xxx,xxx.py使用 -

绕过的技巧通常有:

  1. 字符编码转换
  2. 同等功能转换
  3. 使用注释符

二、脚本展示

字符编码转换

SQLMAP 中 Tamper 模块中的很多脚本都使用字符的不同编码进行绕过,主要有的编码转换方式有:

  • 使用 base64 编码整个Payload
  • Unicode 编码
  • url 编码/双 url 编码
  • utf-8 编码
  • HTML 编码

SQLMAP 中的 Tamper 脚本有:

Tamper 脚本 描述
base64encode base64 编码 Payload
chardoubleencode 双url编码
charencode url编码
charunicodeencode 使用 Unicode 编码
charunicodeescape 使用 Unicode 编码
apostrophemask 使用 UTF-8 编码字符 %EF%BC%87 替换
htmlencode 使用 HTML 编码 Payload
apostrophennullencode 使用 %00%27 替换
overlongutf8 对非字符数字进行 UTF-8 编码,
overlongutf8moremore 对所有Payload 进行 UTF-8 编码

同等功能转换

当 WAF 过滤了特定函数或者关键字时,考虑使用其它方法实现该功能。SQLMAP Tamper 的脚本主要有:

Tamper 脚本 描述
between 使用 BETWEEN 实现 >=的功能
commalesslimit LIMIT N OFFSET M 替换LIMIT M, N ,绕过逗号过滤
commalessmid MID(A FROM B FOR C) 替换 MID(A, B, C),绕过逗号过滤
concat2concatws 使用 concat_ws函数替换 concat函数
equaltolike 使用 LIKE 替换 =
greatest 使用 GREATEST 函数实现 >的功能,1 AND A>B转换为 1 AND GREATEST(A, B+1)=A
least 使用 LEAST 函数实现 >的功能,1 AND A > B 转换为 1 AND LEAST(A,B+1)=B+1
ifnull2ifisnull 使用 IF(ISNULL(A), B, A) 替换 IFNULL(A, B)
ifnull2casewhenisnull 使用 替换 CASE WHEN ISNULL(A) THEN (B) ELSE (A) END替换IFNULL(A, B)
symboliclogical 使用 && 和 `

使用注释符

注释符可以实现空格的替换、绕过函数过滤等。SQLMAP 中的 Tamper 脚本主要有:

Tamper 脚本 描述
commentbeforeparentheses 在括号前添加注释符 /**/,如 ABS() 变为 ABS/**/()
space2comment 使用注释符/**/替换空格,SELECT id FROM users 转换为 SELECT/**/id/**/FROM/**/users
space2dash 使用注释符 –-替换空格
space2hash 使用注释符 #替换空格
space2morecomment SELECT id FROM users 转换为 SELECT/**_**/id/**_**/FROM/**_**/users
randomcomments 随机插入注释符 /**/,如 INSERT 变为 I/**/NS/**/ERT
versionedkeywords 使用 MySQL 特有的注释符 /*!*/,保留关键字,在 MySQL 中/*!内容*/表示内容在 MySQL 中才执行,其它数据库中不会执行。
versionedmorekeywords 使用 MySQL 特有的注释符 /*!*/,保留更多的关键字

二、适配不同数据库类型的测试tamper

当使用SQLMap篡改脚本执行渗透测试时,面对众多tamper可能会比较困惑,一开始不晓得该使用哪些脚本来测试。有的脚本是适用于常用数据库的SQL注入攻击,有的适用于特定类型的数据库,还有的适用于某种数据库的特定版本范围。为了相对明确的了解tamper的使用场景,把tamper的使用类型和范围作一下划分,具体如下:

SQLMap目录中的所有tamper script

1
2
3
4
5
6
tamper=
apostrophemask,apostrophenullencode,appendnullbyte,base64encode,between,bluecoat,chardoubleencode,charencode,charunicodeencode,
concat2concatws,equaltolike,greatest,halfversionedmorekeywords,ifnull2ifisnull,modsecurityversioned,modsecurityzeroversioned,multiplespa
ces,nonrecursivereplacement,percentage,randomcase,randomcomments,securesphere,space2comment,space2dash,space2hash,space2moreh
ash,space2mssqlblank,space2mssqlhash,space2mysqlblank,space2mysqldash,space2plus,space2randomblank,sp_password,unionalltounion,u
nmagicquotes,versionedkeywords,versionedmorekeywords

通用的测试tamper

1
2
3
4
tamper=
apostrophemask,apostrophenullencode,base64encode,between,chardoubleencode,charencode,charunicodeencode,equaltolike,greatest,ifnull
2ifisnull,multiplespaces,nonrecursivereplacement,percentage,randomcase,securesphere,space2comment,space2plus,space2randomblank,unio
nalltounion,unmagicquotes

MSSQL(Microsoft SQL Servre)

1
2
3
tamper=
between,charencode,charunicodeencode,equaltolike,greatest,multiplespaces,nonrecursivereplacement,percentage,randomcase,securesphere,
sp_password,space2comment,space2dash,space2mssqlblank,space2mysqldash,space2plus,space2randomblank,unionalltounion,unmagicquotes

MySQL

1
2
3
4
5
tamper=
between,bluecoat,charencode,charunicodeencode,concat2concatws,equaltolike,greatest,halfversionedmorekeywords,ifnull2ifisnull,modsecuri
tyversioned,modsecurityzeroversioned,multiplespaces,nonrecursivereplacement,percentage,randomcase,securesphere,space2comment,space
2hash,space2morehash,space2mysqldash,space2plus,space2randomblank,unionalltounion,unmagicquotes,versionedkeywords,versionedmore
keywords,xforwardedfor

Oracle

1
2
3
tamper=
between,charencode,equaltolike,greatest,multiplespaces,nonrecursivereplacement,randomcase,securesphere,space2comment,space2plus,sp
ace2randomblank,unionalltounion,unmagicquotes,xforwardedfor

Microsoft Access

1
2
3
4
5
tamper=
between,bluecoat,charencode,charunicodeencode,concat2concatws,equaltolike,greatest,halfversionedmorekeywords,ifnull2ifisnull,modsecuri
tyversioned,modsecurityzeroversioned,multiplespaces,nonrecursivereplacement,percentage,randomcase,securesphere,space2comment,space
2hash,space2morehash,space2mysqldash,space2plus,space2randomblank,unionalltounion,unmagicquotes,versionedkeywords,versionedmore
keywords

PostgreSQL

1
2
3
tamper=
between,charencode,charunicodeencode,equaltolike,greatest,multiplespaces,nonrecursivereplacement,percentage,randomcase,securesp
here,space2comment,space2plus,spae2randomblank,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 * * * *
  • 版权声明: 本博客所有文章除特别声明外,著作权归作者所有。转载请注明出处!

扫一扫,分享到微信

微信分享二维码
  • Copyrights © 2021-2023 Wh1tecell
  • 访问人数: | 浏览次数:

请我喝杯咖啡吧~