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

# Manipulación del handshake de WebSocket

Notas sobre Manipulación del handshake de WebSocket para los laboratorios de PortSwigger Web Security Academy, incluido el flujo de explotación, pruebas de payload, validación en Burp Suite y contexto de mitigación.

### Manipulando el handshake de WebSocket para explotar vulnerabilidades

Esta tienda en línea tiene funcionalidad de chat en tiempo real basada en **WebSockets**. / Hay un filtro XSS: es agresivo, pero tiene fallos explotables.

Un campo de chat permite enviar mensajes que se muestran en tiempo real del lado del agente de soporte.

<figure><img src="https://754079710-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>

#### Prueba inicial del filtro XSS

Al enviar la siguiente carga útil al chat:

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

El servidor responde con el mensaje:

* **Ataque detectado: controlador de eventos**
* La conexión WebSocket es inmediatamente **cerrada**.

<figure><img src="https://754079710-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>

Después de simplemente recargar la página, aparece el siguiente mensaje:

* **Esta dirección está en la lista negra**

La dirección IP queda, por tanto, bloqueada temporalmente.

<figure><img src="https://754079710-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>

#### Sortear la lista negra

Añadiendo la siguiente cabecera HTTP al establecer el handshake de WebSocket:

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

<figure><img src="https://754079710-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>

El servidor acepta de nuevo la conexión. / Para evitar tener que añadirla manualmente cada vez, esta cabecera se configura **permanentemente en el proxy**.

<figure><img src="https://754079710-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>

#### Sortear el filtro XSS

Una vez restaurada la conexión, la carga útil se modifica ligeramente para eludir el filtro:

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

<figure><img src="https://754079710-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>

Este cambio de ruptura y sintaxis permite eludir la detección.

<figure><img src="https://754079710-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/es/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.
