SlideShare a Scribd company logo
SERVER SIDE TEMPALATE INJECTION
BY : NARENDRA KUMAR
Null|OWASP|G4H
16 DEC 2017
@0ddhawk
Outline
• 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
Produces
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 ?
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
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/e22fb872
8b395b306a06785a3ae9b12f3fbc0294/lib/Twig/E
nvironment.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
PDF
"Real-time Collaborative Text Editing on Grammarly’s Front-End Team" Oleksii...
PPTX
Tech talk on code quality
PDF
walkmod: quick start
PPTX
Introduction to Javascript By Satyen
PDF
walkmod: how it works
Ch. 12 security
PowerShell - Be A Cool Blue Kid
"Real-time Collaborative Text Editing on Grammarly’s Front-End Team" Oleksii...
Tech talk on code quality
walkmod: quick start
Introduction to Javascript By Satyen
walkmod: how it works

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
PPTX
Nguyen Phuong Truong Anh - Some new vulnerabilities in modern web application
PDF
Twig, the flexible, fast, and secure template language for PHP
PPTX
Use Symfony2 components inside WordPress
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
Nguyen Phuong Truong Anh - Some new vulnerabilities in modern web application
Twig, the flexible, fast, and secure template language for PHP
Use Symfony2 components inside WordPress
Mastering Twig (DrupalCon Barcelona 2015)
Ad

Recently uploaded (20)

PDF
Parts of Speech Prepositions Presentation in Colorful Cute Style_20250724_230...
PPTX
Effective_Handling_Information_Presentation.pptx
PPTX
An Unlikely Response 08 10 2025.pptx
PPTX
Introduction to Effective Communication.pptx
PPTX
Self management and self evaluation presentation
DOCX
ENGLISH PROJECT FOR BINOD BIHARI MAHTO KOYLANCHAL UNIVERSITY
PPTX
Relationship Management Presentation In Banking.pptx
PDF
Presentation1 [Autosaved].pdf diagnosiss
PPTX
worship songs, in any order, compilation
PDF
Tunisia's Founding Father(s) Pitch-Deck 2022.pdf
PPTX
Intro to ISO 9001 2015.pptx wareness raising
PPTX
ART-APP-REPORT-FINctrwxsg f fuy L-na.pptx
PPTX
Anesthesia and it's stage with mnemonic and images
PPTX
2025-08-10 Joseph 02 (shared slides).pptx
PPTX
BIOLOGY TISSUE PPT CLASS 9 PROJECT PUBLIC
PDF
natwest.pdf company description and business model
PPT
First Aid Training Presentation Slides.ppt
PPTX
Introduction-to-Food-Packaging-and-packaging -materials.pptx
PPTX
Role and Responsibilities of Bangladesh Coast Guard Base, Mongla Challenges
PPTX
Emphasizing It's Not The End 08 06 2025.pptx
Parts of Speech Prepositions Presentation in Colorful Cute Style_20250724_230...
Effective_Handling_Information_Presentation.pptx
An Unlikely Response 08 10 2025.pptx
Introduction to Effective Communication.pptx
Self management and self evaluation presentation
ENGLISH PROJECT FOR BINOD BIHARI MAHTO KOYLANCHAL UNIVERSITY
Relationship Management Presentation In Banking.pptx
Presentation1 [Autosaved].pdf diagnosiss
worship songs, in any order, compilation
Tunisia's Founding Father(s) Pitch-Deck 2022.pdf
Intro to ISO 9001 2015.pptx wareness raising
ART-APP-REPORT-FINctrwxsg f fuy L-na.pptx
Anesthesia and it's stage with mnemonic and images
2025-08-10 Joseph 02 (shared slides).pptx
BIOLOGY TISSUE PPT CLASS 9 PROJECT PUBLIC
natwest.pdf company description and business model
First Aid Training Presentation Slides.ppt
Introduction-to-Food-Packaging-and-packaging -materials.pptx
Role and Responsibilities of Bangladesh Coast Guard Base, Mongla Challenges
Emphasizing It's Not The End 08 06 2025.pptx
Ad

Server side tempalate injection

  • 1. SERVER SIDE TEMPALATE INJECTION BY : NARENDRA KUMAR Null|OWASP|G4H 16 DEC 2017 @0ddhawk
  • 2. Outline • 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 Produces 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 ?
  • 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. 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
  • 18. 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?