> 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-document-write-with-location-search.md).

# XSS DOM document.write مع location.search

### ثغرة XSS في DOM في مخرج document.write باستخدام المصدر location.search

تحتوي هذه المختبر على ثغرة DOM مرتبطة بـ XSS في ميزة تتبع استعلام البحث. تستخدم الصفحة `document.write` لكتابة البيانات من `location.search` إلى DOM، ويمكن التحكم بها عبر عنوان URL.

**وصف الثغرة الأمنية**/ `document.write` يتم استدعاؤه مع `location.search` السلسلة دون تنقية. وبما أن الإدخال يأتي مباشرة من عنوان URL، يمكن للمهاجم حقن HTML/JS في الصفحة عبر التلاعب بـ `location.search`.

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

**هدف الحل** نفّذ هجوم XSS على جانب DOM يستدعي `alert()` الدالة عند تحميل الصفحة.

**تعليقات/تلميحات**/ ينشئ الكود شيئًا مثل `<img>` وسم يحتوي على `searchTerms` معامل بين علامتي اقتباس، على سبيل المثال:

```html
<img src="/resources/images/tracker.gif?searchTerms=Jordan">
```

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

إذا أغلقت `<img>` الوسم وعلامتي الاقتباس، يمكنك إدراج محتوى HTML/JS عشوائي.

**أمثلة على الحمولة المختبرة (المقدَّمة)**/ أغلق الوسم وحقن HTML:

```html
"><h1>hack</h1>
```

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

أغلق الوسم وحقن سكربت لتفعيل `alert`:

```javascript
"><script>alert("xss")</script>
```

<figure><img src="/files/507bceb14d966d7bab278536c75a1dededb9a949" 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-document-write-with-location-search.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.
