defaudit_hook(event, _): # These are the only necessary events for this Math REPL to work ALLOWED_EVENTS = set({'builtins.input', 'builtins.input/result', 'exec', 'compile'}) if event notin ALLOWED_EVENTS: # Thou shalt not hack! raise RuntimeError('Operation not permitted: {}'.format(event))
elif opt == 5: # Add a permitted PATH print("Want more paths to escape? But sorry you are only allowed to take some of our prespecified paths below:") print_paths(WHITELIST_PATHS) pathnumstr = input('Select which paths to add (1-{})> '.format(len(WHITELIST_PATHS))) try: pathnum = int(pathnumstr) ifnot1 <= pathnum <= len(WHITELIST_PATHS): raise ValueError except ValueError: print('Invalid index: {}'.format(pathnumstr)) continue
而且外边并没有nc
这题有一个很神奇的地方,就是当你删除PATH,把path删除完了之后
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
elif opt == 6: # Deprive myself of a permitted PATH print("Weird. I have never seen a prisoner who wants to voluntarily give up their own rights. But whatever.") ifnot PATH_LIST: print('You have no paths! Try adding one.') continue print_paths(PATH_LIST) pathnumstr = input('Select which path to remove (1-{})> '.format(len(PATH_LIST))) try: pathnum = int(pathnumstr) ifnot1 <= pathnum <= len(PATH_LIST): raise ValueError except ValueError: print('Invalid index: {}'.format(pathnumstr)) continue del PATH_LIST[pathnum - 1]
deftest_expr(expr, allowed_codes): """test_expr(expr, allowed_codes) -> codeobj Test that the expression contains only the listed opcodes. If the expression is valid and contains only allowed codes, return the compiled code object. Otherwise raise a ValueError """ import dis allowed_codes = [dis.opmap[c] for c in allowed_codes if c in dis.opmap] try: c = compile(expr, "", "eval") except SyntaxError: raise ValueError("%r is not a valid expression" % expr) codes = _get_opcodes(c) for code in codes: if code notin allowed_codes: raise ValueError("opcode %s not allowed" % dis.opname[code]) return c
# The above only allows Turing-incomplete evaluation, # so we decided to add our own ingenious additions: complete_codes = _expr_codes + ['MAKE_FUNCTION', 'CALL_FUNCTION']