Detection rules › Elastic
Suspicious Script Compilation via Osacompile
Detects the execution of the Osacompile binary followed by the immediate file modification of a script or executable file. This is a technique that threat actors have used by to compile scripts into executable binaries on victim systems.
MITRE ATT&CK coverage
| Tactic | Techniques |
|---|---|
| Execution |
Telemetry coverage
Rule body
[rule]
description = """
Detects the execution of the Osacompile binary followed by the immediate file modification of a script or executable
file. This is a technique that threat actors have used by to compile scripts into executable binaries on victim systems.
"""
id = "60a14513-1793-4798-bad6-99c40fc4791e"
license = "Elastic License v2"
name = "Suspicious Script Compilation via Osacompile"
os_list = ["macos"]
version = "1.0.7"
query = '''
sequence by process.entity_id with maxspan=30s
[process where event.type == "start" and event.action == "exec" and
process.name == "osacompile" and process.args == "-x" and process.args == "-o"]
[file where event.action == "modification" and
process.name == "osacompile" and file.extension == "scpt" and
not Effective_process.executable like~ "/Volumes/PostgreSQL*osx.app/Contents/MacOS/PostgreSQL"]
'''
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.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.11.0"
Stages and Predicates
Ordered sequence: each step below must occur in order within 30s, correlated by process.entity_id.
Stage 1: process
[process where event.type == "start" and event.action == "exec" and
process.name == "osacompile" and process.args == "-x" and process.args == "-o"]
Stage 2: file
[file where event.action == "modification" and
process.name == "osacompile" and file.extension == "scpt" and
not Effective_process.executable like~ "/Volumes/PostgreSQL*osx.app/Contents/MacOS/PostgreSQL"]
Exclusions
The rule actively suppresses these predicates.
| Field | Kind | Excluded values | Search |
|---|---|---|---|
Effective_process.executable | wildcard | /Volumes/PostgreSQL*osx.app/Contents/MacOS/PostgreSQL | excludes:Effective_process.executable field:"Effective_process.executable" value:"/Volumes/PostgreSQL*osx.app/Contents/MacOS/PostgreSQL" |
Indicators
These rows show field, operator, and value matches.
| Field | Kind | Values | Search |
|---|---|---|---|
event.action | eq |
| field:"EventType" kind:eq |
event.type | eq |
| field:"event.type" kind:eq value:"start" |
file.extension | eq |
| field:"file.extension" kind:eq value:"scpt" |
process.args | eq |
| field:"process.args" kind:eq |
process.name | eq |
| field:"process_name" kind:eq value:"osacompile" |