CVE-2019-17571 RCE PoC
This is not my CVE. It's a quick and dirty proof of concept tutorial on achieving RCE abusing CVE-2019-17571 that I put together for a friend.
CVE-2019-17571: Included in Log4j 1.2 is a SocketServer class that is vulnerable to deserialization of untrusted data which can be exploited to remotely execute arbitrary code when combined with a deserialization gadget when listening to untrusted network traffic for log data.
The following PoC is based on this great article by Aman Sapra. I merely modified the payload to showcase a reverse shell and provide a step by step guide for replication. This is not meant to be a write-up on this vuln nor Java deserialization attacks by any means.
Setup
I'll be using a fresh Ubuntu 20.04 VM, though any OS should work. Following Sapras setup I will install the test application that he provides on his github and download the correct JDK.
Download the test server
JankenTestLogServer.jar
from here (credit: Aman Sapra)Download the Java dev-kit for linux: jdk-7u80 and extract it with
tar xf jdk-7u80-linux-x64.tar.gz
Create a simple config file for the test server (
touch config
) and paste the following contents into it:
We can now start the test server on port 5111 with the following command:
For generating the payloads (serialized Java objects) we'll also need an additional tool called ysoserial
which can be downloaded from here or build from source.
RCE via Java Deserialization
While Aman Sapra demonstrates the RCE with a simple curl
I'll be sending and triggering a basic Python reverse shell.
First, create a basic reverse shell script (taken from PentestMonkey), for example rev.sh
:
This should optimally happen somewhere outside of the directory where the server is running or otherwise you will be hosting and downloading the reverse shell in the same location. Just use a parallel directory for example.
Next, (back inside the directory where we extracted the JDK) we will create three payloads to a) download the reverse shell on the target (which actually is localhost in this example), b) make the script executable and c) execute it.
Last thing to do is to host our reverse shell script in one terminal and start a listener for the incoming connection in another one:
Having the test server, the python server and the listener running should look something like this:
Pane 1 shows the running test server, the Python server runs in pane 2 hosting the rev.sh
file on port 8000, pane 3 has the listener running and we're ready to send the payloads from the fourth panel.
Et voilà, we successfully gained shell access.
Last updated