macOS PID Reuse
Last updated
Last updated
Learn & practice AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE) Learn & practice GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
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.
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):
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.
For the exploit to work it's important to export`` ``
OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES
or to put inside the exploit:
First option using NSTasks
and argument to launch the children to exploit the RC
Learn & practice AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE) Learn & practice GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)