Labs / Network Attacks / On the wire and across the network

Lab 2 of 5 · On the wire and across the network

Replay attacks: a valid request, sent twice

Capture a door-unlock request that carries no proof of freshness, then resend the exact bytes and open the door again without cracking anything.

Start this lab 4 steps

The idea

Marnie is testing Ravelin Access, the company behind a client building's badge doors, and they gave her a visitor badge for the lobby that runs out tonight. When she taps it, the reader sends an unlock to the door controller over plain HTTP with one fixed token inside.

Her question for the day: if she copies that one request off the wire and resends it next week, does the door still open? The cure, if it does, is freshness: a one-time nonce from the controller, so a resent request looks stale and gets refused.

The same bytes, good a second time
The same bytes, good a second time

Steps

  1. One tap, one unlock

    The controller opens the door when it gets a POST to /unlock with the badge's token in it. Send that unlock, the same one Marnie's badge makes the reader send, and watch the door open. Look at what the request carries, and at what it leaves out.

    marnie:~# curl -s --data 'token=RAVELIN-VISITOR-3C9F' http://10.0.1.10:8080/unlock
  2. Capture it on the wire

    Plain HTTP has no encryption, so anyone who can see the traffic can read it. Start a capture on Marnie's own laptop with tcpdump, send the unlock again, and read the token out of the captured bytes. Then save that request to send later.

    marnie:~# sudo tcpdump -i eth0 -A -n -s0 -l tcp port 8080
    marnie:~# curl -s --data 'token=RAVELIN-VISITOR-3C9F' http://10.0.1.10:8080/unlock
    marnie:~# printf 'token=RAVELIN-VISITOR-3C9F' | tee /tmp/replay.req
  3. Replay it

    Send the saved request body to the controller. It's the same bytes as before, with no badge tap and no new secret. Picture Marnie doing this next week, after her visitor badge has run out.

    marnie:~# curl -s --data @/tmp/replay.req http://10.0.1.10:8080/unlock
  4. Make each unlock good exactly once

    Marnie's report goes to Ravelin, and their controller already has a stricter mode that nobody switched on. With it on, the controller hands out a one-time nonce (a random value used once) at /nonce, and every unlock must carry a fresh one it hasn't seen spent.

    A real reader fetches a new nonce for each tap. Marnie's saved request has none.

    Here is what Ravelin should do, in order of how much each one helps:

    • Tie each request to one use with a server-issued nonce, or a signed timestamp that is only good for a short window. A resend carries a nonce that's already spent, or a time long past, and gets refused. This is the fix that still works after an attacker has the bytes.
    • Sign the request with a shared key (an HMAC) so nobody can change the token. The signature has to cover the nonce or timestamp too, or the signed message replays as well as the unsigned one did.
    • Use TLS so nobody can read the request off the wire. That makes capture harder, but once someone has a request, only the freshness check stops a replay.

    Marnie can do all this because Ravelin signed an engagement letter for it. Doing it to a system without the owner's written permission is a crime under laws like the UK Computer Misuse Act and the American CFAA.

    controller:~# mkdir -p /etc/door && touch /etc/door/nonce-required && ls /etc/door/nonce-required
    marnie:~# N=$(curl -s http://10.0.1.10:8080/nonce | sed 's/nonce=//'); curl -s --data "token=RAVELIN-VISITOR-3C9F&nonce=$N" http://10.0.1.10:8080/unlock
    marnie:~# curl -s --data @/tmp/replay.req http://10.0.1.10:8080/unlock

Run these steps on real machines

Keep reading

Learn it on real machines.

Every lab is a small network of real Linux machines in your browser. Sign in with Google or email to start.

Start this lab