Detection rules › Elastic
Powershell Execution via Named Pipe
Identifies the execution of a PowerShell script that allow remote command execution via named pipe.
MITRE ATT&CK coverage
| Tactic | Techniques |
|---|---|
| Execution | |
| Lateral Movement |
Rule body
[rule]
description = "Identifies the execution of a PowerShell script that allow remote command execution via named pipe."
id = "c286b078-793f-4c51-a49a-27948e0ed741"
license = "Elastic License v2"
name = "Powershell Execution via Named Pipe"
os_list = ["windows"]
reference = ["https://github.com/threatexpress/invoke-pipeshell/tree/master"]
version = "1.0.2"
query = '''
api where process.Ext.api.name == "AmsiScanBuffer" and
(process.name in~ ("powershell.exe") or process.Ext.api.parameters.app_name == "PowerShell") and
process.Ext.api.parameters.buffer : ("*Pipes.NamedPipeClientStream*.Connect(*", "*Pipes.NamedPipeServerStream*WaitForConnection*") and
process.Ext.api.parameters.buffer : "*.StreamReader*" and process.Ext.api.parameters.buffer : "*.StreamWriter*" and
process.Ext.api.parameters.buffer : "*.ReadLine*" and process.Ext.api.parameters.buffer : "*.WriteLine*" and
process.Ext.api.parameters.buffer : ("*while(*", "*while (*") and
not (process.command_line : "*AZQBjAHQAIABTAHkAcwB0AGUAbQAuAEkATwAuAFAAaQBwAGUAcwAuAE4AYQBtAGUAZABQAGkAcABlAFMAZQByAHYAZQByAFMAdAByAGUAYQBtACgAJwBpAG4AcwBwA*" and
process.Ext.api.parameters.size == 3354)
'''
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/"
[[threat]]
framework = "MITRE ATT&CK"
[[threat.technique]]
id = "T1021"
name = "Remote Services"
reference = "https://attack.mitre.org/techniques/T1021/"
[[threat.technique.subtechnique]]
id = "T1021.002"
name = "SMB/Windows Admin Shares"
reference = "https://attack.mitre.org/techniques/T1021/002/"
[threat.tactic]
id = "TA0008"
name = "Lateral Movement"
reference = "https://attack.mitre.org/tactics/TA0008/"
[internal]
min_endpoint_version = "8.16.0"
Stages and Predicates
Stage 1: api
api where process.Ext.api.name == "AmsiScanBuffer" and
(process.name in~ ("powershell.exe") or process.Ext.api.parameters.app_name == "PowerShell") and
process.Ext.api.parameters.buffer : ("*Pipes.NamedPipeClientStream*.Connect(*", "*Pipes.NamedPipeServerStream*WaitForConnection*") and
process.Ext.api.parameters.buffer : "*.StreamReader*" and process.Ext.api.parameters.buffer : "*.StreamWriter*" and
process.Ext.api.parameters.buffer : "*.ReadLine*" and process.Ext.api.parameters.buffer : "*.WriteLine*" and
process.Ext.api.parameters.buffer : ("*while(*", "*while (*") and
not (process.command_line : "*AZQBjAHQAIABTAHkAcwB0AGUAbQAuAEkATwAuAFAAaQBwAGUAcwAuAE4AYQBtAGUAZABQAGkAcABlAFMAZQByAHYAZQByAFMAdAByAGUAYQBtACgAJwBpAG4AcwBwA*" and
process.Ext.api.parameters.size == 3354)
Exclusions
The rule actively suppresses these predicates.
| Field | Kind | Excluded values | Search |
|---|---|---|---|
process.Ext.api.parameters.size | eq | 3354 | excludes:process.Ext.api.parameters.size field:"process.Ext.api.parameters.size" value:"3354" |
process.command_line | match | AZQBjAHQAIABTAHkAcwB0AGUAbQAuAEkATwAuAFAAaQBwAGUAcwAuAE4AYQBtAGUAZABQAGkAcABlAFMAZQByAHYAZQByAFMAdAByAGUAYQBtACgAJwBpAG4AcwBwA | excludes:process.command_line field:"process.command_line" value:"AZQBjAHQAIABTAHkAcwB0AGUAbQAuAEkATwAuAFAAaQBwAGUAcwAuAE4AYQBtAGUAZABQAGkAcABlAFMAZQByAHYAZQByAFMAdAByAGUAYQBtACgAJwBpAG4AcwBwA" |
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.app_name | eq |
| field:"process.Ext.api.parameters.app_name" kind:eq value:"PowerShell" |
process.Ext.api.parameters.buffer | wildcard |
| field:"process.Ext.api.parameters.buffer" kind:wildcard |
process.name | in |
| field:"process_name" kind:in value:"powershell.exe" |