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 · 2.5 hoursFree account

Modern Web Exploitation

Permissive CORS, a postMessage origin-check bypass, and DNS rebinding against a hostname allowlist.

  • dns-rebinding
  • cors
  • same-origin-policy
  • postmessage
On this page 15 sections
  1. ·Why this lab is different
  2. ·Prerequisites
  3. ·Lab setup
  4. ·Build the target
  5. 1Map the CORS policy
  6. 2Confirm the CORS misconfiguration is exploitable
  7. Locked: Prove the data-theft path end to end
  8. Locked: Find the postMessage listener and its origin check
  9. Locked: Bypass the origin check from an attacker-controlled origin
  10. Locked: Find the hostname-based allowlist behind the webhook feature
  11. Locked: Rebind the hostname and reach the internal service
  12. Locked: Detection and defence
  13. Locked: Check
  14. Locked: Clean-up
  15. Locked: Command reference

Modern browsers trust each other across origins only when a long chain of header, event and DNS checks agrees. Real applications still get those checks wrong — a reflected Origin, a postMessage that trusts a substring of the sender, or an allowlist read before the second DNS lookup. A single gap lets another site read your account. Here you exploit all three classes in one target and watch each check fall.

What You'll Learn

  • Detect a CORS policy that reflects any Origin and allows credentials
  • Prove the impact of permissive CORS by reading authenticated data from a different origin
  • Read client-side JavaScript to find a postMessage listener with a weak origin check
  • Bypass a substring-based origin check to trigger a privileged action across origins
  • Identify a server-side allowlist that trusts a hostname instead of the IP it actually connects to
  • Use DNS rebinding to defeat that allowlist and reach an internal-only service

Why this lab is different

Server-Side Request Forgery & Attacks showed you how a server that fetches a URL on your behalf can be redirected at 127.0.0.1 or an internal IP. This lab attacks a harder target: an app whose checks look correct on paper. It checks the Origin header before answering a cross-origin request. It checks event.origin before trusting a postMessage. It checks a webhook's hostname before fetching it. Each check has a gap. Each gap is a different class of browser-trust failure: a reflected Origin with credentials enabled, a substring match instead of an exact one, and a hostname validated once but resolved again later.

Prerequisites

Lab setup

ItemPurpose
curlSends crafted requests and reads response headers
python3 (standard library only)Serves attacker-controlled pages and runs the DNS responder in Step 7
digConfirms what a DNS query actually returns
A browser with developer toolsLoads the app and the proof-of-concept pages, inspects requests

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 team dashboard, RebindCo, that you build. The addresses 10.0.9.50 and 10.0.9.51 and the domain rebindco.example.com below are the examples of this lab. Replace them with your own.

Your target must have these parts:

HostRole
dashboard.rebindco.example.com (10.0.9.50)The RebindCo web app
10.0.9.51:9091An internal-only metrics page, reachable only from the app's own backend network
  • A login that creates your own account and a session cookie. Sign yourself up; no password is handed to you.
  • GET /api/account, session-cookie authenticated, returning JSON such as {"email":"...","plan":"team","apiKey":"rbc_live_..."}. Make the app set Access-Control-Allow-Origin to whatever Origin header it received, and Access-Control-Allow-Credentials: true, with no allowlist check. This is the flaw of Steps 1 to 3.
  • /static/app.js, served statically, containing exactly this listener:
    window.addEventListener('message', function (event) {
      if (event.origin.indexOf('rebindco.example.com') !== -1) {
        if (event.data && event.data.type === 'setEmail') {
          updateAccountEmail(event.data.email);
        }
      }
    });
    The substring check, instead of an exact match, is the flaw of Steps 4 and 5.
  • POST /api/integrations (take name and url, reject a URL that resolves to a private address at creation time, otherwise return {"id":N,"status":"validated"}) and GET /api/integrations/{id} (return the stored result as lastPreview). Run a background worker that polls each stored URL every 15 seconds and re-resolves its hostname on every poll, with no re-check against the private-address rule. This is the flaw of Steps 6 and 7.
  • The internal metrics page at 10.0.9.51:9091/metrics returning plain text, for example backend_build_info{version="4.2.1"} 1\nbackend_internal_host="rebindco-db-01.corp.local"\n.
  • A DNS zone rebind.rebindco.example.com delegated to your own Kali attack box, so a DNS responder you run there becomes authoritative for it. On a single-machine lab, point your test resolver (for example dnsmasq on the app's host) to forward queries for that zone to your Kali box's address on port 53.

No public training target combines a reflected-Origin CORS bug, a substring postMessage check and a DNS-rebinding allowlist bypass, so write this small app yourself; keep each flaw exactly as described above so the steps work. Take a snapshot of each virtual machine (or note the container state) before Step 1.

Authorized-lab only. Run every command in this lab only against a target that you own or have written permission to test, here 10.0.9.50 and 10.0.9.51 as you set them up, using the account you created on it. Do not point CORS, postMessage, or DNS-rebinding techniques at a real site you do not own or do not have written permission to test.

Step 1: Map the CORS policy

1

Send the same request with different Origin headers

A correct CORS (Cross-Origin Resource Sharing) policy only ever allows the app's own origin. Send a request with an origin that has no business being allowed, and read the response headers, not the body.

# Your own session cookie, from the browser's dev tools after logging in
SESSION="s%3Aexample-session-token"

curl -s -i -H "Origin: https://evil.example.com" \
  -H "Cookie: session=${SESSION}" \
  "https://dashboard.rebindco.example.com/api/account" | head -n 12

Example output:

HTTP/1.1 200 OK
Access-Control-Allow-Origin: https://evil.example.com
Access-Control-Allow-Credentials: true
Content-Type: application/json
Vary: Origin

{"email":"you@example.com","plan":"team","apiKey":"rbc_live_..."}

Access-Control-Allow-Origin reflects whatever Origin you sent, instead of checking it against an allowlist. Access-Control-Allow-Credentials: true tells the browser it may read this response from a cross-origin page even with your session cookie attached. A spec-compliant browser never allows Access-Control-Allow-Origin: * together with credentials, so a vulnerable app has to reflect the value — that reflection is the signature to look for.

Step 2: Confirm the CORS misconfiguration is exploitable

2

Repeat the request with an origin you do not own

Reflection alone is not proof. Confirm the app answers the same way for an origin that was never on any allowlist.

curl -s -i -H "Origin: https://not-rebindco-at-all.example.com" \
  -H "Cookie: session=${SESSION}" \
  "https://dashboard.rebindco.example.com/api/account" | grep -i "access-control-allow-origin"

Example output:

Access-Control-Allow-Origin: https://not-rebindco-at-all.example.com

Every origin gets the same answer. There is no allowlist at all — the app trusts whatever the browser says Origin was. Any page you can get a signed-in user to open can now read /api/account with that user's cookie, including the apiKey field.

Sign in to continue

9 more sections are for signed-in members. It is free: sign in with Google.

Related