Skip to content

Defender Exclusions: Cover for Windows Persistence

How attackers add Microsoft Defender exclusions or switch protection off so their persistence survives scans, and how to find, judge and remove the changes.

MITRE ATT&CK
T1562.001
Tactics
Defense evasion
Runs
Always in effect
Set up by
Administrators
Locations
  • HKLM\SOFTWARE\Microsoft\Windows Defender\Exclusions
  • HKLM\SOFTWARE\Policies\Microsoft\Windows Defender\Exclusions
  • HKLM\SOFTWARE\Microsoft\Windows Defender\Real-Time Protection
  • HKLM\SOFTWARE\Policies\Microsoft\Windows Defender
  • HKLM\SOFTWARE\Policies\Microsoft\Windows Defender\Real-Time Protection

How it works

Microsoft Defender Antivirus skips whatever is excluded. An exclusion is not persistence on its own: it is the cover that keeps persistence alive. A payload in an excluded folder is not scanned when it is written, when a Run key, service or task starts it, or when the next full scan runs with new signatures. The other half of the same technique is protection switched off: real-time or behaviour monitoring disabled, or Defender turned off by policy. ATT&CK files both under T1562.001, Impair Defenses: Disable or Modify Tools.

Custom exclusions come in four kinds:

KindWhat Defender skips
PathOne file, or a folder and everything below it. Wildcards (*, ?) and environment variables are allowed
ExtensionEvery file with that extension, anywhere on the machine
ProcessEvery file that process opens, matched by image name or by full path; the process's own file is still scanned unless its path is excluded too
IP addressTraffic to or from the address, for network inspection

Exclusions apply to real-time protection and to scheduled and on-demand scans. Because the Defender service runs as LocalSystem, environment variables in an exclusion resolve as SYSTEM: %TEMP% is C:\Windows\Temp, not a user's temp folder.

Settings come from two places, merged by default. Local settings (the Windows Security app, Add-MpPreference and Set-MpPreference, the MSFT_MpPreference WMI class) are stored under HKLM\SOFTWARE\Microsoft\Windows Defender. Group Policy and other management tools write HKLM\SOFTWARE\Policies\Microsoft\Windows Defender. The DisableLocalAdminMerge setting makes Defender ignore local exclusions.

Tamper Protection, when on, blocks changes to real-time protection, behaviour monitoring, cloud protection and other protected settings made through the registry or policy, and logs event 5013. It protects exclusion lists only on organisation-managed devices that meet specific conditions; elsewhere an administrator can still add an exclusion. Microsoft also discontinued DisableAntiSpyware on client Windows with Defender platform 4.18.2007.8 (August 2020): current Defender ignores it there, though the value still shows what someone attempted.

Where it lives

KeyContent
HKLM\SOFTWARE\Microsoft\Windows Defender\Exclusions\Paths, Extensions, Processes, IpAddresses, TemporaryPathsLocal exclusions: one value per exclusion, named after it, DWORD 0
HKLM\SOFTWARE\Policies\Microsoft\Windows Defender\Exclusions\Paths, Extensions, ProcessesExclusions set by policy, same layout
HKLM\SOFTWARE\Microsoft\Windows Defender\Real-Time ProtectionLocal switches such as DisableRealtimeMonitoring
HKLM\SOFTWARE\Policies\Microsoft\Windows DefenderDisableAntiSpyware and the policy subkeys
HKLM\SOFTWARE\Policies\Microsoft\Windows Defender\Real-Time ProtectionPolicy switches: DisableRealtimeMonitoring, DisableBehaviorMonitoring, DisableIOAVProtection, DisableOnAccessProtection, DisableScriptScanning

On a stock Windows 10 or 11 install the exclusion lists are empty and the policy key holds nothing that turns protection off. Built-in exclusions for Windows' own files, and the automatic exclusions Windows Server adds for its roles, are not stored in these lists.

Only administrators can add exclusions. Defender guards its own key, so administrators change local settings through its interfaces rather than by writing the registry; the policy key is an ordinary key that any administrator can write, which is why attackers use it too.

How attackers use it

Droppers in commodity malware and ransomware intrusions commonly add an exclusion before writing the payload, or switch protection off, with one PowerShell command each:

Add-MpPreference -ExclusionPath 'C:\ProgramData\SysCache'
Add-MpPreference -ExclusionProcess 'svch0st.exe'
Add-MpPreference -ExclusionExtension '.ps1'
Set-MpPreference -DisableRealtimeMonitoring $true

The policy key gives the same result without Defender's cmdlets, and remote tools reach the same settings through the MSFT_MpPreference class in the root\Microsoft\Windows\Defender WMI namespace:

reg add "HKLM\SOFTWARE\Policies\Microsoft\Windows Defender\Exclusions\Paths" /v "C:\ProgramData\SysCache" /t REG_SZ /d 0 /f

Patterns to recognise:

  • A folder exclusion for the persistence payload's folder, often named like vendor software, followed minutes later by a Run key, service or scheduled task starting a program inside it.
  • Whole drives or broad folders (C:\, C:\Users, C:\ProgramData), so any later tool lands somewhere excluded.
  • Process exclusions for interpreters (powershell.exe, rundll32.exe), so whatever they load or write goes unscanned.
  • Executable or script extensions, which blind Defender to a whole file type.

How to check a host

On a live machine, from an elevated prompt (recent Defender versions hide the exclusion lists from other users):

Get-MpPreference | Select-Object ExclusionPath, ExclusionProcess, ExclusionExtension, ExclusionIpAddress, DisableRealtimeMonitoring, DisableBehaviorMonitoring
Get-MpComputerStatus | Select-Object AMRunningMode, RealTimeProtectionEnabled, BehaviorMonitorEnabled, IsTamperProtected
reg query "HKLM\SOFTWARE\Policies\Microsoft\Windows Defender" /s
Get-WinEvent -FilterHashtable @{ LogName = 'Microsoft-Windows-Windows Defender/Operational'; Id = 5001, 5007, 5013 }

Every exclusion should have an owner and a reason: a documented requirement of line-of-business software, a backup agent, a server role. One that nobody can explain is a finding.

Offline, read the Exclusions subkeys from the SOFTWARE hive in the collection. Each kind has its own key, so the last-write time of Exclusions\Paths is the last time a path exclusion was added or removed. The Defender Operational log (Microsoft-Windows-Windows Defender%4Operational.evtx) records each change as event 5007, with the old and new values, such as the full registry path of a new exclusion. Event 5001 means real-time protection was switched off, and 5013 that Tamper Protection blocked a change. Line these up with process creation (Security 4688, Sysmon 1) to see which command made the change and from which account.

Suspicious: folders users can write to, whole drives, process exclusions for interpreters or for names imitating Windows programs, executable extensions, exclusions created just before other persistence, and real-time protection off on a machine with no other antivirus.

What Windows Persistence flags

parseDefender reads, from the SOFTWARE hive, the local and the policy exclusion lists (Paths, Processes, Extensions, IpAddresses, TemporaryPaths), one entry per exclusion with policy entries marked "Group Policy" and the value shown with its real type. Environment variables in paths are expanded as SYSTEM, the way Defender does (%APPDATA% becomes C:\Windows\System32\config\systemprofile\AppData\Roaming). Each exclusion raises Defender exclusion (kind):

  • High for a drive root or exactly C:\Users, C:\Windows, C:\Program Files or C:\ProgramData; a folder ordinary users can write to, or any folder named Temp; any process exclusion; and the extensions exe, dll, ps1, bat, cmd, vbs, js, scr and hta.
  • Medium otherwise.

Defender protection switched off (high) fires when one of these is 1, in the policy key or the local one: DisableAntiSpyware, or under Real-Time Protection any of DisableRealtimeMonitoring, DisableBehaviorMonitoring, DisableIOAVProtection, DisableOnAccessProtection and DisableScriptScanning. None of these entries is a Windows default, so "Hide Windows entries" never hides them, and Written date marks a list changed in the 7 days before the newest time seen on that host.

The cross-check is the point of this page. Every other entry whose program is covered gets Inside a Defender exclusion (exclusion) (high): the program is an excluded file, sits under an excluded folder, matches a path with * or ? wildcards, has an excluded extension, or matches a process exclusion (a full path at that path only, a bare name anywhere). For a process exclusion the flag's explanation says what Defender actually skips: not the program file, but what the process opens. Separately, Changes Defender settings (high) flags autostart command lines that run Set-MpPreference or Add-MpPreference with a -Disable… or -Exclusion… parameter.

Limits: wildcards are matched approximately. The tool lets * span several folders and tests the program and its own folder, while Defender's * in a folder path stands for exactly one folder and also covers the subfolders below it; check wildcard matches by hand. The tool does not read Tamper Protection, DisableLocalAdminMerge, attack surface reduction exclusions, Controlled folder access allowed apps, or whether another antivirus has put Defender in passive mode.

Cleaning up

  1. Preserve: export both keys with reg export, save the Get-MpPreference output and the Defender log (wevtutil epl "Microsoft-Windows-Windows Defender/Operational" defender.evtx).
  2. Collect what the exclusion hid before removing it. Once the exclusion goes, Defender may quarantine the payload and you lose the sample and its timestamps.
  3. Remove local exclusions with Remove-MpPreference -ExclusionPath 'C:\ProgramData\SysCache' (or -ExclusionProcess, -ExclusionExtension) and restore protection with Set-MpPreference -DisableRealtimeMonitoring $false. Delete attacker-made values under the policy key; if they come from a domain GPO, fix the GPO, or they return at the next refresh.
  4. Update signatures and scan: Update-MpSignature, then Start-MpScan -ScanType FullScan.
  5. Remove the persistence the exclusion was protecting: every entry marked as inside it, using the page for its mechanism.
  6. Turn Tamper Protection on, find how the attacker obtained administrator rights, and leave documented business exclusions in place.

See also

On Windows Forensics

The artifacts behind this technique, in the Windows Forensics reference: