In this post, we are going to solve the lab “JWT authentication bypass via weak signing key”:

JWT authentication bypass via weak signing key lab description

The first thing to do is start the lab:

Button to access the lab

Once we start it, we go to “My account” and log in with the credentials provided in the description:

Lab home page

Login form

Wiener user account page

Once we have logged in, whether with Burp Suite, developer tools, or in this case, the Cookie Editor extension, we can see that a JWT has been assigned to us:

JWT cookie in Cookie Editor

We can decode it on JWT.io:

Decoded JWT showing wiener user

If we look at this JWT, the HMAC algorithm is being used, specifically HS256. This means that the signature and its verification are done through a key.

The interesting thing about this is that it’s as if we had the hash of a password, meaning we can try to crack the “secret” that was used to sign the JWT. If we obtain it, we will be able to sign JWT tokens that are valid for the server and, likewise, we will be able to edit them.

To perform the brute force attack, we can use the jwtear tool:

  • jwtear bruteforce -t <JWT> -l <dictionary>

Jwtear bruteforce result showing the found secret

In this case, the server used the word “secret1” to sign the JWT tokens. Now that we know the word used to sign the tokens, we can try to edit a JWT to our benefit and sign it using “secret1”:

Modified JWT on JWT.io changing user to administrator

JWT signed with the found secret

We have changed the user from “wiener” to “administrator” so that, in case the signature works and the “administrator” user exists, we can become them.

If we now replace our JWT with the JWT we just generated and refresh:

Replacing the JWT in Cookie Editor

Admin panel after successful bypass

We become administrator users :), all due to the use of a weak “secret” in the JWT signature.

Now, to complete the lab, we simply go to the administration panel and delete the “carlos” user:

Access to admin panel

Button to delete carlos user

Carlos user successfully deleted

This way, the lab is now completed:

Lab completed successfully

JWTear is not the only tool that can be used for JWT brute force attacks, with a little searching we can find countless others:

GitHub search for JWT cracking tools

We can also find dictionaries for brute force attacks:

JWT dictionaries in GitHub repositories

SecLists also has a dictionary:

JWT secrets dictionary in SecLists