Mastering Apple Endpoint Security for Advanced macOS Malware Detection
Patrick Wardle
DEF CON 33 · Day 1 · Main Stage
Overview
Apple's Endpoint Security framework (ESF) is the official, Apple-sanctioned mechanism for building security products on macOS. It replaced the deprecated kext-based approach and is the foundation upon

Key moments
- 1:56 And I cannot stress the importance of this enough.
- 9:03 is the message that is delivered.
- 13:22 Apple then scans them for no malware.
- 19:41 These are the structures that describe processes and this is awesome.
- 30:50 and ignore every process except the one specific one we are running the malware.
- 34:56 This is Apple's internal Mac OS antiirus product.
- 38:56 Is it the user giving TCC permissions to something it should not?
Mastering Apple Endpoint Security for Advanced macOS Malware Detection
Speakers: Patrick Wardle
Conference: DEF CON 33
YouTube: https://www.youtube.com/watch?v=AgYGwZjcsLo
Slides: https://media.defcon.org/DEF%20CON%2033/DEF%20CON%2033%20presentations/Patrick%20Wardle%20-%20Mastering%20Apple%27s%20Endpoint%20Security%20Framework%20for%20Advanced%20macOS%20Malware%20Detection.pdf
Overview
Apple's Endpoint Security framework (ESF) is the official, Apple-sanctioned mechanism for building security products on macOS. It replaced the deprecated kext-based approach and is the foundation upon which every modern macOS EDR, antivirus, and security monitoring tool is built. Yet despite ESF's central importance, its darker corners — nuanced behaviors, performance pitfalls, and detection gaps — are poorly documented and widely misunderstood. At DEF CON 33, Patrick Wardle delivered a comprehensive technical deep dive into ESF's architecture, capabilities, and limitations, equipping both defenders building security tools and attackers trying to evade them with a precise understanding of what ESF can and cannot see.
The talk moves from fundamentals to advanced topics, covering event subscription internals, auth vs. notify events, deadlock risks, muting mechanisms, and subtle evasion techniques that real-world malware has already begun to exploit.
Background
▶ Watch: And I cannot stress the importance of this enough. (1:56)
The ESF Transition
Prior to ESF, macOS security software relied on kernel extensions (kexts) — third-party code loaded directly into the kernel. Kexts provided deep system visibility but were notoriously dangerous: a buggy or malicious kext could crash the entire system, and Apple's kernel ABI was never guaranteed to be stable. Beginning with macOS Catalina (10.15) in 2019, Apple began deprecating kexts and introduced ESF as the supported replacement.
ESF is a kernel-level framework that exposes system events — file operations, process launches, network connections, IPC, and more — to user-space clients via a structured API. Security tools register as ESF clients and receive event notifications. This design keeps third-party code out of the kernel while still providing the event visibility needed for security monitoring.
Today, ESF is not optional for vendors: Apple's System Integrity Protection (SIP) prevents kexts from loading on modern hardware without explicit user override, and the App Store and enterprise MDM ecosystems expect ESF-based security products. Understanding ESF is therefore essential for anyone writing macOS security software, and equally important for attackers who want to understand what defenders can see.
ESF's Place in the macOS Security Stack
ESF sits alongside several other macOS security technologies: Transparency, Consent, and Control (TCC) for privacy permissions, Gatekeeper and Notarization for app trust, XProtect and MRT for malware signatures, and the Secure Enclave for cryptographic operations. ESF specifically handles the behavioral monitoring layer — watching what processes do at runtime rather than checking trust at launch time. It is the layer most analogous to kernel callbacks in Windows (PsSetCreateProcessNotifyRoutine, etc.) and auditd on Linux.
Patrick Wardle, founder of the Objective-See Foundation and co-founder of DoubleYou (which builds macOS detection components for enterprise security products), is among the world's leading experts on macOS security. His talk at DEF CON 33 draws on the depth of knowledge compiled in Volume 2 of his freely available "The Art of Mac Malware" book series, which dedicates two full chapters to ESF.
Key Findings
▶ Watch: Apple then scans them for no malware. (13:22)
- ESF distinguishes between AUTH and NOTIFY events, and this distinction is critical for both detection fidelity and system stability. AUTH events require the ESF client to make an allow/deny decision within a strict timeout; missing the deadline can deadlock the system. NOTIFY events are informational only.
- ESF clients can mute specific processes or paths, and attackers can abuse this to create blind spots. The
es_mute_processandes_mute_pathAPIs are intended for performance optimization, but if an attacker can influence which processes are muted (e.g., by injecting into a process that is muted by a security tool), they gain evasion.
- Event ordering and race conditions in ESF create exploitable windows. Because ESF delivers events asynchronously to user space, there are brief windows between a process performing an action and the ESF client observing it. Certain techniques can exploit this window.
- Not all sensitive operations generate ESF events. ESF's coverage is extensive but not exhaustive. Certain lower-level kernel operations, XPC communications, and some Mach port interactions do not surface through the ESF API, leaving detection gaps that sophisticated macOS malware can target.
- The ES_EVENT_TYPE_AUTH_EXEC event is the most powerful ESF hook for detecting process-based attacks, but its interaction with child processes, fork-exec patterns, and scripting language invocations has nuances that can cause false negatives if not handled carefully.
Technical Deep Dive
▶ Watch: These are the structures that describe processes and this is awesome. (19:41)
ESF Architecture and Client Registration
An ESF client is a user-space process (running as root, or entitleled with com.apple.developer.endpoint-security.client) that calls es_new_client() to register with the framework. The client provides a handler block that is invoked for each subscribed event. The client then calls es_subscribe() to specify which event types it wants to receive.
Events are delivered synchronously to the handler block on a dedicated dispatch queue. For AUTH events, the handler must call es_respond_auth_result() before the system-imposed deadline (configurable but typically in the range of several seconds for most event types, shorter for time-sensitive operations). Failing to respond within the deadline results in the default action being taken and, in some cases, system instability.
AUTH vs. NOTIFY Events
This distinction is at the heart of ESF's power and danger. AUTH events give the security client the ability to allow or deny an operation before it completes. Examples include:
ES_EVENT_TYPE_AUTH_EXEC: Decide whether a process is allowed to executeES_EVENT_TYPE_AUTH_OPEN: Decide whether a file open should be permittedES_EVENT_TYPE_AUTH_UNLINK: Decide whether a file deletion is allowed
NOTIFY events are delivered after the fact — the operation has already occurred. They are valuable for logging and forensics but cannot block malicious activity in real time. Examples include:
ES_EVENT_TYPE_NOTIFY_FORK: Process forkedES_EVENT_TYPE_NOTIFY_EXEC: Process executed (delivered after execution begins)ES_EVENT_TYPE_NOTIFY_WRITE: File write occurred
A common mistake in security tool implementation is subscribing to NOTIFY variants of events where AUTH variants exist, effectively reducing the tool to a logger rather than an active blocker.
Deadlock Risks and the AUTH Timeout Problem
The AUTH timeout mechanism is a source of subtle but severe bugs. If an ESF client subscribes to AUTH events and performs any operation within its handler that itself generates an ESF event (creating a reentrancy loop), a deadlock can occur. For example: a security tool subscribes to AUTH_EXEC, and in its handler, it tries to open a file to compute a hash of the binary being executed. If the AUTH_OPEN for that file also triggers the same client's handler, and the client is waiting for a response before proceeding, the system can deadlock.
Wardle details several real-world patterns that trigger this condition and the correct implementation approaches to avoid them: using muting to exempt the security tool's own operations, performing I/O on a separate thread that is not subject to ESF delivery, and using pre-computed caches where possible.
Muting: The Double-Edged Sword
The es_mute_process() API tells ESF to stop delivering events for a specific process (identified by audit token). This is used by security tools to avoid generating events for their own operations (preventing the reentrancy problem above). However, it creates an exploitable pattern: if an attacker can determine which processes are muted by a security tool, they can arrange for malicious code to execute from within a muted process.
More concerning is es_mute_path(), which mutes events for any process launched from a specific file path. If a security tool mutes a system path (e.g., a macOS system daemon's path to reduce noise), an attacker who can create a binary at that path — perhaps via a supply chain or software update attack — inherits the muting and becomes invisible to ESF monitoring.
Wardle presents the concept of "mute inversion" — monitoring for what should not be muted — as a detection technique to identify security tool evasion attempts.
Event Coverage Gaps
ESF does not cover all security-relevant operations. Notable gaps include:
- Direct kernel object manipulation: Rootkit techniques that modify kernel data structures directly (without going through system call interfaces) do not generate ESF events. ESF operates at the system call boundary; operations that bypass system calls are invisible to it.
- Certain XPC and Mach IPC operations: Not all inter-process communication generates observable ESF events. Sophisticated malware using direct Mach port communication may bypass ESF monitoring.
- Some network operations: ESF's network event coverage (
ES_EVENT_TYPE_NOTIFY_*_SOCKET*) was limited in earlier macOS versions and has been incrementally expanded. Security tools relying solely on ESF for network monitoring may miss connections established through lower-level socket APIs in older macOS versions.
Advanced Detection: ES_EVENT_TYPE_AUTH_EXEC Deep Dive
The AUTH_EXEC event is the most powerful primitive for detecting malicious process launches. Wardle covers several subtle aspects:
- The event fires before the process fully initializes. The executable image is mapped but
main()has not yet run. This means the security client can examine the binary and make a blocking decision before any malicious code executes — but also means the process's runtime state is not yet observable. - Script interpreter invocations. When Python, bash, or other interpreters are launched,
AUTH_EXECfires for the interpreter binary, not the script. The script path is available in the event's arguments, but only if the kernel has parsed the argument vector before the event fires. Race conditions in argument parsing have historically created brief windows where the script content was not yet available. #!shebang handling. The kernel handles shebang lines by recursively invokingexecvewith the interpreter binary. This generates a secondAUTH_EXECevent for the interpreter, with the original script as an argument. Security tools that only check the binary name without examining arguments will miss script-based malware.
Demo / Proof of Concept
▶ Watch: and ignore every process except the one specific one we are running the malware. (30:50)
Wardle demonstrates several concrete scenarios:
- Live ESF client implementation: A minimal but functional ESF client is shown implementing AUTH_EXEC monitoring with correct deadlock avoidance, demonstrating the exact API calls and handler structure required.
- Muting evasion: A demonstration shows a proof-of-concept malware binary executing from a path that a poorly configured security tool has muted, resulting in zero ESF events being delivered for the malicious process. The demo illustrates how mute configuration auditing can detect this condition.
- AUTH timeout exhaustion: A proof-of-concept demonstrates how a malicious process can deliberately trigger a flood of ESF events to exhaust the timeout budget for a security tool's AUTH handler, causing the tool to fall behind and default to allowing operations it should be blocking.
- Script evasion via shebang: A demonstration shows that a naive
AUTH_EXECmonitor that only checks binary hashes will completely miss a malicious Python script being executed via/usr/bin/python3, because the security tool whitelisted the Python interpreter binary without examining the script argument.
Defensive Implications
▶ Watch: This is Apple's internal Mac OS antiirus product. (34:56)
For macOS security tool developers:
- Always prefer AUTH variants of events over NOTIFY variants where real-time blocking capability is desired.
- Implement muting narrowly and audit muted paths/processes regularly for abuse potential.
- Use separate I/O threads for all file operations performed within ESF handlers to avoid reentrancy deadlocks.
- Implement process argument inspection in
AUTH_EXEChandlers to catch script-based attacks; binary hash alone is insufficient. - Monitor for unexpected muting patterns as a detection signal for security tool evasion.
For macOS attackers and red teamers:
- Enumerating which processes are muted by installed security tools provides a blueprint for evasion.
- Flooding ESF with high-volume events is a potential DoS technique against over-subscribed security tools.
- Direct kernel operations and certain Mach IPC paths remain outside ESF's visibility.
For macOS defenders generally:
- ESF is powerful but not omniscient. Complement ESF-based monitoring with additional data sources: unified logging, DTTrace where available, and network-layer monitoring.
- Understanding the framework's limitations is essential for accurate assessment of what a macOS EDR product can and cannot detect.
Key Takeaways
- ESF is the mandatory foundation for macOS security monitoring, but it has significant complexity and pitfalls that, if not handled correctly, produce security tools with exploitable blind spots.
- The AUTH/NOTIFY event distinction is fundamental: AUTH events enable real-time blocking; NOTIFY events are forensic-only. Conflating them is a common implementation error.
- The muting API, necessary for correctness, is also an evasion surface. Security tools must implement muting conservatively and monitor for unexpected mute conditions.
- Script interpreter and shebang handling requires argument inspection in
AUTH_EXEChandlers; binary identity alone is insufficient for script-based attack detection. - AUTH timeout exhaustion is a viable denial-of-service technique against security tools; implementations must handle high event volumes gracefully.
About the Speaker(s)
▶ Watch: Is it the user giving TCC permissions to something it should not? (38:56)
Patrick Wardle is the founder of the Objective-See Foundation, a nonprofit that produces free, open-source macOS security tools widely used by the security community. He is also the co-founder of DoubleYou, which builds macOS endpoint security detection components for enterprise security products. He is the author of "The Art of Mac Malware" book series (available free online), which is considered the definitive technical reference for macOS malware analysis. Wardle is one of the most prolific macOS security researchers in the world, with extensive DEF CON and Black Hat speaking history on macOS offensive and defensive topics.
Reviews
Dr. Zero (Offensive Security Researcher) — STRONG ACCEPT
The definitive reference on Apple ESF — auth/notify semantics, deadlock traps, muting abuse, and coverage gaps — from the person who has done more macOS security research than anyone else in the room.
Heather Calloway (CISO) — STRONG ACCEPT
Patrick Wardle maps Apple's Endpoint Security Framework with the precision of someone who has built on it and attacked it — covering AUTH vs. NOTIFY event distinction, muting abuse, deadlock risks, and script evasion. Essential reference for macOS security tool builders and red teamers. Exceptional technical depth on a platform-specific topic with broad enterprise relevance.