Detection rules › Elastic

PowerShell Engine Loaded via Injection

Time window
1m
Sequence by
process.entity_id
Source
github.com/elastic/protections-artifacts

Identifies the PowerShell engine being invoked by unexpected processes. Instead of executing PowerShell functionality with powershell.exe, some attackers do this to operate more stealthily.

MITRE ATT&CK coverage

Rule body

[rule]
description = """
Identifies the PowerShell engine being invoked by unexpected processes. Instead of executing PowerShell functionality
with powershell.exe, some attackers do this to operate more stealthily.
"""
id = "c5473399-8d0b-4cf2-a1a2-0c856649396a"
license = "Elastic License v2"
name = "PowerShell Engine Loaded via Injection"
os_list = ["windows"]
version = "1.0.9"

query = '''
sequence by process.entity_id with maxspan=1m
 [process where event.action == "start" and 
  process.executable : "C:\\*" and 
  not process.Ext.token.integrity_level_name : "low" and 
  not process.executable : 
               ("?:\\Windows\\System32\\WindowsPowerShell\\*.exe", 
                "?:\\Windows\\SysWOW64\\WindowsPowerShell\\*.exe", 
                "?:\\Program Files\\*.exe", 
                "?:\\Program Files (x86)\\*.exe") and 
  not (process.code_signature.status : "trusted" and 
       process.pe.original_file_name : ("LegacyVSTSPowerShellHost.exe", "SqlIaaSExtensionDeployer.exe", "wacrun.exe")) and 
  not process.hash.sha256 :
                   ("07bc2c53c47cf691b8836af4e377990324e612df16de63644c8c3750e9a75a57",
                    "8b66483519a4be8e2cd4b9686ea465e2171731a7a91f623069046450f22b7a39",
                    "2232525e0e8ba5d5877198fbe3589cc8a90b03054ee69e7f7d7c37761a88741f") and
  not process.pe.imphash in ("d41d8cd98f00b204e9800998ecf8427e", "45e4653ae633e067079dd72666b0158b") and
  not (process.code_signature.status : "trusted" and 
       process.code_signature.subject_name : 
            ("Citrix Systems, Inc.", "Veeam Software Group GmbH", "ScriptRunner Software GmbH", "Microsoft 3rd Party Application Component", 
             "Atera Networks Ltd", "Chocolatey Software, Inc.", "Chocolatey Software, Inc", "Datto Inc", "Datto, LLC", "Dell Technologies Inc.",
             "Syxsense Inc.")) and
  not (process.executable : "?:\\Windows\\Microsoft.NET\\Framework64\\*\\mscorsvw.exe" and
       process.parent.executable : "?:\\Windows\\Microsoft.NET\\Framework64\\*\\ngen.exe") and
  process.parent.thread.Ext.call_stack_summary : 
                    ("ntdll.dll|Unbacked", 
                     "ntdll.dll|kernelbase.dll|Unbacked",
                     "ntdll.dll|kernelbase.dll|kernel32.dll|Unbacked",
                     "ntdll.dll|wow64.dll|wow64cpu.dll|wow64.dll|ntdll.dll|kernelbase.dll|Unbacked",
                     "ntdll.dll|wow64.dll|wow64cpu.dll|wow64.dll|ntdll.dll|kernelbase.dll|Unbacked|kernel32.dll|ntdll.dll") and 
   not _arraysearch(process.parent.thread.Ext.call_stack, $entry, 
                    $entry.callsite_trailing_bytes : ("488b556*c6420c01833d*", "48894550488b4d18488b455048894110488b4528ff5040*"))]
 [library where dll.name : ("System.Management.Automation.ni.dll", "System.Management.Automation.dll")]
'''

min_endpoint_version = "8.8.0"
optional_actions = []
[[actions]]
action = "kill_process"
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/"

[internal]
min_endpoint_version = "8.8.0"

Stages and Predicates

Ordered sequence: each step below must occur in order within 1m, correlated by process.entity_id.

Stage 1: process

[process where event.action == "start" and 
  process.executable : "C:\\*" and 
  not process.Ext.token.integrity_level_name : "low" and 
  not process.executable : 
               ("?:\\Windows\\System32\\WindowsPowerShell\\*.exe", 
                "?:\\Windows\\SysWOW64\\WindowsPowerShell\\*.exe", 
                "?:\\Program Files\\*.exe", 
                "?:\\Program Files (x86)\\*.exe") and 
  not (process.code_signature.status : "trusted" and 
       process.pe.original_file_name : ("LegacyVSTSPowerShellHost.exe", "SqlIaaSExtensionDeployer.exe", "wacrun.exe")) and 
  not process.hash.sha256 :
                   ("07bc2c53c47cf691b8836af4e377990324e612df16de63644c8c3750e9a75a57",
                    "8b66483519a4be8e2cd4b9686ea465e2171731a7a91f623069046450f22b7a39",
                    "2232525e0e8ba5d5877198fbe3589cc8a90b03054ee69e7f7d7c37761a88741f") and
  not process.pe.imphash in ("d41d8cd98f00b204e9800998ecf8427e", "45e4653ae633e067079dd72666b0158b") and
  not (process.code_signature.status : "trusted" and 
       process.code_signature.subject_name : 
            ("Citrix Systems, Inc.", "Veeam Software Group GmbH", "ScriptRunner Software GmbH", "Microsoft 3rd Party Application Component", 
             "Atera Networks Ltd", "Chocolatey Software, Inc.", "Chocolatey Software, Inc", "Datto Inc", "Datto, LLC", "Dell Technologies Inc.",
             "Syxsense Inc.")) and
  not (process.executable : "?:\\Windows\\Microsoft.NET\\Framework64\\*\\mscorsvw.exe" and
       process.parent.executable : "?:\\Windows\\Microsoft.NET\\Framework64\\*\\ngen.exe") and
  process.parent.thread.Ext.call_stack_summary : 
                    ("ntdll.dll|Unbacked", 
                     "ntdll.dll|kernelbase.dll|Unbacked",
                     "ntdll.dll|kernelbase.dll|kernel32.dll|Unbacked",
                     "ntdll.dll|wow64.dll|wow64cpu.dll|wow64.dll|ntdll.dll|kernelbase.dll|Unbacked",
                     "ntdll.dll|wow64.dll|wow64cpu.dll|wow64.dll|ntdll.dll|kernelbase.dll|Unbacked|kernel32.dll|ntdll.dll") and 
   not _arraysearch(process.parent.thread.Ext.call_stack, $entry, 
                    $entry.callsite_trailing_bytes : ("488b556*c6420c01833d*", "48894550488b4d18488b455048894110488b4528ff5040*"))]

Stage 2: library

[library where dll.name : ("System.Management.Automation.ni.dll", "System.Management.Automation.dll")]

Exclusions

The rule actively suppresses these predicates.

FieldKindExcluded valuesSearch
process.code_signature.statuseqtrustedexcludes:process.code_signature.status field:"process.code_signature.status" value:"trusted"
process.code_signature.subject_nameeqCitrix Systems, Inc., Veeam Software Group GmbH, ScriptRunner Software GmbH, Microsoft 3rd Party Application Component, Atera Networks Ltd, Chocolatey Software, Inc., Chocolatey Software, Inc, Datto Inc, Datto, LLC, Dell Technologies Inc., Syxsense Inc.excludes:process.code_signature.subject_name
process.pe.original_file_nameeqLegacyVSTSPowerShellHost.exe, SqlIaaSExtensionDeployer.exe, wacrun.exeexcludes:process.pe.original_file_name field:"process.pe.original_file_name" value:"LegacyVSTSPowerShellHost.exe" field:"process.pe.original_file_name" value:"SqlIaaSExtensionDeployer.exe" field:"process.pe.original_file_name" value:"wacrun.exe"
process.executablewildcard?:\Windows\Microsoft.NET\Framework64\*\mscorsvw.exeexcludes:process.executable field:"process.executable" value:"?:\Windows\Microsoft.NET\Framework64\*\mscorsvw.exe"
process.parent.executablewildcard?:\Windows\Microsoft.NET\Framework64\*\ngen.exeexcludes:process.parent.executable field:"process.parent.executable" value:"?:\Windows\Microsoft.NET\Framework64\*\ngen.exe"
process.parent.thread.Ext.call_stackarray_any(no value, null check)excludes:process.parent.thread.Ext.call_stack
process.Ext.token.integrity_level_nameeqlowexcludes:process.Ext.token.integrity_level_name field:"process.Ext.token.integrity_level_name" value:"low"
process.executablewildcard?:\Windows\System32\WindowsPowerShell\*.exe, ?:\Windows\SysWOW64\WindowsPowerShell\*.exe, ?:\Program Files\*.exe, ?:\Program Files (x86)\*.exeexcludes:process.executable
process.hash.sha256eq07bc2c53c47cf691b8836af4e377990324e612df16de63644c8c3750e9a75a57, 8b66483519a4be8e2cd4b9686ea465e2171731a7a91f623069046450f22b7a39, 2232525e0e8ba5d5877198fbe3589cc8a90b03054ee69e7f7d7c37761a88741fexcludes:process.hash.sha256 field:"process.hash.sha256" value:"07bc2c53c47cf691b8836af4e377990324e612df16de63644c8c3750e9a75a57" field:"process.hash.sha256" value:"8b66483519a4be8e2cd4b9686ea465e2171731a7a91f623069046450f22b7a39" field:"process.hash.sha256" value:"2232525e0e8ba5d5877198fbe3589cc8a90b03054ee69e7f7d7c37761a88741f"
process.pe.imphashin45e4653ae633e067079dd72666b0158b, d41d8cd98f00b204e9800998ecf8427eexcludes:process.pe.imphash field:"process.pe.imphash" value:"45e4653ae633e067079dd72666b0158b" field:"process.pe.imphash" value:"d41d8cd98f00b204e9800998ecf8427e"

Indicators

These rows show field, operator, and value matches.

FieldKindValuesSearch
dll.namewildcard
  • System.Management.Automation.dll corpus 5 (elastic 5)
  • System.Management.Automation.ni.dll corpus 2 (elastic 2)
field:"dll.name" kind:wildcard
event.actioneq
  • start corpus 391 (elastic 391)
field:"EventType" kind:eq value:"start"
process.executablewildcard
  • C:\* corpus 16 (elastic 16)
field:"Image" kind:wildcard value:"C:\*"
process.parent.thread.Ext.call_stack_summarywildcard
  • ntdll.dll|Unbacked corpus 3 (elastic 3)
  • ntdll.dll|kernelbase.dll|Unbacked corpus 4 (elastic 4)
  • ntdll.dll|kernelbase.dll|kernel32.dll|Unbacked corpus 3 (elastic 3)
  • ntdll.dll|wow64.dll|wow64cpu.dll|wow64.dll|ntdll.dll|kernelbase.dll|Unbacked corpus 4 (elastic 4)
  • ntdll.dll|wow64.dll|wow64cpu.dll|wow64.dll|ntdll.dll|kernelbase.dll|Unbacked|kernel32.dll|ntdll.dll corpus 4 (elastic 4)
field:"process.parent.thread.Ext.call_stack_summary" kind:wildcard