by fs
I got bored of code-golfing so I decided to come up with ssti-golfing.
This challenge was hosted on http://golf.c1.blahaj.sg/.
This challenge was a classic Jinja2 SSTI challenge but with a (pretty strict) length restriction challenge implemented. Looking at the source code below, it’s quite short and not much to really digest.
1 | from flask import Flask, request, render_template, render_template_string |
The render_template_string()
function directly injects the user supplied data (the comment parameter) into the f-string before rendering it which makes this web app vulnerable to SSTI. However, we see that it checks if the length of the user supplied data exceeds 65 characters (this was a mistake in the source code since it was intended to be 40 but i had deployed this challenge with the restriction being 65 characters so this challenge became significantly more easier (unintended)) and it also blocks a few terms (the blacklist) that can make the SSTI payload extremely short.
However, we can easily get around this restriction by breaking apart our ssti payload into several pieces and storing them into flask config variables since this web app doesn’t block using config variables. So you could store ''.__class__.__mro__[1].__subclassess__
into a config variable by running {{config.update({'u':'ssti-payload'})}}
. Using this method, we can store a payload to read flag.txt such as ''.__class__.__mro[1].__subclassess__[357]("flag.txt").read()
which is using LazyFile class to read flag.txt into the following config variables.
1 | import requests |
By running this, we get the flag blahaj{c0nf1g_v4r14bl35_f7w}
.