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

# Manipulation des WebSocket-Handshakes

Notizen zur Manipulation des WebSocket-Handshakes für die Labs der PortSwigger Web Security Academy, einschließlich Ausnutzungsablauf, Payload-Tests, Burp-Suite-Validierung und Behebungskontext.

### Manipulation des WebSocket-Handshakes zum Ausnutzen von Schwachstellen

Dieser Online-Shop verfügt über Echtzeit-Chat-Funktionalität auf Basis von **WebSockets**. / Ein XSS-Filter ist vorhanden: Er ist aggressiv, weist aber ausnutzbare Schwachstellen auf.

Ein Chat-Feld ermöglicht es Ihnen, Nachrichten zu senden, die auf Seiten des Support-Mitarbeiters in Echtzeit angezeigt werden.

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

#### Erster Test des XSS-Filters

Beim Senden des folgenden Payloads in den Chat:

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

Der Server antwortet mit der Meldung:

* **Angriff erkannt: Event-Handler**
* WebSocket-Verbindung wird sofort **geschlossen**.

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

Nach einfachem Neuladen der Seite erscheint die folgende Meldung:

* **Diese Adresse steht auf der Blacklist**

Die IP-Adresse wird daher vorübergehend blockiert.

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

#### Blacklist-Umgehung

Das Hinzufügen des folgenden HTTP-Headers beim Aufbau des WebSocket-Handshakes:

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

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

Der Server akzeptiert die Verbindung erneut. / Um zu vermeiden, dass er jedes Mal manuell hinzugefügt werden muss, wird dieser Header **dauerhaft im Proxy konfiguriert**.

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

#### XSS-Filter-Umgehung

Sobald die Verbindung wiederhergestellt ist, wird das Payload leicht modifiziert, um den Filter zu umgehen:

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

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

Diese Änderung bei Unterbrechung und Syntax ermöglicht es, die Erkennung zu umgehen.

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