Module 12: Server-side Template Injection - Discovery and Exploitation
Templating Engines
Accessing the Template Sandbox
Start the VPN, VM, and add IP to hosts.
Introduction to Templating Engines
Example Email
Hello Dragan,
Thank you for your order! Your items will be shipped out shortly:
Widget - $10
Quantity: 3
Total: $30
Toolkit - $20
Quantity: 1
Total: $20
_______________
Total: $50
These items will be shipped to:
194 Bridge Avenue Elton, Louisiana 70532Example Template Email
Example Template Variables
Greeting the user
Template For Loop
Displaying the total
Template If Statement
Various Templating Engines
Twig
PHP
Server Side
Freemarker
Java (usually)
Server Side
Pug/Jade
JavaScript
Mostly Server Side
Jinja
Python
Server Side
Handlebars
JavaScript
Both
Mustache
Multiple
Varies

Twig - Discovery and Exploitation
Twig - Discovery
Inline PHP before Twig
Twig Template
Twig Statement
Twig - Exploitation

Twig Documentation Example
Arguments for the reduce Function
var_dump payload
var_dump Payload output
whoami Payload

Apache Freemarker - Discovery and Exploitation
Freemarker - Discovery
Freemarker Template

If Statement in Freemarker

Loop in Freemarker
Freemarker tends to be more susceptible to XSS than other templating engines due to the requirements before 2016 to have developers specify if a variable needs to be HTML escaped.



Freemarker - Exploitation

Freemarker Execute Payload

Pug - Discovery and Exploitation
Pug - Discovery
Pug Template
Attributes in Pug
if statement in Pug
Code in Pug
Buffered Code
Pug Loop

Pug - Exploitation


Storing require as Variable

Executing spawnSync
Jinja - Discovery and Exploitation
Jinja - Discovery
Jinja Templating Engine

Jinja - Exploitation
Obtaining RCE via injection in the Jinja templating engine is the type of complex technique reviewed in the WEB-300 course.

Mustache and Handlebars - Discovery and Exploitation
Mustache and Handlebars - Discovery
Handlebars Template
Handlebars Expression
Handlebars Helpers
Mustache and Handlebars - Exploitation
For the most part Handlebars is fairly safe due to it being logicless, however helpers can cause it to be "vulnerable".


Halo - Case Study
Accessing Halo
Start the VPN, the VM, and add IP to hosts.
Halo - Translation and Discovery
Install an extension to translate the page if the browser won't do it automatically β I installed Translate Web Page from Filipe Dev into Firefox.



404.ftl
404 page with Halo
Non-freemarker template response
Freemarker Template Response
Freemarker template with string response
Halo - Exploitation
Freemarker RCE Payload

/etc/passwd in Halo
Extra Mile
Do the lab.
Craft CMS with Sprout Forms - Case Study
Accessing Craft CMS
Start the VPN, the VM, and add the IP to yours hosts.
Craft CMS with Sprout Forms - Discovery


Running Gobuster against the craft webpage




cURL Payload
Python HTTP Server
SSTI Confirmation
Craft CMS with Sprout Forms - Exploitation

Exfiltration Payload
Exfiltration in HTTP log
URL Encoding Exfil
Encoded message in HTTP log
Executing whoami and Exfiltrating the Output
Output of whoami Logged

/etc/passwd From Craft



Last updated