看了几天的ssti注入然后了解到有python沙箱逃逸
学过ssti注入的话python沙箱逃逸还是很容易理解的。
看一道CTF题目,源码的话我改了改,一开始不能用,直接在py2上运行就好。
题目要求读取./key的值,我们这里来执行命令。
def make_secure():
UNSAFE = ['open',
'file',
'execfile',
'compile',
'reload',
'__import__',
'eval',
'input']
for func in UNSAFE:
del __builtins__.__dict__[func]
from re import findall
# Remove dangerous builtins
make_secure()
print 'Go Ahead, Expoit me >;D'
while True:
try:
# Read user input until the first whitespace character
inp = findall('\S+', raw_input())[0]
a = None
# Set a to the result from executing the user input
exec 'a=' + inp
print 'Return Value:', a
except Exception as e:
print 'Exception:', e
题目一开始就删除了些危险函数,比如file等。
那删除和没删除有什么区别呢?
通俗来说,就是不能直接调用了。builtins里面被删除的函数不能被直接调用了。
那我们能不能通过别的办法调用file呢?答案是肯定的
很轻松的就读到了key,可我们的目标是提权。
- 我想用os模块,一种是从别的模块能不能直接调用它:
- 另一种需要eval配合__import__导入os模块
所以我们先找到<class 'site._Printer'>模块