> 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/websockets/websocket-handshake-manipulation.md).

# Manipulação do handshake WebSocket

### Manipulando o handshake do WebSocket para explorar vulnerabilidades

Esta loja online tem funcionalidade de chat em tempo real baseada em **WebSockets**. / Um filtro de XSS está presente: ele é agressivo, mas tem falhas exploráveis.

Um campo de chat permite enviar mensagens que são exibidas em tempo real no lado do atendente de suporte.

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

#### Teste inicial do filtro de XSS

Ao enviar o seguinte payload no chat:

```javascript
<img src=0 onerror=alert(0)>
```

O servidor responde com a mensagem:

* **Ataque detectado: manipulador de evento**
* A conexão WebSocket é imediatamente **fechada**.

<figure><img src="/files/5092c5ffb58006115ffe586ac72d6598f8e40ffc" alt=""><figcaption></figcaption></figure>

Após simplesmente recarregar a página, a seguinte mensagem aparece:

* **Este endereço está na lista de bloqueio**

O endereço IP está, portanto, bloqueado temporariamente.

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

#### Contornando a lista de bloqueio

Ao adicionar o seguinte cabeçalho HTTP ao estabelecer o handshake do WebSocket:

```http
X-Forwarded-For: 0.0.0.0
```

<figure><img src="/files/23655ef927d037fe5f93b937f978e5fda2a62cc0" alt=""><figcaption></figcaption></figure>

O servidor aceita a conexão novamente. / Para evitar ter que adicioná-lo manualmente a cada vez, esse cabeçalho é configurado **permanentemente no proxy**.

<figure><img src="/files/8a8762b7f74b01dbcec908a1d5355d1fd50a5980" alt=""><figcaption></figcaption></figure>

#### Contornando o filtro de XSS

Assim que a conexão é restabelecida, o payload é ligeiramente modificado para contornar o filtro:

```javascript
<img src=0 OnErrOR=alert`0`>
```

<figure><img src="/files/5e9d40d8413425c1a3fbd350ac3d709637b3909a" alt=""><figcaption></figcaption></figure>

Essa mudança de quebra e sintaxe permite contornar a detecção.

<figure><img src="/files/ae0a1c169d899d82c347c152131544338d988a5d" 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/websockets/websocket-handshake-manipulation.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.
