> 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/es/web/websockets/websocket-message-manipulation.md).

# Manipulación de mensajes WebSocket

### Manipulación de mensajes WebSocket para explotar vulnerabilidades

Esta tienda en línea tiene una **función de chat** implementada usando **WebSockets**. / Los mensajes enviados por el usuario se muestran instantáneamente en el navegador de un **agente de soporte**. / El objetivo del laboratorio es **iniciar una `alert()`** ventana emergente en el navegador del agente manipulando un mensaje WebSocket.

Hay un campo de chat disponible en la aplicación.

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

<figure><img src="/files/111094af6506b8242b4f723dbcf6b1043df23575" alt=""><figcaption></figcaption></figure>

Al inspeccionar el tráfico, los mensajes se envían mediante WebSocket de la siguiente manera:

```json
{
    "user":"Tú",
    "content":"hola"
}
```

**Prueba de filtrado**

Intenta enviar la siguiente carga útil a través del chat:

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

Resultado observado:/ El contenido está \*\*escapado en el lado del servidor\*\* e interpretado como texto:

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

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

Esto indica la presencia de un filtrado básico contra `<script>` etiquetas.

**Elusión del filtrado**

A continuación, se envía manualmente un mensaje WebSocket que contiene la siguiente carga útil:

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

El mensaje es **reenviado directamente** a través de la solicitud WebSocket, sin pasar por los controles habituales de la interfaz.

<figure><img src="/files/29973446266c60b8b9ae64400a2efbfa2c369bf7" alt=""><figcaption></figcaption></figure>

Cuando el agente de soporte recibe el mensaje, el navegador interpreta el `onerror` atributo, lo que desencadena:

* la ejecución de `alert(0)`
* La aparición de una **ventana emergente** en el navegador del agente

<figure><img src="/files/5d832912a74633d351f81a1c9c8dd3bfc63b5c72" 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/es/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.
