SlideShare a Scribd company logo
Server-Side Template
Injection (SSTI) : RCE
for Modern Web App
Mandeep Jadon
Security Analyst @ Flipkart
About Me
 Regular Infosec Enthusiastic
 5 Years into Corporates , 7 years into security
 Security Analyst @Flipkart |Ex Fiserv , KPMG ,TCS
 Mostly into Application Security Side and
code reviews . Lot to learn More 
 Slightly into Bug Bounties
 Extremely inclined to Music
 Travelling
Setting Expectations
 Things to Expect from this Session
 Basic Understanding of SSTI and not just {{7*7}}
 In Depth working of some of the payloads used
 Code reviews
 Memes
 Things not to expect from this session
 SSTI Ninja , Even I am still learning
 RCE in 1 min . BOOM !!
Table of Contents
 Templating Engines
 SSTI
 Constructing a server-side template injection attack
 Detect
 Identify
 Exploit
 Examples
 Python Flask SSTI RCE Case Study
 Preventing SSTI
Templating Engines
 A template engine enables you to use static template files in your
application. At runtime, the template engine replaces variables in a
template file with actual values, and transforms the template into an HTML
file sent to the client.
 Template engines are designed to combine templates with a data model
to produce result documents which helps populating dynamic data into
web pages. Template engines can be used to display information about
users, products etc.
 This approach makes it easier to design an HTML page.
Templating Engines Continued…..
Some of the most popular template engines can be listed as the followings:
 PHP – Smarty, Twigs
 Java – Velocity, Freemaker
 Python – JINJA, Mako, Tornado
 JavaScript – Jade, Rage
 Ruby – Liquid
Templating Engines Continued…..
 Static templates that simply provide placeholders into which dynamic
content is rendered are generally not vulnerable to server-side template
injection. The classic example is an email that greets each user by their
name, such as the following extract from a Twig template:
$output = $twig->render("Dear {first_name},", array("first_name" =>
$user.first_name) );
Demo Code
Twig Template Example
There are two kinds of delimiters:
{% ... %} and {{ ... }}. The first one is
used to execute statements such as
for-loops, the latter outputs the
result of an expression.
SSTI
 Server-side template injection is when an attacker is able to use native
template syntax to inject a malicious payload into a template, which is then
executed server-side.
 Template engines are designed to generate web pages by combining fixed
templates with volatile data. Server-side template injection attacks can
occur when user input is concatenated directly into a template, rather than
passed in as data. This allows attackers to inject arbitrary template
directives in order to manipulate the template engine, often enabling them
to take complete control of the server.
 Does the above statement rings a bell ? Is there another very popular
vulnerability in OWASP Top 10 similar to above ?
SSTI Continued ….
 An example of vulnerable code see the following one:
$output = $twig->render("Dear " . $_GET['name’]);
 In the previous example part of the template itself is being dynamically
generated using the GET parameter name. As template syntax is evaluated
server-side, this potentially allows an attacker to place a server-side
template injection payload inside the name parameter as follows:
http://vulnerable-website.com/?name={{bad-stuff-here}}
Server Side Template Injection by Mandeep Jadon
Constructing a server-side template
injection attack
 Identifying server-side template injection vulnerabilities and crafting a
successful attack typically involves the following high-level process.
Detect
 As with any vulnerability, the first step towards exploitation is being able to
find it. Perhaps the simplest initial approach is to try fuzzing the template
by injecting a sequence of special characters commonly used in template
expressions, such as ${{<%[%'"}}%.
 If an exception is raised, this indicates that the injected template syntax is
potentially being interpreted by the server in some way. This is one sign
that a vulnerability to server-side template injection may exist.
Identify
 Although there are a huge number of templating languages, many of them use very
similar syntax that is specifically chosen not to clash with HTML characters. As a result, it
can be relatively simple to create probing payloads to test which template engine is
being used.
 Simply submitting invalid syntax is often enough because the resulting error message
will tell you exactly what the template engine is, and sometimes even which version. For
example, the invalid expression <%=foobar%> triggers the following response from the
Ruby-based ERB engine:
(erb):1:in `<main>': undefined local variable or method `foobar' for main:Object (NameError)
from /usr/lib/ruby/2.5.0/erb.rb:876:in `eval'
from /usr/lib/ruby/2.5.0/erb.rb:876:in `result'
Exploit
 LAB
 Basic server-side template injection
 Basic server-side template injection (code context)
Python Flask SSTI RCE Case Study
(Demo)
 Walkthrough of the App
 {{ ''.__class__.__mro__[2].__subclasses__()[40]('/etc/passwd').read() }}
 Understanding MRO
 Understanding Python Inheritance
 Finding the correct classes
 RCE
Quick Exercise for You
 Can you find the bug in the code shared
Prevent SSTI
 The best way to prevent server-side template injection is to not allow any
users to modify or submit new templates.
 Another measure is to only execute users' code in a sandboxed
environment where potentially dangerous modules and functions have
been removed altogether.
 Finally, another complementary approach is to accept that arbitrary code
execution is all but inevitable and apply your own sandboxing by
deploying your template environment in a locked-down Docker container,
for example.
Server Side Template Injection by Mandeep Jadon
Ways to reach me
 https://twitter.com/1337tr0lls
 https://in.linkedin.com/in/mandeepjadon
 Blog : https://medium.com/@ciph3r7r0ll
 Github : https://github.com/mandeepjadon
Sources: Portswiggers Labs
Server Side Template Injection by Mandeep Jadon
Server Side Template Injection by Mandeep Jadon

More Related Content

What's hot (20)

PDF
Building Advanced XSS Vectors
Rodolfo Assis (Brute)
 
PDF
OWASP API Security Top 10 Examples
42Crunch
 
PPTX
Cross Site Scripting Defense Presentation
Ikhade Maro Igbape
 
PPTX
Python oop third class
Aleksander Fabijan
 
PDF
Cross site scripting attacks and defenses
Mohammed A. Imran
 
PDF
Web application security & Testing
Deepu S Nath
 
PDF
Neat tricks to bypass CSRF-protection
Mikhail Egorov
 
PPTX
Deep understanding on Cross-Site Scripting and SQL Injection
Vishal Kumar
 
PDF
Real Application Security (RAS) and Oracle Application Express (APEX)
Dimitri Gielis
 
PPTX
Understanding Cross-site Request Forgery
Daniel Miessler
 
PDF
Page Object Model and Implementation in Selenium
Zoe Gilbert
 
PDF
Spring Boot
koppenolski
 
PDF
Spring Boot
Pei-Tang Huang
 
KEY
Prueba De Aplicaciones Web con Selenium 2 y WebDriver
David Gómez García
 
PDF
WEBINAR: OWASP API Security Top 10
42Crunch
 
PPTX
Dangling DNS records takeover at scale
Chandrapal Badshah
 
PPTX
Sharing Data Between Angular Components
Squash Apps Pvt Ltd
 
PPTX
Attacking thru HTTP Host header
Sergey Belov
 
PDF
How to Reverse Engineer Web Applications
Jarrod Overson
 
PDF
A5-Security misconfiguration-OWASP 2013
Sorina Chirilă
 
Building Advanced XSS Vectors
Rodolfo Assis (Brute)
 
OWASP API Security Top 10 Examples
42Crunch
 
Cross Site Scripting Defense Presentation
Ikhade Maro Igbape
 
Python oop third class
Aleksander Fabijan
 
Cross site scripting attacks and defenses
Mohammed A. Imran
 
Web application security & Testing
Deepu S Nath
 
Neat tricks to bypass CSRF-protection
Mikhail Egorov
 
Deep understanding on Cross-Site Scripting and SQL Injection
Vishal Kumar
 
Real Application Security (RAS) and Oracle Application Express (APEX)
Dimitri Gielis
 
Understanding Cross-site Request Forgery
Daniel Miessler
 
Page Object Model and Implementation in Selenium
Zoe Gilbert
 
Spring Boot
koppenolski
 
Spring Boot
Pei-Tang Huang
 
Prueba De Aplicaciones Web con Selenium 2 y WebDriver
David Gómez García
 
WEBINAR: OWASP API Security Top 10
42Crunch
 
Dangling DNS records takeover at scale
Chandrapal Badshah
 
Sharing Data Between Angular Components
Squash Apps Pvt Ltd
 
Attacking thru HTTP Host header
Sergey Belov
 
How to Reverse Engineer Web Applications
Jarrod Overson
 
A5-Security misconfiguration-OWASP 2013
Sorina Chirilă
 

Similar to Server Side Template Injection by Mandeep Jadon (20)

PPTX
Joomla! Day Chicago 2011 Presentation - Steven Pignataro
Steven Pignataro
 
PPTX
Secure programming with php
Mohmad Feroz
 
PPT
selenium.ppt
AmenSheikh
 
PPT
selenium.ppt
ssuser7b4894
 
PPT
selenium.ppt
rajnexient
 
PPT
Selenium
Sun Technlogies
 
PDF
#nullblr bachav manual source code review
Santosh Gulivindala
 
PDF
Create Your Own Framework by Fabien Potencier
Himel Nag Rana
 
PPT
香港六合彩 &raquo; SlideShare
yayao
 
DOCX
Php interview questions
sekar c
 
PPT
Performance and Scalability Testing with Python and Multi-Mechanize
coreygoldberg
 
PDF
NIframer - CPanel IFrame Injector (Bash based) - Virus Bulletin Magazine
Aditya K Sood
 
PPT
Selenium
Purna Chandar
 
PPT
GNUCITIZEN Dwk Owasp Day September 2007
guest20ab09
 
PPT
XSS Primer - Noob to Pro in 1 hour
snoopythesecuritydog
 
DOC
Attackers Vs Programmers
robin_bene
 
PDF
Java Programming
Tracy Clark
 
PDF
Working Effectively With Legacy Perl Code
erikmsp
 
PPTX
introduction to java scriptsfor sym.pptx
gayatridwahane
 
PDF
Web application penetration testing lab setup guide
Sudhanshu Chauhan
 
Joomla! Day Chicago 2011 Presentation - Steven Pignataro
Steven Pignataro
 
Secure programming with php
Mohmad Feroz
 
selenium.ppt
AmenSheikh
 
selenium.ppt
ssuser7b4894
 
selenium.ppt
rajnexient
 
Selenium
Sun Technlogies
 
#nullblr bachav manual source code review
Santosh Gulivindala
 
Create Your Own Framework by Fabien Potencier
Himel Nag Rana
 
香港六合彩 &raquo; SlideShare
yayao
 
Php interview questions
sekar c
 
Performance and Scalability Testing with Python and Multi-Mechanize
coreygoldberg
 
NIframer - CPanel IFrame Injector (Bash based) - Virus Bulletin Magazine
Aditya K Sood
 
Selenium
Purna Chandar
 
GNUCITIZEN Dwk Owasp Day September 2007
guest20ab09
 
XSS Primer - Noob to Pro in 1 hour
snoopythesecuritydog
 
Attackers Vs Programmers
robin_bene
 
Java Programming
Tracy Clark
 
Working Effectively With Legacy Perl Code
erikmsp
 
introduction to java scriptsfor sym.pptx
gayatridwahane
 
Web application penetration testing lab setup guide
Sudhanshu Chauhan
 
Ad

Recently uploaded (20)

PDF
Infrastructure planning and resilience - Keith Hastings.pptx.pdf
Safe Software
 
PPTX
Farrell__10e_ch04_PowerPoint.pptx Programming Logic and Design slides
bashnahara11
 
PPTX
Presentation about variables and constant.pptx
kr2589474
 
PDF
New Download FL Studio Crack Full Version [Latest 2025]
imang66g
 
PDF
Applitools Platform Pulse: What's New and What's Coming - July 2025
Applitools
 
PPTX
ASSIGNMENT_1[1][1][1][1][1] (1) variables.pptx
kr2589474
 
PDF
AWS_Agentic_AI_in_Indian_BFSI_A_Strategic_Blueprint_for_Customer.pdf
siddharthnetsavvies
 
PDF
How Agentic AI Networks are Revolutionizing Collaborative AI Ecosystems in 2025
ronakdubey419
 
PDF
WatchTraderHub - Watch Dealer software with inventory management and multi-ch...
WatchDealer Pavel
 
PDF
SAP GUI Installation Guide for Windows | Step-by-Step Setup for SAP Access
SAP Vista, an A L T Z E N Company
 
PDF
Protecting the Digital World Cyber Securit
dnthakkar16
 
PPTX
Contractor Management Platform and Software Solution for Compliance
SHEQ Network Limited
 
PDF
Virtual Threads in Java: A New Dimension of Scalability and Performance
Tier1 app
 
PDF
System Center 2025 vs. 2022; What’s new, what’s next_PDF.pdf
Q-Advise
 
PDF
Step-by-Step Guide to Install SAP HANA Studio | Complete Installation Tutoria...
SAP Vista, an A L T Z E N Company
 
PDF
Enhancing Security in VAST: Towards Static Vulnerability Scanning
ESUG
 
PDF
SAP GUI Installation Guide for macOS (iOS) | Connect to SAP Systems on Mac
SAP Vista, an A L T Z E N Company
 
PDF
ChatPharo: an Open Architecture for Understanding How to Talk Live to LLMs
ESUG
 
PPTX
Presentation about Database and Database Administrator
abhishekchauhan86963
 
PPTX
slidesgo-unlocking-the-code-the-dynamic-dance-of-variables-and-constants-2024...
kr2589474
 
Infrastructure planning and resilience - Keith Hastings.pptx.pdf
Safe Software
 
Farrell__10e_ch04_PowerPoint.pptx Programming Logic and Design slides
bashnahara11
 
Presentation about variables and constant.pptx
kr2589474
 
New Download FL Studio Crack Full Version [Latest 2025]
imang66g
 
Applitools Platform Pulse: What's New and What's Coming - July 2025
Applitools
 
ASSIGNMENT_1[1][1][1][1][1] (1) variables.pptx
kr2589474
 
AWS_Agentic_AI_in_Indian_BFSI_A_Strategic_Blueprint_for_Customer.pdf
siddharthnetsavvies
 
How Agentic AI Networks are Revolutionizing Collaborative AI Ecosystems in 2025
ronakdubey419
 
WatchTraderHub - Watch Dealer software with inventory management and multi-ch...
WatchDealer Pavel
 
SAP GUI Installation Guide for Windows | Step-by-Step Setup for SAP Access
SAP Vista, an A L T Z E N Company
 
Protecting the Digital World Cyber Securit
dnthakkar16
 
Contractor Management Platform and Software Solution for Compliance
SHEQ Network Limited
 
Virtual Threads in Java: A New Dimension of Scalability and Performance
Tier1 app
 
System Center 2025 vs. 2022; What’s new, what’s next_PDF.pdf
Q-Advise
 
Step-by-Step Guide to Install SAP HANA Studio | Complete Installation Tutoria...
SAP Vista, an A L T Z E N Company
 
Enhancing Security in VAST: Towards Static Vulnerability Scanning
ESUG
 
SAP GUI Installation Guide for macOS (iOS) | Connect to SAP Systems on Mac
SAP Vista, an A L T Z E N Company
 
ChatPharo: an Open Architecture for Understanding How to Talk Live to LLMs
ESUG
 
Presentation about Database and Database Administrator
abhishekchauhan86963
 
slidesgo-unlocking-the-code-the-dynamic-dance-of-variables-and-constants-2024...
kr2589474
 
Ad

Server Side Template Injection by Mandeep Jadon

  • 1. Server-Side Template Injection (SSTI) : RCE for Modern Web App Mandeep Jadon Security Analyst @ Flipkart
  • 2. About Me  Regular Infosec Enthusiastic  5 Years into Corporates , 7 years into security  Security Analyst @Flipkart |Ex Fiserv , KPMG ,TCS  Mostly into Application Security Side and code reviews . Lot to learn More   Slightly into Bug Bounties  Extremely inclined to Music  Travelling
  • 3. Setting Expectations  Things to Expect from this Session  Basic Understanding of SSTI and not just {{7*7}}  In Depth working of some of the payloads used  Code reviews  Memes  Things not to expect from this session  SSTI Ninja , Even I am still learning  RCE in 1 min . BOOM !!
  • 4. Table of Contents  Templating Engines  SSTI  Constructing a server-side template injection attack  Detect  Identify  Exploit  Examples  Python Flask SSTI RCE Case Study  Preventing SSTI
  • 5. Templating Engines  A template engine enables you to use static template files in your application. At runtime, the template engine replaces variables in a template file with actual values, and transforms the template into an HTML file sent to the client.  Template engines are designed to combine templates with a data model to produce result documents which helps populating dynamic data into web pages. Template engines can be used to display information about users, products etc.  This approach makes it easier to design an HTML page.
  • 6. Templating Engines Continued….. Some of the most popular template engines can be listed as the followings:  PHP – Smarty, Twigs  Java – Velocity, Freemaker  Python – JINJA, Mako, Tornado  JavaScript – Jade, Rage  Ruby – Liquid
  • 7. Templating Engines Continued…..  Static templates that simply provide placeholders into which dynamic content is rendered are generally not vulnerable to server-side template injection. The classic example is an email that greets each user by their name, such as the following extract from a Twig template: $output = $twig->render("Dear {first_name},", array("first_name" => $user.first_name) );
  • 8. Demo Code Twig Template Example There are two kinds of delimiters: {% ... %} and {{ ... }}. The first one is used to execute statements such as for-loops, the latter outputs the result of an expression.
  • 9. SSTI  Server-side template injection is when an attacker is able to use native template syntax to inject a malicious payload into a template, which is then executed server-side.  Template engines are designed to generate web pages by combining fixed templates with volatile data. Server-side template injection attacks can occur when user input is concatenated directly into a template, rather than passed in as data. This allows attackers to inject arbitrary template directives in order to manipulate the template engine, often enabling them to take complete control of the server.  Does the above statement rings a bell ? Is there another very popular vulnerability in OWASP Top 10 similar to above ?
  • 10. SSTI Continued ….  An example of vulnerable code see the following one: $output = $twig->render("Dear " . $_GET['name’]);  In the previous example part of the template itself is being dynamically generated using the GET parameter name. As template syntax is evaluated server-side, this potentially allows an attacker to place a server-side template injection payload inside the name parameter as follows: http://vulnerable-website.com/?name={{bad-stuff-here}}
  • 12. Constructing a server-side template injection attack  Identifying server-side template injection vulnerabilities and crafting a successful attack typically involves the following high-level process.
  • 13. Detect  As with any vulnerability, the first step towards exploitation is being able to find it. Perhaps the simplest initial approach is to try fuzzing the template by injecting a sequence of special characters commonly used in template expressions, such as ${{<%[%'"}}%.  If an exception is raised, this indicates that the injected template syntax is potentially being interpreted by the server in some way. This is one sign that a vulnerability to server-side template injection may exist.
  • 14. Identify  Although there are a huge number of templating languages, many of them use very similar syntax that is specifically chosen not to clash with HTML characters. As a result, it can be relatively simple to create probing payloads to test which template engine is being used.  Simply submitting invalid syntax is often enough because the resulting error message will tell you exactly what the template engine is, and sometimes even which version. For example, the invalid expression <%=foobar%> triggers the following response from the Ruby-based ERB engine: (erb):1:in `<main>': undefined local variable or method `foobar' for main:Object (NameError) from /usr/lib/ruby/2.5.0/erb.rb:876:in `eval' from /usr/lib/ruby/2.5.0/erb.rb:876:in `result'
  • 15. Exploit  LAB  Basic server-side template injection  Basic server-side template injection (code context)
  • 16. Python Flask SSTI RCE Case Study (Demo)  Walkthrough of the App  {{ ''.__class__.__mro__[2].__subclasses__()[40]('/etc/passwd').read() }}  Understanding MRO  Understanding Python Inheritance  Finding the correct classes  RCE
  • 17. Quick Exercise for You  Can you find the bug in the code shared
  • 18. Prevent SSTI  The best way to prevent server-side template injection is to not allow any users to modify or submit new templates.  Another measure is to only execute users' code in a sandboxed environment where potentially dangerous modules and functions have been removed altogether.  Finally, another complementary approach is to accept that arbitrary code execution is all but inevitable and apply your own sandboxing by deploying your template environment in a locked-down Docker container, for example.
  • 20. Ways to reach me  https://twitter.com/1337tr0lls  https://in.linkedin.com/in/mandeepjadon  Blog : https://medium.com/@ciph3r7r0ll  Github : https://github.com/mandeepjadon Sources: Portswiggers Labs