githubEdit

JWT

JWT (Json Web Token) Pentesting

JWT is a proposed internet standard for creating data with optional signature and optional encryption whose payload holds JSON that asserts some number of claims.

Decode JWT

None Algorithm Attack

If the website uses JWT and we can see the token, copy the JWT and paste it in jwt.ioarrow-up-right.

  1. Replace the "alg" value with "none" in header. (try the alg header variations such as "none", "None", "nOnE", "NONE".)

  2. Replace arbitrary values of the payload e.g. "username" with "admin".

  3. Empty the signature field.

If the error "Invalid Signature" occured, we can manually create Base64 value for each section (remove the "=" symbol). If you want to empty the signature field manually, you can delete the final section. For example,

eyJ0eXAiOiJKV1QiLCJhbGciOiJub25lIn0.eyJ1c2VybmFtZSI6ImFkbWluIiwiZXhwIjoxNjc4NDYwNjM1fQ.

Now copy the JWT. Go to the website and replace the original JWT with the new one in HTTP header.

RS256 → HS256 Algorithm Attack

Reference: HackTricksarrow-up-right

When changing the alg value from RS256 (asymmetric) to HS256 (symmetric) may, the target server may use the public key as the secret key. It may be possible to verify the signature.

We can retrieve the public key with the following command:

Modify exp Value

If our JWT token is invalid, we can also try to increase the exp (expiration) value.

Automation

JWT Toolkitarrow-up-right is a toolkit for testing, tweaking and cracking JWT.

Decode

Scan

Exploit

Fuzz

Manual Pentesting

Crack JWT Secret

First of all, you need to put the JWT into the text file.

Then crack the hash using John the Ripper or Hashcat.

If you found a secret, you can create a new JWT using the secret on tools like JWT.io.

Also we can use jwt-crackerarrow-up-right.

JWK (Json Web Key) Header Injection

If the server supports the jwk in the JWT header, we may be able to add arbitrary jwk parameters then impersonate another user. To perform that, JWT Editor extension in Burp Suite is useful.

  1. Install JWT Editor in BApp Store in Burp Suite.

  2. Go to JWT Editor Keys tab.

  3. If the server JWT’s algorithm is RSA such as RS256, click New RSA Key then click Generate button in the popup.

  4. Send request containing JWT to Burp Repeater.

  5. Go to Json Web Token tab, then modify arbitrary parameter e.g. username.

  6. Click Attack at the bottom. Select Embedded JWK.

  7. In the popup, choose our generated key.

  8. After that, the jwk is added in the JWT header.

  9. Send request in Repeater.

JKU (JWK Set URL) Header Injection

If the server supports the jku in the JWT header, we may be able to add arbitrary URL in the jku then impersonate another user. As in the JWK section above, JWT Editor is useful. First of all, generate RSA key as the JWK section above, then serve it in our own web server. The body is as below.

After that, add jku in the JWT header and set the URL of our server. Then set the kid of our generated key into the kid. Finally modify arbitrary value e.g. username. As a result, our JWT is as the following.

Now send request using the JWT above. We may be able to become administrator.

References

Tools

General info

Attacks

Payload

Last updated