Skip to content
RCE Write-up Intermediate

From a Broken Error Message to Full Server RCE: A Jinja2 SSTI Writeup ($9,000 Bounty)

A user-customisable confirmation page rendered user-supplied text directly through the Jinja2 template engine, allowing template injection. An attacker could execute arbitrary shell commands on the production server and read environment variables containing database credentials, AWS keys and the Flask session secret.

T4nv1 Follow

Published on medium.com

Some bugs announce themselves. An error page dumps a stack trace.

T4nv1, on medium.com

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 built a Jinja2 template from user-controlled content using from_string() and rendered it, instead of passing that content as data into a fixed template.

Impact

An authenticated user could execute arbitrary OS commands as the web user, read files and environment secrets including database and AWS credentials and the Flask session signing key, and reach internal services from the server's network position.

What the attacker needed

An authenticated account; access to the confirmation page editor

The fix

The vulnerable from_string() call was patched so user content is passed as data into a fixed template rather than rendered as template source.

How it was found

  1. Enter a simple arithmetic expression in a confirmation page text field and save.
  2. Load the preview and observe the expression evaluated to 49.
  3. Use a string-multiplication probe to fingerprint the engine as Jinja2.
  4. Walk the Python object hierarchy to enumerate subclasses and find the index of subprocess.Popen.
  5. Use that index to run the id command and confirm command execution.
  6. Run env and hostname commands to show credentials and internal network position.

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 software that builds web pages by filling in placeholders. Here the site let users type text that the engine treated as instructions rather than plain text, so a user could make the server run commands. That gave the attacker control of 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.

More by T4nv1

View all

113 more disclosed reports, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.