Skip to content

[Rule Tuning] PowerShell Script with Windows Defender Tampering Capabilities: misses "-DisableRealtimeMonitoring" (analyzer keeps the leading dash) #7272

Backlog

Description

@ahmed-aoc

Link to Rule

https://github.com/elastic/detection-rules/blob/main/rules/windows/defense_evasion_posh_defender_tampering.toml

Rule Tuning Type

False Negatives - Enhancing detection of true threats that were previously missed.

Description

The rule misses the most common way of running this technique: Set-MpPreference -DisableRealtimeMonitoring $true.

powershell.file.script_block_text in logs-windows.powershell* uses powershell_script_analyzer, which keeps a leading hyphen on parameter names. _analyze on a current backing index:

POST .ds-logs-windows.powershell-default-*/_analyze
{ "field": "powershell.file.script_block_text",
  "text": "Set-MpPreference -DisableRealtimeMonitoring $true" }

returns the tokens set-mppreference, -disablerealtimemonitoring, true.

The rule lists the parameters as unquoted KQL terms (DisableRealtimeMonitoring or DisableIOAVProtection or ...). Those are searched as disablerealtimemonitoring, which does not equal the stored token -disablerealtimemonitoring. So the rule only fires when the name appears without a dash (for example $p.DisableRealtimeMonitoring or a splatting hashtable), and not for the normal command-line form attackers and admins actually type.

We confirmed this with rule preview: a 4104 script block containing Set-MpPreference -DisableRealtimeMonitoring $true -DisableIOAVProtection $true (non-SYSTEM user) produced no alert.

Suggested fix: also match the quoted dash form of each parameter, for example:

powershell.file.script_block_text: (
  DisableArchiveScanning or "-DisableArchiveScanning" or
  DisableBehaviorMonitoring or "-DisableBehaviorMonitoring" or
  ...
  DisableRealtimeMonitoring or "-DisableRealtimeMonitoring" or
  ...
  HighThreatDefaultAction or "-HighThreatDefaultAction"
)

With that change the same script block alerts in preview, the existing S-1-5-18 exclusion still applies, and 30 days of real PowerShell logs in our environment produced no new matches (no extra noise).

We checked the other KQL rules on script_block_text for the same issue. Terms such as API names (VirtualAlloc, MiniDumpWriteDump), $variables and quoted strings tokenize cleanly, so this seems limited to rules that match PowerShell parameter names. Potential Invoke-Mimikatz PowerShell Script also lists DumpCreds/DumpCerts, but it still fires on the script body ([Switch]$DumpCreds) and on the sekurlsa:: style commands, so it is not affected in practice.

Example Data

{
  "event.category": ["process"],
  "event.code": "4104",
  "host.os.type": "windows",
  "user.id": "S-1-5-21-1111111111-2222222222-3333333333-1001",
  "powershell.file.script_block_text": "Set-MpPreference -DisableRealtimeMonitoring $true -DisableIOAVProtection $true"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions