JWT Attacks¶
← Back to index · Stage 2 (forge an admin token) · Read the mindset page first.
Why it exists: a JWT is header.payload.signature — the payload carries your identity/role in plaintext base64, and the signature is what's supposed to stop you editing it. Every JWT attack targets a flaw in how the server verifies that signature: if it doesn't verify at all, accepts alg:none, uses a weak key, or trusts a key you supply, you forge an admin token. Use the JWT Editor Burp extension.
The one rule: test whether the signature is actually verified before cracking anything — change a claim and leave the signature alone. If it's still accepted, you're done with no crypto.
Decision tree¶
flowchart TD
A["Change a claim, keep the signature"] --> B{"Still accepted?"}
B -->|yes| NONE["Signature not verified — just edit claims"]
B -->|no| C{"Try alg:none"}
C -->|accepted| ANON["alg:none forgery"]
C -->|rejected| D{"HS256 (HMAC)?"}
D -->|yes| WEAK["Brute the secret, re-sign"]
D -->|RS256| E{"Header controls the key?"}
E -->|jwk/jku/kid| HDR["Inject your own key"]
E -->|public key known| CONF["RS256 -> HS256 confusion"]
NONE --> WIN["Forge an admin token"]
ANON --> WIN
WEAK --> WIN
HDR --> WIN
CONF --> WIN
Reading the response: the whole first test is binary — tamper a claim, keep the signature, resend, and read accepted vs rejected. Accepted (you reach the protected page, no error) = the signature isn't verified and you're done. Rejected (
401/redirect) = it is verified, so the response just told you to attack the key instead (alg:none, weak secret, header injection). Every later forgery is judged the same way: did the token get accepted?
1. Signature not verified / alg:none — why they work¶
Not verified: some apps base64-decode the payload and trust it without checking the signature at all — so editing "role":"admin" just works. alg:none: the JWT spec includes a "no signature" algorithm; a server that honours it accepts an unsigned token you fully control.
# not verified — edit claims, resend:
{"sub":"administrator"}
# alg:none — set the header algorithm to none and strip the signature (keep the trailing dot):
header {"alg":"none","typ":"JWT"} . payload {"sub":"administrator"} .
2. Weak HMAC secret — why offline cracking works¶
Why: HS256 signs with a symmetric secret — the same key signs and verifies. If that secret is weak, you crack it offline and then sign your own tampered token with it, and the server verifies it as genuine.
hashcat -m 16500 token.jwt /usr/share/wordlists/rockyou.txt
# JWT Editor: add the cracked secret as a symmetric key, edit claims, sign
3. Header-injected keys (jwk / jku / kid) — why¶
Why: these header fields tell the server which key to verify with. If the server trusts a key embedded in (jwk) or linked from (jku) the token, or selects a key file by a path you control (kid), you supply your own key and sign with it:
jwk -> JWT Editor "Embedded JWK" attack jku -> host your JWKS on the exploit server
kid -> "kid":"../../../../../../dev/null" then sign with an empty key
4. Algorithm confusion (RS256 → HS256) — why¶
Why: RS256 verifies with a public key (not secret). If the server naively uses that public key as the HMAC secret when the header says HS256, you sign an HS256 token with the public key (which you can obtain) and it verifies. JWT Editor → sign with HS256, secret = the public key.
Failure modes¶
- Tamper rejected → signature is verified; move to alg:none / weak-key / header attacks.
- alg:none rejected → try
None,nOnEcapitalisation (some filters only block lowercase). - Hashcat no hit → secret isn't in the list; pivot to RS256 confusion or header injection.
- jku blocked by host filter → host the JWKS on an allowed host, or use the
@/fragment tricks from SSRF.