Courses3 levels
Level 1 · Foundations11 courses
Level 2 · Core5 courses
Level 3 · Advanced5 courses
Labs8 topics
Library Practice exams AI Range Pricing Start free

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.

  • cache-poisoning
  • host-header
  • session-puzzling
  • http
On this page 15 sections
  1. ·Why this lab is different
  2. ·Prerequisites
  3. ·Lab setup
  4. ·Build the target
  5. 1Confirm the target sits behind a shared cache
  6. 2Find one unkeyed header
  7. Locked: Sweep a short header list for more candidates
  8. Locked: Forge a password-reset link with Host-header trust
  9. Locked: Bypass the reset step with session-variable overloading
  10. Locked: Read the proxy config to find the root cause
  11. Locked: Detect the attack in the access log
  12. Locked: Fix the cache key, and verify the fix
  13. Locked: Detection and defence
  14. Locked: Check
  15. 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

Lab setup

ItemPurpose
curlSends the crafted requests and reads cache and header behaviour
ffufA faster alternative to Step 3's loop on a longer header list
A text editorReads and edits the proxy's cache configuration in Steps 6 and 8
A browserReads 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.

PartRole
HelpDeskLiteA small Node.js and Express ticket portal that you write, on port 3000 behind the proxy
Nginx reverse proxyListens on port 80 and caches responses for every visitor
MailHogA 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 same location block, add headers Via: 1.1 edge-cache, X-Cache (the value of $upstream_cache_status: MISS or HIT) and Age (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 text X-Forwarded-Host: and the value of the request header, so the grep in Step 7 finds it. Normal traffic carries your own host, here 10.0.14.30. The counts in Step 7 are examples; yours differ.
  • The page GET /tickets/42 returns an HTML page of about 2.4 KB with <link rel="canonical" href="http://HOST/tickets/42">. The app takes HOST from X-Forwarded-Host, or from X-Original-Host, and falls back to the Host header. It ignores the other headers in Step 3.
  • POST /api/login takes JSON with email and password, sets a session cookie and answers {"status":"logged_in"}.
  • POST /api/password-reset/start takes {"email":"..."}. It mails a link http://HOST/reset?token=... built from the same HOST value, and answers {"status":"reset_email_sent"}.
  • POST /api/account/email-change/verify takes a 6-digit code, answers {"status":"email_verified"} and sets the session flag identityVerified. 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/complete takes {"newPassword":"..."} and answers {"status":"password_changed"}. It checks only identityVerified, 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.com and tester2@example.com, both with the password Str0ngPass!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

1

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: 2

The 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

2

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.

Related