> 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/pt-br/web/cache-poisoning/cache-poisoning-via-abnormal-get-request.md).

# Envenenamento de Cache via Requisição GET Anormal

### Envenenamento do cache da web por meio de uma requisição GET com corpo

Este laboratório é vulnerável a envenenamento do cache da web porque ele aceita **requisições GET com corpo**, mas **o corpo não é incluído na chave do cache**. / Um usuário visita regularmente a página inicial do site com o Chrome. / O objetivo é envenenar o cache para que a resposta execute `alert(1)` no navegador da vítima.

**Análise inicial**

Ao interceptar a requisição para a página inicial, observamos a presença do seguinte cookie

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

Esse cookie é gerado pelo arquivo JavaScript carregado pela página:

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

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

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

Acessando o seguinte diretamente:/ `/js/geolocate.js?callback=setCountryCookie`

O seguinte código é obtido:

{% code overflow="wrap" %}

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

{% endcode %}

Observamos que:

* O `callback` é usado para definir a função chamada.
* O valor passado é então executado no lado do cliente.

**Exploração da vulnerabilidade**

Ao carregar a página inicial, o site chama automaticamente:/ `/js/geolocate.js?callback=setCountryCookie`

Ao explorar o fato de que:

* O servidor aceita requisições GET com corpo.
* O corpo não é incluído na chave do cache.

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

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

Forçamos um **novo parâmetro `callback`** no corpo da requisição GET, atribuindo-lhe o seguinte valor:

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

A resposta em cache agora contém a chamada para `alert(1)`.

<figure><img src="/files/d10b25857090f9c66db7e26484a7951de44f6d78" 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/pt-br/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.
