Detection rules › Elastic
Unusually Large Script Executed by Osascript
Detects when Osascript is executed and an abnormally large script is supplied to be executed. Threat actors have been increasingly been observed utilizing Osascript to collect sensitive files and stage them for exfiltration using AppleScript supplied to Osascript via the -e option for execution. These scripts are abnormally large and very uncommon to see executed in this manner.
MITRE ATT&CK coverage
| Tactic | Techniques |
|---|---|
| Execution |
Telemetry coverage
Rule body
[rule]
description = """
Detects when Osascript is executed and an abnormally large script is supplied to be executed. Threat actors have been
increasingly been observed utilizing Osascript to collect sensitive files and stage them for exfiltration using
AppleScript supplied to Osascript via the -e option for execution. These scripts are abnormally large and very uncommon
to see executed in this manner.
"""
id = "40d4b42d-ad3a-478d-88cd-d440fa45cd81"
license = "Elastic License v2"
name = "Unusually Large Script Executed by Osascript"
os_list = ["macos"]
version = "1.0.5"
query = '''
process where event.type == "start" and event.action == "exec" and process.name == "osascript" and
process.args == "-e" and
(
process.args_count > 40 or
(length(process.command_line) >= 3000 and process.command_line regex """.*\(\{[\s]*\d+[\s]*,[\s]*\d+[\s]*,[\s]*\d+.*""")
) and
not (process.args : "*checkWWAssetsExistence*" and process.args : "*wwAssetsOpenDocuments*" and process.args : "*isWWAssetsInstalled*")
'''
min_endpoint_version = "8.11.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.tactic]
id = "TA0002"
name = "Execution"
reference = "https://attack.mitre.org/tactics/TA0002/"
[internal]
min_endpoint_version = "8.11.0"
Stages and Predicates
Stage 1: process
process where event.type == "start" and event.action == "exec" and process.name == "osascript" and
process.args == "-e" and
(
process.args_count > 40 or
(length(process.command_line) >= 3000 and process.command_line regex """.*\(\{[\s]*\d+[\s]*,[\s]*\d+[\s]*,[\s]*\d+.*""")
) and
not (process.args : "*checkWWAssetsExistence*" and process.args : "*wwAssetsOpenDocuments*" and process.args : "*isWWAssetsInstalled*")
Exclusions
The rule actively suppresses these predicates.
| Field | Kind | Excluded values | Search |
|---|---|---|---|
process.args | match | checkWWAssetsExistence | excludes:process.args field:"process.args" value:"checkWWAssetsExistence" |
process.args | match | isWWAssetsInstalled | excludes:process.args field:"process.args" value:"isWWAssetsInstalled" |
process.args | match | wwAssetsOpenDocuments | excludes:process.args field:"process.args" value:"wwAssetsOpenDocuments" |
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:"-e" |
process.args_count | gt |
| field:"process.args_count" kind:gt value:"40" |
process.command_line | regex_match |
| field:"CommandLine" kind:regex_match value:".*({[\s]*\d+[\s]*,[\s]*\d+[\s]*,[\s]*\d+.*" |
process.name | eq |
| field:"process_name" kind:eq value:"osascript" |