SnakeYaml Constructor Deserialization Remote Code Execution
Summary
SnakeYaml Constructor Deserialization Remote Code Execution
Original description
The description as published by the source.
Summary
SnakeYaml's Constructor class, which inherits from SafeConstructor, allows
any type be deserialized given the following line:
new Yaml(new Constructor(TestDataClass.class)).load(yamlContent);
Types do not have to match the types of properties in the
target class. A ConstructorException is thrown, but only after a malicious
payload is deserialized.
Severity
High, lack of type checks during deserialization allows remote code execution.
Proof of Concept
Execute bash run.sh. The PoC uses Constructor to deserialize a payload
for RCE. RCE is demonstrated by using a payload which performs a http request to
http://127.0.0.1:8000.
Example output of successful run of proof of concept:
$ bash run.sh
[+] Downloading snakeyaml if needed
[+] Starting mock HTTP server on 127.0.0.1:8000 to demonstrate RCE
nc: no process found
[+] Compiling and running Proof of Concept, which a payload that sends a HTTP request to mock web server.
[+] An exception is expected.
Exception:
Cannot create property=payload for JavaBean=Main$TestDataClass@3cbbc1e0
in 'string', line 1, column 1:
payload: !!javax.script.ScriptEn ...
^
Can not set java.lang.String field Main$TestDataClass.payload to javax.script.ScriptEngineManager
in 'string', line 1, column 10:
payload: !!javax.script.ScriptEngineManag ...
^
at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.constructJavaBean2ndStep(Constructor.java:291)
at org.yaml.snakeyaml.construc…
Source: OSV.dev (Open Source Vulnerabilities) NVD GitHub Advisory OSV
Affected packages
Fix status by distribution
Fixed packages published by each distribution for this CVE
- Debian DEBIAN-CVE-2022-1471 snakeyaml
References
- advisory nvd.nist.gov
- package bitbucket.org
- web github.com
- web github.com
- web snyk.io
- web security.netapp.com
- web security.netapp.com
- web infosecwriteups.com
- web groups.google.com
- web github.com
- web confluence.atlassian.com
- web bitbucket.org
- web bitbucket.org
- web bitbucket.org
- web bitbucket.org
- web bitbucket.org
- web bitbucket.org
- web packetstormsecurity.com
- web openwall.com