Skip to content

Instantly share code, notes, and snippets.

@jvns
Created November 6, 2013 22:30
Show Gist options
  • Save jvns/7345372 to your computer and use it in GitHub Desktop.
Save jvns/7345372 to your computer and use it in GitHub Desktop.
pysandbox breakout attempt (it didn't work)
types_checked = set()
remaining_types = set([int, dict, set, buffer, file, type])
# Try to call all the methods on an object x
def call_all_methods(x):
failures = set(dir(x))
successes = set()
results = set()
for num_args in [0, 1, 2, 3]:
args = range(1, num_args+1)
new_failures = set()
for method in failures:
f = getattr(x, method)
if not hasattr(f, '__call__'):
# it isn't a function
results.add((method, type(f)))
successes.add(method)
continue
try:
res = f(*args)
results.add((method, type(res)))
successes.add(method)
except:
new_failures.add(method)
#print "Failure", method
failures = new_failures
return set([t for _, t in results])
#return successes, failures, results
# try to get all the types we can
while len(remaining_types) > 0:
our_type = remaining_types.pop()
try:
new_types = call_all_methods(our_type())
except:
print "=(", our_type
types_checked.add(our_type)
actual_new_types = new_types.difference(types_checked)
remaining_types = remaining_types.union(actual_new_types)
print types_checked
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment