00:00:00.067,00:00:06.206 >>This talk at one o clock is from Xiaolong from Alibaba and Spark. Let’s give them a big 00:00:06.206,00:00:13.180 Defcon hat welcome, come on. [Applause] Louder, I don’t hear you. Louder, yeah! Alright man. 00:00:13.180,00:00:18.185 >>Thank you, thank you. Uh hello, uh okay. Hello everyone uh, I’m Xiaolong Bai from 00:00:21.855,00:00:26.860 Alibaba, uh this is Min Spark and uh he’s my colleague. And, today we are going to talk about 00:00:29.062,00:00:35.702 iOS security. Uh, the title of our talk is uh HackPac: Hacking Pointer Authentication in iOS 00:00:35.702,00:00:40.707 User Space. Uh before starting our talk, I’d like to have a self -self introduction and uh 00:00:42.776,00:00:47.781 I’m from Alibaba and before join Alibaba I have got my uh PhD Degree in uh Tsinghua University 00:00:52.886,00:00:58.525 and I have published several papers on uh Black Hat USA, Black Hat Europe, and uh the big 00:00:58.525,00:01:03.463 4. Uh my, Twitter account name is bxl1989 uh so welcome to uh follow me on Twitter. Uh my 00:01:05.933,00:01:10.938 colleague Spark Zheng is uh is a PhD from uh CUHK and he’s our senior security expert in 00:01:14.241,00:01:19.246 Alibaba. Uh his Twitter account name is SparkZheng. Uh this talk will be separated into several 00:01:22.316,00:01:29.089 parts. Uh firstly, I will have a brief in- uh brief introduction uh of what the point 00:01:29.089,00:01:34.695 authentication is. Uh and then I will show how pointer authentication is protecting iOS 00:01:34.695,00:01:39.700 uh and then uh comes to the uh main part of this talk, that is we found a design flaw in the 00:01:41.969,00:01:47.641 user space pointer authentication and with this uh design flaw I will show you how 00:01:47.641,00:01:52.646 to do uh exploitation in the uh user space of iOS in this PAC era. Uh and -and at last, I will 00:01:57.417,00:02:02.356 show you uh a tool designed to uh to user space exploitations uh which is called the PAC 00:02:05.492,00:02:10.497 gadget. So what is pointer authentication? Um, point authentication is a uh extended 00:02:15.268,00:02:20.273 feature of ARM. Uh it is available in uh A12 uh which is the core of iPhone XR, XS, and 00:02:24.478,00:02:29.483 XS Max. Uh it protects pointers with cryptographic signatures. Uh, how does it work? Uh it 00:02:35.088,00:02:40.093 works by instruction of two uh instruction sets which are called uh PAC instruction uh, 00:02:42.095,00:02:47.100 PAC instructions and uh AUT instructions. Um, PAC instructions calculate uh PAC 00:02:49.403,00:02:56.309 instructions calculate keyed hash of the pointer uh which is named PAC and uh inserts the PAC 00:02:56.309,00:03:01.248 into the pointer. And uh AUT instructions ex -extract the PAC from the signed pointer and 00:03:03.316,00:03:08.855 authenticate whether the PAC is consistent with the original pointer. Uh, you can see from 00:03:08.855,00:03:13.860 the figure that when a PAC instruction is uh executed on uh uh pointer value, the PAC value 00:03:16.663,00:03:19.866 will be uh inserted into the pointer, uh like the red one. Uh, in PAC and AUT instructions 00:03:19.866,00:03:21.868 there are two main factors. Uh they are called keys and context. Uh, uh the PAC 00:03:21.868,00:03:23.870 instructions work like, oh, w- work as -as follows. Uh, it -it will use a key register and a 00:03:23.870,00:03:25.872 context register to sign, to calculate PAC value from the Register Xd and then it will uh 00:03:25.872,00:03:27.874 insert the PAC value into the Register Xd uh which then forms a -a sign upon the pointer. And 00:03:27.874,00:03:29.876 for AUT instructions, uh these instructions uh extract the PAC value from the uh Xd Register 00:03:29.876,00:03:31.878 and then it also use the key register and the context register to verify what the PC 00:03:31.878,00:03:36.883 -PAC value is consistent with the original uh pointer value. That if the verification 00:04:22.796,00:04:27.801 succeeds, uh it will use the uh verified pointer value to do jump or load. Uh if the 00:04:30.237,00:04:35.242 verification uh fails, uh it will insert a error code into the uh uh into the into the into 00:04:37.978,00:04:42.983 the pointer, uh so the pointer cannot be used for further use. Uh, there are five key registers 00:04:47.654,00:04:52.659 in uh in in in, in the CPU. They are called A-ikey, B-ikey, Ad-key, B-dkey, and G-key. Uh, 00:04:57.731,00:05:04.638 here the “I” keys means uh, it’s used for instruction pointers uh signed and verification and the 00:05:04.638,00:05:11.611 “d” keys are used for data pointers. Uh this key registers are only readable and writable 00:05:11.611,00:05:16.616 um exception levels larger than uh EL1. Uh uh different from the key registers, context registers 00:05:21.021,00:05:26.026 are only uh general registers. Uh they are used to prevent intra-process pointer uh 00:05:28.728,00:05:33.733 substitution attacks uh that is uh when we send the same pointer value with the -the same key but 00:05:36.970,00:05:41.975 different context value will result in different PAC values. Uh as a result, uh for example 00:05:44.411,00:05:49.416 uh pointer uh signed with ContextA uh would fail verification with ContextB uh 00:05:51.851,00:05:57.591 even in the same process. Uh but you shou-, you should remember that there are some instructions 00:05:57.591,00:06:02.529 trust using uh null pointer, uh null null null context uh I mean the -the context is all 0. These 00:06:07.067,00:06:12.072 are the list of oh uh, uh supported PAC and uh AUT instructions in ARM. Umm, so we 00:06:22.515,00:06:27.120 know uh what the point uh whe -where how the brief intro- understanding of the pointer 00:06:27.120,00:06:32.759 authentication. So how point authentication is protecting iOS? Uh, let’s answer this 00:06:32.759,00:06:37.764 question. Um pointer authentication uh reduce the threat of memory corruption that 00:06:41.134,00:06:46.906 preventing code-reuse attacks. Uh what is memory corruption vulnerabilities? Uh it is one of 00:06:46.906,00:06:52.579 the most frequently exploited vulnerabilities in iOS user-space services and the 00:06:52.579,00:06:57.917 kernel. A typical memory corruption vulnerability is include uh use-after-free and 00:06:57.917,00:07:03.890 buffer overflow. And when uh we have uh memory corruption vulnerabilities, we always use 00:07:03.890,00:07:08.895 the code-reuse attacks to uh exploit these vulnerabilities. Uh code-reuse uh attacks uh 00:07:12.365,00:07:16.803 always utilize the gadgets that are already present in the program or in uh shadow 00:07:16.803,00:07:18.805 libraries uh to do malicious things. Uh typical code-reuse attacks include a 00:07:18.805,00:07:20.807 return-oriented program which is also called ROP, and uh Jump-oriented program which is 00:07:20.807,00:07:25.812 called uh JOP. Uh the difference between uh ROP eh and JOP, is that ROP in -in ROP gadgets 00:07:39.159,00:07:44.164 always end with uh red instructions and uh for JOP, gadgets uh are often uh ended 00:07:47.634,00:07:52.639 with the BLR and the BR, they are jump instructions. Uh sample buf -buffer overflow is like 00:07:57.310,00:08:02.248 -like this. Uh uh from this code, uh we can see that in the overflow function uh there is a 00:08:04.684,00:08:09.689 -a main copy uh function called um but the memory copy function uh does not, uh before the mem 00:08:12.492,00:08:17.497 copy function called uh this function does not check uh whether the uh buffer site is uh 00:08:20.700,00:08:25.705 lower than is lower than 0, 0 X uh 4,000. Uh, when we encounter this vulnerability, how do we 00:08:33.580,00:08:38.585 exploit them? Uh, uh we -we exploit it -it like follows uh we can write more buffer, uh m- 00:08:43.823,00:08:48.828 more data into the buffer or RET and uh uh the more we uh the data we write will o -overwrite 00:08:53.333,00:08:58.338 the uh the area in victim area. Uh, that is we -we may uh override the uh uh function 00:09:03.343,00:09:08.348 pointer in the victim area uh which is called the dummy. And uh then uh by uh by giving dummy 00:09:12.752,00:09:17.757 uh uh op tree address we can force the uh victim process to jump to uh other locations and 00:09:23.096,00:09:28.101 from those locations, we can use RET chain ROP gadgets or JOP gadgets to do malicious things. 00:09:33.006,00:09:38.011 And here the pointer authentication uh is going to prevent ROP and JOP uh but how? 00:09:40.780,00:09:47.720 Uh it prevents ROP and JOP by replacing dangerous instructions in the uh in the gadgets we -we 00:09:47.720,00:09:52.725 see. Uh, for ROP uh uh ROP f- for ROP um pointer authentication replaces the 00:09:58.231,00:10:04.270 write addresses with a write instruction with uh write RETAB instruction. Uh RETAB 00:10:04.270,00:10:10.243 instruction ensures that the return address is uh was correctly signed so the sign 00:10:10.243,00:10:15.248 return a- addresses will be protected by the key and the context. And for JOP, uh BLR and 00:10:17.717,00:10:22.722 BR is now replaced by uh BRAA and BLRAA. Uh these instructions ensure that the function 00:10:25.692,00:10:32.065 pointers uh we are we are going to use to jump was correctly signed. Uh, so the now the 00:10:32.065,00:10:37.070 signed pointer function pointer is -is uh protected by the key and the context. Uh, so now the 00:10:39.639,00:10:44.644 instruction uh w- by replacing this uh write and uh BLR, BLR uh instructions uh we can prevent 00:10:49.449,00:10:54.454 ROP and JOP. Uh even if the PAC uh, e- e- e- even if in um uh victim processes the um PAC is 00:11:01.161,00:11:06.232 hijacked, there is no way to launch further attacks uh because the hacker cannot fake 00:11:06.232,00:11:11.237 the uh signed pointers that can be correctly verify -verified. Uh, Apple has a, iO- iOS has 00:11:13.339,00:11:19.946 already uh deployed the P- pointer authentication protection in userspace daemons 00:11:19.946,00:11:24.951 and in the kernel. Uh, so -so with the pointer authentication, uh since both the key and the 00:11:27.887,00:11:32.892 context are unknown to the attacker, it can successfully uh prevent the ROP and JOP attacks. 00:11:38.865,00:11:43.870 Sorry. Uh so for now uh, when we talk about iOS attacks and jailbreaks, uh we we -we know 00:11:48.975,00:11:53.980 that the iOS attacks in the JOP has come into the PAC era. Uh, in previous jail -jailbreaks ROP 00:11:58.618,00:12:03.556 and JOP was the first step to ex- exploit userspace daemons and the kernel. But now uh, ROP 00:12:09.195,00:12:14.200 and JOP attacks are prevented by um pointer authentications. Uh instruction pointers are now 00:12:16.569,00:12:21.574 sent everywhere, uh. So uh what can we do now? Uh, this talk will only focus on um pointer 00:12:27.013,00:12:32.018 authentication in the -in the user space. Uh in the us -uh this means uh, when we talk 00:12:34.454,00:12:39.759 about user space attack scenario, we mean that the attacker is a local partition on 00:12:39.759,00:12:46.599 the same device with the uh -with the target system service daemons. Uh the four uh security 00:12:46.599,00:12:53.306 ana- analysis on kernel pointer authentication, please refer to uh Brandon’s blog. Uh, so when 00:12:53.306,00:12:58.311 we we- know that the pointer authentication is should be very strong but uh um, for now, we 00:13:01.581,00:13:07.854 found some weak points in the pointer authentication -pointer authentication in user space. Uh 00:13:07.854,00:13:13.192 the foundation of successful pointer authentication protection, uh should be that 00:13:13.192,00:13:18.197 the attacker cannot fake signed pointers uh that can be correctly verified by the target 00:13:20.299,00:13:25.304 process. Uh, this is based on two uh two uh basic knowledge, it’s that uh we should uh, we 00:13:31.010,00:13:36.015 know that the signed key is unique for different processes and the context is also very 00:13:38.751,00:13:45.558 private in different process. So uh without knowing the signing key and context, the attacker 00:13:45.558,00:13:52.365 cannot create uh a correctly signed pointers. But if the signed key and the context are 00:13:52.365,00:13:57.370 identical in two different processes uh, inter-process pointer substitution attack uh 00:13:59.972,00:14:04.977 would be possible and uh pointer authentication protection will fail. So here comes the 00:14:07.380,00:14:12.385 question, is how iOS correctly protecting signed key and the context? Uh, what if it -it 00:14:15.788,00:14:20.793 fails to successfully protect us? So let’s do some experiments. Uh our experiments 00:14:24.163,00:14:29.168 is set up as follows. Uh we developed two programs called Program A and Program B. Um they 00:14:32.205,00:14:37.210 are developed by different develop -developer accounts uh and uh we set a pointer in pro 00:14:39.545,00:14:44.550 pro- Progress A and verified in Progress B with all the file key, uh four keys with all the 00:14:48.354,00:14:53.359 key and the and two context. Uh the two contexts are 0 context, or uh 0 X 1,2,3,4. So, uh what 00:15:01.200,00:15:06.205 is this experiment for? We want to check whether the pointer signed in Program A can be 00:15:08.574,00:15:13.579 correctly verified in Program B. If it can be correctly verified uh, it is true that it indicated 00:15:17.550,00:15:22.555 that the Program A and Program B and using the same key. So if if this is true uh, there is a 00:15:26.993,00:15:31.998 problem, uh let’s see. So the experimental result results show that uh uh the pointer signed by 00:15:40.106,00:15:45.111 A-ikey and A-dkey uh uh in -in Program A can be correctly verified in Program B. So that’s 00:15:49.715,00:15:54.720 very uh surprising. Uh it seems that iOS is using the same keys in different user space 00:15:58.457,00:16:03.396 processes. But it is more important to know whether the re- the result is -is also true 00:16:07.533,00:16:12.538 uh for user space system daemons. Uh, we did the experiments on our own developed 00:16:15.808,00:16:20.813 programs but uh we should know if it is true for uh system daemons. Uh we can answer this 00:16:22.849,00:16:29.655 question by checking uh whether a signed pointer in a service can be correct uh can be 00:16:29.655,00:16:34.660 correctly verified in our own program. Uh, so how to retrieve a signed pointer from a user 00:16:36.662,00:16:41.667 space daemon or system service? Uh here we use a denial service vulnerability uh our system 00:16:44.070,00:16:49.075 service to retrieve a signed pointer. Uh, the the -the basics here is that when a process uh 00:16:53.312,00:16:58.317 encounters uh a denial of service vulnerability, it uh it would crash and when it crashes, 00:17:01.921,00:17:08.027 its register values will -are included in the crash log which may contain some signed 00:17:08.027,00:17:13.900 pointers. We retrieve those signed pointers from the crash log. Uh, we found uh 00:17:13.900,00:17:18.905 null-pointer deference uh vulnerability in the service uh in the service logd and uh which 00:17:22.008,00:17:27.013 is in iOS uh 12 point 1. This null-pointer dereference vulnerability will cause the 00:17:29.749,00:17:34.754 logd service service to crash. Uh and we know logd se- service is unsandboxed and ru- running 00:17:39.058,00:17:44.063 as root. Uh so where is this vulnerability? Uh logd provides a IPC service which is called 00:17:50.002,00:17:55.575 com dot apple dot logd. Uh this IPC service is implemented in the uh in -in the source code 00:17:55.575,00:18:01.847 firehose uh underscore uh server dot c and uh in in the uh source code we can find that uh 00:18:01.847,00:18:06.852 firehouse server handle mach event is the IPC handler and uh uh from this handler uh it cause 00:18:17.463,00:18:22.468 firehose server demux and then demux this patch the IPC request to different measures including 00:18:30.476,00:18:35.481 firehose server register, firehose server fire firehose server push and wait . And uh 00:18:37.750,00:18:42.755 there in this process it creates uh uh global variable called current client info. Um, but it 00:18:47.927,00:18:52.131 passes this uh global variable to different messers without checking whether the uh global 00:18:52.131,00:18:54.133 variable is now. So in in -in those dispatched messers it just trusted uh uh the current client 00:18:54.133,00:18:59.138 info variable uh without checking whether it is now. Uh when you use it, it will cause 00:19:12.618,00:19:17.623 null-pointer dereference uh and crashes the logd daemon. Uh, by triggering this vulnerabilities 00:19:21.661,00:19:26.665 we can get a -a crash log like follows. In a crash log, we can -we can see that the X16 00:19:29.802,00:19:31.804 register seems like a signed pointer and uh uh by reverse engineering logd, we can find 00:19:31.804,00:19:33.806 that instruc- uh an instruction has just been executed before the crash. Uh, the -the 00:19:33.806,00:19:38.811 instructions like this BRAA X16, uh X17. This instruction verifies X16 with A-ikey as the 00:19:57.997,00:20:04.870 key and the X16 as the context. Uh from the crash log we know that we know the value of for 00:20:04.870,00:20:09.875 X16 and the X17. And uh we get these uh released values and the use these register values to uh 00:20:16.482,00:20:21.487 verify them them in our own process. We try to verify X16 by AUTIA instruction in our own 00:20:25.691,00:20:30.696 process. Uh, uh in this way we are using the uh our own A-ikey as a as the key and the uh the 00:20:35.501,00:20:40.506 previous X17 value as the context to verify X16. And the re- result shows that the 00:20:43.509,00:20:48.514 verification succeeds so uh this re- this experiment is has the same result as the previous 00:20:51.917,00:20:58.157 experiment. That means iOS is really using the same A-key in our own process as the under the 00:20:58.157,00:21:03.095 system services. Uh this is a flaw. Um, but it -it should not be exploitable uh as I have said 00:21:07.967,00:21:12.972 that the context uh register is introduced to uh prevent pointer substitute -substitution attacks 00:21:17.243,00:21:22.248 and the attacker should not know know the context in another process for example the X17. Uh, 00:21:27.686,00:21:34.226 but did you forget that uh I mentioned there are some instructions that just use the 0 00:21:34.226,00:21:40.166 context or null context. Uh these instructions include BLRAAZ an the BRAAZ. Uh when you 00:21:40.166,00:21:45.171 use uh null context or 0 context, uh the context is not do uh is is -is not doing 00:21:50.109,00:21:55.114 anything to help you to protect the signed pointer. So what does that -that mean to attacker? Uh 00:21:59.018,00:22:05.691 that means local attacker can create a signed pointers in his own process and when the 00:22:05.691,00:22:10.696 pointers are used in another system service process uh, they will pass the verification of 00:22:13.332,00:22:18.337 BLRAAZ and BRAAZ in the system service so uh the JOP is alive now. Uh doesn’t mean we can use, 00:22:26.312,00:22:31.317 uh we can we can still use the uh gadgets that are under BLRAA, BRAA, BLRAAZ, or BRAAZ to uh to 00:22:34.019,00:22:39.024 find the JOP gadgets and chain JOP gadgets to do malicious things. Uh but how about ROP? 00:22:48.667,00:22:53.672 Uh, we know that ROP uh gadgets are now ended with should now be ended with R uh RETAB um but in 00:22:59.445,00:23:04.383 this in this instructions uh return addresses are now signed uh by uh by the B key and the 00:23:08.020,00:23:13.025 and uh we we -we uh B find B key is unique in different processes. Uh and uh we also 00:23:15.527,00:23:20.532 know that uh R- RETAB, the context of RETAB is SP and also uh private in different 00:23:24.203,00:23:29.208 processes so ROP uh has no chance, uh. So know that there is a -a key -key management 00:23:36.749,00:23:41.754 problem in iOS user space uh which is this uh. We know A-key is a per-device key. Uh it is 00:23:47.726,00:23:54.300 renewed at uh each device reboot and all processes are using the same A-key. And a B-key is a 00:23:54.300,00:24:00.005 per-process key; it is renewed when a process re- uh restarts and a different processes are 00:24:00.005,00:24:05.010 using the different uh B-keys. Uh, what is the root cause of these key management problems? 00:24:07.613,00:24:12.618 Uh, the root cause is -is a tradeoff between the performance and security. Let’s consider the 00:24:14.820,00:24:19.191 situation that function pointers, there are function pointers in shared libraries. 00:24:22.394,00:24:28.367 Uh, we we know that shared li- memory regions of shared li- libraries are copy and write. Uh 00:24:28.367,00:24:33.372 so if the pointers are signed by different keys in different processes, it will cost more 00:24:35.407,00:24:40.412 time and more memory space to create a new -new process uh in order to copy the shared 00:24:45.984,00:24:52.491 libraries, um. Like this figure shows, uh if we sign the pointers with the same key in 00:24:52.491,00:24:59.398 different processes, uh when we fork or create new a process the shared lib- the share -the 00:24:59.398,00:25:04.336 shared libraries uh do not need to be uh copied uh at the fork. But if we sign pointers with 00:25:09.708,00:25:16.215 different key in different processes, uh we have to uh create a new copy of the shared 00:25:16.215,00:25:21.220 libraries when we fork a process so uh the extra copy will cause them more time and more memory 00:25:25.824,00:25:30.829 space. That’s uh a lot of performance loss. So Apple uh has no choice but to use the 00:25:36.168,00:25:41.173 same key between different processes. This -this is a design which is in- inevitable. 00:25:43.242,00:25:48.247 Mmm, with this issue, uh mmm let me uh let’s have a look at how to do uh exploitations in the uh 00:25:55.988,00:26:00.926 user space right now. Uh, uh here I will use uh real uh iOS user space vulnerability to show 00:26:05.831,00:26:10.836 how to do uh exploitations in iOS user space uh daemons. This is uh a vulnerabilities in the 00:26:15.741,00:26:20.746 uh daemon called medialibraryd. Uh medialibraryd provides a an NSXPC service which allows 00:26:24.283,00:26:29.288 sandbox application to execute uh SQL command on a SQLite database. Uh, the XPC uh 00:26:33.959,00:26:38.964 function is called execute uh query in the left figure. Uh in the right fig uh y- y- you can 00:26:42.968,00:26:47.973 write uh okay you y- y- you can wr- write the code like like like right to uh execute some uh 00:26:50.843,00:26:55.848 SQL command on a uh on SQL on on SQL database. Uh, SQLite has a very interesting feature uh 00:27:00.652,00:27:06.792 which is that the users can create a customized token uh token tokenizer implementation 00:27:06.792,00:27:11.797 and specify the tokenizer to be used uh when indexing uh text. So how to create a customized 00:27:15.467,00:27:20.472 tokenizer implementation? Uh we can provide uh uh uh address in the SQL command and SQLite will 00:27:22.841,00:27:29.748 retrieve a function pointer from the address and function pointer uh is exactly the tokenizer 00:27:29.748,00:27:34.753 implementation. Mmm, uh you can see from the uh figure that we uh create a -a tokenizer called 00:27:37.789,00:27:39.791 mytokenizer uh which uh which is in the address 41414141 and we use the mytokenizer to create a 00:27:39.791,00:27:44.796 table and uh when secur- uh uh commands are executed uh, the SQLite will uh try to uh find 00:27:48.867,00:27:53.872 the function pointer which is indicated in the 414141 uh address uh and use that function 00:28:04.950,00:28:09.955 pointers to uh call that function. So -so when those uh SQL commands are executed, 00:28:20.098,00:28:25.103 medialibraryd will try to uh invoke a -a customized tokenizer uh from a function pointer uh 00:28:33.445,00:28:38.450 like follows. Uh this is the the -the disassembled uh instructions. It will try to 00:28:41.920,00:28:46.925 load uh uh function pointer from uh x24 uh plus 8 and uh the X uh the -the function pointer should 00:28:56.802,00:29:03.642 be uh signed function pointer and installed in x8 and medialibraryd will call the 00:29:03.642,00:29:08.647 signed function pointer uh by BLRAAZ which is installed in x8. So uh here the attacker can 00:29:11.083,00:29:16.088 control the uh x24 as a result the attacker can control x8 and further hijack -hijack the PC in 00:29:25.797,00:29:30.802 medialibraryd. Uh how to further exploit this vulnerability? Uh, we we- know that now uh x8 is 00:29:35.674,00:29:40.679 under our control then we can use Heap Spray uh techniques to uh to to point the x8 to uh uh 00:29:43.649,00:29:48.654 to to point to the x8 to uh uh uh op tree address. Uh uh how to uh sorry. Here we know that x8 00:30:04.603,00:30:11.343 is a signed pointer and uh we created the signed pointer in our own process and put the 00:30:11.343,00:30:16.348 signed pointer in the Heap Spray payload and then when we hijack the keys through the x8, the x8 00:30:18.650,00:30:23.655 will -will go through the signed pointers we uh set in the Heap Spray Payload and then from the 00:30:26.491,00:30:31.496 signed pointers we can do JOP, uh we we we- can use many JOP gadgets to do malicious things. 00:30:34.800,00:30:39.805 Uh as a -as a example, I will show you uh how to print a message in the medialibraryd s- 00:30:42.541,00:30:47.546 service. We use JOP gadget to call NSLog. Uh, uh the first thing we need to do is to find a 00:30:51.383,00:30:56.388 JOP gadget uh to call the NSLog. Uh we found uh uh JO uh uh gadget in the SQLite uh do- 00:31:00.826,00:31:05.831 develop. Uh this gadget size uh uh sets X x0 and also uh retrieval function pointer uh 00:31:11.236,00:31:16.241 from the x24. Uh so we can now control x24, x8, x0 and we can, then we can call X NSLog from 00:31:21.446,00:31:26.451 the x8 and we set the x0 to be a NSString structure. Uh, so now we can create a log uh in the 00:31:37.395,00:31:42.400 medialibraryd. Uh that is uh uh most d- uh detailed uh uh uh graph of of what what what I 00:31:45.170,00:31:50.175 have talked. Uh we uh first controlled the uh x8 to point to uh the purple one and uh the 00:31:56.515,00:32:01.453 purple one will lead to uh the uh right gadget and the gadget will uh further retrieve the 00:32:05.423,00:32:10.428 function pointer uh in the green one and uh also x0 uh from the orange one and then the green 00:32:17.102,00:32:22.107 one will lead us to the NSLog. So, we can successfully ma- make uh uh uh JOP exploit in the 00:32:29.114,00:32:34.119 medialibraryd and from the uh log we can see that medialibrady -lib medialibraryd is -is now 00:32:37.489,00:32:42.494 controlled by us and uh print uh a messages like this, hello you are ex- exploited. Next I will 00:32:48.333,00:32:53.338 show that in order to do a JOP uh attacks in the PAC area, uh we have developed uh a new tool 00:32:56.875,00:33:01.813 which is called PAC gadget, uh. Why we uh uh want to build this tool? Uh, we built this tool 00:33:06.985,00:33:11.990 because that manually looking for JOP gadgets is very tedious uh so so this tool uh so this 00:33:16.661,00:33:21.666 tool will be used to will be used to automatically find the JOP gadgets in binaries 00:33:24.069,00:33:29.074 protected by pointer authentication. And we develop the PAC gadget as a IDA pro 00:33:31.676,00:33:36.681 plugin. Uh the basic work flow of PAC gadget is -is like follows Um, we first find BLRAA, 00:33:42.387,00:33:47.392 BRAA, BLRAAZ, and BRAAZ instructions uh in the binaries and uh then we get a an rec- 00:33:53.598,00:33:59.738 recalled uh new instruction in the backwards order and we check whether the instruction will 00:33:59.738,00:34:04.676 affect the control. Uh if it is true, uh we go to the final uh uh, if if it’s not true we go to 00:34:07.579,00:34:12.584 the uh second and uh we w- w- we get a new instruction in the backwards ord- order. Uh so in 00:34:17.956,00:34:22.961 this way, we can get a field code sequence which uh w- which is one of the ways those BLRAA 00:34:27.632,00:34:32.637 or instructions and the these instructions th- these code sequence can be used uh in our 00:34:35.507,00:34:40.512 JOP gadget. And also BA uh PAC uh gadget will further examines uh each instruction in the 00:34:45.917,00:34:52.157 gadget uh in in the code sequence we have formed. Uh it will check uh whether the branch 00:34:52.157,00:34:58.530 target uh where the branch target is from and what it’s registers uh can be influenced 00:34:58.530,00:35:03.468 uh in the these code sequence. Uh it will also generate a -a short description of what 00:35:07.205,00:35:12.210 registers have been uh you you you can control uh in this code sequence. Uh there is a special 00:35:16.114,00:35:18.984 kind of uh JOP gadget which is called dispatcher gadget. Uh dispatcher gadget re- repeatedly 00:35:18.984,00:35:22.520 un invoke other gadgets or call functions in a while loop. Uh, the feature of this patch gadget 00:35:22.520,00:35:27.525 is that the loop body will load a function pointer from the address which is indicated by uh 00:35:42.340,00:35:47.345 uh base register plus offset. Uh uh thi- this offset is updated by a loop counter. Uh we still 00:35:55.754,00:36:00.692 have our PAC gadget, we automatically find a such a -a dispatcher gadget uh in libc++. 00:36:10.835,00:36:15.840 Uh uh, you can see from the this this figure that a in this gadget uh the gadget will uh 00:36:21.046,00:36:26.051 retrieve the uh function pointer from uh x19 and uh the fun- the the- function pointer will be 00:36:31.956,00:36:36.961 further used to call other gadgets and we -we can loop through the through the gadget. 00:36:46.604,00:36:51.609 So now it’s the uh dispatcher gadget we can uh do arbitrary code execution in user space 00:36:54.112,00:36:59.117 system daemons. Uh, so next I will conclude a umm this talk. Uh, in this talk uh uh, we can 00:37:07.692,00:37:13.732 have a big understandings of what a pointer authentication is and how pointer authentication 00:37:13.732,00:37:20.472 works and how it is protecting iOS user space daemons. More importantly I have shown that 00:37:20.472,00:37:26.144 there is a design flaw in iOS user space pointer authentication. That is iOS 00:37:26.144,00:37:31.149 using the same key in different user space processes. And uh I show that uh attacker can 00:37:33.485,00:37:38.490 leverage this flaw to launch JOP uh attacks in user space daemons and I use uh a real exploit to 00:37:43.695,00:37:48.700 then demonstrate the JOP attacks in pointer authentication protected uh processes. And 00:37:51.202,00:37:57.308 finally, I have shown tool to automatically find JOP gadgets in uh pointer authentication 00:37:57.308,00:38:02.247 protected binaries. And here are some references um Brandon Azad, uh uh Brandon has already uh uh 00:38:09.554,00:38:11.556 do som exp- research on the uh pointer authentication issues in the kernel. And Ian Beer has 00:38:11.556,00:38:13.858 also uh do some experiments uh of pointer authentication in the user space. Uh, okay and the 00:38:13.858,00:38:15.860 Proteas and uh Xerub has developed several tools to help you understanding what pointer 00:38:15.860,00:38:20.865 auth- authentication is and how how you can inspect um pointer authentication instructions in 00:38:28.806,00:38:33.812 binaries. So that’s all thank you. Uh if you are interested in my talk, we can have a further 00:38:48.826,00:38:53.832 discussion. Please follow me on Twitter, thank you very much. [applause]