Lion Cipher Lab

Attack a naive MAC with a hash length-extension attack

Why it matters

Homegrown APIs constantly 'sign' a request by hashing a secret glued in front of the data -- sha256(secret + querystring) -- and treat that as proof the request wasn't tampered with. It isn't. A whole class of hashes leaks enough state in the digest itself that an attacker can append '&admin=true' and produce a valid signature without ever knowing the secret. Doing this attack once, by hand, permanently changes how you build and review any signing code.

What you'll learn

Steps in this lab

  1. The idea: a hash that never really 'finishes'
  2. Build a naive MAC 'server'
  3. Get the tool: build hash_extender
  4. Forge a tampered request without the secret
  5. If you don't know the secret length, brute-force it
  6. Land it: the server accepts your forgery
  7. Fix it: use HMAC, not secret-prefix
  8. When it matters, and the pro instinct

Open the full interactive lab →