<aside> ✍️
SSTI ( Server-Side Template Injection ) → Its a web vulnerability that happens when an application merges user input directly into a server-side template that the engine then evaluates as code, instead of passing that input safely as data.
</aside>
Templates engines exists to merge data into a page, for example when setting a variable {{ name }} that server then dynamically adjust with proper data, because it treats it as code. That means that if user can control not only the value dropped into the filling, but the string itself, he could execute his own code instead.
render_template_string("Hello " + user_input)
// instead of
render_template("hello.html", name=user_input)
Mostly effected engines are :
Lets first deep into more technical step, CVE and CWE scores and detection, before getting into payloads and attack patterns.
Reference:
SSTI , due to its nature, is often mistaken for XSS vulnerability instead, because both start from some sort of user input. However they’re far from the same → XSS is bounded by user’s browser and SSTI runs code on the server instead.
In case of its cousin, SSRF, the attack pattern is the difference. SSTI attacks the server by using injection techniques via templates, however SSRF works by forcing the server to make request ( unauthorized ) to internal or external sources.
NOTE!: There is also client-side template injection ( CSTI ), where the vulnerable engine ( Angular, Vue, and similar ) runs in the browser. The quick way to tell them apart : re-request the input with a non-browser client such as curl. If
49appears in the raw HTTP response body, it is server-side ( SSTI ); if it only appears in the rendered DOM after JavaScript runs, it is client-side ( CSTI ).
Following official documentation of OWASP Web Security Testing Guide, we can follow three stages :
First we detect, for example using polyglots. We inject string with special characters, drawn from many template syntaxes at once, like ${{<%[%'"}}%\ into every input, which ends up rendered. If it returns any sort of error, like expection or 500, instead of echoing the string literally, it means it processed the string literally.
Now we check for two possible contexts, because SSTI comes in two forms, each with its own check:
{{ 7*7 }} will for example return Hello, 49 . Numeric results confirms our context.welcome_data=data.username . In such case we need to break out first, similary to SQL injection. We can append additional }} for example, while observing how the syntax is treated.