Пример #1
0
#!/usr/bin/python -u
'''
This challenge is a tribute to 'python jail' and 'The Sandboxed Terminal'
from Hack.lu 2012's CTF by Fluxfingers. Oh python, why you so why you so.
 
You should read some writeups on these (e.g. at ctftime.org/task/124/ and
ctftime.org/task/130/). You'll want to use a similar strategies to both
get past the character restrictions (e.g. `x`==repr(x) and True+True==2)
and to get past the sandboxing (e.g. the except handler below)
'''

from sys import modules
modules.clear()
del modules

_raw_input = raw_input
_eval = eval
ident = ''.join((chr(i) for i in xrange(256)))

#TIL: the interactive interpreter freaks if 'True' gets undefined,
#and 'None' is actually a keyword pretending to be a variable.
__builtins__.__dict__.clear()
__builtins__ = None

print 'Get a shell. The flag is NOT in ./key, ./flag, etc.'

while 1:
    try:
        inp = _raw_input()
        if not inp: continue
        inp = inp.split()[0][:1900]
Пример #2
0
from imp import acquire_lock
from threading import Thread
from sys import modules, stdin, stdout

# No more importing!
x = Thread(target = acquire_lock, args = ())
x.start()
x.join()
del x
del acquire_lock
del Thread

# No more modules!
for k, v in modules.iteritems():
	if v == None: continue
	if k == '__main__': continue
	v.__dict__.clear()

del k, v

__main__ = modules['__main__']
modules.clear()
del modules

# No more anything!
del __builtins__, __doc__, __file__, __name__, __package__

print >> stdout, "Get a shell. The flag is NOT in ./key, ./flag, etc."
while 1:
	exec 'print >> stdout, ' + stdin.readline() in {'stdout':stdout}