From {{7+7}} to Root: Achieving RCE via SSTI
A web application passed user-controlled input directly into a Jinja2 template, allowing server-side template injection. An attacker could execute arbitrary operating system commands on the server, achieving remote code execution.
medium.com
Published on medium.com
We will see this in a vulnerable application. Check all the parameters that are vulnerable to SSTI.
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
Root cause
Likely the application rendered user-controlled input directly as template code in an unsandboxed Jinja2 engine, instead of passing it as a data variable.
Impact
An attacker could run arbitrary commands on the server, potentially leading to full compromise.
What the attacker needed
A parameter that is rendered as a template; no authentication mentioned
The fix
The application should pass user data as template variables rather than template code, and enable strict sandboxing for the template engine.
How it was found
- Identify a parameter that is vulnerable to SSTI.
- Send a simple arithmetic expression to confirm the template evaluates it.
- Enumerate internal objects by accessing Python classes through the template.
- Use the exposed objects to run operating system commands and read their output.
- Automate the detection and exploitation with SSTImap.
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 application let a visitor's input be treated as part of the template itself, so the visitor could write instructions that the server ran. That let the attacker run commands on the server, which is called remote code execution.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.