Since I’ve created this website, I didn’t write a “real” post yet. So, as a first start, I’ll talk about the new labs provided by Portswigger’s Web Security Academy few days ago: JWT Attacks). This is also my very first writeup ever, I hope everything will be clear (Let me know in a private message on Linkedin if you see something wrong, I’ll fix it).
As I write this post, I solved only the 3 first labs. The next ones will be added in an update to this post or in a “part 2”, soon.
Preparation
Before starting, install the JWT Editor extension on Burp Suite (available for Community and Professional versions), it will be used for all labs.
Lab 1: JWT authentication bypass via unverified signature
Go to My Account
Enter the credentials “wiener” and “peter”
From the HTTP History, send the “/my-account” page to repeater
Highlight the payload part of the token and go to the “Decoded from” section on the right side
Change “wiener” to “administrator” and click on “Apply changes”
Send the modified page, if successful the response will be a code 200
Get the link to the response and paste it in the web browser
When the admin account is displayed, click on “Admin panel” link
Find the “/admin” page in the HTTP History and repeat the previous steps from 3 to 7
When the “Admin panel” is displayed, click on the “delete” link for “carlos”
Repeat the same steps again, from 3 to 7 (except the time, the final response will be a 302 and not a 200), for the “/admin/delete?username=carlos” page
Go back to the browser, the lab is solved
Lab 2: JWT authentication bypass via flawed signature verification
Go to My Account
From the HTTP History, send the “/my-account” page to Repeater
Highlight the Header part of the token and go to the “Decoded from” section on the right side
Change “RS256” to “none” and click on “Apply changes”
Highlight the Payload part of the token and go to the “Decoded from” section on the right side
Change “wiener” to “administrator” and click on “Apply changes”
Highlight the Signature of the token and delete it
Send the modified reset, if successful, the response will be a code 200
Get the link to the response and paste it in the browser
When the admin account is displayed, click on “Admin panel”
Find the “/admin” page in the HTTP History and repeat the same steps from 2 to 9
When the Admin panel is displayed, click on the “delete” link for “carlos”
Find the “/admin/delete?username=carlos” page in the HTTP History and repeat the same steps from 2 to 9 (The final response will be a code 302, not 200)
Go back to the browser, the lab is solved
Lab 3: JWT authentication bypass via weak signing key
- Save this JWT secrets list: https://raw.githubusercontent.com/wallarm/jwt-secrets/master/jwt.secrets.list
Enter the credentials “wiener:peter”
Go to “My account” page
In the HTTP History, send the page to the Repeater
Copy the token
Use hashcat to get the secret, using the token copied above and the JWT Secret List downloaded at step 1:
hashcat -a 0 -m 16500 <token> <JWT secrets list>
Use the upper arrow (↑) the go back to the previous command and add
—show
at the end to get the secret key (the result will be “secret1”)On jwt.io, paste the token in the “Encoded” section, replace “wiener” with “administrator” and add “secret1” as a secret
Copy the new token generated on jwt.io, paste it in the Repeater and send the reset, you’ll get code 200
Get the link to the response and paste it in the browser
When the admin account is displayed, go to the “Admin panel”
In the HTTP History, find the “/admin” page and send it to the Repeater
Repace the JWT token with the one previously generated on jwt.io and send the reset, you’ll get a code 200
Again, get the link to the response and paste it in the browser
Finally, click on the “delete” link for “carlos”
In the HTTP History, find the “/admin/delete?username=carlos” page and send it to the Repeater
Replace the token with the modified previous one (the same previously generated on jwt.io). Send the reset, you’ll get a code 302
Go back to the browser, the lab is solved
———- update july 1st, 2022 ———-
Lab 4: JWT authentication bypass via jwk header injection
Go to “My account”
Enter the credentials “wiener” and “peter”
In the HTTP History, find the page “/account” and send it to Repeater
Go to the tab JWT Editor Keys on the right side
Click on “New RSA Key”
Click on “Generate”, the content will appear below, click on “OK”
The new RSA key appears in the list
Go back to the Repeater, in the JWS section, replace “wiener” with “administrator”, click on “sign” at the bottom window. If you have many keys, select the last one created just before (if you just have one, it’s selected by default) and click on “OK”
When it’s done, click on “Attack” and select “Embedded JWK
Choose the last key created, if needed and click on “OK”
In the Repeater, go back to the “Raw” tab, send the reset (the few last steps has modified the JWT token), you’ll see a response with a code 200
Generate the link for this response
Copy this link
Paste it on the web browser, you’re now an administrator. Go to the admin panel
In the HTTP History, find the page “/admin” and send it to the Repeater
Replace the token with the same one used for the previous reset (For simplicity, you can just copy it directly from the previous reset and paste it on this new reset), and get a response with a code 200
Generate the link to this response and copy it
Paste it in the web browser, and click on the “delete” link for “carlos”
In the HTTP History, find the page “/admin/delete?username=carlos” and repeat the same steps (send to Repeater, paste the same modified token used on steps 11 and 16), you’ll get a code 302
Go back to the web browser, the lab is now solved