Lion Cipher Lab
Attack and fix JSON Web Tokens (alg=none, weak secrets, and algorithm confusion)
- Penetration Testing / Red Team
- Intermediate
- ~50 min
- Free · no account required
Why it matters
A JSON Web Token (JWT) is the little signed token most modern sites and APIs hand your browser after you log in, then trust on every request that follows. Because the server trusts whatever a valid token says — who you are, what role you hold — the security of an entire application often rests on one thing: whether that token's signature is verified carefully, with a key and algorithm the server chose. This lab makes that abstract risk physical. On an app running on your own machine you will forge a token that claims you are an admin and walk straight into a protected route, then crack a weak…
What you'll learn
- standing up a tiny vulnerable JWT auth API (Flask + PyJWT) on your own machine and running it
- decoding a JWT by hand from base64url to prove the claims are readable, not encrypted
- forging an alg=none / unsigned token with role=admin and reaching a protected route through an unverified-signature flaw
- cracking a weak HMAC (HS256) secret offline with hashcat mode 16500 and a wordlist, then re-signing a valid admin token
- understanding RS256->HS256 algorithm confusion: signing an HS256 token with the server's PUBLIC key bytes
- fixing a JWT verifier: pin the algorithm, never disable verification, use a long random secret, validate exp/iss/aud
- the judgment: the alg header is attacker-controlled, a JWT is signed not encrypted, and stateless tokens are hard to revoke
Steps in this lab
- Read this first: your machine, your rules
- Build the vulnerable auth API on your own machine
- Log in, then decode the token by hand
- Exploit #1 - forge an alg=none token and reach /admin
- Exploit #2 - crack a weak HMAC secret with hashcat, then re-sign
- Exploit #3 (optional, conceptual) - RS256 -> HS256 algorithm confusion
- Fix the server the right way
- Re-test every attack and watch it die
- The judgment - what a pro actually carries away