This project demonstrates a pre-authentication remote code execution vulnerability found in Apache Log4j 2 via the FilteredObjectInputStream. It exploits the bypass in deserialization when using MarshalledObject, allowing attackers to trigger unfiltered object streams, potentially compromising any Java service that utilizes Log4j for logging.
This repository demonstrates a pre-auth Remote Code Execution (RCE) vulnerability affecting any Java service that utilizes Apache Log4j's FilteredObjectInputStream to deserialize LogEvent. No credentials are required to exploit this vulnerability.
The FilteredObjectInputStream (FOIS) is designed as a safe deserialization wrapper, enforcing an allowlist for specific classes. However, it allows the use of java.rmi.MarshalledObject, which circumvents the filtering mechanism. When a MarshalledObject is deserialized, it creates a fresh ObjectInputStream that lacks any filtering, enabling the execution of arbitrary code through malicious payloads embedded in the stream.
Log4j's design includes a LogEventProxy class that wraps the event message in MarshalledObject<Message>. During deserialization, the marshalledMessage.get() method is called, generating an unfiltered stream from the MarshalledObject, thus exposing the application to the attack without logging or errors. The exploit triggers a command execution via a gadget chain hidden within the MarshalledObject.objBytes.
The attack is facilitated through the following flow:
LogEventProxy via an HTTP POST request to the target service.LogEventProxy, MarshalledObject, and the primitive byte[].LogEventProxy.readResolve() accesses the unfiltered input stream from the marshalledMessage and triggers the gadget chain that leads to remote code execution.To exploit this vulnerability, a payload and a specific message type called GadgetMessage are formed. This technique involves configuring the gadget correctly inside the marshal object while avoiding early triggers. The steps include:
Log4jLogEvent that encapsulates the GadgetMessage.The vulnerability affects the following Log4j components:
| Component | Vulnerable Versions |
|---|---|
log4j-api (FilteredObjectInputStream) | 2.11.0 to 2.24.3 |
log4j-core (LogEventProxy's MarshalledObject field) | 2.8.0 to 2.24.3 |
To demonstrate the exploit, the following setup is required:
The repository includes a victim Docker setup and an exploitation script. Instructions for building and running the victim service, as well as executing the exploit, are provided.
This exploit is intended solely for authorized testing. Ensure to obtain written permission before executing the payload against any systems.
No comments yet.
Sign in to be the first to comment.