Practice library / Web attacks
Lab · Hard · 3 hoursFree account
HTTP Misconfiguration Abuse
Cache poisoning, host-header trust and session puzzling against one lab target, with detection and defence for each.
On this page 15 sections
- ·Why this lab is different
- ·Prerequisites
- ·Lab setup
- ·Build the target
- 1Confirm the target sits behind a shared cache
- 2Find one unkeyed header
- Locked: Sweep a short header list for more candidates
- Locked: Forge a password-reset link with Host-header trust
- Locked: Bypass the reset step with session-variable overloading
- Locked: Read the proxy config to find the root cause
- Locked: Detect the attack in the access log
- Locked: Fix the cache key, and verify the fix
- Locked: Detection and defence
- Locked: Check
- Locked: Clean-up
Shared web caches, trusted Host headers and session variables are everyday infrastructure, and a single misconfiguration turns each one into a path to account takeover. Cloudflare, Facebook and GitHub have all shipped fixes for the same three classes of bug. The lab poisons a cache, forges a password-reset link through Host-header trust, and skips an OTP step with session puzzling against one small target.
What You'll Learn
- Identify a shared HTTP cache from its own response headers
- Find an unkeyed input: something the app uses but the cache does not key on
- Poison a cached response so it reaches a request that never sent your payload
- Abuse Host-header trust to forge a password-reset link
- Bypass a reset step with session-variable overloading (session puzzling)
- Detect each misconfiguration in a log and fix its root cause
Why this lab is different
None of these three bugs is a single broken line of code. Each one is a trust assumption that two parts of a system make about each other, and no one checks. The cache trusts that the app's output is the same for everyone. The app trusts that the Host header came from its own proxy. The password-reset step trusts a session flag that a completely different, unrelated feature also sets. You find all three the same way: by asking "who actually controls this value, and does the part that trusts it know that?"
Prerequisites
- Finish HTTP & Web Requests first. This lab assumes you can already read request and response headers and explain what a reverse proxy and a shared cache do to a request.
- Do Web Fuzzing & Directory Brute Forcing if you have not used
ffufbefore. Step 3 points you at it as a faster alternative to a hand-rolled loop. - Read Attacking Authentication Mechanisms and Broken Authentication & Sessions first if "session puzzling" in Step 5 is a new term. This lab uses that theory; it does not teach it from scratch.
Lab setup
| Item | Purpose |
|---|---|
curl | Sends the crafted requests and reads cache and header behaviour |
ffuf | A faster alternative to Step 3's loop on a longer header list |
| A text editor | Reads and edits the proxy's cache configuration in Steps 6 and 8 |
| A browser | Reads the captured emails in MailHog (Steps 4 and 5) |
Build the target
KaliRange hosts no targets, no virtual machines and no lab files. You run this lab on your own machine, against a small web application that you build. The names and 10.0.14.x addresses below are the example addresses of this lab. Replace them with the addresses of your own lab.
Your lab must have these parts. All of them run on one host that you reach at 10.0.14.30.
| Part | Role |
|---|---|
| HelpDeskLite | A small Node.js and Express ticket portal that you write, on port 3000 behind the proxy |
| Nginx reverse proxy | Listens on port 80 and caches responses for every visitor |
| MailHog | A local mail catcher: web inbox on port 8025; the app sends its mail to it |
- The proxy configuration is
~/helpdesklite-src/proxy/cache.conf. Its first nine lines are the excerpt in Step 6. Below them, in the samelocationblock, add headersVia: 1.1 edge-cache,X-Cache(the value of$upstream_cache_status:MISSorHIT) andAge(the seconds since the entry was stored). The cache is shared by all visitors. - The proxy writes an access log to
~/helpdesklite-src/logs/cache-access.log. Each line includes the textX-Forwarded-Host:and the value of the request header, so the grep in Step 7 finds it. Normal traffic carries your own host, here10.0.14.30. The counts in Step 7 are examples; yours differ. - The page
GET /tickets/42returns an HTML page of about 2.4 KB with<link rel="canonical" href="http://HOST/tickets/42">. The app takesHOSTfromX-Forwarded-Host, or fromX-Original-Host, and falls back to theHostheader. It ignores the other headers in Step 3. POST /api/logintakes JSON withemailandpassword, sets a session cookie and answers{"status":"logged_in"}.POST /api/password-reset/starttakes{"email":"..."}. It mails a linkhttp://HOST/reset?token=...built from the sameHOSTvalue, and answers{"status":"reset_email_sent"}.POST /api/account/email-change/verifytakes a 6-digitcode, answers{"status":"email_verified"}and sets the session flagidentityVerified. The app mails that code to the user when the user asks for an email change. Add a small endpoint or form for that request.POST /api/password-reset/completetakes{"newPassword":"..."}and answers{"status":"password_changed"}. It checks onlyidentityVerified, not a flag that belongs to the reset flow. This is the flaw of Step 5. A reset OTP step exists but this endpoint does not demand it.- Two test accounts,
tester1@example.comandtester2@example.com, both with the passwordStr0ngPass!23. Use your own password and put it in the commands. Seed them with fake data only.
Build this with containers or virtual machines on your own computer. No public training application has this exact flaw set, so write the small application yourself and keep the flaws that the steps use. Take a snapshot of each virtual machine (or note the container state) before Step 1.
Legal note. Run every command in this lab only against 10.0.14.30, a target that you own or have written permission to test, and only against the two seeded test accounts. Never send a crafted Host or X-Forwarded-Host header at a cache, or at an authentication flow, that you do not own or have written permission to test. Unauthorised cache poisoning and account takeover are crimes in most countries.
Step 1: Confirm the target sits behind a shared cache
Read the cache's own response headers
Request the same page twice, a few seconds apart. A shared cache almost always leaves a trace in its own headers: look for Age, X-Cache, or Via.
curl -s -D - -o /dev/null "http://10.0.14.30/tickets/42"
sleep 2
curl -s -D - -o /dev/null "http://10.0.14.30/tickets/42"Example output:
HTTP/1.1 200 OK
Via: 1.1 edge-cache
X-Cache: MISS
Age: 0
HTTP/1.1 200 OK
Via: 1.1 edge-cache
X-Cache: HIT
Age: 2The second request is a HIT with a non-zero Age: the proxy served a stored copy instead of asking the app again. Every visitor who requests /tickets/42 in the next few minutes gets that exact stored copy. That shared copy is what makes cache poisoning possible — whatever you put into it, they receive.
Step 2: Find one unkeyed header
Add a cache buster, then test one header
Add a query parameter no real visitor would guess, so you always get a fresh MISS to test against. Send one candidate header on the first request, then repeat the exact same URL with no special header at all.
# Fresh entry, with a canary value in a candidate header
curl -s -D - "http://10.0.14.30/tickets/42?cb=7731" \
-H "X-Forwarded-Host: canary.example.com" | grep -iE "x-cache|canonical"
# The SAME url again — no header this time, simulating a plain visitor
curl -s -D - "http://10.0.14.30/tickets/42?cb=7731" | grep -iE "x-cache|canonical"Example output:
X-Cache: MISS
<link rel="canonical" href="http://canary.example.com/tickets/42">
X-Cache: HIT
<link rel="canonical" href="http://canary.example.com/tickets/42">The second request carried no X-Forwarded-Host header at all, yet it still got canary.example.com back, and it was a cache HIT. The proxy's cache key does not include this header — it is unkeyed. The value you sent on the first request is now stored for anyone who loads that exact URL.
Sign in to continue
9 more sections are for signed-in members. It is free: sign in with Google.