Skip to content
RCE Write-up Advanced

SnakeYaml Deserilization exploited

A Spring Boot application parsed user-supplied YAML with SnakeYAML's unsafe load method, which allows the YAML to name arbitrary Java classes and invoke their constructors. An attacker could supply a crafted YAML document that loads a remote class and executes code on the server.

medium.com

Published on medium.com

This blog is about a SnakeYaml deserilization vulnerability that was exploited by my friend in one of the recent penetration testing engagements. I have recreated the scenario here to demonstrate the deserilization exploitation.

Swapneil Kumar Dash, on medium.com

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

Root cause

The application passed untrusted input to SnakeYAML's default constructor, which supports the special tag syntax that instantiates arbitrary Java classes during parsing.

Impact

An attacker who can submit YAML could execute arbitrary code on the server, demonstrated by launching the calculator application.

What the attacker needed

Ability to submit YAML to the app; attacker-hosted class and descriptor files; server can reach attacker host

The fix

The application should avoid SnakeYAML's default constructor and instead use a safe loader that restricts which classes may be instantiated.

How it was found

  1. Build a small Spring Boot app that accepts YAML text and parses it with SnakeYAML's load method.
  2. Send a sample YAML document from the web form and confirm it is parsed and returned.
  3. Send a YAML document that names a script engine manager class with a remote class loader URL, and observe the server requesting the attacker host.
  4. Host a class file and a service descriptor file on the attacker server so the loader can find and instantiate it.
  5. Resend the same YAML document and observe the class execute on the server.

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.

YAML is a text format for configuration data. This application let users paste YAML, and the library it used to read that text could be told to create Java objects of any class named in the text. Because creating some objects runs code, a malicious YAML file could make the server run the attacker's program.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.