Remote Code Execution in Apache Tomcat via Java Deserialization
A misconfigured Tomcat allows PUT and partial PUT uploads to the webapps directory, letting an attacker place a serialized Java payload. A servlet then deserializes that file, triggering a gadget chain that executes a reverse shell.
Published on medium.com
Part 1 deals with trying to upload using partial PUTs however it doesnt really do RCE because not gets executed on the remote server. This part 2 deals with that plus using Java deserialization technique.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the servlet deserialized a session file from a directory that remote users could write to via PUT, so attacker-controlled bytes reached ObjectInputStream.
Impact
An attacker could execute arbitrary commands on the server, here demonstrated as a reverse shell.
What the attacker needed
Tomcat with PUT and partial PUT enabled; Network access to the Tomcat port; ysoserial and a compatible gadget on the classpath
The fix
The text does not state a fix; it advises validating and sanitising uploaded file paths and types and avoiding deserialisation of untrusted data.
How it was found
- Start the vulnerable Tomcat container with PUT and partial PUT enabled.
- Start a listener for the reverse shell.
- Generate a serialized payload with ysoserial using a gadget chain.
- Upload the payload to the webapps directory using partial PUT with Content-Range headers.
- Send a GET request to the vulnerable servlet to trigger deserialization.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
Java can turn objects into bytes and back again, a process called serialization. If a server rebuilds an object from bytes an attacker supplied, the attacker can pick a class whose rebuild step runs commands. Here the server also let anyone write files into the folder it serves, so the attacker could plant the bytes and then ask the app to load them.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.