Server-Side Template Injection
{{7*7}}
Last updated
{{7*7}}
Last updated
Server-Side Template Injection (SSTI) exploits Template Engines, like node.js, Flask, Twig used in web applications. These engines are used by web apps to present dynamic data via web pages and emails. However, template injection occurs when the user input is embedded in a template in an unsafe manner.
Template injection works because websites fail to take in the data as just text, but rather process it and directly use it as part of a template, thus allowing attackers to inject template directives to manipulate the template engine used. This often leads to RCE.
To test for this, follow this flowchart from Hacktricks:
Generally, I try to identify what backend the website runs on (PHP, Ruby, etc.) and see if there are portions where user-input is displayed to run my tests on. This includes usernames, posts made to forums, etc.
The HTB machine Doctor uses SSTI for the initial access step.
The machine has a secret page that allows for posts by the user to be made with a title and content. We do not know the template engine being used yet.
I tested for SSTI. I tested a few payloads and made a new post:
The 49 present indicates that it worked, and that the other payload was not processed. Further testing with {{7*'7'}}
would shows this:
From here, based on the flowchart, the website is running on either Jinja2 or Twig. A payload from PayloadAllTheThings can then be used:
Editing the payload with the correct IP and port number gave me a reverse shell. SSTI is rather easy to exploit once found. Here are some other payloads used for testing: