> 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-via-abnormal-get-request.md).

# Envenenamiento de caché mediante una solicitud GET anómala

### Envenenamiento de la caché web mediante una solicitud GET pesada

Este laboratorio es vulnerable al envenenamiento de la caché web porque acepta **solicitudes GET con un cuerpo**, pero **el cuerpo no se incluye en la clave de caché**. / Un usuario visita regularmente la página de inicio del sitio con Chrome. / El objetivo es envenenar la caché para que la respuesta ejecute `alert(1)` en el navegador de la víctima.

**Análisis inicial**

Al interceptar la solicitud a la página de inicio, observamos la presencia de la siguiente cookie

<pre class="language-http"><code class="lang-http"><strong>Cookie: country=[object Object]
</strong></code></pre>

Esta cookie se genera a partir del archivo JavaScript cargado por la página:

```bash
/js/geolocate.js
```

<figure><img src="/files/98c372935b301b6d0189e3046e300c0329fdf794" alt=""><figcaption></figcaption></figure>

**Análisis de `geolocate.js`**

Accediendo directamente a lo siguiente:/ `/js/geolocate.js?callback=setCountryCookie`

Se obtiene el siguiente código:

{% code overflow="wrap" %}

```javascript
const setCountryCookie = (country) => {
    document.cookie = 'country=' + country;
};
const setLangCookie = (lang) => {
    document.cookie = 'lang=' + lang;
};
setCountryCookie"({"country":"United Kingdom"});
```

{% endcode %}

Observamos que:

* El `callback` se utiliza para definir la función llamada.
* El valor pasado se ejecuta entonces en el lado del cliente.

**Explotación de la vulnerabilidad**

Cuando se carga la página de inicio, el sitio llama automáticamente a:/ `/js/geolocate.js?callback=setCountryCookie`

Aprovechando el hecho de que:

* El servidor acepta solicitudes GET con un cuerpo.
* El cuerpo no se incluye en la clave de caché.

```bash
callback=alert(1)
```

<figure><img src="/files/6b5302151c6f25ecc980945c6bdcbd70142ddf51" alt=""><figcaption></figcaption></figure>

Forzamos un **nuevo parámetro `callback`** en el cuerpo de la solicitud GET, dándole el siguiente valor:

<figure><img src="/files/11394e70e0439b6d757f5bb04fd3346dc6180738" alt=""><figcaption></figcaption></figure>

La respuesta almacenada en caché ahora contiene la llamada a `alert(1)`.

<figure><img src="/files/cec8f5994fc12b878836a556723515dc606f61ba" 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-via-abnormal-get-request.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.
