SlideShare a Scribd company logo
2
Most read
4
Most read
6
Most read
SERVER-SIDE TEMPLATE
INJECTION
(SSTI)
Presented by – Amit Dubey
Agenda –
■ Introduction to Template Engines
■ Serve-Side Template Injection (SSTI)
■ Impact
■ Mitigation
■ References
■ Case-Studies
Template Engines –
■ Generates dynamic web pages.
■ Separating business logic with presentation logic.
■ Reusability.
■ Uses.
Example –
■ PHP – Twig, Smarty, VlibTemplate.
■ Java – Velocity, WebMacros, Freemaker.
■ Python – Jinja2, Django, Mako.
■ JavaScript – Jade, Rage.
Example Code –
Template Injection -
■ User input is embedded in unsafe manner.
■ Confused by XSS.
Marketing application with email greeting
$output = $twig->render(“Dear, $_GET[‘name’]”, array("first_name" => $user.first_name) );
Name =Tester Name = {{7*7}}
> Dear,Tester > Dear, 49
Name = {{self}}
> Dear, Object of class __TwigTemplate_7ae62e582f8a35e5ea6cc639800ecf15b96c0d6f78db3538221c1145580ca4a5 could not
be converted to string
■ Detect –
Plain Text Context
- Can be confused with XSS
- {var} {{var}} ${var} <%var%> [% var %]
- Results in execution or error message.
- a{{var}}b
> Expect : ab or Error message
- a{{7*7}}b
> Expect : a49b
smarty=Hello {user.name}
> Hello user1
■ Detect –
Code Context
- Results in blank results or error messages
- Need to breakout the syntax
- Results in execution or error message.
- personal_greeting=user.name<tag>
> Expect : Hello
- personal_greeting=user.name}}<tag>
> Expect : Hello user01<tag>
personal_greeting=user.name
> Hello user01
■ Identify –
- Identify which template engine in use.
- {{7*’7’}} will result 49 in Twig and 7777777 in Jinja2
- Burp suite decision making tree to find SSTI
■ Exploit –
- READ :
- Read the documentation.
- EXPLORE :
- Explore the environment
- Brute-force the variables
- ATTACK :
- Firm idea of attack surface.
■ Exploit Development –
- Freemaker:
One of most famous java template languages.
The official website explains the dangers of allowing user-supplied templates:
Ref : http://freemarker.org/docs/app_faq.html#faq_template_uploading_security
One of the risk we found
■ Exploit Development –
“new” built-in offers a possibility for exploitation.
- Are there any useful classes implementing TemplateModel?
One of these class names stands out - Execute
■ Exploit Development –
Details confirm that function take input and executes.
- Let's develop our payload –
■ Automated Tool –
- Tplmap :
Tplmap assists the exploitation of Code Injection and Server-Side Template Injection vulnerabilities with
several sandbox escape techniques to get access to the underlying operating system.
- Uses :
$ ./tplmap.py -u 'http://www.target.com/page?name=John’
- Link :
https://github.com/epinna/tplmap
- Burp Extension :
https://github.com/epinna/tplmap/blob/master/burp_extension/README.md
Demonstration -
■ Application used : Xtreme Vulnerable Web Application (XVWA)
■ Back-End Server : Apache
■ Template Engine : Twig
■ Back-End PL : PHP
Server-side template injection- Slides
Impact -
■ Cross-site scripting
■ Information disclosure
■ Remote Code Execution
Mitigation -
■ Update Framework/libraries
■ Input Sanitization
■ Sandboxing
■ Input Sanitization –
- PHP
- JAVA
- ASP.NET
str_replace( array( ''', '"', ',' , ';', '<', '>','{','}', ), '', $name);
preg_replace('/[^a-zA-Z0-9_ -]/s','',$value);
Text = text.replaceAll ("[^a-zA-Z0-9]", "");
Regex.Replace(Your String, @"[^0-9a-zA-Z:,]+", "")
Mitigation Demonstration -
■ Input Sanitization
Server-side template injection- Slides
References -
■ https://www.blackhat.com/docs/us-15/materials/us-15-Kettle-Server-Side-
Template-Injection-RCE-For-The-Modern-Web-App-wp.pdf
■ https://www.owasp.org/images/7/7e/Owasp_SSTI_final.pdf
■ https://www.we45.com/blog/server-side-template-injection-a-crash-course-
■ https://www.youtube.com/watch?v=3cT0uE7Y87s
■ https://www.phpflow.com/php/php-remove-special-character-fromstring/
Case-Studies -
■ https://hackerone.com/reports/125980
■ https://hackerone.com/reports/164224
■ https://hackerone.com/reports/230232
■ https://medium.com/@david.valles/gaining-shell-using-server-side-template-injection-ssti-
81e29bb8e0f9
■ https://medium.com/bugbountywriteup/frapp%C3%A9-technologies-erpnext-server-side-
template-injection-74e1c95ec872
■ http://ha.cker.info/exploitation-of-server-side-template-injection-with-craft-cms-plguin-
seomatic/
Thank You !

More Related Content

PPTX
Basics of Server Side Template Injection
PPTX
Server Side Template Injection by Mandeep Jadon
PDF
Penetration testing web application web application (in) security
PDF
Building Advanced XSS Vectors
PPT
A Brief Introduction in SQL Injection
PPT
Introduction to Web Application Penetration Testing
PPTX
A2 - broken authentication and session management(OWASP thailand chapter Apri...
PPTX
Cross Site Scripting: Prevention and Detection(XSS)
Basics of Server Side Template Injection
Server Side Template Injection by Mandeep Jadon
Penetration testing web application web application (in) security
Building Advanced XSS Vectors
A Brief Introduction in SQL Injection
Introduction to Web Application Penetration Testing
A2 - broken authentication and session management(OWASP thailand chapter Apri...
Cross Site Scripting: Prevention and Detection(XSS)

What's hot (20)

PPTX
SQL Injections - A Powerpoint Presentation
PPTX
SSRF For Bug Bounties
PDF
OWASP Top 10 - 2017
PPT
Sql injection attack
PPTX
Waf bypassing Techniques
PPTX
SQL INJECTION
PPTX
Owasp Top 10 A1: Injection
PDF
How to identify and prevent SQL injection
PDF
Bug bounty null_owasp_2k17
PPTX
Sql injections - with example
PPT
SQL Injection
PPTX
SQL INJECTION
PPTX
Vulnerabilities in modern web applications
PPTX
Bug Bounty 101
PPTX
Bug Bounty for - Beginners
PDF
Broken access control
PPTX
SQL Injections (Part 1)
PPTX
OWASP Top 10 - Day 1 - A1 injection attacks
PPTX
Http request smuggling
PPTX
Cross Site Scripting ( XSS)
SQL Injections - A Powerpoint Presentation
SSRF For Bug Bounties
OWASP Top 10 - 2017
Sql injection attack
Waf bypassing Techniques
SQL INJECTION
Owasp Top 10 A1: Injection
How to identify and prevent SQL injection
Bug bounty null_owasp_2k17
Sql injections - with example
SQL Injection
SQL INJECTION
Vulnerabilities in modern web applications
Bug Bounty 101
Bug Bounty for - Beginners
Broken access control
SQL Injections (Part 1)
OWASP Top 10 - Day 1 - A1 injection attacks
Http request smuggling
Cross Site Scripting ( XSS)
Ad

Similar to Server-side template injection- Slides (20)

PDF
Owasp top 10 web application security hazards part 2
PPTX
Hadoop cluster performance profiler
PPT
GNUCITIZEN Dwk Owasp Day September 2007
PDF
Exploits Attack on Windows Vulnerabilities
PDF
I got 99 trends and a # is all of them
PPTX
Hacker's Practice Ground - Wall of Sheep workshops - Defcon 2015
PPTX
AppSec California 2016 - Making Security Agile
PDF
Oopp Lab Work
PPTX
Penetration testing dont just leave it to chance
PPTX
Self-Protecting JavaScript: A Lightweight Approach to Enforcing Security Poli...
PPTX
Nguyen Phuong Truong Anh - Some new vulnerabilities in modern web application
PDF
Tips on Securing Drupal Sites - DrupalCamp Atlanta (DCA)
PPTX
Owasp web application security trends
PPTX
[2.1] Web application Security Trends - Omar Ganiev
PDF
EN - BlackHat US 2009 favorite XSS Filters-IDS and how to attack them.pdf
PDF
Iwt note(module 2)
PDF
idsecconf2023 - Satria Ady Pradana - Launch into the Stratus-phere Adversary ...
PDF
Testing Vue Apps with Cypress.io (STLJS Meetup April 2018)
PDF
Ekoparty 2017 - The Bug Hunter's Methodology
PDF
OSCP Preparation Guide @ Infosectrain
Owasp top 10 web application security hazards part 2
Hadoop cluster performance profiler
GNUCITIZEN Dwk Owasp Day September 2007
Exploits Attack on Windows Vulnerabilities
I got 99 trends and a # is all of them
Hacker's Practice Ground - Wall of Sheep workshops - Defcon 2015
AppSec California 2016 - Making Security Agile
Oopp Lab Work
Penetration testing dont just leave it to chance
Self-Protecting JavaScript: A Lightweight Approach to Enforcing Security Poli...
Nguyen Phuong Truong Anh - Some new vulnerabilities in modern web application
Tips on Securing Drupal Sites - DrupalCamp Atlanta (DCA)
Owasp web application security trends
[2.1] Web application Security Trends - Omar Ganiev
EN - BlackHat US 2009 favorite XSS Filters-IDS and how to attack them.pdf
Iwt note(module 2)
idsecconf2023 - Satria Ady Pradana - Launch into the Stratus-phere Adversary ...
Testing Vue Apps with Cypress.io (STLJS Meetup April 2018)
Ekoparty 2017 - The Bug Hunter's Methodology
OSCP Preparation Guide @ Infosectrain
Ad

Recently uploaded (20)

PDF
Encapsulation theory and applications.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
sap open course for s4hana steps from ECC to s4
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Empathic Computing: Creating Shared Understanding
PDF
cuic standard and advanced reporting.pdf
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Network Security Unit 5.pdf for BCA BBA.
Encapsulation theory and applications.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
NewMind AI Weekly Chronicles - August'25 Week I
The Rise and Fall of 3GPP – Time for a Sabbatical?
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Understanding_Digital_Forensics_Presentation.pptx
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Per capita expenditure prediction using model stacking based on satellite ima...
sap open course for s4hana steps from ECC to s4
20250228 LYD VKU AI Blended-Learning.pptx
Programs and apps: productivity, graphics, security and other tools
Empathic Computing: Creating Shared Understanding
cuic standard and advanced reporting.pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Network Security Unit 5.pdf for BCA BBA.

Server-side template injection- Slides

  • 2. Agenda – ■ Introduction to Template Engines ■ Serve-Side Template Injection (SSTI) ■ Impact ■ Mitigation ■ References ■ Case-Studies
  • 3. Template Engines – ■ Generates dynamic web pages. ■ Separating business logic with presentation logic. ■ Reusability. ■ Uses.
  • 4. Example – ■ PHP – Twig, Smarty, VlibTemplate. ■ Java – Velocity, WebMacros, Freemaker. ■ Python – Jinja2, Django, Mako. ■ JavaScript – Jade, Rage.
  • 6. Template Injection - ■ User input is embedded in unsafe manner. ■ Confused by XSS. Marketing application with email greeting $output = $twig->render(“Dear, $_GET[‘name’]”, array("first_name" => $user.first_name) ); Name =Tester Name = {{7*7}} > Dear,Tester > Dear, 49 Name = {{self}} > Dear, Object of class __TwigTemplate_7ae62e582f8a35e5ea6cc639800ecf15b96c0d6f78db3538221c1145580ca4a5 could not be converted to string
  • 7. ■ Detect – Plain Text Context - Can be confused with XSS - {var} {{var}} ${var} <%var%> [% var %] - Results in execution or error message. - a{{var}}b > Expect : ab or Error message - a{{7*7}}b > Expect : a49b smarty=Hello {user.name} > Hello user1
  • 8. ■ Detect – Code Context - Results in blank results or error messages - Need to breakout the syntax - Results in execution or error message. - personal_greeting=user.name<tag> > Expect : Hello - personal_greeting=user.name}}<tag> > Expect : Hello user01<tag> personal_greeting=user.name > Hello user01
  • 9. ■ Identify – - Identify which template engine in use. - {{7*’7’}} will result 49 in Twig and 7777777 in Jinja2 - Burp suite decision making tree to find SSTI
  • 10. ■ Exploit – - READ : - Read the documentation. - EXPLORE : - Explore the environment - Brute-force the variables - ATTACK : - Firm idea of attack surface.
  • 11. ■ Exploit Development – - Freemaker: One of most famous java template languages. The official website explains the dangers of allowing user-supplied templates: Ref : http://freemarker.org/docs/app_faq.html#faq_template_uploading_security One of the risk we found
  • 12. ■ Exploit Development – “new” built-in offers a possibility for exploitation. - Are there any useful classes implementing TemplateModel? One of these class names stands out - Execute
  • 13. ■ Exploit Development – Details confirm that function take input and executes. - Let's develop our payload –
  • 14. ■ Automated Tool – - Tplmap : Tplmap assists the exploitation of Code Injection and Server-Side Template Injection vulnerabilities with several sandbox escape techniques to get access to the underlying operating system. - Uses : $ ./tplmap.py -u 'http://www.target.com/page?name=John’ - Link : https://github.com/epinna/tplmap - Burp Extension : https://github.com/epinna/tplmap/blob/master/burp_extension/README.md
  • 15. Demonstration - ■ Application used : Xtreme Vulnerable Web Application (XVWA) ■ Back-End Server : Apache ■ Template Engine : Twig ■ Back-End PL : PHP
  • 17. Impact - ■ Cross-site scripting ■ Information disclosure ■ Remote Code Execution
  • 18. Mitigation - ■ Update Framework/libraries ■ Input Sanitization ■ Sandboxing
  • 19. ■ Input Sanitization – - PHP - JAVA - ASP.NET str_replace( array( ''', '"', ',' , ';', '<', '>','{','}', ), '', $name); preg_replace('/[^a-zA-Z0-9_ -]/s','',$value); Text = text.replaceAll ("[^a-zA-Z0-9]", ""); Regex.Replace(Your String, @"[^0-9a-zA-Z:,]+", "")
  • 20. Mitigation Demonstration - ■ Input Sanitization
  • 22. References - ■ https://www.blackhat.com/docs/us-15/materials/us-15-Kettle-Server-Side- Template-Injection-RCE-For-The-Modern-Web-App-wp.pdf ■ https://www.owasp.org/images/7/7e/Owasp_SSTI_final.pdf ■ https://www.we45.com/blog/server-side-template-injection-a-crash-course- ■ https://www.youtube.com/watch?v=3cT0uE7Y87s ■ https://www.phpflow.com/php/php-remove-special-character-fromstring/
  • 23. Case-Studies - ■ https://hackerone.com/reports/125980 ■ https://hackerone.com/reports/164224 ■ https://hackerone.com/reports/230232 ■ https://medium.com/@david.valles/gaining-shell-using-server-side-template-injection-ssti- 81e29bb8e0f9 ■ https://medium.com/bugbountywriteup/frapp%C3%A9-technologies-erpnext-server-side- template-injection-74e1c95ec872 ■ http://ha.cker.info/exploitation-of-server-side-template-injection-with-craft-cms-plguin- seomatic/