macOS PID Reuse

PID Reuse

When a macOS XPC service is checking the called process based on the PID and not on the audit token, it's vulnerable to PID reuse attack. This attack is based on a race condition where an exploit is going to send messages to the XPC service abusing the functionality and just after that, executing posix_spawn(NULL, target_binary, NULL, &attr, target_argv, environ) with the allowed binary.

This function will make the allowed binary own the PID but the malicious XPC message would have been sent just before. So, if the XPC service use the PID to authenticate the sender and checks it AFTER the execution of posix_spawn, it will think it comes from an authorized process.

Exploit example

If you find the function shouldAcceptNewConnection or a function called by it calling processIdentifier and not calling auditToken. It highly probable means that it's verifying the process PID and not the audit token. Like for example in this image (taken from the reference):

https://wojciechregula.blog/images/2020/04/pid.png

Check this example exploit (again, taken from the reference) to see the 2 parts of the exploit:

  • One that generates several forks

  • Each fork will send the payload to the XPC service while executing posix_spawn just after sending the message.

First option using NSTasks and argument to launch the children to exploit the RC

Other examples

Refereces

Last updated