Server Side Template Injection (SSTI ) Got Exploited
The application concatenated user input directly into a Jinja2 template, allowing an attacker to inject template syntax. The attacker could then execute arbitrary shell commands on the server.
Published on mainekhacker.medium.com
Server Side Template Injection (SSTI) is a web exploit which takes advantage of an insecure implementation of a template engine.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Impact
An attacker could run arbitrary commands on the server, potentially reading or deleting files and taking over the entire server.
What the attacker needed
A web application using Jinja2; user input reflected in a template; no input sanitisation
The fix
User input should be passed as data to the template, not concatenated into the template string, and templates should be sandboxed with allowlists.
How it was found
- Find an injection point where user input is reflected in the page.
- Identify the server and template engine by injecting test expressions.
- Use Jinja2 syntax to access Python's object hierarchy.
- Climb to the root object and list its subclasses.
- Select the subclass that corresponds to subprocess.Popen.
- Invoke it to run a shell command and capture the output.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
A template engine is a tool that builds web pages by filling in blanks. Here, the website put user input straight into the page's code instead of treating it as plain text, so the engine ran the input as instructions. That let the attacker run commands on the server.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.