JWT
Introduction:
JWT is most commonly used in authorization.
A JSON Web Token (JWT) is a standardised format for securely exchanging data between two parties.
It is compact, readable and digitally signed using a private key/ or a public key pair by the Identity Provider(IdP). So the integrity and authenticity of the token can be verified by other parties involved.
The goal of using JWT is not to hide data, but to ensure the data's authenticity. JWT is signed and encoded rather than encrypted.
JWT is a stateless authentication mechanism based on tokens. Because it is a client-side stateless session, the server does not have to rely solely on a datastore (database) to save session information.
It consists of three elements:
Header - JWT header consists of token type and algorithm used for signing and encoding. Algorithms can be HMAC, SHA256, RSA, HS256 or RS256.
Payload - This is also a JSON object and is used to store the user’s information like id, username, role, token generation time and other custom claims.
Signature - The most crucial aspect of a JSON Web Token is its signature (JWT). The signature is generated by encoding the header and payload with Base64url Encoding and concatenating them with a period separator(.). This information is subsequently passed to the cryptography algorithm. As a result, if the header or payload changes, the signature must be computed again. Only the Identity Provider (IdP) has access to the private key used to generate the signature, which prohibits token manipulation.
header.payload.signatureJWT can be generated with two encryption mechanisms called Symmetric and Asymmetric encryption.
Symmetric: This mechanism requires a single key to create and verify the JWT. The most common algorithm for this type is HS256.
Asymmetric: This mechanism requires a Public key for verification and a Private key for signing the Signature. The most common algorithm for this type is RS256.
Key ID (kid) is an optional header with a string type that is used to identify a specific key in the filesystem or database and then use its content to validate the Signature. This argument is useful if the Application has several keys for signing tokens, but it can be problematic if it is injectable since an attacker can refer to a specific file with predictable content.
In addition to a key ID, JSON web token standards also provide developers with the ability to specify keys via a URL.
The token header contains a version (“ver”) claim. It contains the version of the JWT Token library used.
jku header parameter - JKU is an abbreviation for "JWK Set URL." It is an optional header field that specifies a URL that refers to a collection of keys needed to validate the token. If this field is not properly controlled and is permitted, an attacker might host their own key file and declare that the application uses it to validate tokens.
jwk header parameter - The optional JWK (JSON Web Key) header parameter allows attackers to embed the key used to verify the token directly in the token.
x5u and x5c header parameter - The x5u and x5c header arguments, like the jku and jwk headers, allow attackers to define the public key certificate or certificate chain used to verify the token. x5u defines information in URI form, whereas x5c permits certificate data to be incorporated in the token.
x5t parameter - The "x5t" (x.509 certificate thumbprint) header argument returns a base64url encoded SHA-256 thumbprint (i.e., digest) of an X.509 certificate's DER encoding, which may be used to match a certificate. As a result, it is equivalent to the key identifier or the kid claim!!
Inside Payload section you may also find: ****
jti param which is used to prevent replay attack on JWT
iss param — The name of the entity that issued the token.
iat param — Identifies the time at which the JWT token was issued.
nbf param — Identifies the time before which the JWT token MUST NOT be accepted for processing.
exp param — Identifies the expiration time on or after which the JWT MUST NOT be accepted for processing.
aud (audience) claim — identifies the recipients that the JWT is intended for.
Workflow:
Basically the identity provider(IdP) generates a JWT certifying user identity and Resource server decodes and verifies the authenticity of the token using secret salt / public key.

Tools:
GitHub - ticarpi/jwt_tool: A toolkit for testing, tweaking and cracking JSON Web Tokens
GitHub - mazen160/jwt-pwn: Security Testing Scripts for JWT
GitHub - brendan-rius/c-jwt-cracker: JWT brute force cracker written in C
GitHub - jmaxxz/jwtbrute: Brute forcing jwt tokens signed with HS256 since 2014
GitHub - Sjord/jwtcrack: Crack the shared secret of a HS256-signed JWT
Attacking JWT:
Check for sensitive data in the JWT
None algorithm
Change algorithm from RS256 to HS256
Signature not being checked
Crack the secret key
Attacks using kid in JWT token.
Forged Header Parameter
Other Attacks:
Key Database Mismanagement
Hacking JWT Tokens: Key Database Mismanagement
Verification Key Mismanagement
Hacking JWT Tokens: Verification Key Mismanagement
Hacking JWT Tokens: Verification Key Mismanagement II
Hacking JWT Tokens: Verification Key Mismanagement III
Hacking JWT Tokens: Verification Key Mismanagement IV
Vulnerable Key Generator
Hacking JWT Tokens: Vulnerable Key Generator
Transaction Replay
Hacking JWT Tokens: Transaction Replay
Hacking JWT Tokens: Transaction Replay II
JWS Standard for JWT
Hacking JWT Tokens: JWS Standard for JWT
Hacking JWT Tokens: JWS Standard for JWT II
Bypassing NBF Claim
Hacking JWT Tokens: Bypassing NBF Claim
Special Version Claim
Hacking JWT Tokens: Special Version Claim
Cross Service Relay Attack — Missing audience claim
Hacking JWT Tokens: Cross Service Relay Attack - Missing audience claim
Cross Service Relay Attack — Misconfigured audience claim
Hacking JWT Tokens: Cross Service Relay Attack - Misconfigured audience claim
Client Side Token Decode
Hacking JWT Tokens: Client Side Token Decode
Quick Methodology:
MindMap:
Labs:
https://github.com/h-a-c/jwt-lab
GitHub - Sjord/jwtdemo: Practice hacking JWT tokens
Reference:
Write-ups & Reports:
CTFtime.org / Union CTF 2021 / Cr0wnAir / Writeup
Web - JWT - Cr0wnAir - Union CTF [Walkthrough]
Exploiting JWT to Account Takeover
The Bad Twin: a peculiar case of JWT exploitation scenario
Hijacking accounts by retrieving JWT tokens via unvalidated redirects
Mail.ru disclosed on HackerOne: [smena.samokat.ru] Predictable JWT...
Trint Ltd disclosed on HackerOne: Insecure Zendesk SSO...
HackerOne disclosed on HackerOne: HackerOne Jira integration plugin...
Hacking JWT Tokens: "kid" Claim Misuse - Command Injection
Hacking JWT Tokens: Blind SQLi
Hacking JWT Tokens: jku Claim Misuse
Blogs:
Attack Methodology · ticarpi/jwt_tool Wiki
Attacking JSON Web Tokens (JWTs)
JSON Web Token Exploitation for Red Team
https://medium.com/swlh/hacking-json-web-tokens-jwts-9122efe91e4a
How JSON Web Token(JWT) authentication works?
Attacks on JSON Web Token (JWT)
Get a Feel of JWT ( JSON Web Token )
Hacker Tools: JWT_Tool - The JSON Web Token Toolkit - Intigriti
Video:
How to Exploit "Json Web Token"(JWT) vulnerabilities | Full Practical
Tips:
Author:
Last updated