> 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

### Manipulando el handshake de WebSocket para explotar vulnerabilidades

Esta tienda en línea tiene una funcionalidad de chat en tiempo real basada en **WebSockets**. / Está presente 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="/files/f858c5c71b1ad93b5d9f25e854172e47710c1559" alt=""><figcaption></figcaption></figure>

#### Prueba inicial del filtro XSS

Al enviar el siguiente payload 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="/files/ce4d4f72e69ced606b801e8b0b6d19121f31e466" alt=""><figcaption></figcaption></figure>

Tras simplemente recargar la página, aparece el siguiente mensaje:

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

Por lo tanto, la dirección IP queda bloqueada temporalmente.

<figure><img src="/files/56316f0ec6485750f122bfdb6edeeef6cd2eab4f" alt=""><figcaption></figcaption></figure>

#### Elusión de 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="/files/4a1de2e4927d7253e964920c1c678b8cbe5293e4" alt=""><figcaption></figcaption></figure>

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

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

#### Elusión del filtro XSS

Una vez restablecida la conexión, el payload se modifica ligeramente para eludir el filtro:

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

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

Este cambio de mayúsculas/minúsculas y sintaxis permite eludir la detección.

<figure><img src="/files/3ef5337415c701e65b8e4a8e5bbc6e1b8269e8b8" 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-handshake-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.
