Course contentsShow
← Security
Lesson 1249 of 3,05225. Application Security - Secure CodingFree lesson

SSTI Detection and Exploitation Techniques

Recognizing template injection vulnerabilities through payloads and understanding exploitation methods.

SSTI Detection and Exploitation Techniques

You'll learn: How attackers identify and weaponize Server-Side Template Injection vulnerabilities to execute arbitrary code on the server.

Understanding Detection

Server-Side Template Injection (SSTI) occurs when user input is embedded into templates without proper escaping. Attackers detect SSTI by injecting template expression syntax and observing whether the server evaluates it.

Think of it like this: Imagine asking someone to write your name on a form. If you say "write 2+2" and they write "4" instead of the literal text "2+2", they're evaluating your input—that's the vulnerability.

Common Detection Payloads

Attackers probe with engine-specific syntax:

  • Generic math: {{7*7}}, ${7*7}, <%= 7*7 %>
  • Jinja2/Flask: {{7*'7'}} → returns 7777777
  • ERB/Ruby: <%= 7*7 %>
  • Freemarker: ${7*7}

If the server returns 49 or 7777777 instead of the literal payload string, SSTI exists.

Exploitation Progression

Once detected, attackers escalate through template features:

  1. Object inspection: Access built-in objects ({{config}} in Flask)
  2. Class traversal: Navigate object hierarchies to reach dangerous classes
  3. Code execution: Invoke system functions through template syntax
  4. File access: Read sensitive files or write malicious code

For example, in Jinja2 without proper sandboxing, attackers might traverse Python's object model to reach os.system() and execute shell commands—all through template syntax that bypasses your application code entirely.

Why This Matters

SSTI is particularly dangerous because it occurs after your application logic, directly in the rendering layer. Traditional input validation may miss it if you're checking for SQL or XSS patterns but not template expressions.

Key Takeaway: SSTI detection relies on injecting template-specific syntax and observing evaluation; successful exploitation can lead to complete server compromise through template engine features you never intended to expose.