Detection rules › Elastic
Encoded Powershell Execution via MsiExec
Detects attempts to execute encoded powershell commands via Windows Installers.
MITRE ATT&CK coverage
| Tactic | Techniques |
|---|---|
| Execution | |
| Stealth |
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.
| Field | Kind | Values | Search |
|---|---|---|---|
event.action | eq |
| field:"EventType" kind:eq value:"start" |
process.args | wildcard |
| field:"process.args" kind:wildcard |
process.name | wildcard |
| field:"process_name" kind:wildcard value:"powershell.exe" |
process.parent.name | wildcard |
| field:"parent_process_name" kind:wildcard value:"msiexec.exe" |
process.pe.original_file_name | eq |
| field:"OriginalFileName" kind:eq value:"PowerShell.EXE" |