Overview
macOS implements a layered defense-in-depth security model. Understanding each layer is essential for both bypassing them during authorized assessments and configuring them properly for hardening.Gatekeeper
Gatekeeper is the combination of three macOS security modules that work together to prevent execution of potentially malicious downloaded software:Quarantine
Marks downloaded files with a
com.apple.quarantine extended attribute. Files with this attribute trigger Gatekeeper checks when opened.Gatekeeper
Verifies code signatures and notarization for quarantined applications. Blocks unsigned or un-notarized apps by default.
XProtect
Apple’s built-in malware scanner. Checks files as they are downloaded against known malware signatures and blocks opening if matched.
SIP — System Integrity Protection
SIP prevents modification of system files, directories, and processes — even by root:macOS Sandbox
The macOS Sandbox (Seatbelt) limits applications to only the resources specified in their sandbox profile:- Applications are assigned a profile that defines which files, network connections, and system resources they may access
- Sandbox profiles are written in a Scheme-like language
- Third-party App Store apps must be sandboxed
- Process violations are denied and may be logged to the system console
TCC — Transparency, Consent, and Control
TCC is the framework that manages application access to sensitive features through explicit user consent:TCC-Protected Resources
TCC-Protected Resources
- Full Disk Access (
kTCCServiceSystemPolicyAllFiles) - Camera (
kTCCServiceCamera) - Microphone (
kTCCServiceMicrophone) - Location Services (
kTCCServiceLocation) - Contacts (
kTCCServiceAddressBook) - Photos (
kTCCServicePhotos) - Accessibility (
kTCCServiceAccessibility) - Screen Recording (
kTCCServiceScreenCapture)
TCC Database Locations
TCC Database Locations
TCC Inheritance
TCC Inheritance
Child processes may inherit TCC permissions from their parent. This has been historically exploited by:
- Launching privileged child processes from already-entitled parents
- Abusing
NSPredicateexpression injection in entitled daemons
Launch Constraints and Trust Cache
Introduced in macOS Ventura, Launch Constraints regulate process initiation:- Self constraints — rules about who can launch the binary itself
- Parent constraints — rules about what process can be the parent
- Responsible constraints — rules about which process is responsible
MRT — Malware Removal Tool
MRT is the reactive complement to XProtect:| Tool | Function | When it runs |
|---|---|---|
| XProtect | Preventative — blocks known malware before opening | On download (via certain apps) |
| MRT | Reactive — removes malware after detection | On system updates, new malware definition downloads |
/Library/Apple/System/Library/CoreServices/MRT.app
MRT rules are compiled into the binary itself and update automatically with macOS security updates.
Background Tasks Management (BTM)
Starting with macOS Ventura, BTM alerts users when software uses persistence mechanisms:/private/var/db/com.apple.backgroundtaskmanagement/BackgroundItems-v4.btm
How BTM Monitors Persistence
BTM usesFSEvents to watch for modifications to well-known persistence locations (Login Items, Launch Daemons, Launch Agents) and generates ES_EVENT_TYPE_NOTIFY_BTM_LAUNCH_ITEM_ADD events when new persistence is detected.
Bypassing BTM (Offensive)
Reset the BTM Database
Reset the BTM Database
Stop the BTM Agent
Stop the BTM Agent
Race Condition
Race Condition
If the process that created the persistence exits immediately after doing so, the BTM daemon fails to retrieve process information and cannot send the alert event. Short-lived persistence installers may not trigger BTM alerts.
MACF — Mandatory Access Control Framework
MACF is the underlying framework that all macOS mandatory access control policies (SIP, Sandbox, TCC) are built on. It provides kernel-level policy enforcement hooks. Key policy modules:- Sandbox — app confinement
- AppleMobileFileIntegrity (AMFI) — code signing enforcement
- Endpoint Security — EDR/antivirus framework