Detection rules › Elastic
Shell Command Piped to Osascript via Shell Script
Detects when shell commands are piped to osascript for execution. This technique can be used by adversaries to execute AppleScript commands indirectly through shell scripts.
MITRE ATT&CK coverage
Telemetry coverage
Rule body
[rule]
description = """
Detects when shell commands are piped to osascript for execution. This technique can be used by adversaries to execute
AppleScript commands indirectly through shell scripts.
"""
id = "2b6eac2a-c533-463c-bcbb-098d40fe3854"
license = "Elastic License v2"
name = "Shell Command Piped to Osascript via Shell Script"
os_list = ["macos"]
version = "1.0.4"
query = '''
sequence with maxspan = 10s
[process where event.type == "start" and event.action == "exec" and process.parent.name in ("bash", "sh", "zsh") and process.name == "osascript" and process.args_count == 1] by process.entity_id
[process where event.type == "start" and event.action == "exec" and process.name in ("bash", "sh", "zsh") and process.args == "-c"] by process.parent.entity_id
'''
min_endpoint_version = "8.16.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.002"
name = "AppleScript"
reference = "https://attack.mitre.org/techniques/T1059/002/"
[[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/"
[internal]
min_endpoint_version = "8.16.0"
Stages and Predicates
Ordered sequence: each step below must occur in order within 10s, correlated by process.entity_id, process.parent.entity_id.
Stage 1: process
[process where event.type == "start" and event.action == "exec" and process.parent.name in ("bash", "sh", "zsh") and process.name == "osascript" and process.args_count == 1] by process.entity_id
Stage 2: process
[process where event.type == "start" and event.action == "exec" and process.name in ("bash", "sh", "zsh") and process.args == "-c"] by process.parent.entity_id
Indicators
These rows show field, operator, and value matches.