PowerShell Script with Windows Defender Tampering Capabilities
Detects PowerShell scripts that uses Set-MpPreference with parameters that disable or weaken Defender. Attackers tamper with antivirus settings to reduce detection and enable follow-on payload execution.
Rule type: query
Rule indices:
- winlogbeat-*
- logs-windows.powershell*
Rule Severity: medium
Risk Score: 47
Runs every:
Searches indices from: now-9m
Maximum alerts per execution: 100
References:
Tags:
- Domain: Endpoint
- OS: Windows
- Use Case: Threat Detection
- Tactic: Defense Evasion
- Data Source: PowerShell Logs
- Resources: Investigation Guide
Version: 107
Rule authors:
- Elastic
Rule license: Elastic License v2
PowerShell Script Block Logging must be enabled to generate the events used by this rule (e.g., 4104). Setup instructions: https://ela.st/powershell-logging-setup
Disclaimer: This guide was created by humans with the assistance of generative AI. While its contents have been manually curated to include the most valuable information, always validate assumptions and adjust procedures to match your internal runbooks and incident triage and response policies.
This alert highlights PowerShell script block activity that attempts to change Windows Defender preferences in ways that can reduce host protections. These changes are frequently used to create a window for follow-on execution (for example, staging payloads, running tools, or maintaining access with reduced scanning and response).
Triage should focus on (1) what protections were targeted and how, (2) who initiated the change and on which host(s), (3) whether the change took effect and persisted, and (4) whether there is surrounding activity that suggests initial access or follow-on malicious actions.
user.name,user.domain,user.id: Account execution context for correlation, prioritization, and scoping.host.name,host.id: Host execution context for correlation, prioritization, and scoping.powershell.file.script_block_text: Script block content that matched the detection logic.powershell.file.script_block_id,powershell.sequence,powershell.total: Script block metadata to pivot to other fragments or reconstruct full script content when split across multiple events.file.path,file.directory,file.name: File-origin context when the script block is sourced from an on-disk file.powershell.file.script_block_length: Script block length (size) context.
Review the script block content and determine the intended Defender impact:
- Inspect
powershell.file.script_block_textand enumerate eachSet-MpPreferenceparameter present. - Capture whether the script is disabling protections (for example, real-time monitoring, script scanning, network file scanning) or changing default threat actions (low/moderate/high) to more permissive outcomes.
- Note whether the script changes multiple settings in one execution, repeats the changes, or includes additional logic that suggests deliberate defense impairment rather than a single configuration adjustment.
- Inspect
Reconstruct full script content when it is split across multiple events:
- If
powershell.totalis greater than 1, pivot onpowershell.file.script_block_idand order fragments bypowershell.sequenceto rebuild the full script. - Ensure you capture all fragments for the same
powershell.file.script_block_idon the samehost.idanduser.idnear the alert time; missing fragments can hide follow-on behavior embedded in later chunks.
- If
Establish scope across hosts and accounts:
- Use
@timestamp,host.name/host.id, anduser.name/user.domain/user.idto determine whether the activity is isolated or distributed. - Look for the same user context making similar changes across multiple hosts in a short time window (suggesting automation or compromised credentials).
- Look for multiple distinct user contexts making similar changes on the same host (suggesting lateral movement or multiple access paths).
- Use
Determine the execution and origin context:
- If
file.pathorfile.nameis populated, treat the activity as file-backed scripting and capture the location for scoping (where else this script exists, who can write to it, and when it was last introduced). - If the file fields are not populated, treat the activity as potentially interactive or dynamically generated content and expand the search for adjacent script blocks from the same
user.idon the samehost.idaround@timestampto identify staging, execution flow, or repeated attempts.
- If
Validate whether Defender settings were actually changed and whether the change persisted:
- Using available endpoint security telemetry and configuration auditing, validate whether the targeted preferences were applied on the affected host(s) and whether they remained in the weakened state after the alert time.
- Compare against your approved baseline for Defender settings and identify deviations that would materially reduce protection coverage.
Correlate with adjacent activity to identify initial access and follow-on execution:
- Correlate by
host.idand time to nearby process activity to identify the PowerShell host process and its launching context (interactive use vs scheduled/automated execution vs another process initiating PowerShell). - Review file and network telemetry around the same time for indicators of payload staging or execution (new files written, unusual outbound connections, or repeated attempts after the change).
- Check for repeated Defender preference modifications over time on the same host (suggesting persistent tampering) and for other suspicious activity tied to the same
user.id.
- Correlate by
Legitimate activity can modify Defender preferences, but it should be explainable, consistent, and controlled.
Common benign drivers:
- Approved endpoint management or administrative maintenance that adjusts scanning behavior for performance or operational compatibility.
- Controlled troubleshooting where settings are temporarily changed and later restored.
Validation questions to reduce uncertainty:
- Does
user.idmap to an expected administrative or management identity for this host population? - Is the activity aligned with known maintenance windows, change records, and documented procedures?
- Is
file.path(when present) consistent with a known, maintained script location, and does the script content align with an approved baseline?
- Does
If the activity is benign, document the owner, expected scope (hosts/users), expected recurrence, and the intended steady-state protection posture.
If the activity is unauthorized or suspicious, treat it as a defense evasion attempt with potential follow-on actions.
Contain and preserve evidence:
- Prioritize affected endpoints identified by
host.id/host.nameand preserve relevant evidence, including the full reconstructed script frompowershell.file.script_block_idandpowershell.file.script_block_text. - Capture the initiating identity context (
user.name,user.domain,user.id) for incident scoping and credential review.
- Prioritize affected endpoints identified by
Restore protections and eliminate the change source:
- Restore Windows Defender preferences to the approved baseline using authorized operational processes and verify protections are active.
- If
file.pathis present, identify the responsible script and remove or disable unauthorized automation that applies the changes. - If the activity appears user-driven or interactive, investigate how the user obtained execution capability on the host and address the root cause.
Address potential account compromise and lateral movement:
- Review recent activity associated with the initiating account and affected hosts for signs of credential misuse, unexpected access patterns, or follow-on execution.
- Apply appropriate credential remediation for impacted identities and review privileged access assignments relevant to the affected endpoints.
Scope and monitor:
- Hunt for the same Defender-tampering parameters within
powershell.file.script_block_textacross other hosts and users to identify additional impacted systems. - Continue monitoring for recurrence of similar preference changes tied to the same
user.id, as repeated tampering may indicate persistence or an active intrusion.
- Hunt for the same Defender-tampering parameters within
event.category: "process" and host.os.type:windows and
(
powershell.file.script_block_text: "Set-MpPreference" and
powershell.file.script_block_text: (
DisableArchiveScanning or DisableBehaviorMonitoring or
DisableIntrusionPreventionSystem or DisableIOAVProtection or
DisableRemovableDriveScanning or DisableBlockAtFirstSeen or
DisableScanningMappedNetworkDrivesForFullScan or
DisableScanningNetworkFiles or DisableScriptScanning or
DisableRealtimeMonitoring or LowThreatDefaultAction or
ModerateThreatDefaultAction or HighThreatDefaultAction
)
) and
not powershell.file.script_block_text : (
("cmdletization" and "cdxml-Help.xml") or
("function Set-MpPreference" and "Microsoft.PowerShell.Cmdletization.GeneratedTypes.MpPreference.SubmitSamplesConsentType")
) and
not file.directory : "C:\ProgramData\Microsoft\Windows Defender Advanced Threat Protection\SenseCM" and
not user.id : "S-1-5-18"
Framework: MITRE ATT&CK
Tactic:
- Name: Defense Evasion
- Id: TA0005
- Reference URL: https://attack.mitre.org/tactics/TA0005/
Technique:
- Name: Impair Defenses
- Id: T1562
- Reference URL: https://attack.mitre.org/techniques/T1562/
Sub Technique:
- Name: Disable or Modify Tools
- Id: T1562.001
- Reference URL: https://attack.mitre.org/techniques/T1562/001/
Framework: MITRE ATT&CK
Tactic:
- Name: Execution
- Id: TA0002
- Reference URL: https://attack.mitre.org/tactics/TA0002/
Technique:
- Name: Command and Scripting Interpreter
- Id: T1059
- Reference URL: https://attack.mitre.org/techniques/T1059/
Sub Technique:
- Name: PowerShell
- Id: T1059.001
- Reference URL: https://attack.mitre.org/techniques/T1059/001/