> 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/cache-poisoning/cache-key-injection.md).

# Injection in den Cache-Key

Notizen zur Injection in den Cache-Key für die Labs der PortSwigger Web Security Academy, einschließlich Ausnutzungsablauf, Payload-Tests, Burp-Suite-Validierung und Behebungskontext.

### Cache-Key-Injektion

### Injektion in den Cache-Key

Wir müssen mehrere Schwachstellen kombinieren (einschließlich **Cache-Key-Injektion**) um auszuführen **`alert(1)`** im Browser des Opfers. Das Labor erfordert die Verwendung des Headers **`Pragma: x-get-cache-key`**.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-4a1acbb2d438aa7bece67036c8469117944898d1%2F%7BBB8AEC0B-2845-4707-92E0-E0EC29FFBE3A%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### Aufklärung

1/) Anmeldeverhalten

* Wir haben ein Verbindungs-Panel.
* Nach dem Login werden wir weitergeleitet zu **`/login/?lang=en`**.
* Anschließend wird ein Session-Cookie gesetzt.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-cc2a931ab62b85905c663ead76ee92cf365cc591%2F%7BCFDA343D-18D9-4A4E-B201-AD2D2F448C34%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

2/) Spiegelung des `lang` Parameters

* Unser Eintrag erscheint in der Antwort über `lang`:
* Beispiel: **`/login/?lang=HELLLOOOO`**

```bash
/login/?lang=HELLLOOOO
```

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-3f28cdf50b4733c230a62e09dce3a6395f0ba559%2F%7B17906ACC-07FB-404C-A3F6-42BF0D0407C6%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Wenn wir HTML-Tags einfügen (z. B. `<h1>`), **es wird nicht ausgeführt**: es gibt HTML-Kodierung\*\*.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-60fad42f0ec8cc458181020f44e82c2045433331%2F%7B475BC26C-7E37-43FF-99FE-E6EA7448F512%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### Operativer Einstiegspunkt

Versteckte JS-Datei: `localize.js`

```bash
/js/localize.js?lang=en&cors=0
```

Wir bemerken ein Skript im Hintergrund:

* **`/js/localize.js?lang=en&CORS=0`**
* Beobachtete Antwort:
* `document.cookie = 'lang=en';`

Wenn wir ändern `lang`, wird der Wert gespiegelt:

* **`/js/localize.js?lang=hello&CORS=0`** → `hello` erscheint in der Antwort.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-7743c4ea0cf45a253f8bd6de63e3cae9592ab5ce%2F%7B7FB44CFC-718B-41C9-8590-00A0B2841462%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### Beobachtung des Cache-Keys

Wir fügen hinzu:

```http
Pragma: x-get-cache-key
```

Und wir erhalten den Key:

* `X-Cache-Key: /js/localize.js?lang=en&CORS=0$$`

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-8aabb24c2d9bcf343b42fb004c768a9b4572c8e3%2F%7B3354A351-D591-4D44-A0AB-4E95DDDAF7FA%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Wir stellen fest, dass `CORS` den Key beeinflusst und dass wir beim Spielen **Origin** + `CORS`, variieren können, was in den Cache gelangt.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-8811b02b819b929fa990224dc9f5335437a805ed%2F%7B6FB2F228-2C46-4DA5-81D4-9D3AF46409A0%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### Header-Injektion über Back Cart

Wir verwenden CRLF-Injektion:

* `%0d%0a`

```
man ascii
```

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

#### 1) Test: Cookie-Injektion

Wir senden:

* `Origin: hello%0d%0aSet-Cookie:%20csrfKey=a`

Ergebnis: Der Cookie wird auf der Antwortseite korrekt interpretiert.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-163ad6f6a0e182eb18fa7ce90134fdf2259b9d77%2F%7B51717951-1BA3-466A-849A-AE795F6B5783%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### JavaScript-Injektion durch Manipulation `Content-Length`

Wir versuchen dann, Inhalt mit folgendem in die Antwort einzuschleusen:

* `Origin: x%0d%0aContent-Length:%208%0d%0a%0d%0aalert(1)$$$$`

In der Antwort finden wir **`alert(1)`**.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-5f4dadb4419f9e798e6edd81836d7db4d6b84892%2F%7B66177E98-484A-472A-B58B-FADF52A67773%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### Gezielte versteckte Antwort erstellen

Damit der Server diese Version speichert (mit `alert(1)`), wird die **Cache-Key** muss er mit einem Format übereinstimmen, das unseren injizierten `Origin`, zum Beispiel:

{% code overflow="wrap" %}

```http
X-Cache-Key: /js/localize.js?lang=hello&cors=1$$origin=hello%0d%0aContent-Length: 8%0d%0a%0d%0aalert(1)
```

{% endcode %}

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-b27a41b9949dcdd648331b13506c94ade3d9fb49%2F%7BCE27C2CE-0BCC-4773-80C4-D26191AFA5A1%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### Versatz auf der Opferseite über einen ignorierten Parameter

Wir suchen nach einem vom Cache ignorierten Parameter (gefunden mit Param Miner):

* **`utm_content`**

Wir verwenden den Cache-Key erneut und platzieren die Nutzlast in `utm_content` um die vergiftete Ressource auszuliefern, während wir besuchen `lang=en`.

Endgültige Anfrage (wie wir sie verwendet haben):

{% code overflow="wrap" %}

```bash
GET /login?lang=en?utm_content=x%26cors=1%26x=1$$origin=x%250d%250aContent-Length:%208%250d%250a%250d%250aalert(1)$$%23 HTTP/2
```

{% endcode %}

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-d0bd7ade7e74687ff349fe8ff48548b416b6cb63%2F%7B8B884C36-3E90-4DDF-8249-3CA7DAAFB044%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Wenn das Opfer die Seite in **`/login/?lang=en`** (über Weiterleitung) wird der vergiftete Inhalt aus dem Cache ausgeliefert, und **`alert(1)`** wird ausgeführt.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-688fd4eebedefee8f767ea116d0a28dad5ed05cf%2F%7BC2D5999F-6555-4179-B883-EC42FECE47B3%7D.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/cache-poisoning/cache-key-injection.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.
