Page cover
githubEdit

Server-side template injection [SSTI]

Server-side template injection :

occurs when user-controlled input is embedded into a server-side template, allowing users to inject template directives. This allows an attacker to inject malicious template directives and possibly execute arbitrary code on the affected server.

Template engines :

are designed to generate web pages by combining fixed templates with volatile data.

How can SSTI occur ?

when user input is concatenated directly into a template rather than passed in as data



What is the IMPACT ?

attacker can potentially achieve remote code execution (RCE), taking full control of the back-end server and using it to perform other attacks on internal infrastructure.

Even in cases where full remote code execution is not possible : attacker can use SSTI to read a sensitive data and files.

Is vulnerable or Not?

$output = $twig->render("Dear {first_name},", array("first_name" => $user.first_name) );

is Not vulnerable because user input is passed as data

vulnerable because instead of static value passed into template

Vulnerabilities like this are sometimes caused by accident due to poor template design by people unfamiliar with the security implications.



Constructing SSTI Attack

Detection Steps

  • Identify the application’s built-in language and the running template engine by wrong message , payloads , etc.

  • Identify injectable user-controlled inputs in GET and POST requests.

  • Fuzz the application with special characters ${{<%[%'"}}%\\ Observe which ones get interpreted by the server and which ones raise errors.

  • Insert basic template injection payloads in all user inputs, and observe if the application engine evaluates them.

Most template languages allow you to freely input content either by using HTML tags directly or by using the template's native syntax



Exploit :



Methodology :

1- user input reflection

2- Technology and use some payload related for this technology

3- Exploit

Some Payloads For Test:

LINK: https://x.com/jae_hak99/status/1331967876417327104arrow-up-right



Automation

TPLMAP tool:



Some Notes

Payloads : https://book.hacktricks.xyz/pentesting-web/ssti-server-side-template-injectionarrow-up-right

Payloads : https://github.com/VHAE04/bookhack/blob/master/pentesting-web/ssti-server-side-template-injection/README.mdarrow-up-right

Jinja → is limit who can import in template

We can get Stored XSS via SSTI(Template injection) : payload → {{constructor.constructor('alert(1)')()}}

Link : https://hackerone.com/reports/250837arrow-up-right

Reflected XSS

Link : https://hackerone.com/reports/399462arrow-up-right



Mitigation

  • Sanitize user inputs before passing them into the templates.

  • Sandboxing: execute user’s code in a sandboxed environment; though some of these environments can be bypassed, they are still considered a protection mechanism to reduce the risk of the SSTI vulnerability.


https://wise-monitor-956.notion.site/SSTI-6f295eee2f97481ab821b6b5d348b53farrow-up-right


Last updated