Hands on with WebLogic Serialization Vulnerability

January 23, 2016

Backstory

On November 7, 2015 FoxGlove Security released a blog entry entitled “What Do WebLogic, WebSphere, JBoss, Jenkins, OpenNMS, and Your Application Have in Common? This Vulnerability.” Along with their documentation, they released exploits for a variety of major Java applications. Their work was based on a talk at AppSec California 2015, “Marshalling Pickles: How Deserializing Objects Will Ruin Your Day”. The initial talk mentioned a vulnerability in Apache’s java Common Collection library. Additionally, the presenters released a tool that could generate Java serialized payloads for this library and more, this tool was called ysoserial. FoxGlove Security expanded upon the talk’s work and released the previously mentioned exploits that use ysoserial generated payloads.

I suggest checking out the blog entry and the talk if you haven’t, really interesting topic and great work from both groups!  

Hands On

So after reading up on this topic, I had to start playing with this stuff. I decided to jump into the WebLogic exploit!

I went ahead and built my lab environment for testing. It consisted of two VMs: one Kali Linux and the other CentOS.

Configure CentOS

First things first, I made sure everything is up-to-date.

Next, I installed JDK and checked version to verify that it was installed.

Lastly, I downloaded  WebLogic’s generic install and started the installation. I then created a base_domain by clicking through the GUI prompts that appeared after running the .jar.

Note: In order to download WebLogic, I had to sign-in to Oracle. I used credentials from BugMeNot.com.

I opened the firewall for WebLogic and then started the server.

Configure Kali

Once again, I made sure that every is up-to-date.

Next, I pulled down the exploit code and ysoserial from GitHub into a fresh directory.

Exploit

Before any exploitation can be done, I first had to identify my target. WebLogic’s default port is 7001, so potential victims can be identified with nmap.

In order to use this exploit, I first had to generate my payload using ysoserial using the following syntax.

I generated my payload for the Apache Common Collection, had it touch a new file to verify the exploit, and saved it to payload.out

With the payload generated, I could now use the python exploit from FoxGlove Security by using the following syntax.

Unfortunately, due to the nature of the T3 protocol WebLogic uses, the exploit code must be modified to account for the different lengths of payload. The FoxGlove Security blog post pokes fun at this hassle, “You might have to adjust this depending on the payload you decide to use. You can easily do this dynamically as well, I’ll leave that as an exercise for the reader :)”. Challenged accepted!

I opened the python script and found that before the script sends the payload to the victim’s port, it appends the ysoserial generated payload behind some protocol header bytes, the payload length is defined by the first 4 bytes of this header. All we need to do is find the length of our payload, convert the length to hex, update the header with the correct length, and prepend our updated header to the front of the payload.

I did this by adding the following lines right before the payload is sent:

The first line gets the length of the payload and pads it to be the full 4 bytes. The second line prepends the length in hex to the payload, which is stripped of it’s hard coded length. Now the script will dynamically adjust for varying payload lengths.

Because I’m lazy, I didn’t like having to generate the payload with ysoserial and then have to run the python script. So I again updated the python script to automatically generate and use the payload. I also added some cheap command line argument checking. I did this by adding the following lines:

The new syntax is:

python weblogic.py [victim ip] [victim port] [path to ysoserial] ‘[command to execute]’

The exploit can now be leveraged with a single command. My updated script with my modifications can be found on my BitBucket and GitHub.

Here is a video of the whole process! My WebLogic instance just so happened to be running as root for demonstration purposes, but the commands executed will only have the privileges of the user who started the WebLogic server.

Thanks for reading!