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_av_excluded.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::Windows::Registry78def initialize(info = {})9super(10update_info(11info,12'Name' => 'Windows Antivirus Exclusions Enumeration',13'Description' => %q{14This module will enumerate the file, directory, process and15extension-based exclusions from supported AV products, which16currently includes Microsoft Defender, Microsoft Security17Essentials/Antimalware, and Symantec Endpoint Protection.18},19'License' => MSF_LICENSE,20'Author' => [21'Andrew Smith', # original metasploit module22'Jon Hart <jon_hart[at]rapid7.com>' # improved metasploit module23],24'Platform' => [ 'win' ],25# XXX: this will work with 'shell' when the sysinfo parts are removed26# and https://github.com/rapid7/metasploit-framework/issues/6328 and27# perhaps https://github.com/rapid7/metasploit-framework/issues/631628# are fixed29'SessionTypes' => [ 'meterpreter' ]30)31)3233register_options(34[35OptBool.new('DEFENDER', [true, 'Enumerate exclusions for Microsoft Defender', true]),36OptBool.new('ESSENTIALS', [true, 'Enumerate exclusions for Microsoft Security Essentials/Antimalware', true]),37OptBool.new('SEP', [true, 'Enumerate exclusions for Symantec Endpoint Protection (SEP)', true])38]39)40end4142DEFENDER = 'Windows Defender'43DEFENDER_BASE_KEY = 'HKLM\\SOFTWARE\\Microsoft\\Windows Defender'44ESSENTIALS = 'Microsoft Security Essentials / Antimalware'45ESSENTIALS_BASE_KEY = 'HKLM\\SOFTWARE\\Microsoft\\Microsoft Antimalware'46SEP = 'Symantec Endpoint Protection (SEP)'47SEP_BASE_KEY = 'HKLM\\SOFTWARE\\Symantec\\Symantec Endpoint Protection'4849def av_installed?(base_key, product)50if registry_key_exist?(base_key)51print_good("Found #{product}")52true53else54false55end56end5758def excluded_sep59base_exclusion_key = "#{SEP_BASE_KEY}\\Exclusions\\ScanningEngines\\Directory"60admin_exclusion_key = "#{base_exclusion_key}\\Admin"61client_exclusion_key = "#{base_exclusion_key}\\Client"6263admin_paths = []64if (admin_exclusion_keys = registry_enumkeys(admin_exclusion_key, @registry_view))65admin_exclusion_keys.map do |key|66admin_paths << registry_getvaldata("#{admin_exclusion_key}\\#{key}", 'DirectoryName', @registry_view)67end68print_exclusions_table(SEP, 'admin path', admin_paths)69end70client_paths = []71if (client_exclusion_keys = registry_enumkeys(client_exclusion_key, @registry_view))72client_exclusion_keys.map do |key|73client_paths << registry_getvaldata("#{client_exclusion_key}\\#{key}", 'DirectoryName', @registry_view)74end75end76print_exclusions_table(SEP, 'client path', client_paths)77end7879def excluded_defender80print_exclusions_table(DEFENDER, 'extension', registry_enumvals("#{DEFENDER_BASE_KEY}\\Exclusions\\Extensions", @registry_view))81print_exclusions_table(DEFENDER, 'path', registry_enumvals("#{DEFENDER_BASE_KEY}\\Exclusions\\Paths", @registry_view))82print_exclusions_table(DEFENDER, 'process', registry_enumvals("#{DEFENDER_BASE_KEY}\\Exclusions\\Processes", @registry_view))83end8485def excluded_mssec86print_exclusions_table(ESSENTIALS, 'extension', registry_enumvals("#{ESSENTIALS_BASE_KEY}\\Exclusions\\Extensions", @registry_view))87print_exclusions_table(ESSENTIALS, 'path', registry_enumvals("#{ESSENTIALS_BASE_KEY}\\Exclusions\\Paths", @registry_view))88print_exclusions_table(ESSENTIALS, 'process', registry_enumvals("#{ESSENTIALS_BASE_KEY}\\Exclusions\\Processes", @registry_view))89end9091def print_exclusions_table(product, exclusion_type, exclusions)92exclusions ||= []93exclusions = exclusions.compact.reject(&:blank?)94if exclusions.empty?95print_status("No #{exclusion_type} exclusions for #{product}")96return97end98table = Rex::Text::Table.new(99'Header' => "#{product} excluded #{exclusion_type.pluralize}",100'Indent' => 1,101'Columns' => [ exclusion_type.capitalize ]102)103exclusions.map { |exclusion| table << [exclusion] }104print_line(table.to_s)105end106107def setup108unless datastore['DEFENDER'] || datastore['ESSENTIALS'] || datastore['SEP']109fail_with(Failure::BadConfig, 'Must set one or more of DEFENDER, ESSENTIALS or SEP to true')110end111112# all of these target applications seemingly store their registry113# keys/values at the same architecture of the host, so if we happen to be114# in a 32-bit process on a 64-bit machine, ensure that we read from the115# 64-bit keys/values, and otherwise use the native keys/values116if sysinfo['Architecture'] == ARCH_X64 && session.arch == ARCH_X86117@registry_view = REGISTRY_VIEW_64_BIT118else119@registry_view = REGISTRY_VIEW_NATIVE120end121end122123def run124print_status("Enumerating Excluded Paths for AV on #{sysinfo['Computer']}")125126found = false127if datastore['DEFENDER'] && av_installed?(DEFENDER_BASE_KEY, DEFENDER)128found = true129excluded_defender130end131if datastore['ESSENTIALS'] && av_installed?(ESSENTIALS_BASE_KEY, ESSENTIALS)132found = true133excluded_mssec134end135if datastore['SEP'] && av_installed?(SEP_BASE_KEY, SEP)136found = true137excluded_sep138end139140print_error 'No supported AV identified' unless found141end142end143144145