00:00:00.000-->00:00:05.005 >>Fasten your seatbelts. From Alibaba Security Lab. For eh it looks like their talk is about 00:00:07.641-->00:00:12.646 escaping IOS 11 Sandbox. Give em a round of applause. [applause] >>Uh, hello everyone. Uh, can 00:00:16.216-->00:00:21.221 you hear me? Okay. Uh hello everyone. Today we are going to talk about the security of IOS 00:00:23.490-->00:00:28.495 11 Sandbox and this talk will be presented by my friend Min Spark Zheng and me. Uh we are from 00:00:30.497-->00:00:35.502 Alibaba Security. Uh [speaker sighs] firstly let let's have a look at a an a our system. Uh 00:00:37.871-->00:00:44.211 there are 3 levels in our system and the first level is Sandbox applications. Uh their are quite 00:00:44.211-->00:00:50.450 a few attack surfaces to uh and kernel in applications uh and the second level is Userland 00:00:50.450-->00:00:56.957 system services. Encoding some uh services called Mac services. Uh in this system services we 00:00:56.957-->00:01:01.895 can have more attack services to the kernel and the third level is the kernel. Uh so in IOS our 00:01:04.498-->00:01:11.371 application is a sandbox. Uh this sandbox was first first in-introduced as Seatbelt in Mac 00:01:11.371-->00:01:16.376 OS uh and the uh in uh now uh mmm mmm there are over a hun uh 100 operations uh hoo- that are 00:01:22.015-->00:01:28.322 hooked by uh sandbox policies. And these sandbox policies were f our first uh uh black laced 00:01:28.322-->00:01:33.327 and now they are r-red lacing now. Uh with uh with this table, uh this table is uh uh from the 00:01:35.629-->00:01:40.634 OS internal roots. Uh with this t-table we can know that there are over 100 uh uh uh sandbox 00:01:42.703-->00:01:47.708 hosts in IOS 11. Uh, and uh there is uh a concept called sandbox profiles. Uh sandbox 00:01:51.044-->00:01:57.250 profiles defend what uh mac services account be accessed by uh um by a sandbox applications. 00:01:57.250-->00:02:03.123 In Mac OS these profiles are visible and stored in system library sandbox profile it's 00:02:03.123-->00:02:09.863 found and in IOS uh the profiles were hard coded and difficult to be decoded. And but we can 00:02:09.863-->00:02:14.901 travers all mach services to get the list of services that uh uh can be uh accessed uh by sandbox 00:02:17.838-->00:02:24.344 applications. Uh a-also we can use uh some tool. For example the SB tool developed by 00:02:24.344-->00:02:29.349 Jonathan. Uh in order to find vulnerabilities in mach service we need uh disassemble and 00:02:32.386-->00:02:37.391 analyze the binary that handles the uh uh mach service. Uh uh ss there uh there is a directory 00:02:41.194-->00:02:46.933 called system library launch daemons uh which contains uh the configuration plist of files of 00:02:46.933-->00:02:51.938 most mach services. From these plist files we can know the path to uh mach services uh 00:02:54.775-->00:03:01.081 bandwidth. And next uh Spark will uh give you more details about the vulnerabilities we 00:03:01.081-->00:03:06.086 found in IOS 11 sandbox. Thank you. [speaker walks off stage] >>Thanks Xiaolong. [speaker 00:03:10.190-->00:03:14.728 clears throat] Okay. So there are 3 sets of IP sand mechanism in IOS and most of them are 00:03:14.728-->00:03:19.733 available to third party applications. In this talk we will focus on mach service. Um 00:03:22.402-->00:03:28.909 mach messages are most common used uh IP sand mechanism in XNU. In addition mach messages 00:03:28.909-->00:03:35.449 contains typed data which can include port rights and references to large range of 00:03:35.449-->00:03:40.454 memory. Based on mach message Apple developed XPC compared with through mach message XPC is 00:03:43.423-->00:03:50.363 safer and easier to be used. But the cost of XP service maintenance is very high. NXSPC 00:03:50.363-->00:03:55.368 message is built on top of XPC message which allow abstractions of XPC connections and the 00:03:59.339-->00:04:04.277 remote objects. Through mach p-uh through mach message, sandbox app can communicate with 00:04:07.214-->00:04:12.219 uh ma-mach services XPC services and NSXPC services. Consequently if the server doesn't uh doesn't 00:04:16.890-->00:04:21.895 don't handle the message in expected ways uh they may be corrupted by malicious apps. So 00:04:25.966-->00:04:30.971 in this talk I will share 3 old bug today. This first the f-first bug exists in the 00:04:32.973-->00:04:37.978 gatekeeper XPC service. Uh the related binary is alert alerts uh the service receives uh 2 00:04:40.447-->00:04:45.452 parameters. 1 is test sub paramet uh sub di-dictionary and the uh second one is source 00:04:47.921-->00:04:52.926 path. Mmm but the if the doesn't check the validator of the path string. Therefor if the attacker 00:04:56.329-->00:05:03.270 can use a path uh traversal vulnerability to achieve a arbitrary file move outside the 00:05:03.270-->00:05:08.275 sandbox with uh with mobile privilege uh this bug was used in Pangu9 for jailbreak. So the 00:05:14.147-->00:05:19.152 second vulnerability is in uh media library D and SXPC uh it can be exploited to read write 00:05:22.489-->00:05:27.494 and query uh arbitrary SQlite files outside the sandbox. Since the remote object of the service 00:05:30.797-->00:05:35.802 have mobile privilege and it does not check uh the input path of the SQlite file and attacker 00:05:38.905-->00:05:43.910 can achieve uh an arbitrary query in the uh of the files on the system. [coughing] Uh the 00:05:46.446-->00:05:52.519 attacker can use begin transition for database at the path to connect an arbitrary uh 00:05:52.519-->00:05:57.524 files u-uh arbitrary SQlite files on the system and then use execute the query to execute SQL 00:05:59.960-->00:06:04.965 commands uh on it. For example a malicious app can leverage this vulnerability to modify uh SMS 00:06:07.867-->00:06:12.872 messages or emails on the device. Uh in addition it has another vulnerability uh because 00:06:17.344-->00:06:22.349 it uses SQlite3. Uh the SQlite3 has a feature that called FTS3 tokenizer. Uh it used for built 00:06:27.053-->00:06:32.058 in for text search. Developer can use commands to get a set tokenizer. However, uh attackers 00:06:35.996-->00:06:42.235 can leverage this feature to leak memory information and even execute arbitrary code. For 00:06:42.235-->00:06:47.207 example the first conander commander h-herb asks link the address of the default to 00:06:47.207-->00:06:54.214 another which had herb asked to uh bypass ASRR. Uh in addition attacker can register a new 00:06:54.214-->00:06:59.920 tokenizer and the trick their callback using the following commands. Uh the the second 00:06:59.920-->00:07:06.159 collan commands because the call callback address is set by us and uh the process doesn't check 00:07:06.159-->00:07:12.165 it so it's possible for us to hijack the PC register and control the NSXPC service a-as 00:07:12.165-->00:07:14.167 we want. This vulnerability was used in our private jailbreak. So uh here is the third uh third 00:07:14.167-->00:07:19.172 bug. The f-uh t-this bug exists in the bluetooth steam mach mach service. There are 100 and uh uh 00:07:28.715-->00:07:33.720 32 uh functions in the com apple service bluetooth D mach service. Bluetooth D 00:07:39.359-->00:07:44.364 communicates with other sandbox apps and unsandboxed processes. For example Springboard through 00:07:47.167-->00:07:52.172 com apple service bluetooth D. A process can use BT session attach to create a session token 00:07:56.343-->00:08:01.281 for the bluetooth D and then use a beat BT local device at callbacks to register a callback 00:08:03.583-->00:08:08.588 for event notification. However, it had a vulnerability which I found by running uh he found 00:08:12.692-->00:08:18.965 that the bluetooth D only use a session token to identify the process which means uh we can 00:08:18.965-->00:08:25.872 use a sandbox app to hijack a communication between bluetooth D and unsandboxed processes 00:08:25.872-->00:08:30.877 through the session token. Uh the king problem is the session token is too easy to be brute 00:08:33.146-->00:08:38.151 forced. It only have 1, 0, 0, 0, 0 possible uh values. Therefore the uh therefore apple fixed 00:08:42.355-->00:08:47.360 this problem by adding a user ID uh to each session which is a random number and the only the 00:08:49.963-->00:08:54.968 process and the bluetooth D know the user ID and the bluetooth D will check the map uh of S uh 00:08:58.972-->00:09:03.910 SES token with the user ID in the add callbacks. So as we mentioned before, a user ID is 00:09:09.048-->00:09:14.054 very very large random number. So if uh if we know the session token, we can still try to 00:09:16.689-->00:09:23.563 h-hijack the communication through user ID brute force. But when I try it I found it will 00:09:23.563-->00:09:28.568 take a very very long time. About 12 hours. So I don't think this is a good bug so uh what if 00:09:31.704-->00:09:36.709 we can find some other functions without a user ID verification. Yes, I found one. Uh this this 00:09:39.512-->00:09:44.517 function is called BT accessory manager add a add a callbacks. However afte after sending 00:09:47.487-->00:09:52.892 messages to that function nothing happened. Well what's wrong? Finally I found the 00:09:52.892-->00:09:57.897 problem. The call back event can be triggered only when the IOS device connects to a new device 00:10:00.166-->00:10:05.171 which means we need to trigger the call back by click the bluetooth steam manually. This 00:10:08.041-->00:10:13.046 is not a good bug because we need to do something on the device uh manually so the first 00:10:15.548-->00:10:20.553 bug takes a very very long time. The second bug is very hard to trigger can we find the third 00:10:22.689-->00:10:27.694 bug to to to to uh to get a callbacks and uh easy to trigger. [coughing] Finally, 00:10:30.230-->00:10:35.235 finally I found it. Uh th-this one is called BT discovery agent create. We can use it to create 00:10:37.937-->00:10:44.143 a callback for the discovery agent. The we can use BT discovery agent start scan to 00:10:44.143-->00:10:49.148 trigger the call back without manual click. So uh we find a very good bug. But uh the goal 00:10:52.685-->00:10:59.459 for uh the goal is not only control the PC register but uh the process as well. So the next 00:10:59.459-->00:11:05.965 step is to create a ROP chain and do a heap heap spray for the target process. In this case uh 00:11:05.965-->00:11:10.970 we used complex mach message with OOL descriptor memories. Uh th-this is a very useful mach 00:11:15.108-->00:11:20.880 mach message because if we send t-the message u-uh to the process and don't receive it, 00:11:20.880-->00:11:26.819 the message will stay in the targetor's memory's base persistently. Then we can use a 00:11:26.819-->00:11:31.824 magick a-address ff uh for example. Uh i-in this case is 1 0 5 4 0 0 0 0. To set this call 00:11:35.528-->00:11:40.533 back address and t-the PC can jump to this address. It will uh point to a ROP chain. So after 00:11:45.004-->00:11:50.009 we trigger the vulnerability, we can control the following in registers and the last BR is X4. 00:11:52.579-->00:11:57.584 So now we can do BOP or JOP. Uh but it's hard for us to control the whole proc uh program flaw 00:12:01.888-->00:12:06.893 because we need a stack pivoter to the control the stack and change the BOP to ROP. So a good 00:12:09.295-->00:12:14.300 stack pivot gadget can be found in the system platform DY lib. Uh this gadget is very useful if 00:12:17.704-->00:12:22.709 we can control X0 we can control SP. Uh after that we can do real ROP. Uh, by using ROP we can 00:12:27.914-->00:12:32.919 steal files or open a sandbox uh IO kit user client. Uh but ROP is not elegant. We want the task 00:12:36.589-->00:12:42.695 port to control everything. So what is task port? Uh let me briefly introduce what is port. 00:12:42.695-->00:12:47.700 A port in XNU provides a an end point for IPC. Uh messages can be sent to a port or receive 00:12:50.403-->00:12:55.408 from it. Ports can contains rights and the port rights can be passed in message. The most 00:12:57.510-->00:13:02.448 important part for the process is uh task port. Uh which can be get from mach task self. Uh one 00:13:06.252-->00:13:11.257 can control the memory o-or the registers for the process through it's task port. Uh this 00:13:15.395-->00:13:22.001 this port is very useful. For example, we can use mach VM allocate to allocate memories in 00:13:22.001-->00:13:28.608 a remote process though the task port and mach VM write to copy data into a remote t-remote 00:13:28.608-->00:13:33.613 process and uh thread create running to create a new thread and control registers in your 00:13:36.315-->00:13:41.320 remote process. So if we can get the task port, we can control everything over the process. 00:13:44.290-->00:13:49.295 Okay, so let's try to get the task port of a a remote process. Here is steps. First we ask a 00:13:53.199-->00:13:58.204 launch D to get the port port name of bluetooth D. Then we send a lot of ports with the pwn 00:14:01.007-->00:14:07.280 apps that's on the right to the bluetooth D and send ROPS through heap spray. After that 00:14:07.280-->00:14:13.653 we trigger the vulnerability to control the PC of bluetooth D. After that we use a ROP chain to 00:14:13.653-->00:14:18.891 send mach messages which contains the task port of bluetooth D back to our port 00:14:18.891-->00:14:25.765 app. After that we can use the target process uh we can control the whole target process through 00:14:25.765-->00:14:30.770 it's task port. There are some tricks learned from mach portal. Uh which our developed by Beer. 00:14:34.107-->00:14:40.446 Uh we can use insert right to insert a sender right to the port and the port can be sent by 00:14:40.446-->00:14:45.451 OOL messages with port description. In most cases, uh the mach the mach mach task self 00:14:48.121-->00:14:53.126 returns 1 0 3 so when so we can adjust the old 1 0 3 without ROP to call the mach task self. Uh 00:14:56.229-->00:15:02.201 in order to get the task port back to our pwn app, we need to know the port number or our pwn 00:15:02.201-->00:15:07.206 app. However, we can't use launch D to help us. So we so that's why we send a lot of 00:15:09.208-->00:15:15.882 ports because it can be br-brute forced. So we send a lot of ports to the remote server and 00:15:15.882-->00:15:20.887 to in order to increase successful rate. Uh after that we can try to r-remotely malloc 00:15:25.591-->00:15:30.596 malloc some memories in the target process or just the execute some functions in the 00:15:32.765-->00:15:37.770 target process. Uh however, IOS 11 uh had a new mitigation that uh we can we can not easily use 00:15:43.009-->00:15:48.014 the task port in the user land. So uh there uh but uh w-we have a plan B that the ROP's always 00:15:52.819-->00:15:57.824 work in the user mode. So we can use a generic uh prim primitive for the function calls with 00:16:00.660-->00:16:07.600 arbitrary parameters in the core foundation. Uh, this gadget is very useful because we can have 00:16:07.600-->00:16:12.605 our limited parameters uh and then call f-uh X X8 and uh l-last return to uh the program. 00:16:18.077-->00:16:23.082 Uh by using the uh bluetooth D when we break it we successfully uh exploit IOS kernel so our 00:16:29.121-->00:16:34.193 sandbox allocated your the client and the break can all slide and then gain the kernel 00:16:34.193-->00:16:39.198 reader and the writer ability on the IOS 11. Also we uh we got a root shell and a jailbreak on 00:16:42.068-->00:16:47.073 the uh IOS 11. So uh here is the concluding. First we introduce the basic concept of IOS sandbox 00:16:54.380-->00:16:59.385 and summarize several classic ways to escape the IOS sandbox. Uh based on uh old bluetooth D 00:17:03.756-->00:17:08.761 vulnerability we found 2 new 0 day sandbox escape vulnerability on the latest IS IOS version and 00:17:11.430-->00:17:18.237 we present a classic way to do heap spray, stack pivot and ROP in IOS userland. Then we show 00:17:18.237-->00:17:25.077 how to get and the control. The task port of the remote process during [inaudible word] the 00:17:25.077-->00:17:30.082 exploit. Uh during the e-exploit. Uh there is a update uh after we uh submit our talk 00:17:34.353-->00:17:39.358 to Defcon uh we uh we also report this to uh this to zero day bugs to apple on July 7th um 00:17:46.165-->00:17:51.170 apple fixed them in the latest IOS uh and as well as IOS 12 beta with CVE's so please update 00:17:55.908-->00:18:01.814 uh your device to the latest version in order to defend against potential attask uh 00:18:01.814-->00:18:06.819 po-potential attacks. Uh so here is some reference for this talk. Uh okay th=that's all for our 00:18:11.757-->00:18:16.762 talk. You can follow us on Twitter. Thank you all for listening. [applause]