之前,协会的同学去天津交流,天津大学的同学讲了一个python沙箱逃逸的案例。今天结合之前的所学和比赛经验写一个小结。
案例1
这是hackuctf 2012的一道题
defmake_secure():
UNSAFE = ['open',
'file',
'execfile',
'compile',
'reload',
'__import__',
'eval',
'input']
for func in UNSAFE:
del __builtins__.__dict__[func]
fromre import findall
#Remove dangerous builtins
make_secure()
print'Go Ahead, Expoit me >;D'
whileTrue:
try:
print ">>>",
# Read user input until the firstwhitespace character
inp = findall('\S+',raw_input())[0]
a = None
# Set a to the result from executingthe user input
exec 'a=' + inp
print '>>>', a
except Exception, e:
print 'Exception:', e