Detection rules › Splunk

PowerShell 4104 Hunting

Author
Michael Haag, Splunk
Source
upstream

The following analytic identifies suspicious PowerShell execution using Script Block Logging (EventCode 4104). It leverages specific patterns and keywords within the ScriptBlockText field to detect potentially malicious activities. This detection is significant for SOC analysts as PowerShell is commonly used by attackers for various malicious purposes, including code execution, privilege escalation, and persistence. If confirmed malicious, this activity could allow attackers to execute arbitrary commands, exfiltrate data, or maintain long-term access to the compromised system, posing a severe threat to the organization's security.

MITRE ATT&CK coverage

TacticTechniques
ExecutionT1059.001 Command and Scripting Interpreter: PowerShell

Event coverage

ProviderEvent IDTitle
PowerShell4104Creating Scriptblock text (MessageNumber of MessageTotal).

Stages and Predicates

Stage 1: search

search EventCode=4104

Stage 2: eval

eval ... using (ScriptBlockText)

Stage 3: eval

eval ... using (ScriptBlockText)

Stage 4: eval

eval ... using (ScriptBlockText)

Stage 5: eval

eval ... using (ScriptBlockText)

Stage 6: eval

eval ... using (ScriptBlockText)

Stage 7: eval

eval ... using (ScriptBlockText)

Stage 8: eval

eval ... using (ScriptBlockText)

Stage 9: eval

eval ... using (ScriptBlockText)

Stage 10: eval

eval ... using (ScriptBlockText)

Stage 11: eval

eval ... using (ScriptBlockText)

Stage 12: eval

eval ... using (ScriptBlockText)

Stage 13: eval

eval ... using (ScriptBlockText)

Stage 14: eval

eval ... using (ScriptBlockText)

Stage 15: eval

eval ... using (ScriptBlockText)

Stage 16: eval

eval ... using (ScriptBlockText)

Stage 17: eval

eval ... using (ScriptBlockText)

Stage 18: eval

eval ... using (ScriptBlockText)

Stage 19: eval

eval ... using (ScriptBlockText)

Stage 20: addtotals

addtotals

Stage 21: stats

stats BY UserID, Computer, DoIt, enccom, compressed, downgrade, iex, mimikatz, rundll32, empire, webclient, syswow64, httplocal, reflection, invokewmi, invokecmd, base64, get, suspcmdlet, suspkeywrd

Stage 22: rename

rename

Stage 23: search

search `macro`

Indicators

Each row is a field, operator, and value that the rule matches. The corpus column counts how many other rules in the catalog look for the same combination: high numbers point to widely-used, community-vetted indicators. Blank or 1 shows that the indicator is specific to this rule.

FieldKindValues
EventCodeeq
  • 4104 corpus 108 (splunk 108)

Neighbors

Stricter alternatives (narrower than this rule)

The rules below may be useful if you find the current rule is too noisy / lacks specificity.

Broader alternatives (more inclusive than this rule)

These rules match a superset of what this rule catches. They cover the same events plus more. Use them if you want wider coverage and can absorb more false positives.