$npx -y skills add SnailSploit/Claude-Red --skill offensive-jwtJWT attack methodology for penetration testers. Covers algorithm confusion (alg:none, RS256→HS256), weak HMAC secret brute force, kid parameter injection (SQLi, path traversal), jku/x5u/jwk header injection, JWKS cache poisoning, JWS/JWE confusion, timing attacks, and mobile JWT
| 1 | ## Overview |
| 2 | |
| 3 | Comprehensive JWT attack checklist for offensive security engagements. Follow steps in order; apply each technique to the current target context and track which items have been completed. |
| 4 | |
| 5 | ## Quick Reference: Misconfigurations to Check |
| 6 | |
| 7 | - Algorithm set to `none` — signature verification bypassed entirely |
| 8 | - Algorithm switching between `RSA` and `HMAC` (confusion attack) |
| 9 | - Weak or guessable HMAC secret (brute-forceable) |
| 10 | - `kid`, `jku`, `jwk`, `x5u` header parameters accepted without validation |
| 11 | - Expired or tampered tokens accepted by server |
| 12 | - Sensitive data stored unencrypted in payload |
| 13 | |
| 14 | Useful tool: [JWT Tool](https://github.com/ticarpi/jwt_tool) |
| 15 | |
| 16 | ## Mechanisms |
| 17 | |
| 18 | JWTs (RFC 7519) consist of three Base64URL-encoded parts: `header.payload.signature`. |
| 19 | |
| 20 | **Signing algorithms:** |
| 21 | |
| 22 | | Algorithm | Type | Notes | |
| 23 | |-----------|------|-------| |
| 24 | | HS256/384/512 | Symmetric HMAC | Shared secret; confusion target | |
| 25 | | RS256/384/512 | Asymmetric RSA | Public key can be misused as HMAC secret | |
| 26 | | ES256/384/512 | Asymmetric ECDSA | | |
| 27 | | PS256/384/512 | RSASSA-PSS | | |
| 28 | | EdDSA (Ed25519/Ed448) | Asymmetric | | |
| 29 | | none | Unsigned | Critically insecure | |
| 30 | |
| 31 | **Additional pitfalls:** |
| 32 | - JWS/JWE confusion: server accepts encrypted token (JWE) where signed (JWS) is expected, or fails open on unexpected `typ`/`cty` |
| 33 | - JWKS retrieval: SSRF via `jku`/`x5u`, insecure TLS, poisoned key caching, `kid` collisions |
| 34 | - Token binding (DPoP, mTLS): incorrectly implemented allows replay from other clients |
| 35 | |
| 36 | ## Hunt: Identifying JWT Usage |
| 37 | |
| 38 | 1. Check `Authorization: Bearer <token>` headers in all requests |
| 39 | 2. Look for cookies containing JWT structures (`eyJ...`) |
| 40 | 3. Examine browser local/session storage |
| 41 | 4. Decode the token at jwt.io or via BurpSuite JWT extension — inspect claims and header parameters |
| 42 | 5. Note any `kid`, `jku`, `jwk`, `x5u` fields in the header — these are attack surfaces |
| 43 | |
| 44 | ## Vulnerability Map |
| 45 | |
| 46 | ``` |
| 47 | JWT Vulnerabilities |
| 48 | ├── Algorithm Bypass |
| 49 | │ ├── alg:none attack |
| 50 | │ └── RS256→HS256 confusion (public key as HMAC secret) |
| 51 | ├── Weak Secret Key → Brute force |
| 52 | ├── kid Parameter Injection |
| 53 | │ ├── SQL injection via kid |
| 54 | │ └── Path traversal via kid |
| 55 | ├── Header Injection |
| 56 | │ ├── jwk (inline fake key) |
| 57 | │ ├── jku/x5u (remote attacker-controlled JWKS) |
| 58 | │ └── JWKS cache poisoning |
| 59 | └── Missing / Broken Validation |
| 60 | ├── No signature check |
| 61 | ├── Expired tokens accepted |
| 62 | └── iss/aud/exp not validated |
| 63 | ``` |
| 64 | |
| 65 | ## Vulnerabilities |
| 66 | |
| 67 | ### Algorithm Vulnerabilities |
| 68 | |
| 69 | - **alg:none** — Some libraries disable signature validation when `alg` is `none` or a case variant (`None`, `NONE`, `nOnE`) |
| 70 | - **Algorithm Confusion (RS256→HS256)** — Server uses RSA public key as HMAC secret when attacker switches `alg` to HS256; attacker re-signs token with the public key |
| 71 | - **Key ID (`kid`) Manipulation** — Exploiting `kid` to load wrong keys or inject file paths / SQL; enforce strict lookups |
| 72 | |
| 73 | ### Signature Vulnerabilities |
| 74 | |
| 75 | - **Weak HMAC Secrets** — Brute-forceable with dictionary or hashcat |
| 76 | - **Missing Signature Validation** — Token accepted without any verification |
| 77 | - **Broken Validation** — Implementation errors in signature checking logic |
| 78 | |
| 79 | ### Implementation Issues |
| 80 | |
| 81 | - **Missing Claims Validation** — `exp`, `nbf`, `aud`, `iss` not verified |
| 82 | - **Insufficient Entropy** — Predictable JWT IDs or tokens |
| 83 | - **No Expiration** — Tokens valid indefinitely |
| 84 | - **Insecure Transport** — Token sent over HTTP |
| 85 | - **Debug Leakage** — Detailed error messages expose implementation |
| 86 | |
| 87 | ### Header Injection Attacks |
| 88 | |
| 89 | - **JWK Injection** — Supply a custom attacker-controlled public key via the `jwk` header |
| 90 | - **JKU Manipulation** — Point `jku` (JWK Set URL) to attacker-controlled JWKS endpoint |
| 91 | - **x5u Misuse** — Load untrusted X.509 key URL; exploit lax TLS validation or open redirects |
| 92 | - **JWKS Cache Poisoning** — Force caches to accept attacker keys via `kid` collisions or response header manipulation |
| 93 | - **`crit` Header Abuse** — Server ignores unknown critical parameters, enabling bypass |
| 94 | |
| 95 | ### Information Disclosure |
| 96 | |
| 97 | - Sensitive data (PII, credentials, session details) stored unencrypted in payload |
| 98 | - Internal service/backend information leaked via claims |
| 99 | |
| 100 | ## Additional Attack Vectors |
| 101 | |
| 102 | ### Mobile App JWT Storage |
| 103 | |
| 104 | **Android:** |
| 105 | - `SharedPreferences`: Check if world-readable; location `/data/data/<package>/shared_prefs/` |
| 106 | - Keystore extraction: root device or exploit app |
| 107 | - Backup extraction: `adb backup -f backup.ab <package>` (if `allowBackup=true`) |
| 108 | - Tools: Frida, objection, MobSF |
| 109 | |
| 110 | **iOS:** |
| 111 | - Keychain: Check `kSecAttrAcces |