Detection rules › Elastic

Encoded Powershell Execution via MsiExec

Source
github.com/elastic/protections-artifacts

Detects attempts to execute encoded powershell commands via Windows Installers.

MITRE ATT&CK coverage

Rule body

[rule]
description = "Detects attempts to execute encoded powershell commands via Windows Installers."
id = "5a7148dc-338a-4998-8adb-5b64d7557dfc"
license = "Elastic License v2"
name = "Encoded Powershell Execution via MsiExec"
os_list = ["windows"]
version = "1.0.3"

query = '''
process where event.action == "start" and
 (process.name : "powershell.exe" or process.pe.original_file_name == "PowerShell.EXE") and
 process.args : ("-e", "-enc", "-ec", "-encod", "-encode", "iex (gc *") and
 (
  descendant of [process where event.action == "start" and process.name : "msiexec.exe"] or
  process.parent.name : "msiexec.exe"
  )
'''

min_endpoint_version = "7.16.0"
[[actions]]
action = "kill_process"
field = "process.entity_id"
state = 0

[[actions]]
action = "kill_process"
field = "process.parent.entity_id"
state = 0

[[optional_actions]]
action = "rollback"
field = "process.entity_id"
state = 0

[[threat]]
framework = "MITRE ATT&CK"
[[threat.technique]]
id = "T1059"
name = "Command and Scripting Interpreter"
reference = "https://attack.mitre.org/techniques/T1059/"
[[threat.technique.subtechnique]]
id = "T1059.001"
name = "PowerShell"
reference = "https://attack.mitre.org/techniques/T1059/001/"



[threat.tactic]
id = "TA0002"
name = "Execution"
reference = "https://attack.mitre.org/tactics/TA0002/"
[[threat]]
framework = "MITRE ATT&CK"
[[threat.technique]]
id = "T1218"
name = "System Binary Proxy Execution"
reference = "https://attack.mitre.org/techniques/T1218/"
[[threat.technique.subtechnique]]
id = "T1218.007"
name = "Msiexec"
reference = "https://attack.mitre.org/techniques/T1218/007/"



[threat.tactic]
id = "TA0005"
name = "Defense Evasion"
reference = "https://attack.mitre.org/tactics/TA0005/"

[internal]
min_endpoint_version = "7.16.0"

Stages and Predicates

Stage 1: process

process where event.action == "start" and
 (process.name : "powershell.exe" or process.pe.original_file_name == "PowerShell.EXE") and
 process.args : ("-e", "-enc", "-ec", "-encod", "-encode", "iex (gc *") and
 (
  descendant of [process where event.action == "start" and process.name : "msiexec.exe"] or
  process.parent.name : "msiexec.exe"
  )

Indicators

These rows show field, operator, and value matches.

FieldKindValuesSearch
event.actioneq
  • start corpus 391 (elastic 391)
field:"EventType" kind:eq value:"start"
process.argswildcard
  • -e corpus 46 (elastic 46)
  • -ec
  • -enc corpus 2 (elastic 2)
  • -encod
  • -encode
  • iex (gc *
field:"process.args" kind:wildcard
process.namewildcard
  • powershell.exe corpus 184 (elastic 140, splunk 44)
field:"process_name" kind:wildcard value:"powershell.exe"
process.parent.namewildcard
  • msiexec.exe corpus 19 (elastic 14, splunk 3, kusto 2)
field:"parent_process_name" kind:wildcard value:"msiexec.exe"
process.pe.original_file_nameeq
  • PowerShell.EXE corpus 138 (sigma 84, splunk 30, elastic 24)
field:"OriginalFileName" kind:eq value:"PowerShell.EXE"