Hacktricks-skills macos-office-sandbox-bypass
Security testing skill for macOS Microsoft Office sandbox escape techniques. Use this skill when performing authorized security assessments, penetration testing, or vulnerability research on macOS Office applications. Trigger when users mention Office sandbox testing, macOS security auditing, privilege escalation research, or need to understand Office sandbox bypass methods for defensive purposes.
git clone https://github.com/abelrguezr/hacktricks-skills
skills/macos-hardening/macos-security-and-privilege-escalation/macos-security-protections/macos-sandbox/macos-sandbox-debug-and-bypass/macos-office-sandbox-bypasses/SKILL.MDmacOS Office Sandbox Bypass Testing
This skill provides guidance on testing Microsoft Office sandbox escapes on macOS for authorized security research and penetration testing only. Never use these techniques on systems you don't own or have explicit permission to test.
Overview
Microsoft Office on macOS uses a custom sandbox with the entitlement
com.apple.security.temporary-exception.sbpl. This allows writing files anywhere if the filename starts with ~$. Several bypass techniques have been discovered over time.
Bypass Techniques
1. Launch Agent Bypass (Original)
Mechanism: Write a LaunchAgent plist to
~/Library/LaunchAgents/~$escape.plist
Sandbox Rule:
(require-any (require-all (vnode-type REGULAR-FILE) (regex #"(^|/)~$[^/]+$")))
How it works:
- Office sandbox allows writing files starting with
~$ - LaunchAgents in
are executed at login~/Library/LaunchAgents/ - Writing
creates persistence~$escape.plist
Test with script:
python scripts/create-launchagent-plist.py --payload "your-command-here"
Reference: MDSEC Report
2. Login Items + Zip Bypass
Mechanism: Use Login Items to unzip a malicious plist into LaunchAgents
Why it works:
- After patch #1, writing to
was blocked~/Library/LaunchAgents - Login Items can be set to zip files
- Archive Utility unzips to current location
- If
doesn't exist, it gets created~/Library/LaunchAgents
Steps:
- Create a plist file for LaunchAgent
- Zip it as
~$escape.zip - Add zip to Login Items
- User login triggers unzip → persistence
Test with script:
python scripts/create-loginitem-zip.py --payload "your-command-here"
Reference: Objective-See Report
3. Login Items + .zshenv/.bash_profile Bypass
Mechanism: Overwrite shell profile files via Login Items
Why it works:
- Previous technique failed if
already existed~/Library/LaunchAgents - Shell profiles (
,.zshenv
) execute on terminal launch.bash_profile - Zip can overwrite these files
Steps:
- Create
and.zshenv
with payload.bash_profile - Zip them as
~$escape.zip - Write zip to
~/~$escape.zip - Add zip to Login Items, then add Terminal app
- User login → unzip → terminal executes payload
Test with script:
python scripts/create-loginitem-zip.py --shell-profile --payload "your-command-here"
Reference: Desi Jarvis Report
4. Open + Environment Variables Bypass
Mechanism: Use
open --env to run Terminal with modified HOME
Why it works:
utility can launch apps from sandboxed processesopen
option sets environment variables for launched app--env- Setting
to a folder containingHOME
causes execution.zshenv
Steps:
- Create
with payload inside sandbox-accessible folder.zshenv - Run:
open --env HOME=/path/to/folder --env __OSINSTALL_ENVIROMENT=1 -a Terminal - Terminal executes
from modified HOME.zshenv
Test with script:
python scripts/create-env-bypass.py --payload "your-command-here" --target-folder /path/to/sandbox/folder
Reference: Perception Point Report
5. Open + Stdin Bypass
Mechanism: Pass Python script via stdin to bypass quarantine
Why it works:
parameter allows passing input to launched appopen --stdin- Python won't execute quarantined files from filesystem
- But stdin input bypasses quarantine checks
- Child process of launchd, not bound to Word's sandbox
Steps:
- Drop
with Python payload~$exploit.py - Run:
open --stdin='~$exploit.py' -a Python - Python executes code from stdin
Test with script:
python scripts/create-env-bypass.py --stdin --payload "your-python-code-here"
Testing Workflow
Before Testing
- Verify authorization - Only test on systems you own or have written permission to assess
- Document scope - Record which techniques you're testing and why
- Backup data - Some techniques modify system files
- Use isolated environment - Prefer VMs or test machines
Testing Steps
- Identify Office version - Different versions have different patches
- Check sandbox status - Verify Office is running sandboxed
- Select appropriate bypass - Based on Office version and system state
- Run test script - Use provided scripts to generate test files
- Verify execution - Check if payload executed (use logging, not destructive commands)
- Clean up - Remove test files and restore system state
Cleanup Commands
# Remove test LaunchAgents rm -f ~/Library/LaunchAgents/~$*.plist # Remove test shell profiles rm -f ~/.zshenv ~/.bash_profile # Remove test Python files rm -f ~/~$*.py # Remove test zips rm -f ~/~$*.zip
Defensive Recommendations
For Security Teams
- Keep Office updated - Microsoft patches these vulnerabilities
- Monitor LaunchAgents - Alert on new plist files in
~/Library/LaunchAgents/ - Watch Login Items - Monitor for unusual additions
- Restrict shell profile modifications - Use configuration management
- Deploy EDR - Detect sandbox escape attempts
- Application allowlisting - Restrict which apps can be launched
Detection Indicators
- New files starting with
in user directories~$ - Unusual LaunchAgent plists created
- Login Items modified to include zip files
commands withopen
or--env
parameters--stdin- Python processes spawned from Office parent
Legal and Ethical Notice
This skill is for authorized security testing only.
- Only use on systems you own or have explicit written permission to test
- Document all testing activities
- Clean up after testing
- Report findings to appropriate parties
- Never use for malicious purposes
Violating computer misuse laws can result in criminal charges and civil liability.