COMP6841 Something Awesome

z5418112 (Sam Zheng)

Render Quest

By: leanthedev

3 hours

Medium
Golang
SSTI

This challenge was quite a fun one to solve, and with experience in Golang, I figured it shouldn't be too difficult to figure out. Funnily enough, this particular challenge had a lot of red herrings, which made it a bit more difficult to pin-point what the actual vulnerability was.

The application

The application

Reconnaissance

From previous challenges, I started taking a bit more time to note down the things that I found interesting, before I went in to start planning an approach.

Dockerfile

Dockerfile

Taking a look inside the Dockerfile - once again we have a random flag file name, we will most likely have to get some form of RCE to be able to figure out the name of the flag.

There is a static folder - but this doesn't seem to have much to it - just looks like the CSS for a simple bootstrap theme, and its corresponding JS scripts. There is also a custom JS script file, which contains some basic cookie setting and some script to run a function to get the template file. There's nothing particularly interesting other than the fact that we can put in any link for the template file, seemingly.

window.onload = async () => {
document.getElementById("templateButton").addEventListener("click", () => {
window.location.href = "/render?use_remote=true&page=" + document.getElementById("templateLink").value;
});
if (isCookieSet("user_ip")) {
return;
}
const response = await fetch("https://freeipapi.com/api/json/");
if (response.status === 200) {
const ipData = await response.json();
const trueClientIP = ipData.ipAddress;
document.cookie = `user_ip=${trueClientIP}; path=/`;
} else {
console.error("Failed to fetch IP data");
}
}

Now, we get to the main meat of the program: the main.go file. There are a few interesting things to note here, let's explore them - a lot of which were unfortunately red herrings, or at least was not the immediate vulnerability.

Red Herring Central

The Vulnerability

Then it hit me - the whole entire purpose of this website allowed one to render any potential given URL with a template. This was a classic Server-Side Template Injection (SSTI) vulnerability. While I had heard about SSTI vulnerabilities before, I had never actually encountered one in the wild. This was a good opportunity to learn more about it.

Using our good friend HackTricks , I found that the Go template engine was quite powerful, and could be used to execute arbitrary code. How? Well - the Go template engine essentially allows for the substitution of certain Go code within the template for values.

I have a free Oracle Cloud instance that I use for testing, so I decided to use that to host a simple file hosting service using the default Python HTTP server. (Why are there no basic file hosting services without fancy bells and whistles?)

File hosting service

File hosting service

Testing a different SSTI payload, I used this:

{{ . }}

Ooh now we're talking. This particular payload allowed me to see the underlying data structure in the context that we were in, and proved that our Go SSTI was working.

Further reading on HackTricks showed me that I could access other methods within Go templates:

Source: hacktricks.com

Source: hacktricks.com

Remember the FetchServerInfo function that I mentioned earlier? Because it was defined in the RequestData struct and we were working within the context of the struct, I was able to call it directly in the template:

{{.FetchServerInfo "ls ../flag*.txt | xargs cat"}}

And there we have it - the flag!

Reflection and Learnings

Last Writeup

Pop Restaurant

Next Writeup

Insomnia