SSTI -Bypassing Single Quotes Filter
A Flask application was vulnerable to server-side template injection, allowing an attacker to execute system commands. The attacker bypassed a single-quote filter by placing the command in a custom HTTP header and referencing it via the request object.
Published on infosecwriteups.com
{{media:0}}
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 passed user input into a Flask template without sanitisation, and the single-quote filter was insufficient because other ways to access request data existed.
Impact
An attacker could execute arbitrary system commands on the server, potentially leading to remote code execution.
What the attacker needed
Access to the input field; ability to intercept HTTP requests
The fix
The application should avoid rendering user input as templates and use proper input validation and output encoding.
How it was found
- Test the input field with a simple template expression to confirm SSTI.
- Try a payload using url_for and os.popen with a command in single quotes, which fails due to filtering.
- Identify that single quotes are filtered by testing characters one by one.
- Craft a payload that reads the command from a custom HTTP header named 'hack'.
- Intercept the request with Burp Suite and add the header with the desired command.
- Send the request and read the command output in the response.
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.
Server-side template injection (SSTI) happens when a web app puts user input directly into a template that the server processes. If the input contains template code, the server runs it, which can let an attacker run commands on the server. Here, the attacker used a trick to avoid using single quotes, which were blocked.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.