JWT attacks in CTF: none, a weak secret and confusion part 1

Depov

Moderator
Staff member
MODERATOR
ULTIMATE
SUPREME
PREMIUM
MEMBER
Joined
Feb 18, 2025
Messages
646
Reaction score
1,454
Where to search for JWT and what to check first


JWT is a three-part string separated by points: header.payload.signature. Each part is encoded in base64url. The token is hidden in one of four places: cookies (names jwt, token, session, auth), the title Authorization: Bearer <token>, URL parameter (?token=eyJ...) or body of POST request. On the CTF most often – cookie or Authorization-title. Opening DevTools → Application → Cookies, or intercept the request in Burp Proxy and look for a string, beginning with eyJ (base64url from {" – characteristic JWT signature). More details in our review of the authentication attack.





Decode header and payload directly in the terminal: echo '<часть>' | tr '_-' '/+' | base64 -d. Quicker – insert the entire token into jwt.io or start python3 jwt_tool.py <token> no flags. jwt_tool will show decoded header, payload and signature information.





In the header we look at the field alg: meaning HS256 – symmetrical HMAC-SHA256 (one secret for both signature and verification), RS256 – asymmetrical RSA-SHA256 (private key signs, public checks), none - there is no signature at all. Each value opens its own attack vector.





In payload looking for custom claims: "role": "user", "isAdmin": false, "username": "guest". Payload is not encrypted — base64url-decoding shows all the data in open text. The JWT token’s forgery comes down to changing these fields and re-signing (or waivering the token).





If you compare the stages of the JWT attack with MITRE ATT&CK (in the author’s interpretation, not the official chain): detection of a vulnerability in the processing of tokens - Exploit Public-Facing Application (T1190, Initial Access), the creation of a fake token - Forge Web Credentials (T1606, Credential Access), the use of fakes for access to protected resources - Application0. For the exploitation of cryptographic weaknesses, JWT is also relevant to Exploitation for Credential Access (T1212).





Outside the CTF fake token with "role": "admin" in the production application - account capture, access to the admin, leakage of customer data. According to OWASP Top 10 2021, JWT authentication vulnerabilities fall into three categories: A01 (Broken Access Control) – increase of privileges through substitution of claims, A02 (Cryptographic Failures) – weak keys and lack of cryptographic protection, A05 (Security Misconfiguration) – adoption of the algorithm none without whitelist. Each CTF task on JWT is training on real web application vulnerabilities.






JWT's None Algorithm: Vulnerability and Bypass


JWT specification (RFC 7518) allows the value "alg": "none" – token without a signature. If the server library trusts the field alg from the token itself and does not check the algorithm according to whitelist, the signature is removed completely. The server will read "alg": "none", will miss the verification and accept any claims. As described in the JWT attacks PortSwigger Web Security Academy (portswigger.net/web-security/jwt) section, the problem is fundamental: the server is “forced” to trust the metadata from the token, and without a clear limitation of permissible algorithms, it opens the door for alg none bypass.





The most common vulnerability in the CTF level Easy and Medium. And the most offensive when you do not check the first.






Manual token assembly without signature


Let’s say the original token:





eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VybmFtZSI6Imd1ZXN0Iiwicm9sZSI6InVzZXIifQ.ZvkYYnyM929FM4NW9_hSis7_x3_9rymsDAx9yuOcc1I





Decode the header: {"typ":"JWT","alg":"HS256"}. Decode payload: {"username":"guest","role":"user"}. The task is obvious to change role on admin and remove the signature.



# Шаг 1: кодируем новый header с alg:none

echo -n '{"typ":"JWT","alg":"none"}' | base64 | tr '+/' '-_' | tr -d '='

# Результат: eyJ0eXAiOiJKV1QiLCJhbGciOiJub25lIn0



# Шаг 2: кодируем payload с нужными claims

echo -n '{"username":"admin","role":"admin"}' | base64 | tr '+/' '-_' | tr -d '='

# Результат: eyJ1c2VybmFtZSI6ImFkbWluIiwicm9sZSI6ImFkbWluIn0



# Шаг 3: собираем токен с пустой подписью (trailing dot обязателен)

# eyJ0eXAiOiJKV1QiLCJhbGciOiJub25lIn0.eyJ1c2VybmFtZSI6ImFkbWluIiwicm9sZSI6ImFkbWluIn0.





Sending via curl -H "Cookie: jwt=<token>" <URL> or substituted in Burp Repeater. If the response is 200 and the content has changed, the authorization bypass worked.





Through jwt_tool, the whole process is one command: python3 jwt_tool.py <JWT> -X a. Flag -X a triggers the attack alg:none and automatically generates token variants with a modified algorithm.






Bypass filters and boundary cases


Some servers block the string none, but check without register. According to the OWASP Web Security Testing Guide, the bypass is achieved by alternative spellings: None, NONE, nOnE, noNe. jwt_tool in flag -X a overdo these options automatically - you do not need to put everyone with their hands.





The signature format also affects: some implementations are expected header.payload. (trailing dot, empty signature), others — header.payload (without the final point). The first option did not pass – we try the second one.





When none-algorithm will not work: modern libraries (PyJWT >= 2.x, jsonwebtoken >= 9.x for Node.js) deflect none Default. On the CTF level Hard, the task author usually uses a fresh library with whitelist algorithms. If none Didn't pass - we go to the brutforce of the secret.






Weak secret JWT: Brutforce through hashcat


The server rejects correctly none, but uses HS256 with a short or vocabulary secret – the key is selected offline in seconds. According to MITRE ATT&CK, this is Password Cracking (T1110.002, Credential Access): The attacker extracts the signature of JWT and selects the secret key in the dictionary. Hacking JWT tokens through the brutforce is one of the most reliable vectors, because the authors of CTF tasks often lay weak secrets intentionally: secret, password, admin123, your-256-bit-secret (default jwt.io), iloveyou.





In real applications, the situation is not much better. The 2016 Exploit.In Combo (593,427,119 pairs of email+ passwords aggregated from various leaks) shows the scale of the problem of weak and reused passwords — the same ones that developers often ask as HMAC secrets. According to the IBM X-Force Threat Intelligence Index 2025, the rise in attacks using valid credentials was 71% year-on-year — including because of weak signature keys.
 
Top Bottom