0xma Cyber Security Articles




May 1, 2022

Server Side Template Injection - Example 1

In this tutorial, we will see how to perform a SSTI (Server-Side Template Injection) attack. The web server is running nginx. This SSTI attack will allow us to upload a netcat executable to the target and gain a reverse shell on the local box.

This shows the main page of the website.

Main page of the website.

There is a directory called "/maintenance" that is currently under maintenance.

maintenance directory.

This page provides more information about this attack. The web server is vulnerable to path normalization issue. Adding ..; at the end of the URL redirects us to "/nuxeo/nxstartup.faces".

Trying to discover SSTI vulnerability.

Trying to discover SSTI vulnerability.

It is the redirection response in Burp Suite.

Trying to discover SSTI vulnerability.

Trying to browse to "/maintenance/..;/nuxeo/nxstartup.faces" redirects us to "/nuxeo/login.jsp".

Following the redirection.

Following the redirection.

It shows the redirection in Burp Suite.

Following the redirection.

Browsing to "/maintenance/..;/nuxeo/login.jsp" returns a "Sorry, the page you requested cannot be found." message.

Page not found message.

Removing "nuxeo" from the URL and adding the payload pwn${7*7}.xhtml displays the result of the multiplication. This shows that SSTI is possible.

Successful SSTI payload.

Paste in this payload in the URL bar of the browser. It tries to ping the local box.

Pinging our local box using SSTI payload.

The ICMP packets are received in the local box which is an indication that command execution is successful.

Pinging our local box using SSTI payload.

We need to download a 64-bit netcat to the local box so that we could upload it to the web server.

netcat executable on the local box.

This uploads the netcat executable to the "c:\programdata\" directory.

Uploading netcat to the web server.

Uploading netcat to the web server.

We have to have this Python web server running before executing the previus payload. It shows that the netcat executable has been successfully retrieved.

Python web server serving the netcat executable.

Executing this payload uses netcat to connect powershell to our local listener.

Executing the netcat reverse shell.

Executing the netcat reverse shell.

It shows us receiving a reverse shell on the local box. Note that it is important to have this netcat listener running before executing the payload.

Receiving the netcat reverse shell.

If you liked reading this article, you can follow me on Twitter: 0xmaCyberSec.