macOS XPC Connecting Process Check
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 connection is stablished to an XPC service, the server will check if the connection is allowed. These are the checks it would usually perform:
Check if the connecting process is signed with an Apple-signed certificate (only given out by Apple).
If this isn't verified, an attacker could create a fake certificate to match any other check.
Check if the connecting process is signed with the organization’s certificate, (team ID verification).
If this isn't verified, any developer certificate from Apple can be used for signing, and connect to the service.
Check if the connecting process contains a proper bundle ID.
If this isn't verified, any tool signed by the same org could be used to interact with the XPC service.
(4 or 5) Check if the connecting process has a proper software version number.
If this isn't verified, an old, insecure clients, vulnerable to process injection could be used to connect to the XPC service even with the other checks in place.
(4 or 5) Check if the connecting process has hardened runtime without dangerous entitlements (like the ones that allows to load arbitrary libraries or use DYLD env vars)
If this isn't verified, the client might be vulnerable to code injection
Check if the connecting process has an entitlement that allows it to connect to the service. This is applicable for Apple binaries.
The verification must be based on the connecting client’s audit token instead of its process ID (PID) since the former prevents PID reuse attacks.
Developers rarely use the audit token API call since it’s private, so Apple could change at any time. Additionally, private API usage is not allowed in Mac App Store apps.
If the method processIdentifier
is used, it might be vulnerable
xpc_dictionary_get_audit_token
should be used instead of xpc_connection_get_audit_token
, as the latest could also be vulnerable in certain situations.
For more information about the PID reuse attack check:
macOS PID ReuseFor more information xpc_connection_get_audit_token
attack check:
Trustcache is a defensive method introduced in Apple Silicon machines that stores a database of CDHSAH of Apple binaries so only allowed non modified binaries can be executed. Which prevent the execution of downgrade versions.
The server will implement this verification in a function called shouldAcceptNewConnection
.
The object NSXPCConnection has a private property auditToken
(the one that should be used but could change) and a the public property processIdentifier
(the one that shouldn't be used).
The connecting process could be verified with something like:
If a developer doesn't want to check the version of the client, he could check that the client is not vulnerable to process injection at least:
Learn & practice AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE) Learn & practice GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)