> 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-information-disclosure-via-python-user-objects.md).

# 通过 Python 用户对象进行的 SSTI 信息泄露

通过 Python 用户对象进行的 SSTI 信息泄露笔记，适用于 PortSwigger Web Security Academy 实验室，包括利用流程、载荷测试、Burp Suite 验证和修复上下文。

### 通过用户提供的对象进行信息泄露的服务器端模板注入

该实验的目标是利用因对象传递到模板的方式而导致的 SSTI 来获取敏感数据，尤其是框架的密钥。/ 我们有一个账户： `content-manager: C0nt3ntM4n4g3r`.

#### ITST 的分析与识别

第一步是使用以下表达式使模板引擎出错：

```
{{}}
```

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

* 这证实了我们可以注入服务器端模板代码。

然后尝试通过注入以下内容来显示更多调试信息：/ `{% debug %}`

```python
{% debug %}
```

* 然而，输出中并未出现任何有趣或敏感的信息。

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

#### 秘密密钥的获取

* 由于传递给模板的对象使我们能够访问配置，因此可以尝试通过以下参数直接读取框架的密钥：/ `{{settings.SECRET_KEY}}`

```python
{{settings.SECRET_KEY}}
```

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-8378193f896630d9508c393cf47e7dcfe42876b3%2Fimage%20(299).png?alt=media" 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 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/web/ssti/ssti-information-disclosure-via-python-user-objects.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.
