SlideShare a Scribd company logo
BY : Narendra Kumar
@0ddhawk
SERVER SIDETEMPALATE
INJECTION
Null Bhopal
17 DEC 2017
Agenda
• Introduction
• Template /template engines
• Detect
• Identify
• Exploit
What is template?
What is template?
• Layout /predefine structure
• Might need to provide specific information before
its usable.
• Produces HTML
• Reduce typing
• Faster
Example
• Welcome to Null meet
• Null meets are open for everyone
Produce
HTML
• <h1>Welcome to Null meet</h1>
• Null meets are open for everyone
Classic
HTML
• H1 Welcome to Null meet
• P Null meets are open for everyonetemplate
What is template engine ?
Template
Data
Template
Engine
Resulting Document
Example :
• Welcome to OWASP
• OWASP meets are open for everyoneProduce
• {name : ‘OWASP’
• Category : ‘meets are open for everyone’}Data
• <h1>Welcome to<%=name%><h1>
• <p><%=name%><%=category%></p>Template
Type of template engines
• Freemarker
• Velocity
• Smarty
• Twig/Twig sandbox
• Jade
• EJS etc.
What is template injection?
What is template injection
Example 1: Marketing application for bulk emails
$output = $twig->render("Dear {first_name},", array("first_name" =>
$user.first_name) );
Example 2:
$output = $twig->render($_GET['custom_email'], array("first_name" => $user.first_name) );
Note: Customize input arise problems
A template injection may occur when an untrusted input is concatenated to a template file
Template engine behavior
• Plaintext context
• Code context
Plain context
• Template engine syntax:
• Ex 1: smarty
• Hello {user.name}
Hello user1
• Ex 2: Freemarker
• Hello ${username}
Hello user2
Detection of SSTI
• Ex 1: smarty
Hello ${7*7}
Hello 49
• Ex2: freemarker
Hello ${7*7}
Hello 49
• Other payloads syntax:
{ var} ${var} {{var}} <%var%> [%var%]
Code Context
• Ex 1:
personal_greeting=username
Hello user01
Breaking out template
• personal_greeting=username<tag>
Expected error/empty string
personal_greeting=username}}<tag>
Hello user01 <tag>
First step done
How to identify template engine
•language-specific payloads decision tree
Note: this technique fails when error messages are suppressed
Example: the probe {{7*'7'}} would result in 49 in Twig, 7777777 in Jinja2
Time to get ready
Exploit
• Read
|-cover basic syntax
|-Security considerations-chances are whoever developed the app you're
| testing didn't read this, and it may contain some useful hints
|- built-in methods, functions, filters, and variables
|-extensions/plugins - some may be enabled by default
• Explore
• Default objects provided by template/application : self
• If no builtin self object : burteforce variable name(developer supplied
objects are particularly contain sensitive information)
• Attack
• firm idea of the attack surface available to you
Demo
References
• http://blog.portswigger.net/2015/08/server-side-
template-injection.html
• https://github.com/twigphp/Twig/blob/e22fb8728
b395b306a06785a3ae9b12f3fbc0294/lib/Twig/Envi
ronment.php#L874
• https://twig.symfony.com/
• http://mrbool.com/understanding-twig-php-
template-engine/32460

More Related Content

PDF
Ch. 12 security
PPTX
PowerShell - Be A Cool Blue Kid
PPTX
Tech talk on code quality
PDF
"Real-time Collaborative Text Editing on Grammarly’s Front-End Team" Oleksii...
PDF
walkmod: quick start
PDF
walkmod: how it works
PPTX
Introduction to Javascript By Satyen
Ch. 12 security
PowerShell - Be A Cool Blue Kid
Tech talk on code quality
"Real-time Collaborative Text Editing on Grammarly’s Front-End Team" Oleksii...
walkmod: quick start
walkmod: how it works
Introduction to Javascript By Satyen

Similar to Server side tempalate injection (9)

PPTX
Server side tempalate injection
PPTX
Server Side Template Injection by Mandeep Jadon
PPTX
Server-side template injection- Slides
PPTX
Basics of Server Side Template Injection
PDF
Basics of ssti infosec girlswebinar
PDF
Twig, the flexible, fast, and secure template language for PHP
PPTX
Use Symfony2 components inside WordPress
PPTX
Nguyen Phuong Truong Anh - Some new vulnerabilities in modern web application
PDF
Mastering Twig (DrupalCon Barcelona 2015)
Server side tempalate injection
Server Side Template Injection by Mandeep Jadon
Server-side template injection- Slides
Basics of Server Side Template Injection
Basics of ssti infosec girlswebinar
Twig, the flexible, fast, and secure template language for PHP
Use Symfony2 components inside WordPress
Nguyen Phuong Truong Anh - Some new vulnerabilities in modern web application
Mastering Twig (DrupalCon Barcelona 2015)
Ad

Recently uploaded (20)

PDF
Classroom Observation Tools for Teachers
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
UNIT III MENTAL HEALTH NURSING ASSESSMENT
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
Lesson notes of climatology university.
PPTX
UV-Visible spectroscopy..pptx UV-Visible Spectroscopy – Electronic Transition...
PDF
Trump Administration's workforce development strategy
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
Practical Manual AGRO-233 Principles and Practices of Natural Farming
PPTX
History, Philosophy and sociology of education (1).pptx
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Classroom Observation Tools for Teachers
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
STATICS OF THE RIGID BODIES Hibbelers.pdf
UNIT III MENTAL HEALTH NURSING ASSESSMENT
Final Presentation General Medicine 03-08-2024.pptx
2.FourierTransform-ShortQuestionswithAnswers.pdf
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Module 4: Burden of Disease Tutorial Slides S2 2025
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Lesson notes of climatology university.
UV-Visible spectroscopy..pptx UV-Visible Spectroscopy – Electronic Transition...
Trump Administration's workforce development strategy
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
Practical Manual AGRO-233 Principles and Practices of Natural Farming
History, Philosophy and sociology of education (1).pptx
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Ad

Server side tempalate injection

  • 1. BY : Narendra Kumar @0ddhawk SERVER SIDETEMPALATE INJECTION Null Bhopal 17 DEC 2017
  • 2. Agenda • Introduction • Template /template engines • Detect • Identify • Exploit
  • 4. What is template? • Layout /predefine structure • Might need to provide specific information before its usable. • Produces HTML • Reduce typing • Faster
  • 5. Example • Welcome to Null meet • Null meets are open for everyone Produce HTML • <h1>Welcome to Null meet</h1> • Null meets are open for everyone Classic HTML • H1 Welcome to Null meet • P Null meets are open for everyonetemplate
  • 6. What is template engine ? Template Data Template Engine Resulting Document
  • 7. Example : • Welcome to OWASP • OWASP meets are open for everyoneProduce • {name : ‘OWASP’ • Category : ‘meets are open for everyone’}Data • <h1>Welcome to<%=name%><h1> • <p><%=name%><%=category%></p>Template
  • 8. Type of template engines • Freemarker • Velocity • Smarty • Twig/Twig sandbox • Jade • EJS etc.
  • 9. What is template injection?
  • 10. What is template injection Example 1: Marketing application for bulk emails $output = $twig->render("Dear {first_name},", array("first_name" => $user.first_name) ); Example 2: $output = $twig->render($_GET['custom_email'], array("first_name" => $user.first_name) ); Note: Customize input arise problems A template injection may occur when an untrusted input is concatenated to a template file
  • 11. Template engine behavior • Plaintext context • Code context
  • 12. Plain context • Template engine syntax: • Ex 1: smarty • Hello {user.name} Hello user1 • Ex 2: Freemarker • Hello ${username} Hello user2
  • 13. Detection of SSTI • Ex 1: smarty Hello ${7*7} Hello 49 • Ex2: freemarker Hello ${7*7} Hello 49 • Other payloads syntax: { var} ${var} {{var}} <%var%> [%var%]
  • 14. Code Context • Ex 1: personal_greeting=username Hello user01 Breaking out template • personal_greeting=username<tag> Expected error/empty string personal_greeting=username}}<tag> Hello user01 <tag>
  • 16. How to identify template engine •language-specific payloads decision tree Note: this technique fails when error messages are suppressed Example: the probe {{7*'7'}} would result in 49 in Twig, 7777777 in Jinja2
  • 17. Time to get ready
  • 18. Exploit • Read |-cover basic syntax |-Security considerations-chances are whoever developed the app you're | testing didn't read this, and it may contain some useful hints |- built-in methods, functions, filters, and variables |-extensions/plugins - some may be enabled by default • Explore • Default objects provided by template/application : self • If no builtin self object : burteforce variable name(developer supplied objects are particularly contain sensitive information) • Attack • firm idea of the attack surface available to you
  • 19. Demo

Editor's Notes

  • #11: 3:TI occurs when user input is embedded in template why example1 safe?
  • #12: How to detect template engine is in use? Plaintext context what is it?