Panic!! At the YAML
The SnakeYAML library, by default, allows an attacker who controls a YAML file to instantiate arbitrary Java classes and execute code. An attacker could craft a YAML payload that loads a remote class and runs arbitrary commands on the victim's machine.
This week, I got nerdsniped by an advisory from Atlassian that fixes a potential remote code execution vulnerability in the SnakeYAML library - CVE-2022-1471. I spent a bit of time looking at Confluence and Bitbucket, which are apparently vulnerable, but couldn’t quickly find a remotely accessible YAML sink; so…
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Impact
An attacker could execute arbitrary code on the server if it parses attacker-controlled YAML, leading to remote shell access.
What the attacker needed
Application parses untrusted YAML; attacker can supply YAML input; victim server can reach attacker's server
How it was found
- Create a YAML file that uses the !! tag to instantiate a class like javax.script.ScriptEngineManager with a URLClassLoader pointing to an attacker-controlled server.
- Serve a file at /META-INF/services/javax.script.ScriptEngineFactory containing the name of a malicious class.
- Serve the compiled malicious class file at the corresponding path.
- Run the vulnerable application that parses the YAML file, causing it to fetch and instantiate the malicious class, which executes arbitrary code.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
SnakeYAML is a tool that reads YAML files, which are often used for configuration. By default, it can create any Java object described in the file, and some objects can run code when created. So if a program reads a YAML file from an untrusted source, an attacker can make it run their own code.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.