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

# Manipulation du handshake WebSocket

### Manipuler la négociation WebSocket pour exploiter des vulnérabilités

Cette boutique en ligne dispose d'une fonctionnalité de chat en temps réel basée sur **WebSockets**. / Un filtre XSS est présent : il est agressif mais présente des failles exploitables.

Un champ de chat vous permet d'envoyer des messages qui s'affichent en temps réel du côté de l'agent d'assistance.

<figure><img src="/files/0cb4621155e5f35c0036bf2d11388ed264c1a067" alt=""><figcaption></figcaption></figure>

#### Test initial du filtre XSS

Lors de l'envoi du payload suivant dans le chat :

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

Le serveur répond avec le message :

* **Attaque détectée : gestionnaire d'événements**
* La connexion WebSocket est immédiatement **fermée**.

<figure><img src="/files/6b7dc4fcb25da460790126a56845dff87c7d30d8" alt=""><figcaption></figcaption></figure>

Après avoir simplement rechargé la page, le message suivant apparaît :

* **Cette adresse est sur liste noire**

L'adresse IP est donc temporairement bloquée.

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

#### Contournement du blocage par liste noire

Ajouter l'en-tête HTTP suivant lors de l'établissement de la négociation WebSocket :

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

<figure><img src="/files/72a60b128ea8adb5f6afc7f2435acf7ff500b18a" alt=""><figcaption></figcaption></figure>

Le serveur accepte à nouveau la connexion. / Pour éviter de devoir l'ajouter manuellement à chaque fois, cet en-tête est configuré **de manière permanente dans le proxy**.

<figure><img src="/files/5421a1472ecd8092af0ddfa8887fe409a847638a" alt=""><figcaption></figcaption></figure>

#### Contournement du filtre XSS

Une fois la connexion rétablie, le payload est légèrement modifié pour contourner le filtre :

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

<figure><img src="/files/243ab5bac75a33ff72c4ff178da3b43c3e763492" alt=""><figcaption></figcaption></figure>

Cette modification de casse et de syntaxe permet de contourner la détection.

<figure><img src="/files/a7799cfed9e24ed9dfca80d3101fc2efba2ffcfc" 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/fr/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.
