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_artifacts.rb
Views: 11655
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45require 'yaml'67class MetasploitModule < Msf::Post8include Msf::Auxiliary::Report9include Msf::Post::File10include Msf::Post::Windows::Registry1112def initialize(info = {})13super(14update_info(15info,16'Name' => 'Windows Gather File and Registry Artifacts Enumeration',17'Description' => %q{18This module will check the file system and registry for particular artifacts.1920The list of artifacts is read in YAML format from data/post/enum_artifacts_list.txt21or a user specified file. Any matches are written to the loot.22},23'License' => MSF_LICENSE,24'Author' => [ 'averagesecurityguy <stephen[at]averagesecurityguy.info>' ],25'Platform' => [ 'win' ],26'SessionTypes' => %w[shell powershell meterpreter],27'Notes' => {28'Stability' => [CRASH_SAFE],29'Reliability' => [],30'SideEffects' => []31}32)33)3435register_options([36OptPath.new(37'ARTIFACTS',38[39true,40'Full path to artifacts file.',41::File.join(Msf::Config.data_directory, 'post', 'enum_artifacts_list.txt')42]43)44])45end4647def run48# Load artifacts from yaml file. Artifacts are organized by what they are evidence of.49begin50yaml = YAML.load_file(datastore['ARTIFACTS'])51raise 'File is not valid YAML' unless yaml.instance_of?(Hash)52rescue StandardError => e53fail_with(Failure::BadConfig, "Could not load artifacts YAML file '#{datastore['ARTIFACTS']}' : #{e.message}")54end5556loot_data = ''5758yaml.each_key do |key|59print_status("Searching for artifacts of #{key}")60artifacts = []6162# Process file entries63files = yaml[key]['files']64vprint_status("Processing #{files.length} file entries for #{key} ...")6566files.each do |file|67fname = file['name']68csum = file['csum']6970digest = file_remote_digestmd5(fname)71if digest == csum72artifacts << fname73end74end7576# Process registry entries77regs = yaml[key]['reg_entries']78vprint_status("Processing #{regs.length} registry entries for #{key} ...")7980regs.each do |reg|81k = reg['key']82v = reg['val']83rdata = registry_getvaldata(k, v)84if rdata.to_s == reg['data']85artifacts << "#{k}\\#{v}"86end87end8889# Process matches90if artifacts.empty?91print_status("No artifacts of #{key} found.")92next93end9495print_status("Artifacts of #{key} found.")96loot_data << "Evidence of #{key} found.\n"97loot_data << artifacts.map { |a| "\t#{a}\n" }.join98end99100return if loot_data.blank?101102vprint_line(loot_data)103104loot_name = 'Enumerated Artifacts'105f = store_loot(106loot_name.downcase.split.join('.'),107'text/plain',108session,109loot_data,110loot_name111)112print_good("#{loot_name} stored in: #{f}")113end114end115116117