Suspicious File Creation via Pkg Install Script

Last updated a month ago on 2026-01-30
Created a month ago on 2026-01-30

About

Detects when an installer package executes a pre or post install script that immediately copies a file to suspicious locations on the filesystem. This activity is not common and usually indicates a malicious package attempting to install persistence or establish a working directory for malware.
Tags
Domain: EndpointOS: macOSUse Case: Threat DetectionTactic: PersistenceData Source: Elastic DefendLanguage: eql
Severity
high
Risk Score
73
MITRE ATT&CK™

Persistence (TA0003)(external, opens in a new tab or window)

License
Elastic License v2(external, opens in a new tab or window)

Definition

Rule Type
Event Correlation Rule
Integration Pack
Prebuilt Security Detection Rules
Index Patterns
logs-endpoint.events.process-*logs-endpoint.events.file-*
Related Integrations

endpoint(external, opens in a new tab or window)

Query
text code block:
sequence by process.entity_id with maxspan=30s [process where host.os.type == "macos" and event.type == "start" and process.name in ("bash", "sh", "zsh") and process.args like~ ("/tmp/PKInstallSandbox.*/Scripts/com.*/preinstall", "/tmp/PKInstallSandbox.*/Scripts/*/postinstall") and process.args like ("/Users/*", "/Volumes/*") and not process.args like~ "/Users/*/Library/Caches/*"] [file where host.os.type == "macos" and event.action != "deletion" and process.name in ("mv", "cp") and (file.extension in ("py", "js", "sh", "scpt", "terminal", "tcl", "app", "pkg", "dmg", "command") or file.Ext.header_bytes like~ ("cffaedfe*", "cafebabe*")) and file.path like ("/private/etc/*", "/var/tmp/*", "/tmp/*", "/var/folders/*", "/Users/Shared/*", "/Library/Graphics/*", "/Library/Containers/*", "/Users/*/Library/Containers/*", "/Users/*/Library/Services/*", "/Users/*/Library/Preferences/*", "/var/root/*", "/Library/WebServer/*", "/Library/Fonts/*", "/usr/local/bin/*") and not file.name == "CodeResources"]

Install detection rules in Elastic Security

Detect Suspicious File Creation via Pkg Install Script in the Elastic Security detection engine by installing this rule into your Elastic Stack.

To setup this rule, check out the installation guide for Prebuilt Security Detection Rules(external, opens in a new tab or window).