Detection rules › Elastic
Suspicious Script or Process Execution from Mounted Device
Detects potential execution of a script or unsigned macOS binary from a mounted device. Malware may abuse DMG files to deliver malicious code or scripts to gain initial access.
MITRE ATT&CK coverage
| Tactic | Techniques |
|---|---|
| Execution |
Telemetry coverage
Rule body
[rule]
description = """
Detects potential execution of a script or unsigned macOS binary from a mounted device. Malware may abuse DMG files to
deliver malicious code or scripts to gain initial access.
"""
id = "c6ee0cc0-efc4-4353-bbfc-da16ebc4e1a5"
license = "Elastic License v2"
name = "Suspicious Script or Process Execution from Mounted Device"
os_list = ["macos"]
version = "1.0.45"
query = '''
sequence with maxspan=30s
[file where event.action == "mount" and
not (process.executable like "/usr/libexec/lsd" and file.path like~ "/private/var/folders/*/AppTranslocation/*") and
not file.path like~ ("/Volumes/*/Contents/MacOS/*", "/Library/Developer/CoreSimulator/Volumes/*")] as event0
[process where event.action == "exec" and
(stringcontains~(process.executable, event0.file.path) or
stringcontains~(process.parent.executable, event0.file.path)) and
(
/* Focus on truly suspicious patterns */
(process.code_signature.trusted == false and process.code_signature.exists == true and process.args_count >= 2) or
/* Shells executing inline commands with suspicious content */
(process.name in ("bash", "sh", "zsh") and process.args == "-c" and
process.args like~ ("*curl*http*", "*wget*", "*python*-c*", "*perl*-e*", "*base64*", "*chmod*+x*")) or
/* Scripting interpreters with suspicious args */
(process.name like~ "python*" and (process.args == "-c" or process.args : "*exec(*" or process.args : "*eval(*")) or
(process.name == "perl" and process.args == "-e") or
(process.name == "osascript" and process.args == "-e") or
/* chmod making things executable */
(process.name == "chmod" and process.args in ("+x", "a+x", "0777", "777") and process.args like "/Volumes/*")
) and
/* Legitimate installer patterns */
not process.executable like~ ("/Volumes/*/Contents/MacOS/*",
"/Volumes/*/*.app/Contents/MacOS/*",
"/private/tmp/PKInstallSandbox.*",
"/Applications/Solarwinds Discovery Agent.app/Contents/Resources/agent/ruby/bin/ruby",
"/opt/homebrew/Cellar/*") and
not process.args like~ ("/tmp/PKInstallSandbox.*/Scripts/*",
"/Library/Apple/System/Library/InstallerSandboxes/.*",
"/private/tmp/dmg.*/.PKInstallSandboxManager-SystemSoftware/*") and
/* Legitimate parent processes */
not process.parent.executable like~ ("/sbin/launchd",
"/usr/bin/sudo",
"/Library/PrivilegedHelperTools/*",
"/System/Library/*") and
not (process.parent.code_signature.team_id in ("5C3VHX9RG5", "UBF8T346G9") and
process.parent.code_signature.trusted == true) and
/* Legitimate management tools - consolidated */
not process.Ext.effective_parent.executable like~ ("/usr/local/jamf/bin/*",
"/Library/Application Support/JAMF/*",
"/Library/Kandji/*",
"/Library/Application Support/Mosyle/*",
"/Applications/NinjaRMMAgent/*",
"/Library/Application Support/com.atera.ateraagent/*")]
'''
min_endpoint_version = "8.11.0"
optional_actions = []
[[actions]]
action = "kill_process"
field = "process.entity_id"
state = 1
[[actions]]
action = "kill_process"
field = "process.parent.entity_id"
state = 1
[[threat]]
framework = "MITRE ATT&CK"
[[threat.technique]]
id = "T1204"
name = "User Execution"
reference = "https://attack.mitre.org/techniques/T1204/"
[[threat.technique.subtechnique]]
id = "T1204.002"
name = "Malicious File"
reference = "https://attack.mitre.org/techniques/T1204/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: file
[file where event.action == "mount" and
not (process.executable like "/usr/libexec/lsd" and file.path like~ "/private/var/folders/*/AppTranslocation/*") and
not file.path like~ ("/Volumes/*/Contents/MacOS/*", "/Library/Developer/CoreSimulator/Volumes/*")] as event0
Stage 2: process
[process where event.action == "exec" and
(stringcontains~(process.executable, event0.file.path) or
stringcontains~(process.parent.executable, event0.file.path)) and
(
(process.code_signature.trusted == false and process.code_signature.exists == true and process.args_count >= 2) or
(process.name in ("bash", "sh", "zsh") and process.args == "-c" and
process.args like~ ("*curl*http*", "*wget*", "*python*-c*", "*perl*-e*", "*base64*", "*chmod*+x*")) or
(process.name like~ "python*" and (process.args == "-c" or process.args : "*exec(*" or process.args : "*eval(*")) or
(process.name == "perl" and process.args == "-e") or
(process.name == "osascript" and process.args == "-e") or
(process.name == "chmod" and process.args in ("+x", "a+x", "0777", "777") and process.args like "/Volumes/*")
) and
not process.executable like~ ("/Volumes/*/Contents/MacOS/*",
"/Volumes/*/*.app/Contents/MacOS/*",
"/private/tmp/PKInstallSandbox.*",
"/Applications/Solarwinds Discovery Agent.app/Contents/Resources/agent/ruby/bin/ruby",
"/opt/homebrew/Cellar/*") and
not process.args like~ ("/tmp/PKInstallSandbox.*/Scripts/*",
"/Library/Apple/System/Library/InstallerSandboxes/.*",
"/private/tmp/dmg.*/.PKInstallSandboxManager-SystemSoftware/*") and
not process.parent.executable like~ ("/sbin/launchd",
"/usr/bin/sudo",
"/Library/PrivilegedHelperTools/*",
"/System/Library/*") and
not (process.parent.code_signature.team_id in ("5C3VHX9RG5", "UBF8T346G9") and
process.parent.code_signature.trusted == true) and
not process.Ext.effective_parent.executable like~ ("/usr/local/jamf/bin/*",
"/Library/Application Support/JAMF/*",
"/Library/Kandji/*",
"/Library/Application Support/Mosyle/*",
"/Applications/NinjaRMMAgent/*",
"/Library/Application Support/com.atera.ateraagent/*")]
Exclusions
The rule actively suppresses these predicates.
| Field | Kind | Excluded values | Search |
|---|---|---|---|
file.path | wildcard | /private/var/folders/*/AppTranslocation/* | excludes:file.path field:"file.path" value:"/private/var/folders/*/AppTranslocation/*" |
process.executable | eq | /usr/libexec/lsd | excludes:process.executable field:"process.executable" value:"/usr/libexec/lsd" |
file.path | wildcard | /Volumes/*/Contents/MacOS/*, /Library/Developer/CoreSimulator/Volumes/* | excludes:file.path field:"file.path" value:"/Volumes/*/Contents/MacOS/*" field:"file.path" value:"/Library/Developer/CoreSimulator/Volumes/*" |
process.parent.code_signature.team_id | in | 5C3VHX9RG5, UBF8T346G9 | excludes:process.parent.code_signature.team_id field:"process.parent.code_signature.team_id" value:"5C3VHX9RG5" field:"process.parent.code_signature.team_id" value:"UBF8T346G9" |
process.parent.code_signature.trusted | eq | true | excludes:process.parent.code_signature.trusted field:"process.parent.code_signature.trusted" value:"true" |
process.Ext.effective_parent.executable | starts_with | /usr/local/jamf/bin/, /Library/Application Support/JAMF/, /Library/Kandji/, /Library/Application Support/Mosyle/, /Applications/NinjaRMMAgent/, /Library/Application Support/com.atera.ateraagent/ | excludes:process.Ext.effective_parent.executable |
process.args | wildcard | /tmp/PKInstallSandbox.*/Scripts/*, /Library/Apple/System/Library/InstallerSandboxes/.*, /private/tmp/dmg.*/.PKInstallSandboxManager-SystemSoftware/* | excludes:process.args field:"process.args" value:"/tmp/PKInstallSandbox.*/Scripts/*" field:"process.args" value:"/Library/Apple/System/Library/InstallerSandboxes/.*" field:"process.args" value:"/private/tmp/dmg.*/.PKInstallSandboxManager-SystemSoftware/*" |
process.executable | wildcard | /Volumes/*/Contents/MacOS/*, /Volumes/*/*.app/Contents/MacOS/*, /private/tmp/PKInstallSandbox.*, /Applications/Solarwinds Discovery Agent.app/Contents/Resources/agent/ruby/bin/ruby, /opt/homebrew/Cellar/* | excludes:process.executable |
process.parent.executable | wildcard | /sbin/launchd, /usr/bin/sudo, /Library/PrivilegedHelperTools/*, /System/Library/* | excludes:process.parent.executable |
Indicators
These rows show field, operator, and value matches.
| Field | Kind | Values | Search |
|---|---|---|---|
event.action | eq |
| field:"EventType" kind:eq |
process.args | eq |
| field:"process.args" kind:eq |
process.args | in |
| field:"process.args" kind:in |
process.args | wildcard |
| field:"process.args" kind:wildcard |
process.args_count | ge |
| field:"process.args_count" kind:ge value:"2" |
process.code_signature.exists | eq |
| field:"process.code_signature.exists" kind:eq value:"true" |
process.code_signature.trusted | eq |
| field:"process.code_signature.trusted" kind:eq value:"false" |
process.executable | contains |
| field:"Image" kind:contains value:"event0.file.path" |
process.name | eq |
| field:"process_name" kind:eq |
process.name | in |
| field:"process_name" kind:in |
process.name | wildcard |
| field:"process_name" kind:wildcard value:"python*" |
process.parent.executable | contains |
| field:"ParentImage" kind:contains value:"event0.file.path" |