Skip to content
Threat Feed
medium advisory

Abuse of macOS AppleScript Utilities for Execution

Adversaries leverage 'osascript' and 'osacompile' utilities on macOS to execute shell commands or stage malicious AppleScript payloads via the 'do shell script' command.

Adversaries targeting macOS systems frequently abuse built-in scripting utilities to facilitate post-exploitation activities. Specifically, the 'osascript' and 'osacompile' binaries are used to interact with the AppleScript engine. 'osascript' allows for the direct execution of AppleScript code, including the 'do shell script' command, which enables the execution of arbitrary shell commands with the privileges of the script runner. 'osacompile' is used to compile AppleScript into executable script formats, serving as a staging mechanism for secondary payloads. By monitoring these utilities for the presence of 'do shell script' syntax, security teams can identify attempts to achieve persistence, execute reconnaissance commands, or stage malicious scripts on the host. This activity is a common component of macOS post-exploitation workflows and provides a clear signal for detecting unauthorized script-based execution.

Attack Chain

  1. Adversary gains initial access to a macOS system via phishing or other delivery vectors.
  2. Attacker writes a malicious AppleScript file containing a 'do shell script' command to a local directory.
  3. Attacker uses 'osacompile' to convert the AppleScript into a compiled binary format to bypass basic string-based detections.
  4. Attacker executes the compiled script using 'osascript' to initiate the shell command.
  5. The 'do shell script' command spawns a shell process (e.g., /bin/sh or /bin/bash).
  6. The spawned shell process executes the payload (e.g., downloading secondary malware or exfiltrating data).
  7. The process hierarchy reflects 'osascript' as the parent of the shell process, facilitating detection.

Impact

Successful abuse of these utilities enables attackers to execute arbitrary commands, bypass security controls, and establish persistence on compromised macOS endpoints. This technique is frequently observed as part of broader post-exploitation campaigns where attackers move to expand access, download additional malware, or steal sensitive user data.

Recommendation

Prioritize visibility into AppleScript-based execution patterns to identify potentially malicious shell activity.

  • Implement process monitoring for 'osascript' and 'osacompile' executions that utilize the 'do shell script' argument string.
  • Deploy the provided Sigma rule to your SIEM/EDR platform to alert on these specific process patterns.
  • Utilize osquery or Endpoint Security (ES) frameworks to ensure process-level command-line telemetry is captured and ingested into your security monitoring infrastructure.
  • Tune the detection logic to account for known administrative automation scripts within your environment to reduce false-positive noise.

Immediate actions

Deploy the Sigma rule to detect 'do shell script' activity

Detection Engineering 48h

Threat Hunt

Search for historical logs of 'osascript' or 'osacompile' with 'do' and 'shell' in the command line

T1059.002 medium high confidence hunt now

Data: Process creation events

Detection coverage 1

Detect MacOS AppleScript Shell Execution and Compilation

medium

Detects the use of 'osascript' to execute shell commands or 'osacompile' to stage scripts involving 'do shell script' logic.

sigma tactics: execution techniques: T1059.002 sources: process_creation, macos

Detection queries are available on the platform. Get full rules →