AppleScript

T1059.002

Sub-technique of T1059 Command and Scripting Interpreter.View on attack.mitre.org

About this technique

Adversaries may abuse AppleScript for execution. AppleScript is a macOS scripting language designed to control applications and parts of the OS via inter-application messages called AppleEvents. These AppleEvent messages can be sent independently or easily scripted with AppleScript. These events can locate open windows, send keystrokes, and interact with almost any open application locally or remotely.

Scripts can be run from the command-line via osascript /path/to/script or osascript -e "script here". Aside from the command line, scripts can be executed in numerous ways including Mail rules, Calendar.app alarms, and Automator workflows. AppleScripts can also be executed as plain text shell scripts by adding #!/usr/bin/osascript to the start of the script file.

AppleScripts do not need to call osascript to execute. However, they may be executed from within mach-O binaries by using the macOS Native APIs NSAppleScript or OSAScript, both of which execute code independent of the /usr/bin/osascript command line utility.

Adversaries may abuse AppleScript to execute various behaviors, such as interacting with an open SSH connection, moving to remote machines, and even presenting users with fake dialog boxes. These events cannot start applications remotely (they can start them locally), but they can interact with applications if they're already running remotely. On macOS 10.10 Yosemite and higher, AppleScript has the ability to execute Native APIs, which otherwise would require compilation and execution in a mach-O binary file format. Since this is a scripting language, it can be used to launch more common techniques as well such as a reverse shell via Python.

Detection rules13

Rules on DetectionCode tagged with T1059.002.

Sigma7

RuleLevelLog source
JXA In-memory Execution Via OSAScripthighmacos / process_creation
OSACompile Run-Only Executionhighmacos / process_creation
Suspicious Microsoft Office Child Process - MacOShighmacos / process_creation
Clipboard Access Via OSAScriptmediummacos / process_creation
MacOS Scripting Interpreter AppleScriptmediummacos / process_creation
Osacompile Execution By Potentially Suspicious Applet/Osascriptmediummacos / process_creation
Suspicious Execution via macOS Script Editormediummacos / process_creation

Splunk6

RuleTypeRiskData source
Cisco NVM - Osascript Network Connection for a Long DurationAnomalyNULLCisco Network Visibility Module Flow Data
MacOS AMOS Stealer - Virtual Machine Check ActivityAnomalyNULLOsquery Results
MacOS AppleScript Shell Execution and CompilationAnomalyNULLOsquery Results
MacOS Osascript Displaying Suspicious User PromptAnomalyNULLOsquery Results
MacOS Osascript Executing Interactive ShellAnomalyNULLOsquery Results
MacOS Osascript Executing JavaScript Code With ObjCAnomalyNULLOsquery Results

Groups0

None recorded.

Software6

Campaigns0

None recorded.

Procedure examples6

Software6

Used byProcedure example
MalwareBundlore

Bundlore can use AppleScript to inject malicious JavaScript into a browser.

MalwareCuckoo Stealer

Cuckoo Stealer can use osascript to generate a password-stealing prompt, duplicate files and folders, and set environmental variables.

MalwareDok

Dok uses AppleScript to create a login item for persistence.

MalwareGlassWorm

GlassWorm has utilized AppleScript to include `set keychainPassword to do shell script` to execute shell command that retrieves passwords from the macOS keychain.

MalwaremacOS.OSAMiner

macOS.OSAMiner has used `osascript` to call itself via the `do shell script` command in the Launch Agent `.plist` file.

MalwareThiefQuest

ThiefQuest uses AppleScript's osascript -e command to launch ThiefQuest's persistence via Launch Agent and Launch Daemon.

References4

  1. Apple AppleScript Open source
    Apple. (2016, January 25). Introduction to AppleScript Language Guide. Retrieved March 28, 2020.
  2. Macro Malware Targets Macs Open source
    Yerko Grbic. (2017, February 14). Macro Malware Targets Macs. Retrieved July 8, 2017.
  3. SentinelOne AppleScript Open source
    Phil Stokes. (2020, March 16). How Offensive Actors Use AppleScript For Attacking macOS. Retrieved July 17, 2020.
  4. SentinelOne macOS Red Team Open source
    Phil Stokes. (2019, December 5). macOS Red Team: Calling Apple APIs Without Building Binaries. Retrieved July 17, 2020.

Data from MITRE ATT&CK® (Enterprise). ATT&CK® is a registered trademark of The MITRE Corporation.