Your seatbelts from Alibaba Security Lab for, it looks like their talk is about escaping iOS 11 Sandbox. Give them a round of applause. Uh, hello everyone. Uh, can you hear me? Okay. Uh, hello everyone. Today we are going to talk about the security of iOS 11 Sandbox. Uh, this talk will be presented by my friend, Ms. Park Jung and me. Uh, we are from Alibaba Security. Uh, firstly, let, let's have a look at, uh, uh, uh, our system. Uh, there are three levels in our system. Uh, the first level is sandbox of applications. Uh, there are quite a few attack surfaces to, uh, the kernel in applications. Uh, and the second level is user-landed system services, including some, uh, services called Maxbox. Uh, Maxbox is a services. Uh, in this system services, we can have more attack surfaces to the kernel. And the third level is the kernel. Uh, so in iOS, every application is sandboxed. Uh, this sandbox was first, first introduced as seatbelt in macOS. Uh, and, uh, uh, in, uh, now, uh, mm, mm, there are over 100 operations, uh, that are hooked by, uh, sandbox policies. Uh, this sandbox policies were, were first, uh, blacklisted and now they are vetted now. Uh, it's, uh, with this table. Uh, this table is, uh, from the OS internals. Uh, with this table, we can know that there are over 100, uh, uh, sandbox hosts in iOS 11. Uh, and, uh, there is, uh, a concept called sandbox profiles. Uh, sandbox profiles define what, uh, Mac services can be, uh, accessed by, uh, uh, by sandbox applications. In macOS these profiles are visible and stored in system library sandbox profile as well. Uh, and in iOS, uh, the profiles were hard-coded and difficult to be decoded. Um, but we can traverse all Mac services to get, uh, the list of services that, uh, can be, uh, accessed, uh, by sandbox applications. Uh, also we can use, uh, some tools. For example, the SB2 developed by Jonathan. Uh, in order to find one of the bits in a Mac service we need to, uh, disassemble and analyze the binary that handles the, uh, uh, Mac service. Uh, uh, there, uh, there is a directory called system library large demons, uh, which contains, uh, the configuration P list files of most Mac services. From these P list files we can know, uh, uh, uh, the, uh, the, uh, the, uh, the, uh, the path to, uh, Mac services, uh, uh, binaries. And next, uh, Spark will, uh, give more details about, uh, the vulnerabilities we found in iOS 11 sandbox. Thank you. Thanks Xiaolong. Okay, so there are a rich set of IPC mechanism in iOS and most of them are available to third-party applications. In this talk we will focus on Mac service. Uh, the, uh, the, uh, the, uh, um, Mac messages are most commonly used of ICP mechanism in XNU. In addition, Mac messages contains typed data, which can include the portrait and reference to large range of memory. Based on Mac message, Apple developed the XPC, compared with the role Mac message, XPC is safer and easier to be used. But the cost of the XPC service minimum is very high just because message is built on top of XPC message which allow abstraction of XPC connections and remote objects. Through Mac message, Sandbox app can communicate with Mac services, XPC services and NSXPC services. Consequently if the server doesn't uh doesn't don't handle the message in expected ways, uh they may be corrupted by malicious apps. So in this talk I will share three old bugs today. The first the first bug exists in the gatekeeper XPC service. Uh the related binary is other others. Uh the service receives uh two parameters. One is test sub-parameter uh sub-dictionary. And uh uh second one is source. Uh the service receives two parameters. One is pass. Um but it doesn't check the validator of the passed string. Therefore if the attacker can use a pass uh traversal vulnerability to achieve uh arbitrary file move outside the Sandbox with uh with mobile privilege. Uh this bug was used in Pangu 9 for jailbreak. So the second vulnerability is in uh media library D. Uh this bug is used in uh mobile privilege. Uh this bug was used in NSXPC. Uh it can be exploited to read, write, and query uh arbitrary SQLite files outside the Sandbox. Since the remote object of the service have mobile privilege and it does not check uh the input path of the SQLite file. An attacker can achieve uh an arbitrary query in the uh of the files on the system. Uh the attacker can use sing command. Now we can easily begin transition for database at the path to connect the arbitrary uh files uh arbitrary SQLite files on the system and then use execute query to execute SQL commands uh on it. For example a malicious app can leverage this vulnerability to modify uh SMS messages or emails on the device. Uh in addition it has another vulnerability uh because it uses SQLite 3. Uh the SQLite 3 has a feature that's called FTS3 tokenizer. Uh it is used for built in full text search. Developer can use commands to get or set tokenizer. However uh attackers can leverage this feature to link memory information and even execute arbitrary code. For example the first commander commander has helped us link the address of the default tokenizer which can help us to uh bypass ASLR. Uh in addition attacker can register a new tokenizer and trigger the callbacks using the following commands uh the the second command commands. Because the call callback address is set by us and uh the process doesn't check it. So it's possible for us to hijack the PC register and control the ASXPC service as as we want. Uh this vulnerability was used in our private jailbreak. So, uh, here is the third, uh, third box. The, uh, this box exists in the Bluetooth D Mac, Mac service. There are 132, uh, functions in the com Apple service Bluetooth D Mac service. Bluetooth D communicates with other Sandbox apps and the, uh, Sandbox, the processes, for example, through com Apple service Bluetooth D. A process can use BT session attached to create a session token for the Bluetooth D and then use, uh, BT, BT local device at the callbacks to register a callback for event notification. However, it has a vulnerability, uh, which are found by Rennie. Uh, uh, Rennie, uh, uh, he found that the Bluetooth D only use the session token to identify the process, which means, uh, we can use a Sandbox app to hijack a communication between Bluetooth D and our Sandbox, uh, processes through the session token. Uh, the key problem is the session token is too easy to be brute forced. It only have a 1 0 0 0 0 possible, uh, values. Therefore, the, uh, uh, therefore Apple fix this problem by adding a user ID, uh, to each session, which is a random number. And, uh, only the process, uh, and Bluetooth D know the user ID and Bluetooth D will check the map of SES token with the user ID in the, uh, at the callbacks. So as we mentioned before, a user ID is a very, very large random number. So, uh, even though the user ID is running, uh, for, uh, a, uh, machine, there will be no issue. So, uh, due to the, uh,很有- So, if, uh, if we know the session token, we can still try to hijack the communication through user ID brute force. But when I try it, I found it will take a very, very long time, about 12 hours. So I don't think this is a good bug. So, uh, what if we can find some other functions without, uh, user ID verification? Yes, I found one. Uh, this, this function is called BT accessory manager add, add callbacks. However, after, after sending messages to that function, nothing happened. Uh, what's wrong? Finally, I found the problem. The callback event can be triggered only when the iOS device connects to a new device, which means we need to trigger the callback by click the Bluetooth D manually. This is not a good bug because we need to do something on the device, uh, manually. So the first bug takes a very, very long time. The second bug is very hard to trigger. How we find the third bug to, to, to, uh, to get a callback and easy to trigger? Finally, finally I found it. Uh, this, this one is called BT discovery agent create. We can use it to create a callback for the discovery agent. Then we can use BT discovery agent start scan to trigger the callback without manual click. So uh we find a very good bug. But uh the goal for uh the goal is not only control the PC register but the process as well. So the next step is to create a rope chain and do a hip, hip spree for the target process. In this case uh we use complex mark message with all our descriptor memories. Uh this this is a very useful uh mark mark message because if we send the message uh to the process and don't receive it the message will stay in the targeter's memory space persistently. Then we can use a magic address. Uh for example uh in in this case it is one oh five four. Zero, zero, zero, zero. To set this callback address and the PC can jump to this address. It will uh point to a rope chain. So after we trigger the vulnerability we can control the following registers. And the last BR is X4. So now we can do BOP or GOP. Uh but it's hard for us to control the whole pro uh program flow. Because we need a stack of BOP. So we need a stack of BOP. Pivot to control the stack and change the BOP to ROP. So a good uh stack pivot gadget can be found in the system platform. Uh this gadget is very useful. If we can control X0 we can control SP. Uh after that we can do real rope. Uh by using rope we can steal files or open a sandboxed uh I.O.K. user client. Uh but uh rope is not elegant. We want the task port to control everything. So what is task port? Uh let me briefly introduce what is port. A port in XNU provides an end point for IPC. Uh messages can be sent to a port or received from it. Ports can contains writes and the port writes can be passed in message. The most important port for the process is the uh IPC. Uh that is for the uh task port. Uh which can be get from Mac task self. Uh one can control the memory or other registers for the process through it's task port. Uh this this port is very useful. For example we can use Mac VM Eilog to Eilog memories in a remote process through the task port. And a Mac VM write to copy data into a remote t- a remote process. Uh so we can control the thread create a running to create a new thread and control registers in your remote process. So if we can get the task port, we can control everything of the process. Okay. So let's try to get the task port of a remote process. Here is the steps. First we ask LaunchD to get the port name of Bluetooth D. Then we send a lot of ports with the PwnApps send write to the Bluetooth D and send the ropes through HIP3. After that, we trigger the vulnerability to control the PC of Bluetooth D. After that, we use the rope chain to send the MAC messages which contains the task port of Bluetooth D back to our PwnApp. After that we can use the target process, we can control the whole target process through its task port. Uh there are some tricks learned from March portal uh which are developed by beer. Uh we can use insert write to insert a send write to the port. And the port can be sent by all our messages with port description. In most cases uh the March the March task self returns 103. So when so we can just use 103 without the rope to call the March task self. Uh in order to get the task port back to our Pong app we need to know the port number of our Pong app. However we can't use launch D to help us. So we so that's why we send a lot of ports because it can be brute force. So we send a lot of ports to the remote server and to in order to increase the successful rate. Uh after that we can try to remotely some memories in the target process or just uh execute some functions in the target process. Uh however iOS 11 uh add a new mitigation that uh we uh we cannot easily use the task port in the user land. So uh there uh but uh we we have a plan B that the ropes always work in the user mode. So we can use the generic uh pre primitive for the function code we have amper parameters in the code foundation. Uh this gadget is very useful because we can have our limited parameters uh and then call X X eight and uh last return to uh the program. Uh by using Pong app to uh and uh to uh I can create the program. Uh the, uh, Bluetooth D vulnerability, we successfully, uh, exploit the iOS kernel through, uh, Sandbox IOKit user client and break kernel slides and then gain the kernel read and write ability on the iOS 11. Also, we, uh, we got a root shell and a jailbreak on the, uh, iOS 11. So, uh, here is the conclusion. First, we introduce the basic concept of iOS Sandbox and summarize several classic ways to escape the iOS Sandbox. Uh, based on, uh, old Bluetooth D vulnerability, we found two new zero-day sandbox escape vulnerabilities on the latest iOS, iOS version. And we present a classic way to do it. So, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, the taskubit of the remote process during the, uh, the exploit, uh, during the exploit. Uh, there is a, uh, update. Uh, after we, uh, submit our talk to DEF CON, uh, we, uh, we also report these, uh, these two zero-day bugs. Uh, they are the main ones, the, uh, the, uh, the, uh, the to Apple on July 7. Apple fixed them in the latest IOS and as well as IOS 12 beta with CVEs. So please update your device to the latest version in order to defend against potential attacks. So here is some reference for this talk. Okay. That's all for our talk. You can follow us on Twitter. Thank you for your listening.