macOS Kernel-to-Userland Process Creation Notification via undocumented kev_msg_post
The kev_msg_post function can be abused by malware to broadcast process creation notifications from a kernel extension (kext) to a user-mode application, potentially bypassing security tools that rely on standard APIs and leading to undetected malicious activity.
This threat brief describes the abuse of the undocumented kev_msg_post function in macOS to broadcast process creation notifications from a kernel extension (kext) to a user-mode application. This technique, highlighted in Objective-See’s research, allows a kext to bypass standard userland APIs for process monitoring. The kev_msg_post function is part of the Kernel Events API. It’s designed for kernel-to-userland communication but lacks proper documentation, which makes it difficult to monitor.
The communication involves a kext utilizing kev_msg_post to send data to a user-mode application through a system socket. Objective-See’s BlockBlock tool uses this technique to correlate persistent file I/O events with the responsible process. Abuse of kev_msg_post can allow malicious kexts to exfiltrate sensitive kernel-level information or trigger actions in user-mode without detection by conventional monitoring tools. This technique is relevant to defenders because it provides a stealthy mechanism for malware to operate within macOS, potentially leading to undetected data theft, privilege escalation, or system compromise.
Attack Chain
- A malicious kext is loaded into the macOS kernel, often requiring elevated privileges or exploiting a vulnerability.
- The kext uses the
kev_vendor_code_findfunction to obtain a vendor ID associated with the kext (e.g., “com.objective-see”). - The kext registers for process execution events using kauth or MAC policies.
- When a new process is created, the kext’s callback function is triggered.
- The kext populates a
kev_msgstructure with process information, including the process ID (PID), user ID (UID), parent process ID (PPID), and path to the executable. - The kext calls the undocumented
kev_msg_postfunction to broadcast the process information to a system socket. - A user-mode application with a socket connected to the same vendor ID receives the broadcasted message, extracting the process information.
- The attacker can use the process information for malicious purposes, such as injecting code into the new process, monitoring its activity, or terminating it.
Impact
Successful exploitation could allow attackers to monitor and manipulate processes on a compromised macOS system without detection by standard userland monitoring tools. This could lead to data exfiltration, privilege escalation, or other malicious activities. Due to the nature of the kernel, even a single successful compromise can lead to complete system compromise.
Recommendation
- Monitor for the loading of unsigned or untrusted kernel extensions using system integrity monitoring tools that track kext loading events.
- Implement detections for user-mode applications creating system sockets with the
SYSPROTO_EVENTprotocol, as described in the “Receiving the Data in User-Mode” section. This can be done using an endpoint detection and response (EDR) solution or auditd. - Develop YARA rules to scan kernel memory for the presence of kexts using the undocumented
kev_msg_postfunction to detect malicious kexts attempting to communicate outside kernel space. - Audit the use of
ioctlcalls withSIOCGKEVVENDORandSIOCSKEVFILTto detect user-mode applications attempting to filter for specific kernel events, using the code samples from the “Receiving the Data in User-Mode” section as reference.
Detection coverage 2
Detect Userland Process Requesting Kernel Event Vendor Code
mediumDetects userland processes using ioctl to get the kernel event vendor code, which is a prerequisite to receiving process notifications from a kext.
Detect Userland Process Setting Kernel Event Filters
mediumDetects userland processes using ioctl to set kernel event filters, indicating an attempt to subscribe to kernel events.
Detection queries are available on the platform. Get full rules →