Detection rules › Elastic

Linux Powershell Encoded Command

Source
github.com/elastic/protections-artifacts

Detects the execution of Powershell (pwsh) with the encoded command flag set in the process arguments, in conjunction with an unusual process command line length. Powershell usage on Linux is rare, and the usage of encoded commands with unusual lengths is through Powershell may indicate malicious behavior.

MITRE ATT&CK coverage

Rule body

[rule]
description = """
Detects the execution of Powershell (pwsh) with the encoded command flag set in the process arguments, in conjunction
with an unusual process command line length. Powershell usage on Linux is rare, and the usage of encoded commands with
unusual lengths is through Powershell may indicate malicious behavior.
"""
id = "cd6e64ec-2890-4bd8-9d07-bef06465b06f"
license = "Elastic License v2"
name = "Linux Powershell Encoded Command"
os_list = ["linux"]
version = "1.0.15"

query = '''
process where event.action == "exec" and event.type == "start" and process.name == "pwsh" and
process.args : ("-EncodedCommand", "-enc", "-E") and process.args : ("-nop", "-noprofile") and 
length(process.command_line) >= 100 and not (
  process.parent.name in ("node", "code", "code-insiders", "cursor") or
  process.parent.command_line : "*Invoke-Pester*" or
  process.parent.args == "--utility-sub-type=node.mojom.NodeService" or
  process.parent.executable like ("/data/user/docker/*", "/tmp/.mount_Cursor*/usr/share/cursor/cursor") or
  process.parent.executable in ("/usr/lib/electron30/electron", "/usr/lib/electron32/electron", "/tmp/newroot/proc/self/exe") or
  (
    process.args == "IAAoAEcAZQB0AC0ASABvAHMAdAApAC4AVgBlAHIAcwBpAG8AbgAuAFQAbwBTAHQAcgBpAG4AZwAoACkAIAA=" and 
    process.parent.args == "Invoke-LightRail.ps1"
  ) or
  process.args like~ "JABFAHIAcgBvAHIAQQBjAHQAaQBvAG4AUAByAGUAZgBlAHIAZQBuAGMAZQAgAD0AIAAnAFMAdABvAHAAJwAKAFsAdgBlAHIAcwBp*" or
  process.args in (
    "VwByAGkAdABlAC0ATwB1AHQAcAB1AHQAIAAnAEgARQBMAEwATwAgAFcATwBSAEwARAAnAA==", "dwByAGkAdABlAC0AaABvAHMAdAAgACIAdABlAHMAdAAiAA=",
    "dwByAGkAdABlAC0AaABvAHMAdAAgACIAdABlAHMAdAAiAA=="
  )
)
'''

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

[[actions]]
action = "kill_process"
field = "process.parent.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 = "7.15.0"

Stages and Predicates

Stage 1: process

process where event.action == "exec" and event.type == "start" and process.name == "pwsh" and
process.args : ("-EncodedCommand", "-enc", "-E") and process.args : ("-nop", "-noprofile") and 
length(process.command_line) >= 100 and not (
  process.parent.name in ("node", "code", "code-insiders", "cursor") or
  process.parent.command_line : "*Invoke-Pester*" or
  process.parent.args == "--utility-sub-type=node.mojom.NodeService" or
  process.parent.executable like ("/data/user/docker/*", "/tmp/.mount_Cursor*/usr/share/cursor/cursor") or
  process.parent.executable in ("/usr/lib/electron30/electron", "/usr/lib/electron32/electron", "/tmp/newroot/proc/self/exe") or
  (
    process.args == "IAAoAEcAZQB0AC0ASABvAHMAdAApAC4AVgBlAHIAcwBpAG8AbgAuAFQAbwBTAHQAcgBpAG4AZwAoACkAIAA=" and 
    process.parent.args == "Invoke-LightRail.ps1"
  ) or
  process.args like~ "JABFAHIAcgBvAHIAQQBjAHQAaQBvAG4AUAByAGUAZgBlAHIAZQBuAGMAZQAgAD0AIAAnAFMAdABvAHAAJwAKAFsAdgBlAHIAcwBp*" or
  process.args in (
    "VwByAGkAdABlAC0ATwB1AHQAcAB1AHQAIAAnAEgARQBMAEwATwAgAFcATwBSAEwARAAnAA==", "dwByAGkAdABlAC0AaABvAHMAdAAgACIAdABlAHMAdAAiAA=",
    "dwByAGkAdABlAC0AaABvAHMAdAAgACIAdABlAHMAdAAiAA=="
  )
)

Exclusions

The rule actively suppresses these predicates.

FieldKindExcluded valuesSearch
process.argseqIAAoAEcAZQB0AC0ASABvAHMAdAApAC4AVgBlAHIAcwBpAG8AbgAuAFQAbwBTAHQAcgBpAG4AZwAoACkAIAA=excludes:process.args field:"process.args" value:"IAAoAEcAZQB0AC0ASABvAHMAdAApAC4AVgBlAHIAcwBpAG8AbgAuAFQAbwBTAHQAcgBpAG4AZwAoACkAIAA="
process.parent.argseqInvoke-LightRail.ps1excludes:process.parent.args field:"process.parent.args" value:"Invoke-LightRail.ps1"
process.argsinVwByAGkAdABlAC0ATwB1AHQAcAB1AHQAIAAnAEgARQBMAEwATwAgAFcATwBSAEwARAAnAA==, dwByAGkAdABlAC0AaABvAHMAdAAgACIAdABlAHMAdAAiAA=, dwByAGkAdABlAC0AaABvAHMAdAAgACIAdABlAHMAdAAiAA==excludes:process.args field:"process.args" value:"VwByAGkAdABlAC0ATwB1AHQAcAB1AHQAIAAnAEgARQBMAEwATwAgAFcATwBSAEwARAAnAA==" field:"process.args" value:"dwByAGkAdABlAC0AaABvAHMAdAAgACIAdABlAHMAdAAiAA=" field:"process.args" value:"dwByAGkAdABlAC0AaABvAHMAdAAgACIAdABlAHMAdAAiAA=="
process.argsstarts_withJABFAHIAcgBvAHIAQQBjAHQAaQBvAG4AUAByAGUAZgBlAHIAZQBuAGMAZQAgAD0AIAAnAFMAdABvAHAAJwAKAFsAdgBlAHIAcwBpexcludes:process.args field:"process.args" value:"JABFAHIAcgBvAHIAQQBjAHQAaQBvAG4AUAByAGUAZgBlAHIAZQBuAGMAZQAgAD0AIAAnAFMAdABvAHAAJwAKAFsAdgBlAHIAcwBp"
process.parent.argseq--utility-sub-type=node.mojom.NodeServiceexcludes:process.parent.args field:"process.parent.args" value:"--utility-sub-type=node.mojom.NodeService"
process.parent.command_linematchInvoke-Pesterexcludes:process.parent.command_line field:"process.parent.command_line" value:"Invoke-Pester"
process.parent.executablein/tmp/newroot/proc/self/exe, /usr/lib/electron30/electron, /usr/lib/electron32/electronexcludes:process.parent.executable field:"process.parent.executable" value:"/tmp/newroot/proc/self/exe" field:"process.parent.executable" value:"/usr/lib/electron30/electron" field:"process.parent.executable" value:"/usr/lib/electron32/electron"
process.parent.executablewildcard/data/user/docker/*, /tmp/.mount_Cursor*/usr/share/cursor/cursorexcludes:process.parent.executable field:"process.parent.executable" value:"/data/user/docker/*" field:"process.parent.executable" value:"/tmp/.mount_Cursor*/usr/share/cursor/cursor"
process.parent.nameincode, code-insiders, cursor, nodeexcludes:process.parent.name

Indicators

These rows show field, operator, and value matches.