Race Against the (Mac)hine: Local Privilege Escalation in Microsoft Defender for macOS

Eugene Lim (Security Researcher · JPMorganChase)

BlueHat Asia 2026 · Day 1 · Main Stage

Overview

In his BlueHat Asia talk, "Race Against the (Mac)hine: Local Privilege Escalation in Microsoft Defender for macOS," security researcher Eugene Lim unveiled a critical local privilege escalation (LPE) vulnerability affecting Microsoft Defender for macOS. This presentation delved into the intricacies of cross-platform software development, highlighting how subtle differences in operating system security mechanisms can lead to significant security flaws, even when similar vulnerabilities have been addressed on other platforms. Lim’s research serves as a compelling case study in variant analysis, demonstrating how a previously patched race condition in Microsoft Defender for Windows could be re-exploited on macOS due to divergent security assumptions and API implementations.

Watch on YouTube

Visual summary for Race Against the (Mac)hine: Local Privilege Escalation in Microsoft Defender for macOS by Eugene Lim
Visual summary for Race Against the (Mac)hine: Local Privilege Escalation in Microsoft Defender for macOS by Eugene Lim

Key moments

  1. 0:00 Introduction and variant analysis motivation
  2. 8:00 Defender's IPC architecture and flawed PID authorization
  3. 11:00 Exploiting execve for PID authorization bypass
  4. 13:00 Arbitrary file read using macOS hard links
  5. 16:00 Arbitrary file write by skipping authorization checks
  6. 21:45 Root command execution using macOS crontab
  7. 22:20 Key takeaways: cross-platform security differences

Race Against the (Mac)hine: Local Privilege Escalation in Microsoft Defender for macOS

Speakers: Eugene Lim, Security Researcher, JPMorganChase

Conference: BlueHat Asia

YouTube: https://www.youtube.com/watch?v=xmdAG1roFPg

Overview

In his BlueHat Asia talk, "Race Against the (Mac)hine: Local Privilege Escalation in Microsoft Defender for macOS," security researcher Eugene Lim unveiled a critical local privilege escalation (LPE) vulnerability affecting Microsoft Defender for macOS. This presentation delved into the intricacies of cross-platform software development, highlighting how subtle differences in operating system security mechanisms can lead to significant security flaws, even when similar vulnerabilities have been addressed on other platforms. Lim’s research serves as a compelling case study in variant analysis, demonstrating how a previously patched race condition in Microsoft Defender for Windows could be re-exploited on macOS due to divergent security assumptions and API implementations.

The talk meticulously dissects the journey from an authentication bypass to arbitrary file read and write primitives, culminating in root-level command execution. Lim, known for his work on zero-day research and author of "Day Zero to Zero Day," provided a deep technical dive into macOS interprocess communication (IPC) and file system nuances, contrasting them with Windows. His findings underscore the profound challenges in securing applications designed to run across diverse operating systems, urging developers and security researchers to consider OS-specific security models rather than relying solely on cross-platform libraries or generalized patching efforts.

Background

▶ Watch: Introduction and variant analysis motivation (0:00)

The genesis of this research stems from a prior privilege escalation vulnerability discovered earlier in the year within Microsoft Defender for Windows. That particular flaw exploited a race condition in the file quarantining logic, specifically leveraging NTFS junctions. Recognizing that enterprise security solutions like Microsoft Defender are often deployed across entire fleets—encompassing Windows, macOS, and Linux—Lim embarked on a variant analysis to investigate whether a similar vulnerability pattern could manifest on macOS, despite the inherent differences in its operating system architecture.

The core problem often lies in interprocess communication (IPC) between unprivileged user applications (e.g., a GUI) and privileged backend services (e.g., a root-level daemon). Such interactions are fertile ground for vulnerabilities, broadly categorized into:

  1. Missing or broken authentication checks: The privileged service fails to properly verify the identity of the calling unprivileged process.
  2. Insufficient input validation: Even if authenticated, the inputs from the unprivileged process are not thoroughly sanitized, leading to injection or other abuses.
  3. Incorrect configuration or misuse of authorization APIs: Developers fail to correctly implement or call the operating system's built-in security mechanisms.

macOS, like other modern operating systems, employs several mechanisms to mitigate these risks:

  • Code Signing: Ensures that binaries originate from trusted developers, preventing execution of unsigned or tampered code. This allows privileged services to verify the legitimacy of IPC callers.
  • Hardened Runtime and System Integrity Protection (SIP): Kernel-level protections that prevent injection into trusted processes (e.g., dynamic library injection, akin to DLL injection on Windows) and restrict root access to certain system locations, even for the root user.
  • Authorization Services API: An explicit, opt-in API that developers must call to consult a policy database for named rights. This can involve prompting an administrator for credentials before sensitive actions are taken. Crucially, its "self-restricted" nature means developers must explicitly invoke it; forgetting to do so bypasses its protection.
  • Audit Tokens: Introduced to combat process spoofing (e.g., PID reuse attacks famously demonstrated by Samuel Gross), audit tokens tie a process ID (PID) to a version identifier. This prevents a malicious process from adopting a recently freed PID and impersonating a legitimate, previously exited process. However, this relies on using first-party macOS IPC mechanisms like XPC.

Understanding these macOS security primitives is crucial for appreciating how Microsoft Defender, a cross-platform application, might inadvertently expose itself to vulnerabilities by misinterpreting or misimplementing these OS-specific controls.

Key Findings

▶ Watch: Exploiting execve for PID authorization bypass (11:00)

Eugene Lim's research uncovered a critical chain of vulnerabilities in Microsoft Defender for macOS, ultimately leading to local privilege escalation. The key findings are:

  1. PID Race Condition for Authentication Bypass: Microsoft Defender for macOS utilized AF_UNIX stream sockets for IPC between its unprivileged GUI helper process and the root-level daemon. Instead of leveraging macOS's robust audit tokens via XPC, Defender implemented a custom per-connection authentication check based on the calling process's PID and its executable path. This check was susceptible to a Time-of-Check to Time-of-Use (TOCTOU) race condition, where an attacker could use the execve syscall to temporarily swap their process identity to a legitimate Defender binary during the authentication check, then revert to their malicious process once authorized. This granted the attacker the ability to make arbitrary calls to the privileged daemon.
  1. Arbitrary File Read Primitive via Hard Links: Leveraging the authentication bypass, Lim discovered an arbitrary file read vulnerability. The get diagnostic files opcode, intended to collect system logs, performed a file type check using the Boost C++ standard library's file_status function. While this check adequately prevented symlink abuses on Windows, it failed to account for the distinct behavior of Unix-style hard links on macOS. Unlike Windows hard links, macOS hard links do not require write access to the target file, only search permissions to the containing directory. This allowed an attacker to create a hard link from a user-controlled directory to a root-readable sensitive file (e.g., /etc/master.passwd), pass the hard link path to the daemon, and have the daemon include the sensitive file's content in a world-readable diagnostic zip archive.
  1. Arbitrary File Write Primitive with Authorization Bypass: The handle threat opcode, used for quarantining and restoring files, presented an arbitrary file write primitive. The vulnerability stemmed from the Authorization Services API's optional authorization blob. By omitting this optional blob in the IPC request, the daemon's authorization check was inadvertently skipped, allowing an unprivileged attacker to trigger a file restore operation with root privileges. The attacker could stage an arbitrary payload as a quarantined file and then restore it to any desired location on the filesystem.
  1. Local Privilege Escalation to Root via /etc/crontab: The arbitrary file write primitive was then leveraged for full LPE. While initial attempts to write to launch demons failed due to ownership and overwrite limitations, Lim discovered that overwriting the non-existent (by default) /etc/crontab file allowed for immediate execution of arbitrary commands as root. This method bypassed the need for rebooting and the ownership restrictions encountered with launch demons, as cron jobs do not require root ownership for their configuration file.

These findings collectively demonstrate how an accumulation of subtle OS-specific security model differences, coupled with common cross-platform development patterns, can lead to severe security vulnerabilities, even in widely deployed enterprise software.

Technical Deep Dive

▶ Watch: Arbitrary file read using macOS hard links (13:00)

Microsoft Defender for macOS employs a typical privileged/unprivileged process architecture. The core component is a daemon process that runs as root, responsible for privileged operations. An unprivileged Microsoft Defender helper process (the GUI) communicates with this daemon. Interestingly, instead of utilizing macOS's native and more secure XPC (cross-process communication) framework, Defender relies on more traditional AF_UNIX stream sockets. These sockets manifest as world-writable socket files, implying that any process could theoretically write to them.

Communication over these sockets follows a simple packet structure: a header followed by a body. The body contains an opcode dictating the desired action. Two opcodes were of particular interest:

  • handle threat: Used for quarantining and restoring files, implying write operations.
  • get diagnostic files: Used to collect system diagnostic information, implying read operations.

For authorization, Defender's daemon performs a per-connection check by fetching the connecting process's PID from the socket. It then queries the metadata associated with this PID, specifically retrieving the executable path. A strict prefix match is performed to ensure the executable path falls within the legitimate Microsoft Defender application bundle. If the path matches, the request is deemed authorized.

This custom authentication mechanism, however, is vulnerable to a Time-of-Check to Time-of-Use (TOCTOU) race condition. The window exists between the daemon fetching the PID and its associated metadata (time of check) and performing the requested action (time of use). An attacker can exploit this using the execve syscall.

  1. The attacker's process establishes a connection to the AF_UNIX socket.
  2. The attacker then immediately calls execve to replace its current process image with that of a legitimate, unprivileged Microsoft Defender binary (e.g., the helper process).
  3. Because the legitimate Defender binary is designed as a singleton, it quickly exits, returning control to the original attacker's process.
  4. During this brief window, when the daemon performs its PID-based check, it observes the metadata of the legitimate Defender binary, passing the authentication.
  5. Once the check passes, the original attacker's process regains control and can send arbitrary, privileged requests through the now-authorized socket connection.

With this authentication bypass, the next step was to achieve arbitrary file read. The get diagnostic files opcode accepts a list of files to include in a diagnostic zip. While Defender implemented checks to prevent symbolic links (symlinks), the implementation used the Boost C++ standard library's file_status function to verify that files were "regular files." This check, effective on Windows against junction points and symlinks, failed on macOS due to the distinct nature of Unix-style hard links.

On macOS (and Unix-like systems), a hard link creates a new directory entry that points directly to the same inode as an existing file. Crucially, creating a hard link to a target file does not require write permissions to the target file itself, only search permissions to its containing directory and write permissions to the directory where the hard link is being created. This contrasts sharply with Windows, where creating a hard link requires specific FILE_WRITE_ATTRIBUTES access to the target, a patch introduced over a decade ago following research by James Forshaw.

The attacker could:

  1. Create a hard link from a user-owned directory to a sensitive, root-readable file (e.g., /etc/master.passwd).
  2. Use the get diagnostic files opcode (via the race condition bypass) to request a diagnostic package including this hard link.
  3. The Boost file_status check would identify the hard link as a "regular file," bypassing the symlink mitigation.
  4. The daemon, running as root, would read the content of the target sensitive file and include it in a world-readable zip archive, which the attacker could then access.

To achieve arbitrary file write, the handle threat opcode was targeted. This opcode is responsible for quarantining files and, more importantly, restoring them. It accepts parameters like a thread ID, a destination path, and an optional authorization blob. The key vulnerability here was the optional nature of the authorization blob. The Authorization Services API, being "self-restricted" (opt-in), would skip authorization checks entirely if this blob was not provided.

The arbitrary file write primitive worked as follows:

  1. An attacker would stage a malicious payload by "quarantining" a user-owned file. Defender's quarantine mechanism encodes files (e.g., using Zole encoding) and stores them in a user-writable location. The attacker could simply overwrite this quarantined file with their desired payload.
  2. Using the PID race condition bypass, the attacker would then call the handle threat opcode, specifically the restore function, without providing the authorization blob.
  3. Because the authorization check was skipped, the root-level daemon would restore the attacker's arbitrary payload to any specified destination path with root privileges.

A critical limitation of this write primitive was that the destination path must not already exist. Defender's logic was designed to prevent accidental overwrites during file restoration. This meant direct overwriting of existing system files was not possible without an additional primitive.

Demo / Proof of Concept

▶ Watch: Root command execution using macOS crontab (21:45)

The final step was to leverage the arbitrary file write primitive for full Local Privilege Escalation (LPE) to root. Eugene Lim outlined his attempts and the successful path:

Failed Attempt 1: Launch Daemons

macOS uses launch demons (.plist files in /Library/LaunchDaemons) as a primary mechanism for running services at boot or on demand, analogous to Windows services. Lim's initial thought was to write a malicious launch daemon script to gain root execution. However, macOS imposes a strict security requirement: root-privileged launch daemon files must be owned by the root user.

When Microsoft Defender restores a file:

  1. It creates the file as root (satisfying the write privilege).
  2. It renames the file from a temporary GUID/UUID-based name to the original filename.
  3. Crucially, it then changes the permissions and ownership of the file back to the original owner (the unprivileged user who initiated the quarantine).

This meant the restored launch daemon file would not be owned by root, preventing its execution as a root-privileged service. Racing this ownership change proved too difficult and unreliable.

Failed Attempt 2: Microsoft Windows Install Monitor Launch Demons

Another approach considered was abusing an existing Microsoft Defender mechanism: the install monitor launch demon. This component watches for a "wake file" in its application directory. If present, it executes an install helper to copy files into the launch demons folder and bootstrap the system. The appeal was instant execution without a reboot.

However, this path was blocked by the arbitrary file write limitation: the "wake file" (and potentially the install helper) already existed. Since the restore primitive could not overwrite existing files, this method was infeasible.

Successful LPE: Overwriting /etc/crontab

The ultimate solution capitalized on a legacy Unix feature still present in macOS: crontab. The /etc/crontab file defines system-wide scheduled tasks.

  1. By default, /etc/crontab does not exist on most modern macOS installations, as launch demons are the preferred method. This neatly bypasses the "destination must not exist" limitation of the arbitrary file write.
  2. Crucially, a root-privileged cron job defined in /etc/crontab does not need to be owned by the root user for cron to execute it. This circumvents the ownership problem encountered with launch demons.
  3. When /etc/crontab is created or modified, the cron daemon (if running, or it can be easily started) picks up the changes and immediately begins executing the scheduled tasks. This provides instant command execution without requiring a system reboot.

By writing a simple cron job entry to /etc/crontab (e.g., * root /usr/bin/open -a Calculator), an attacker could achieve arbitrary command execution as root seconds after the file was written, thus demonstrating full local privilege escalation.

Defensive Implications

▶ Watch: Key takeaways: cross-platform security differences (22:20)

This research provides crucial insights for both developers and defenders, particularly in the context of cross-platform software:

  1. Understand OS-Specific Security Models: Developers building cross-platform applications must deeply understand the nuanced security models and API implementations of each target operating system. Relying on generalized library functions or assuming consistent behavior across OSes (e.g., file system linking, IPC authentication) is a significant risk. What works as a mitigation on Windows may be ineffective or even bypassed on macOS or Linux.
  1. Prioritize First-Party IPC Mechanisms: For macOS, utilize XPC for interprocess communication. XPC is designed with robust security features, including audit tokens, which inherently prevent PID reuse and process spoofing. Custom IPC implementations, like AF_UNIX sockets combined with custom PID-based checks, are prone to TOCTOU race conditions and other authentication bypasses.
  1. Explicitly Call Authorization APIs: When using "self-restricted" APIs like macOS's Authorization Services API, ensure they are explicitly and correctly called for all privileged operations. The optional nature of authorization blobs, as seen in the handle threat opcode, can lead to critical bypasses if not rigorously enforced.
  1. Robust File System Checks: Implement comprehensive and OS-aware file system checks. For file type validation, go beyond basic "is regular file" checks. Specifically, for macOS/Unix, account for hard links and their distinct permissions model compared to Windows. If sensitive operations involve paths provided by unprivileged users, resolve all symbolic and hard links to their canonical paths and verify the security context of the final target. Consider using redirection guard mechanisms (similar to Windows) where applicable to prevent link-based attacks.
  1. Secure File Operations: When privileged processes perform file operations (create, rename, restore), carefully manage file ownership and permissions. Avoid changing ownership back to unprivileged users if the file is intended for root-level execution (e.g., launch demons). Implement strict validation on destination paths for restore operations to prevent overwriting existing critical system files, even if the destination doesn't exist by default.
  1. Variant Analysis for Defenders: Security teams should incorporate variant analysis into their vulnerability management and patching strategies. When a vulnerability is disclosed and patched on one platform (e.g., Windows), actively investigate whether similar logic or underlying assumptions exist in the same software on other platforms (macOS, Linux). The core primitive might be the same, but the exploitation vector could differ due to OS-specific differences.
  1. Least Privilege Principle: Ensure that privileged components only perform the actions strictly necessary. Scrutinize any functionality that allows a root-level process to operate on user-supplied paths or data, as these are common vectors for privilege escalation.

Key Takeaways

  • Cross-platform software development introduces significant security challenges due to subtle, yet critical, differences in operating system security models.
  • A race condition (TOCTOU) in Microsoft Defender for macOS allowed an unprivileged attacker to bypass authentication by temporarily spoofing their process identity using execve.
  • macOS's Unix-style hard links behave differently from Windows hard links, allowing an arbitrary file read primitive to bypass file type checks designed for Windows.
  • An optional authorization blob in the handle threat opcode led to an authorization bypass, enabling arbitrary file writes as root.
  • The final Local Privilege Escalation was achieved by writing to /etc/crontab, exploiting its legacy nature and lack of default existence, and bypassing ownership restrictions of launch demons.
  • Developers must explicitly call OS-specific security APIs and understand platform nuances for IPC, file system operations, and authorization, rather than relying on generic cross-platform libraries.
  • Security researchers and defenders should proactively conduct variant analysis when vulnerabilities are patched on one OS, checking for similar flaws on other platforms running the same software.

About the Speaker(s)

Eugene Lim is a Security Researcher at JPMorganChase. He is also known by his hacker handle "Space Raccoon." Hailing from Singapore, Eugene is an accomplished author, having recently published "Day Zero to Zero Day" with No Starch Press, a book focused on bug bounty research and finding zero-day vulnerabilities. His work often involves deep dives into operating system internals and cross-platform security, as demonstrated by his research on Zscaler Client Connector and Microsoft Defender. He is a strong advocate for variant analysis, encouraging researchers to explore how vulnerabilities can manifest differently across various operating systems.

Reviews

Dr. Zero (Offensive Security Researcher) — SOLID

Solid variant analysis work that demonstrates real skill in understanding cross-platform security model divergence. Eugene Lim chains three distinct primitives—PID race, hardlink abuse, authz bypass—into a clean root escalation. Not earth-shattering in novelty, but executed well and genuinely useful for anyone shipping cross-platform security software.

Heather Calloway (CISO) — STRONG ACCEPT

Solid variant analysis work that turned a patched Windows vuln into a macOS root chain. Worth your time if you're running Defender on Mac fleets — and it's a clean illustration of why cross-platform security assumptions break down in ways your vendors won't tell you about.

→ Top-rated talks at BlueHat Asia 2026

All talks from BlueHat Asia 2026