Detection rules › Splunk

Powershell Windows Defender Exclusion Commands

Status
production
Severity
low
Group by
Guid, Name, Opcode, Path, ScriptBlockId, ScriptBlockText, dest, process_id, signature, signature_id, user_id, vendor_product
Author
Teoderick Contreras, Splunk
Source
github.com/splunk/security_content

The following analytic detects the use of PowerShell commands to add or set Windows Defender exclusions. It leverages EventCode 4104 to identify suspicious Add-MpPreference or Set-MpPreference commands with exclusion parameters. This activity is significant because adversaries often use it to bypass Windows Defender, allowing malicious code to execute without detection. If confirmed malicious, this behavior could enable attackers to evade antivirus defenses, maintain persistence, and execute further malicious activities undetected.

Known false positives

  • admin or user may choose to use this windows features.

MITRE ATT&CK coverage

TacticTechniques
Defense Impairment

Telemetry coverage

Rule body

name: Powershell Windows Defender Exclusion Commands
id: 907ac95c-4dd9-11ec-ba2c-acde48001122
version: 17
creation_date: '2021-11-25'
modification_date: '2026-06-29'
author: Teoderick Contreras, Splunk
status: production
type: Anomaly
description: |-
    The following analytic detects the use of PowerShell commands to add or set Windows Defender exclusions.
    It leverages EventCode 4104 to identify suspicious `Add-MpPreference` or `Set-MpPreference` commands with exclusion parameters.
    This activity is significant because adversaries often use it to bypass Windows Defender, allowing malicious code to execute without detection.
    If confirmed malicious, this behavior could enable attackers to evade antivirus defenses, maintain persistence, and execute further malicious activities undetected.
data_source:
    - Powershell Script Block Logging 4104
search: |-
    `powershell`
    EventCode=4104
    ScriptBlockText IN (
        "*Add-MpPreference *",
        "*Set-MpPreference *"
    )
    ScriptBlockText = "*-exclusion*"
    | fillnull
    | stats count min(_time) as firstTime
                  max(_time) as lastTime
      by dest signature signature_id
         user_id vendor_product EventID
         Guid Opcode Name
         Path ProcessID ScriptBlockId
         ScriptBlockText
    | `security_content_ctime(firstTime)`
    | `security_content_ctime(lastTime)`
    | `powershell_windows_defender_exclusion_commands_filter`
how_to_implement: To successfully implement this search you need to be ingesting information on process that include the name of the process responsible for the changes from your endpoints into the `Endpoint` datamodel in the `Registry` node. Also make sure that this registry was included in your config files ex. sysmon config to be monitored.
known_false_positives: admin or user may choose to use this windows features.
references:
    - https://tccontre.blogspot.com/2020/01/remcos-rat-evading-windows-defender-av.html
    - https://app.any.run/tasks/cf1245de-06a7-4366-8209-8e3006f2bfe5/
    - https://www.microsoft.com/security/blog/2022/01/15/destructive-malware-targeting-ukrainian-organizations/
intermediate_findings:
    entities:
        - field: dest
          type: system
          score: 20
          message: A suspicious powershell script with the ScriptBlockId [$ScriptBlockId$] containing exclusion commands to add or set Windows Defender exclusions was executed on host $dest$
        - field: user_id
          type: user
          score: 20
          message: A suspicious powershell script with the ScriptBlockId [$ScriptBlockId$] containing exclusion commands to add or set Windows Defender exclusions was executed on host $dest$ by user $user_id$
analytic_story:
    - CISA AA22-320A
    - AgentTesla
    - Remcos
    - Windows Defense Evasion Tactics
    - Data Destruction
    - WhisperGate
    - Warzone RAT
    - NetSupport RMM Tool Abuse
    - BlankGrabber Stealer
    - Salat Stealer
asset_type: Endpoint
mitre_attack_id:
    - T1685
product:
    - Splunk Enterprise
    - Splunk Enterprise Security
    - Splunk Cloud
category: endpoint
security_domain: endpoint

Stages and Predicates

Stage 1: search

`powershell`
EventCode=4104
ScriptBlockText IN (
    "*Add-MpPreference *",
    "*Set-MpPreference *"
)
ScriptBlockText = "*-exclusion*"

Stage 2: fillnull

| fillnull

Stage 3: stats

| stats count min(_time) as firstTime
              max(_time) as lastTime
  by dest signature signature_id
     user_id vendor_product EventID
     Guid Opcode Name
     Path ProcessID ScriptBlockId
     ScriptBlockText

Stage 4: search

| `security_content_ctime(firstTime)`

Stage 5: search

| `security_content_ctime(lastTime)`

Stage 6: search

| `powershell_windows_defender_exclusion_commands_filter`

Indicators

These rows show field, operator, and value matches.

FieldKindValuesSearch
EventCodeeq
  • 4104 corpus 269 (splunk 269)
field:"EventID" kind:eq value:"4104"
ScriptBlockTexteq
  • "*-exclusion*"
field:"ScriptBlockText" kind:eq
ScriptBlockTextin
  • "*Add-MpPreference *"
  • "*Set-MpPreference *"
field:"ScriptBlockText" kind:in