> 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 do WebSocket

Notas sobre manipulação do handshake do WebSocket para os laboratórios do PortSwigger Web Security Academy, incluindo fluxo de exploração, teste de payload, validação no Burp Suite e contexto de remediação.

### Manipulando o handshake do WebSocket para explorar vulnerabilidades

Esta loja online possui 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 do lado do agente de suporte.

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-7e167899ebc6f6893c92a84b8deca11ad45207f5%2F%7BBD656235-BB53-498B-9FDC-C64F9A2A7784%7D.png?alt=media" 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 **encerrada**.

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-be096d21e9bfaabb72aa5560a09d24d9cec94b57%2F%7B880823DF-F5A4-4802-9978-933D5A8B289D%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Depois de simplesmente recarregar a página, a seguinte mensagem aparece:

* **Este endereço está na lista negra**

O endereço IP é, portanto, bloqueado temporariamente.

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-2e33bd956aec874d584e04f7ace1a80422569d98%2F%7B2816FFE2-3D7D-4A5E-B5D4-067DBDF33F7A%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### Contornando a lista negra

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

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

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-2fb005e0471d574c87fc426d0dee90538d45a100%2F%7B945882E2-E46A-4509-9A6D-D108717481CB%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

O servidor aceita a conexão novamente. / Para evitar ter que adicionar manualmente toda vez, este cabeçalho é configurado **permanentemente no proxy**.

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-952feb57fb13e416a58916a89b9fa5fa47a45a64%2F%7BF1745B76-CF31-4A2D-A7F3-676136BE4FD5%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### Contornando o filtro de XSS

Uma vez que a conexão é restaurada, o payload é ligeiramente modificado para contornar o filtro:

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

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-fc0cb7c6ea20369b6bb250a51f13b799dc90ba1f%2F%7B0C6DB5F8-6777-4263-AAFA-086A9424FF9B%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-516c9a384c0d6a8043d8bc11a7c924d6e6e825de%2F%7B46B6F48D-4B77-4AAC-A4B4-F12D6FD070A6%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/websockets/websocket-handshake-manipulation.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.
