Charles Proxy Local Root Privilege Escalation Exploit
Charles Proxy is a great mac application for debugging web services and inspecting SSL traffic for any application on your machine. In order to inspect the SSL traffic it needs to configure the system to use a proxy so that it can capture the packets and use its custom root CA to decode the SSL. Setting a system-wide proxy requires root permissions so this is handled by an suid binary located within the Charles application folder. Unfortunately this binary is vulnerable to a race condition which allows a local user to spawn a root shell. It supports a parameter '--self-repair' which it uses to re-set the root+suid permissions on itself, with a graphical dialog shown to the user. However if this is called when the binary is already root+suid then no password dialog is shown. It doesn't validate the path to itself and uses a simple API call to get the path to the binary at the time it was invoked. This means that between executing the binary and reaching the code path where root+suid is set there is enough time to replace the path to the binary with an alternate payload which will then receive the suid+root permissions instead of the Charles binary.