> For the complete documentation index, see [llms.txt](https://ganesha-hk.gitbook.io/cybersecurity-writeups/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ganesha-hk.gitbook.io/cybersecurity-writeups/port-swigger-jwt-labs/lab-3.md).

# lab-3

## JWT Authentication Bypass via Weak Signing Key

**Difficulty:** Practitioner

### Lab Description

This lab uses a JWT-based mechanism for handling sessions. It uses an extremely weak secret key to both sign and verify tokens, which can be brute-forced using a wordlist of common secrets.

**Objective:** Brute-force the website's secret key, use it to sign a modified session token that gives you access to the admin panel at `/admin`, then delete the user `carlos`.

**Credentials:** `wiener:peter`

### Root Cause

When a developer fails to use a strong, unguessable value as the JWT signing secret, an attacker can brute-force the token against a wordlist of common secrets. Once the secret is cracked, the attacker can modify any claim in the payload, generate a valid new signature, and bypass the server's verification step entirely — leading to account takeover, session hijacking, and access control bypass.

### Exploitation

1. Start the login process and capture all packets in Burp Suite.
2. Find `GET /my-account?id=wiener` and send it to Repeater.
3. Copy the JWT token from the request.
4. Crack the secret using Hashcat:

   ```
   hashcat -a 0 -m 16500 <jwt> <wordlist>
   ```
5. Go to [jwt.io](https://jwt.io/) and paste the JWT token into the encoder.
6. Update `"sub"` to `"administrator"`, paste the cracked secret into the **Verify Signature** field, and copy the newly signed JWT.
7. Paste the new JWT into the `GET /my-account?id=wiener` request in Repeater and update the URL to `GET /admin`.
8. Send the request and open the response in the browser.
9. Click **Delete carlos** in the browser and capture the resulting request.
10. Send that request to Repeater, update the JWT token with the new signed token again, and send.
11. The user `carlos` is deleted.

### Lesson Learned

Always use a long, randomly generated, and unguessable secret value for JWT signing. A weak or common secret provides no real protection — it can be cracked with widely available tools and wordlists, completely undermining the cryptographic integrity of the token.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://ganesha-hk.gitbook.io/cybersecurity-writeups/port-swigger-jwt-labs/lab-3.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
