Yaml maktaba za python pia zina uwezo wa kuunda vitu vya python na sio tu data safi:
print(yaml.dump(str("lol")))
lol
...
print(yaml.dump(tuple("lol")))
!!python/tuple
- l
- o
- l
print(yaml.dump(range(1,10)))
!!python/object/apply:builtins.range
- 1
- 10
- 1
Angalia jinsi tuple si aina ya data ya msingi na kwa hivyo ilifanywa serialized. Na jambo hilo lilitokea pia na range (iliyotolewa kutoka kwa builtins).
safe_load() au safe_load_all() hutumia SafeLoader na haziungi mkono deserialization ya vitu vya darasa. Mfano wa deserialization ya kitu cha darasa:
import yamlfrom yaml import UnsafeLoader, FullLoader, Loaderdata =b'!!python/object/apply:builtins.range [1, 10, 1]'print(yaml.load(data, Loader=UnsafeLoader))#range(1, 10)print(yaml.load(data, Loader=Loader))#range(1, 10)print(yaml.load_all(data))#<generator object load_all at 0x7fc4c6d8f040>print(yaml.load_all(data, Loader=Loader))#<generator object load_all at 0x7fc4c6d8f040>print(yaml.load_all(data, Loader=UnsafeLoader))#<generator object load_all at 0x7fc4c6d8f040>print(yaml.load_all(data, Loader=FullLoader))#<generator object load_all at 0x7fc4c6d8f040>print(yaml.unsafe_load(data))#range(1, 10)print(yaml.full_load_all(data))#<generator object load_all at 0x7fc4c6d8f040>print(yaml.unsafe_load_all(data))#<generator object load_all at 0x7fc4c6d8f040>#The other ways to load data will through an error as they won't even attempt to#deserialize the python object
Kifungu kilichopita kilitumia unsafe_load kupakia darasa la python lililosajiliwa. Hii ni kwa sababu katika toleo >= 5.1, hairuhusu kufanya deserialization ya darasa lolote la python lililosajiliwa au sifa za darasa, bila Loader iliyotajwa katika load() au Loader=SafeLoader.
Note that in recent versions you cannot no longer call .load()without a Loader and the FullLoader is no longer vulnerable to this attack.
RCE
Custom payloads can be created using Python YAML modules such as PyYAML or ruamel.yaml. These payloads can exploit vulnerabilities in systems that deserialize untrusted input without proper sanitization.