GHSL-2021-087: Pre-auth unsafe deserialization in ZStack - CVE-2021-32836
The ZStack REST API deserialises attacker-controlled JSON into arbitrary Java classes without authentication. An attacker could cause a denial of service by closing file descriptors, and potentially achieve remote code execution if a suitable gadget class is available.
Originally disclosed on GitHub Security Lab
POST requests to the REST API (/api) are handled by the RESTApiController:
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 report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The custom deserialiser uses Class.forName on an attacker-supplied class name and then deserialises the attacker-supplied data into that class, allowing instantiation of arbitrary types with attacker-controlled fields.
Impact
This issue may lead to a Denial Of Service. If a suitable gadget is available, then an attacker may also be able to exploit this vulnerability to gain pre-auth remote code execution.
What the attacker needed
Network access to the REST API; no authentication required
The fix
The issue was fixed according to the advisory.
How it was found
- Send a POST request to the /api endpoint with a JSON body that specifies a class name and field values.
- The server deserialises the JSON into an instance of the specified class.
- The garbage collector later calls the finalize() method on the object, triggering side effects such as closing a file descriptor.
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 report has not been written yet. The Original tab links to the source.
The ZStack REST API accepts JSON data and uses a library to turn it into Java objects. Because the attacker can specify which Java class to create and what values to set, they can trigger harmful side effects when the object is cleaned up by the garbage collector. This could crash the service or, with the right class, run malicious code.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.