Detection rules › Elastic
Execution via Obfuscated PowerShell Script
Identifies the execution of PowerShell with potentially obfuscated content. This behavior is often observed during malware installation leveraging PowerShell.
MITRE ATT&CK coverage
| Tactic | Techniques |
|---|---|
| Execution |
Rule body
[rule]
description = """
Identifies the execution of PowerShell with potentially obfuscated content. This behavior is often observed during
malware installation leveraging PowerShell.
"""
id = "ce95fc52-051e-4409-9c99-f2daf3e6e609"
license = "Elastic License v2"
name = "Execution via Obfuscated PowerShell Script"
os_list = ["windows"]
version = "1.0.11"
query = '''
api where process.Ext.api.name == "AmsiScanBuffer" and
process.name : "powershell.exe" and user.id != "S-1-5-18" and
/* obfuscated content */
process.Ext.api.parameters.buffer : ("*-bxor*", "*:sptth*", "*//:p##h*", "*.rEplAcE(([chAr]*", "*$pShOMe[*", "*$ShellId[*", "*$env:Public[*",
"*$env:ComSpec[*", "*ecalper-*", "*]rahc[*", "*NoiSsErpXe-eKoVNi*", "*elbairav-*", "*ECNErEFERpESObREv$*", "*.Name[3,11,2]*",
"*sailA-teS*", "*]rtPtnI[*", "*-ekovnI*", "*TVqQAAMAAAAEAAAA*", "*System.Management.Automation.$([cHAr]*") and
not (process.Ext.api.parameters.buffer : "*-bxor*" and process.Ext.api.parameters.buffer : "#powershellskript *") and
not (process.Ext.api.parameters.buffer : "*-bxor*" and process.Ext.api.parameters.buffer : ("*-bxor 0xFFFF0000*", "*Ansible.Basic.AnsibleModule*")) and
not (process.Ext.api.parameters.buffer : ("function Get-DbaProductKey*", "function Invoke-DbaDbDecryptObjec*") and process.Ext.api.parameters.buffer : "* -bxor *") and
not (process.Ext.api.parameters.size >= 155000 and process.Ext.api.parameters.buffer : "*HSTITest_Encoded*TVqQAAMAAAAEAAAA*") and
not (process.Ext.api.parameters.size == 38324 and
process.command_line : "*AkAGUAeABlAGMAXwB3AHIAYQBwAHAAZQByAF8AcwB0AHIALgBTAHAAbABpAHQAKABAACgAIgBgADAAYAAwAGAAMABgADAAIgApAC*") and
not process.Ext.api.parameters.content_name :
("?:\\Program Files\\*.ps1",
"?:\\Program Files (x86)\\*.ps1",
"D:\\*", "E:\\*", "F:\\*", "I:\\*", "X:\\*",
"C:\\ProgramData\\NinjaRMMAgent\\scripting\\*.ps1",
"C:\\ProgramData\\chocolatey\\*.ps1",
"C:\\WINDOWS\\IMECache\\*",
"C:\\ProgramData\\CentraStage\\Packages\\*\\command.ps1") and
not process.command_line : "\"C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe\" -windowstyle hidden -nologo Invoke-Expression $env:Include" and
not process.parent.executable : ("C:\\Program Files (x86)\\ManageSoft\\Tracker\\ndtrack.exe",
"C:\\Program Files (x86)\\CentraStage\\Gui.exe",
"C:\\Program Files (x86)\\Spiceworks Agent Shell\\AgentShell.exe",
"C:\\Program Files\\SentinelOne\\Sentinel Agent *\\Addons\\SentinelAddonHost.exe",
"C:\\Program Files (x86)\\Spiceworks Agent Shell\\AgentShellService.exe",
"C:\\Program Files\\Microsoft VS Code\\Code.exe",
"C:\\Windows\\System32\\gpscript.exe",
"C:\\Program Files\\Windows Defender Advanced Threat Protection\\SenseIR.exe",
"C:\\Program Files (x86)\\Microsoft Intune Management Extension\\AgentExecutor.exe",
"C:\\Windows\\System32\\drivers\\Intel\\ICPS\\IntelConnectivityNetworkService.exe",
"C:\\Program Files\\Axis Communications\\AXIS Camera Station\\Components\\AXIS System Health Monitoring\\AXISSystemHealthMonitoring.exe")
'''
min_endpoint_version = "8.16.0"
[[actions]]
action = "kill_process"
field = "process.entity_id"
state = 0
tree = true
[[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/"
[internal]
min_endpoint_version = "8.16.0"
Stages and Predicates
Stage 1: api
api where process.Ext.api.name == "AmsiScanBuffer" and
process.name : "powershell.exe" and user.id != "S-1-5-18" and
process.Ext.api.parameters.buffer : ("*-bxor*", "*:sptth*", "*//:p##h*", "*.rEplAcE(([chAr]*", "*$pShOMe[*", "*$ShellId[*", "*$env:Public[*",
"*$env:ComSpec[*", "*ecalper-*", "*]rahc[*", "*NoiSsErpXe-eKoVNi*", "*elbairav-*", "*ECNErEFERpESObREv$*", "*.Name[3,11,2]*",
"*sailA-teS*", "*]rtPtnI[*", "*-ekovnI*", "*TVqQAAMAAAAEAAAA*", "*System.Management.Automation.$([cHAr]*") and
not (process.Ext.api.parameters.buffer : "*-bxor*" and process.Ext.api.parameters.buffer : "#powershellskript *") and
not (process.Ext.api.parameters.buffer : "*-bxor*" and process.Ext.api.parameters.buffer : ("*-bxor 0xFFFF0000*", "*Ansible.Basic.AnsibleModule*")) and
not (process.Ext.api.parameters.buffer : ("function Get-DbaProductKey*", "function Invoke-DbaDbDecryptObjec*") and process.Ext.api.parameters.buffer : "* -bxor *") and
not (process.Ext.api.parameters.size >= 155000 and process.Ext.api.parameters.buffer : "*HSTITest_Encoded*TVqQAAMAAAAEAAAA*") and
not (process.Ext.api.parameters.size == 38324 and
process.command_line : "*AkAGUAeABlAGMAXwB3AHIAYQBwAHAAZQByAF8AcwB0AHIALgBTAHAAbABpAHQAKABAACgAIgBgADAAYAAwAGAAMABgADAAIgApAC*") and
not process.Ext.api.parameters.content_name :
("?:\\Program Files\\*.ps1",
"?:\\Program Files (x86)\\*.ps1",
"D:\\*", "E:\\*", "F:\\*", "I:\\*", "X:\\*",
"C:\\ProgramData\\NinjaRMMAgent\\scripting\\*.ps1",
"C:\\ProgramData\\chocolatey\\*.ps1",
"C:\\WINDOWS\\IMECache\\*",
"C:\\ProgramData\\CentraStage\\Packages\\*\\command.ps1") and
not process.command_line : "\"C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe\" -windowstyle hidden -nologo Invoke-Expression $env:Include" and
not process.parent.executable : ("C:\\Program Files (x86)\\ManageSoft\\Tracker\\ndtrack.exe",
"C:\\Program Files (x86)\\CentraStage\\Gui.exe",
"C:\\Program Files (x86)\\Spiceworks Agent Shell\\AgentShell.exe",
"C:\\Program Files\\SentinelOne\\Sentinel Agent *\\Addons\\SentinelAddonHost.exe",
"C:\\Program Files (x86)\\Spiceworks Agent Shell\\AgentShellService.exe",
"C:\\Program Files\\Microsoft VS Code\\Code.exe",
"C:\\Windows\\System32\\gpscript.exe",
"C:\\Program Files\\Windows Defender Advanced Threat Protection\\SenseIR.exe",
"C:\\Program Files (x86)\\Microsoft Intune Management Extension\\AgentExecutor.exe",
"C:\\Windows\\System32\\drivers\\Intel\\ICPS\\IntelConnectivityNetworkService.exe",
"C:\\Program Files\\Axis Communications\\AXIS Camera Station\\Components\\AXIS System Health Monitoring\\AXISSystemHealthMonitoring.exe")
Exclusions
The rule actively suppresses these predicates.
| Field | Kind | Excluded values | Search |
|---|---|---|---|
process.Ext.api.parameters.buffer | match | -bxor | excludes:process.Ext.api.parameters.buffer field:"process.Ext.api.parameters.buffer" value:" -bxor " |
process.Ext.api.parameters.buffer | starts_with | function Get-DbaProductKey, function Invoke-DbaDbDecryptObjec | excludes:process.Ext.api.parameters.buffer field:"process.Ext.api.parameters.buffer" value:"function Get-DbaProductKey" field:"process.Ext.api.parameters.buffer" value:"function Invoke-DbaDbDecryptObjec" |
process.Ext.api.parameters.buffer | match | -bxor 0xFFFF0000, Ansible.Basic.AnsibleModule | excludes:process.Ext.api.parameters.buffer field:"process.Ext.api.parameters.buffer" value:"-bxor 0xFFFF0000" field:"process.Ext.api.parameters.buffer" value:"Ansible.Basic.AnsibleModule" |
process.Ext.api.parameters.buffer | match | -bxor | excludes:process.Ext.api.parameters.buffer field:"process.Ext.api.parameters.buffer" value:"-bxor" |
process.Ext.api.parameters.buffer | starts_with | #powershellskript | excludes:process.Ext.api.parameters.buffer field:"process.Ext.api.parameters.buffer" value:"#powershellskript " |
process.Ext.api.parameters.buffer | wildcard | *HSTITest_Encoded*TVqQAAMAAAAEAAAA* | excludes:process.Ext.api.parameters.buffer field:"process.Ext.api.parameters.buffer" value:"*HSTITest_Encoded*TVqQAAMAAAAEAAAA*" |
process.Ext.api.parameters.size | ge | 155000 | excludes:process.Ext.api.parameters.size field:"process.Ext.api.parameters.size" value:"155000" |
process.Ext.api.parameters.size | eq | 38324 | excludes:process.Ext.api.parameters.size field:"process.Ext.api.parameters.size" value:"38324" |
process.command_line | match | AkAGUAeABlAGMAXwB3AHIAYQBwAHAAZQByAF8AcwB0AHIALgBTAHAAbABpAHQAKABAACgAIgBgADAAYAAwAGAAMABgADAAIgApAC | excludes:process.command_line field:"process.command_line" value:"AkAGUAeABlAGMAXwB3AHIAYQBwAHAAZQByAF8AcwB0AHIALgBTAHAAbABpAHQAKABAACgAIgBgADAAYAAwAGAAMABgADAAIgApAC" |
process.Ext.api.parameters.content_name | wildcard | ?:\Program Files\*.ps1, ?:\Program Files (x86)\*.ps1, D:\*, E:\*, F:\*, I:\*, X:\*, C:\ProgramData\NinjaRMMAgent\scripting\*.ps1, C:\ProgramData\chocolatey\*.ps1, C:\WINDOWS\IMECache\*, C:\ProgramData\CentraStage\Packages\*\command.ps1 | excludes:process.Ext.api.parameters.content_name |
process.command_line | eq | "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -windowstyle hidden -nologo Invoke-Expression $env:Include | excludes:process.command_line |
process.parent.executable | wildcard | C:\Program Files (x86)\ManageSoft\Tracker\ndtrack.exe, C:\Program Files (x86)\CentraStage\Gui.exe, C:\Program Files (x86)\Spiceworks Agent Shell\AgentShell.exe, C:\Program Files\SentinelOne\Sentinel Agent *\Addons\SentinelAddonHost.exe, C:\Program Files (x86)\Spiceworks Agent Shell\AgentShellService.exe, C:\Program Files\Microsoft VS Code\Code.exe, C:\Windows\System32\gpscript.exe, C:\Program Files\Windows Defender Advanced Threat Protection\SenseIR.exe, C:\Program Files (x86)\Microsoft Intune Management Extension\AgentExecutor.exe, C:\Windows\System32\drivers\Intel\ICPS\IntelConnectivityNetworkService.exe, C:\Program Files\Axis Communications\AXIS Camera Station\Components\AXIS System Health Monitoring\AXISSystemHealthMonitoring.exe | excludes:process.parent.executable |
Indicators
These rows show field, operator, and value matches.
| Field | Kind | Values | Search |
|---|---|---|---|
process.Ext.api.name | eq |
| field:"process.Ext.api.name" kind:eq value:"AmsiScanBuffer" |
process.Ext.api.parameters.buffer | wildcard |
| field:"process.Ext.api.parameters.buffer" kind:wildcard |
process.name | wildcard |
| field:"process_name" kind:wildcard value:"powershell.exe" |
user.id | ne |
| field:"user.id" kind:ne value:"S-1-5-18" |