JWT attacks
https://portswigger.net/web-security/jwt
Lab: JWT authentication bypass via unverified signature
This lab uses a JWT-based mechanism for handling sessions. Due to implementation flaws, the server doesn't verify the signature of any JWTs that it receives.
Solution:
Change sub value to administrator in JWT
Lab: JWT authentication bypass via flawed signature verification
This lab uses a JWT-based mechanism for handling sessions. The server is insecurely configured to accept unsigned JWTs.
Solution:
Change alg to none and sub to administrator in JWT
Lab: JWT authentication bypass via weak signing key
This lab uses a JWT-based mechanism for handling sessions. It uses an extremely weak secret key to both sign and verify tokens. This can be easily brute-forced using a wordlist of common secrets.
Save JWT value to a file
Wordlist - https://github.com/wallarm/jwt-secrets/blob/master/jwt.secrets.list
Solution:
Generate JWT Key with JWT Editor plugin -> New Symmetric Key -> Replace k value with base64 encoded secret
Replace sub parameter to administrator in JWT, then Sign it with the signing key <- You can do it on JSON Web Token tab in the Repeater
To complete, make a request to this url with the newly signed JWT:
GET /admin/delete?username=carlos HTTP/1.1
Lab: JWT authentication bypass via jwk header injection.
This lab uses a JWT-based mechanism for handling sessions. The server supports the jwk
parameter in the JWT header. This is sometimes used to embed the correct verification key directly in the token. However, it fails to check whether the provided key came from a trusted source.
Solution:
In JWT Editor Keys tab -> Generate New RSA Key - 2048
Replace sub parameter to administrator in JWT, then choose Attack option with Embedded JWK -> choose generated RSA key
To complete, make a request to this url with the newly signed JWT:
GET /admin/delete?username=carlos HTTP/1.1
Lab: JWT authentication bypass via jku header injection
This lab uses a JWT-based mechanism for handling sessions. The server supports the jku parameter in the JWT header. However, it fails to check whether the provided URL belongs to a trusted domain before fetching the key.
In JWT Editor Keys tab -> Generate New RSA Key - 2048
In Exploit Server -> Set Body with the RSA key some contents:
Add jku value exploit server endpoint to header, Replace sub parameter to administrator in JWT, then choose sign option with Don't modify header -> choose generated RSA key
Lab: JWT authentication bypass via kid header path traversal
This lab uses a JWT-based mechanism for handling sessions. In order to verify the signature, the server uses the kid parameter in JWT header to fetch the relevant key from its filesystem.
Generate JWT Key with JWT Editor plugin -> New Symmetric Key -> Replace k value with AA== -> Replace kid value to "../../../../../../../dev/null"
k value is an encoded null value, kid value will return null and then verified as null=null
Replace sub parameter to administrator in JWT, then Sign it with the signing key
To complete, make a request to this url with the newly signed JWT:
GET /admin/delete?username=carlos HTTP/1.1
Lab: JWT authentication bypass via algorithm confusion
This lab uses a JWT-based mechanism for handling sessions. It uses a robust RSA key pair to sign and verify tokens. However, due to implementation flaws, this mechanism is vulnerable to algorithm confusion attacks.
To solve the lab, first obtain the server's public key. This is exposed via a standard endpoint. Use this key to sign a modified session token that gives you access to the admin panel at /admin
, then delete the user carlos
.
The site gives a JWK containing a single public key on /jwks.json
endpoint.
Generate JWT Key with JWT Editor plugin -> New RSA Key -> Paste contents of array in /jwks.json
After the creation, right click then choose "copy public key as pem" option
In Decoder Tab, encode the contents of it to Base64
Generate JWT Key with JWT Editor plugin -> New Symmetric Key -> Generate -> Replace k value with encoded the pem value
Replace sub parameter to administrator in JWT, replace alg parameter from RS256 to HS256, then Sign it with the symmetric key
To complete, make a request to this url with the newly signed JWT:
GET /admin/delete?username=carlos HTTP/1.1
Lab: JWT authentication bypass via algorithm confusion with no exposed key
This lab uses a JWT-based mechanism for handling sessions. It uses a robust RSA key pair to sign and verify tokens. However, due to implementation flaws, this mechanism is vulnerable to algorithm confusion attacks.
To solve the lab, first obtain the server's public key. Use this key to sign a modified session token that gives you access to the admin panel at /admin
, then delete the user carlos
.
To get 2 different JWT, login 2 time with wiener user, after getting 2 JWT:
Replace the session cookie with this new tampered JWT and then send the request. It should get 200 response.
Generate JWT Key with JWT Editor plugin -> New Symmetric Key -> Generate -> Replace k value with Base64 encoded x509 key value
Replace sub parameter to administrator in JWT, replace alg parameter from RS256 to HS256, then Sign it with the symmetric key
To complete, make a request to this url with the newly signed JWT:
GET /admin/delete?username=carlos HTTP/1.1
Last updated