Detection rules › Elastic
Shell Command Discovery Execution via Untrusted Binary
Detects untrusted binaries spawning shell interpreters to execute discovery commands like whoami, osascript, and dscacheutil within 15 seconds. This pattern indicates malicious reconnaissance activities.
MITRE ATT&CK coverage
| Tactic | Techniques |
|---|---|
| Execution |
Telemetry coverage
Rule body
[rule]
description = """
Detects untrusted binaries spawning shell interpreters to execute discovery commands like whoami, osascript, and
dscacheutil within 15 seconds. This pattern indicates malicious reconnaissance activities.
"""
id = "a1d2c79e-bb1f-4191-8e48-9f240cfcfb40"
license = "Elastic License v2"
name = "Shell Command Discovery Execution via Untrusted Binary"
os_list = ["macos"]
version = "1.0.11"
query = '''
sequence with maxspan=15s
[process where event.type == "start" and process.parent.code_signature.trusted == false and (process.name in ("bash", "sh", "zsh", "dash", "csh", "tcsh", "ksh", "tclsh", "fish") or process.name like "tclsh*") and
process.args == "-c" and not process.parent.executable like ("/opt/homebrew/*", "/usr/local/Cellar/*")] by process.entity_id
[process where event.type == "start" and event.action == "exec" and (process.parent.name in ("bash", "sh", "zsh", "dash", "csh", "tcsh", "ksh", "tclsh", "fish") or process.parent.name like "tclsh*") and
process.name in ("osascript", "whoami", "dscacheutil", "dsconfigad", "dsexport", "sqlite3") and
not process.Ext.effective_parent.executable like ("/Applications/*", "/opt/homebrew/*")] by process.parent.entity_id
'''
min_endpoint_version = "8.10.2"
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.004"
name = "Unix Shell"
reference = "https://attack.mitre.org/techniques/T1059/004/"
[threat.tactic]
id = "TA0002"
name = "Execution"
reference = "https://attack.mitre.org/tactics/TA0002/"
[[threat]]
framework = "MITRE ATT&CK"
[threat.tactic]
id = "TA0007"
name = "Discovery"
reference = "https://attack.mitre.org/tactics/TA0007/"
[internal]
min_endpoint_version = "8.10.2"
Stages and Predicates
Ordered sequence: each step below must occur in order within 15s, correlated by process.entity_id, process.parent.entity_id.
Stage 1: process
[process where event.type == "start" and process.parent.code_signature.trusted == false and (process.name in ("bash", "sh", "zsh", "dash", "csh", "tcsh", "ksh", "tclsh", "fish") or process.name like "tclsh*") and
process.args == "-c" and not process.parent.executable like ("/opt/homebrew/*", "/usr/local/Cellar/*")] by process.entity_id
Stage 2: process
[process where event.type == "start" and event.action == "exec" and (process.parent.name in ("bash", "sh", "zsh", "dash", "csh", "tcsh", "ksh", "tclsh", "fish") or process.parent.name like "tclsh*") and
process.name in ("osascript", "whoami", "dscacheutil", "dsconfigad", "dsexport", "sqlite3") and
not process.Ext.effective_parent.executable like ("/Applications/*", "/opt/homebrew/*")] by process.parent.entity_id
Exclusions
The rule actively suppresses these predicates.
| Field | Kind | Excluded values | Search |
|---|---|---|---|
process.parent.executable | starts_with | /opt/homebrew/, /usr/local/Cellar/ | excludes:process.parent.executable field:"process.parent.executable" value:"/opt/homebrew/" field:"process.parent.executable" value:"/usr/local/Cellar/" |
process.Ext.effective_parent.executable | starts_with | /Applications/, /opt/homebrew/ | excludes:process.Ext.effective_parent.executable field:"process.Ext.effective_parent.executable" value:"/Applications/" field:"process.Ext.effective_parent.executable" value:"/opt/homebrew/" |
Indicators
These rows show field, operator, and value matches.
| Field | Kind | Values | Search |
|---|---|---|---|
event.action | eq |
| field:"EventType" kind:eq value:"exec" |
event.type | eq |
| field:"event.type" kind:eq value:"start" |
process.args | eq |
| field:"process.args" kind:eq value:"-c" |
process.name | in |
| field:"process_name" kind:in |
process.name | wildcard |
| field:"process_name" kind:wildcard value:"tclsh*" |
process.parent.code_signature.trusted | eq |
| field:"process.parent.code_signature.trusted" kind:eq value:"false" |
process.parent.name | in |
| field:"parent_process_name" kind:in |
process.parent.name | wildcard |
| field:"parent_process_name" kind:wildcard value:"tclsh*" |