Server-side template injection (SSTI)
Detect -> Identify -> Exploit
Detect
Fuzzing the template by using special characters commonly used in template expressions.
Plaintext context
Injecting mathematical operations, such as ${7*7}
. If the output is 49
, it was evaluated server-side.
E.g.
Code context
Try to append an html <tag>
. Output will probably be blank.
E.g.
Next, try to break out of the statement.
E.g.
-> "Blank output": wrong template syntax, or not vulnerable.
-> Rendered correctly including <tag>
: vulnerable.
Exploit
ERB RCE (Ruby)
Tornado RCE (Python)
FreeMarker RCE (Java)
Handlebars RCE (Node/JS)
See http://mahmoudsec.blogspot.com/2019/04/handlebars-template-injection-and-rce.html.
Django Templates (Python)
See also:
Last updated