If website allow us inject the code into template engines, we can manipulate the behavior of the template engines.
e.g. Inserting expression invoke the system function. (RCE)
Template Engine
laravel -> blade (Template engine)
symphony -> Twig (Template Engine )
Flask -> Jinja
Jinja Template
(Main Goal)
RCE (remote code execution) (Not Always Achieve)
Read arbitrary file.
Path Traversal
Install Twig (template engine)
Environment setting
$twig object is used to load the twig template
Creating Instances and views
Basic Demo
index.php
views/meowhecker.html
Result
User input Directly embedding to the template. (Danger!)
Injecting special character to trigger the exception.
Inject point
Distinguish XSS
Some we will identity this issue just simple XSS
We can use mathematical operation to testing there whether have SSTI issue or not.
IF Return Hello 54 -> SSTI Detected !!
Passing value to template expression
the result URL would be like
we can attempt to inject arbitrary HTML
if arise exception arises
, we could try to bread out of statement using common template syntax.
Identify the type of template the server uses.
FUzzing string
https://github.com/vladko312/sstimap
https://github.com/epinna/tplmap
Require: Identify template
Reading the document to understand the expression syntax for invoking system function to execute systems commands.
e.g. (Python-base Mako)
https://docs.ruby-lang.org/en/2.3.0/ERB.html
Flawed Design
**Testing SSTI vulnerability **
Not Word
Not work
-> ERB Template
Confirm Defense Mechanisms
None
Read Document
RCE !!
Solved
Tools
https://github.com/vladko312/sstimap
Receive Shell !!!
wiener:peter
Evaluate Comment functionality
Flawed Design
Passing User controllable vale to expression
SSTI Detected !!!
Identify Template Engine
-> Tornado
Confirm Defense Mechanisms
None
Read Document
https://book.hacktricks.xyz/pentesting-web/ssti-server-side-template-injection#tornado-python
RCE (Remote Code Execution)
Code Context -> Like XSS context -> 拼接
RCE (Remote Code Execution )
Solved !
Valid Credential
/Change email
No Vulnerability
Flawed Design
Confirm Defense Mechanisms
None
Read Document
https://book.hacktricks.xyz/pentesting-web/ssti-server-side-template-injection#freemarker-java
Remote Code Execution
Solved !
Flawed Design
Page reflect get parameter!
Confirm Defense Mechanisms
None
Detected : SSTI vulnerabilities !
Template Engine -> Handlebars
Read Document
https://book.hacktricks.xyz/pentesting-web/ssti-server-side-template-injection#handlebars-nodejs
RCE Payload (Blind CMD injectio)
RCE !!!
SSTI is not always possible to lead to Remote code execution but , it can still provide opportunities to perform other high-severity exploit
we could try to inject the default objects or methods provided by template engine using a fuzzing approach
Read Document
(Brute Force - fuzzing)
1.SecLists (wordlists)
2.burpsuite intruder (profession version)
We can also enumerate developer-supplied objects or method to exploit them.
Enumerate
content-manager:C0nt3ntM4n4g3r
Flawed Design
SSTI Detected !!
Python Template
Template Engine -> Jinja2 (Python)
Read Document
https://book.hacktricks.xyz/pentesting-web/ssti-server-side-template-injection#jinja2-python
framework's secret key.
Solved
content-manager:C0nt3ntM4n4g3r
Flawed Design
SSTI detection
Template -> FreeMarker
Confirm Defense Mechanisms
Not allow invoke Danger methods
-> inference template in sandbox env
Bypass
Other exploit Using Product object
According the error message, I guess template didn't have article object
we can attempt use Product to replace it.
Read Document
https://book.hacktricks.xyz/pentesting-web/ssti-server-side-template-injection#freemarker-java
only works on Freemarker versions below 2.3.30
RCE !!!
Solved
Flawed Design
SSTI Detected
Template Engine -> Twig!
Confirm Defense Mechanisms
Bypass
Not Work
Not Work
RCe payload not work
Attempt find other path
Construct Object chain
Delete
Solved
Owner :侯智晟 meowheckerouo@gmail.com