1 00:00:00,000 --> 00:00:02,600 Okay, hello everyone. 2 00:00:02,600 --> 00:00:06,100 And I think this is the time for my talk. 3 00:00:06,100 --> 00:00:18,660 And it's now half past one, and welcome to my talk on the Android security, which I believe maybe is the only topic at this year's DEF CON on Android security. 4 00:00:18,900 --> 00:00:30,800 So the topic of my talk is Dem Made Alive Again, Bypassing Intended Destination Checks and Introducing Launch Anywhere Privilege Escalations. 5 00:00:30,820 --> 00:00:33,640 So a brief introduction about myself. 6 00:00:33,640 --> 00:00:38,280 I'm currently the Center Director and Chief Security Researcher at GD.com. 7 00:00:38,280 --> 00:00:47,260 I'm leading the Dawn Security Lab, which our lab is mainly doing anti-fraud, client security, security research, et cetera. 8 00:00:47,260 --> 00:00:56,500 And I'm previously a winner of the Pantone and Mobile Pantone competitions, and the 2022 Pony Awards Best Privilege Escalations. 9 00:00:56,620 --> 00:01:03,090 And I'm also a speaker at Black Hat, DEF CON, Consulate West, Recon, POC, and Hacking the Box. 10 00:01:04,220 --> 00:01:07,420 So today's agenda is as follows. 11 00:01:07,760 --> 00:01:10,220 My talk will be categorized into five parts. 12 00:01:10,220 --> 00:01:17,100 The first part is the Android security backgrounds for those who are not currently Android experts. 13 00:01:17,100 --> 00:01:28,420 And the second part will be the recap of the launch anywhere stories and mitigations and the vulnerabilities in history and can help you have a better understanding of the battery resolve. 14 00:01:28,560 --> 00:01:31,240 And the third part is the core part of this talk. 15 00:01:31,240 --> 00:01:37,200 It's the battery resolve vulnerability series of CVs we have found in the newest Android system. 16 00:01:37,380 --> 00:01:42,700 And the fourth part is about using the power of ARM and MCP. 17 00:01:42,940 --> 00:01:45,160 The final part will be summary and QA. 18 00:01:46,860 --> 00:01:55,580 So for a quick introduction of backgrounds, I will talk about some knowledge about the intents in Android. 19 00:01:55,860 --> 00:01:57,200 So what is intent? 20 00:01:57,200 --> 00:02:01,960 Intents are actually the core of the IPC mechanism in Android. 21 00:02:01,960 --> 00:02:07,800 It's actually abstraction for messages sent within and between the applications containing the embedded data. 22 00:02:07,980 --> 00:02:27,660 And in Android, applications communicate with each other using largely, you can see a figure that activity A, if it wants to call activity B, it needs to use the start activity API call and passing intent as arguments. 23 00:02:27,720 --> 00:02:31,500 And this API call will be processed by the Android system. 24 00:02:31,560 --> 00:02:35,260 And in particular, it's the activity manager service. 25 00:02:35,380 --> 00:02:48,340 And the activity manager service handles this call and actually invokes the callback, the uncreated callback of the target activity and passes intent for the activity B to process. 26 00:02:48,460 --> 00:02:53,280 So this is a basic flow of the activities communicating with each other using intents. 27 00:02:54,020 --> 00:02:59,560 So there are like 5 major parts, 5 parts of complements in Android applications. 28 00:02:59,560 --> 00:03:02,200 We usually call it like 5 King Kongs. 29 00:03:02,200 --> 00:03:07,360 And complements can be studied by intents and receive from- receive input from it. 30 00:03:07,360 --> 00:03:14,240 And complements can declare intent filters in the Android manifest about what kind of intents they are expecting. 31 00:03:14,480 --> 00:03:20,760 And the exception is the dynamic broadcast receiver and this is out of scope for today's talk. 32 00:03:20,960 --> 00:03:24,000 And the expected here means that it's not always enforced. 33 00:03:24,000 --> 00:03:32,500 It's only the intent filters criteria is only needed to be met when in the implicit intent resolving. 34 00:03:33,900 --> 00:03:39,280 So the lower part is the screenshots of the search trampoline activity in the Android manifest. 35 00:03:39,280 --> 00:03:42,380 I'm not sure if you can see it very clearly. 36 00:03:42,380 --> 00:03:55,340 You can see that this activity declares an intent filter that's saying that it wants an action that named the search result trampoline and the category with the default category. 37 00:03:57,500 --> 00:04:16,720 So intents itself uses bundle to store the key value pairs and the key value pairs can contain like primitive data types like arrays for example like intents put extra defcon 2025 and it can also contain objects implementing the serializable and the possible. 38 00:04:16,780 --> 00:04:22,920 And objects, the serializable and the possible, they can define their custom serialization scheme. 39 00:04:22,920 --> 00:04:33,860 And intent itself also implements possible which means that intents can contain intents that contain intents and you can loop whatever long you want and so as bundle. 40 00:04:36,400 --> 00:04:42,600 So for the intent resolution, as we have mentioned earlier, intents can be explicit or implicit. 41 00:04:42,740 --> 00:04:48,480 The explicit intent target is deduced from the complement set within it. 42 00:04:48,680 --> 00:04:58,060 This means that you can call set complement on the intent and ask it to be explicitly directed to a certain complement. 43 00:04:58,060 --> 00:05:06,340 However, for implicit intent, it must go through the resolution process if there's no complement specified in this intent. 44 00:05:06,340 --> 00:05:15,640 The resolution process is currently defined in the resolve internal function of the resolve intent helper class of the android system. 45 00:05:15,640 --> 00:05:26,460 And this resolution process considers intent filters of the complements, the permissions of the complements, the privilege level of the complements and also the preferred options of this activity. 46 00:05:26,460 --> 00:05:29,760 There are lots of details here and we will go back to it later on. 47 00:05:29,760 --> 00:05:34,740 The details are very important in the exploration of the bad resolve. 48 00:05:34,900 --> 00:05:47,220 And also, of course, security restrictions that a normal application cannot start the protected activity or unexplored activity of other applications. 49 00:05:47,220 --> 00:05:50,240 This is the security restrictions of the intent resolution. 50 00:05:50,920 --> 00:05:56,500 And in the right part of the slide, we can see an example of the implicit intent resolution. 51 00:05:56,620 --> 00:06:07,180 An application calls start activity with an implicit intent with the action android.internaction.callprivileged, which means that it wants to make a phone call. 52 00:06:07,180 --> 00:06:16,080 And this implicit action, this implicit intent is finally resolved to the privilege call activity of comp.android.phone. 53 00:06:16,280 --> 00:06:23,980 And we can see that this activity declares the matching intent filters, the intent actions, and the intent categories. 54 00:06:24,060 --> 00:06:28,400 And then the onCreate function of this activity is called. 55 00:06:28,400 --> 00:06:38,200 But there is one important point here that in order to call this activity, you need to hold the specific permission of the call from privileged. 56 00:06:38,360 --> 00:06:46,900 So in the following slides, we will see how we use the intent privilege escalations to bypass this restriction. 57 00:06:47,800 --> 00:06:55,700 So this is the background of the intent security and the second part will be the recap of the historical launch anywhere vulnerabilities. 58 00:06:56,140 --> 00:06:59,320 So uh what's the non-launch anywhere? 59 00:06:59,600 --> 00:07:09,760 Uh we recall that we have mentioned in previous uh slides that activity can perform sensitive actions like install packages, perform calls, or even execute commands. 60 00:07:09,760 --> 00:07:15,560 And these sensitive activities should be protected with permission or is always un-exported. 61 00:07:15,560 --> 00:07:21,820 So it cannot be accessed by a normal application uh uh application hold by attacker. 62 00:07:22,120 --> 00:07:29,220 However, I recall that intent can contain nasty intents which will lead to the intent reduction and injection vulnerability. 63 00:07:29,380 --> 00:07:35,160 For example, in the lower part of the slide, we can see that uh a victim application complements. 64 00:07:35,160 --> 00:07:43,160 It contains uh a secret action or privileged action and it actually commands from the intent income. 65 00:07:43,160 --> 00:07:46,680 However, this complement is usually protected or un-exported. 66 00:07:46,680 --> 00:07:51,000 So an attacking application cannot directly access this complement. 67 00:07:51,000 --> 00:08:05,380 However, if there is a vulner- if there is a vulnerability in a breach application, which we can see that it takes an intent from a possible extra and start act- and cause start activity on this possible. 68 00:08:05,480 --> 00:08:12,860 And then the attacker application can use this breach uh breach application to attack the victim application. 69 00:08:12,860 --> 00:08:16,160 So this is an example of the intent redirection. 70 00:08:16,580 --> 00:08:33,940 So if this breach application is a privileged uh privileged application like the system UID applications like settings, and uh this is a juicy target for the attacker and uh this kind of vulnerabilities will be called launch hand-aware because the system UID application, 71 00:08:33,940 --> 00:08:39,640 the settings applications, they hold the privilege to call arbit- to call arbitrary activities. 72 00:08:41,180 --> 00:08:52,040 So uh in 2014, we have uh very typical uh example of the bar of the launch hand-aware in the android.com.android.settings. 73 00:08:52,040 --> 00:08:55,500 This is a very old bar, but a very typical example. 74 00:08:55,500 --> 00:08:56,720 Very classical. 75 00:08:56,960 --> 00:09:03,960 And uh in this uh bar, we can see that uh it's in the account management functionality of android. 76 00:09:03,960 --> 00:09:10,620 Uh the account management uh functionality android allows application to create an account. 77 00:09:10,620 --> 00:09:15,200 And uh when it creates an account, it need to ask the settings application. 78 00:09:15,200 --> 00:09:21,020 It sends an intent to the settings application and the settings application calls the account managers at account. 79 00:09:21,140 --> 00:09:34,480 And here uh this uh account manager at account will call into a system server and system server will in turn invokes a callback in the at account callback of the calling application. 80 00:09:34,480 --> 00:09:36,660 And here we mean the attacker application. 81 00:09:36,680 --> 00:09:46,820 The attacker application passes by- passes back a bundle and this bundle is uh you- it is processed in the system server and finally passed back to the settings application. 82 00:09:46,940 --> 00:09:52,760 And the settings application just blindly take a possible intent from it and calls that- that activity on it. 83 00:09:52,760 --> 00:09:56,100 So this is a very classical example of a non-training weird. 84 00:09:57,380 --> 00:10:03,540 Of course, this vulnerability gets fixed very quickly and uh this is the first round of fix. 85 00:10:03,600 --> 00:10:05,880 And we will go back to it uh later on. 86 00:10:05,880 --> 00:10:08,720 This is a very important fix and with many details. 87 00:10:08,960 --> 00:10:16,500 Uh this fix can be actually categorized or summarized as that uh there is a check added in the account manager service. 88 00:10:16,620 --> 00:10:26,280 And the account manager service uh checks that if the bundle contains an intent and if there is an intent in the bundle, it will check if the intent is allowed to start. 89 00:10:26,460 --> 00:10:34,240 And if the intent check passed, it will then pass it- pass the intent to the settings application- pass the bundle to the settings application. 90 00:10:34,740 --> 00:10:43,520 So uh currently all the checks are in the checking intent function of the uh account manager of the account manager service. 91 00:10:43,520 --> 00:10:47,240 And we can see that the check is mainly as follows. 92 00:10:47,240 --> 00:10:58,280 It's uh perform a resolve activity on this incoming intent and it checks if the target activity have this- have the same signature as the calling application. 93 00:10:58,280 --> 00:11:00,720 Uh which means the attacker application. 94 00:11:00,740 --> 00:11:08,760 So this check restricts that the attacker application can only use this functionality to start an activity of itself. 95 00:11:09,040 --> 00:11:15,780 And uh it is- it is disallowed to start other activities, other privileged activities of arbitrary application. 96 00:11:16,180 --> 00:11:18,540 So this is round one, right? 97 00:11:18,540 --> 00:11:19,800 Round one is not finished. 98 00:11:19,800 --> 00:11:21,260 We still have round two. 99 00:11:21,260 --> 00:11:28,280 And uh what if the account manager service, the system server, sees a different intent as settings? 100 00:11:28,640 --> 00:11:33,840 So maybe they see the different intents and the check will of course fail. 101 00:11:33,840 --> 00:11:41,380 Recall that a bundle can contain the possible objects and it's the developer's responsibility to write the park and unpark code. 102 00:11:41,500 --> 00:11:46,920 So when developers create their own code, the things will really go wrong here. 103 00:11:47,020 --> 00:11:52,040 Uh here is an example, the CAE certificate info possible of the Samsung class. 104 00:11:52,080 --> 00:11:57,840 We can see that the developers implements a read from possible which is the deserialization function. 105 00:11:57,840 --> 00:12:00,920 And a write to possible which is a serialization function. 106 00:12:00,980 --> 00:12:07,120 And there's a tiny difference here that's uh on the possession of the third length, the integer. 107 00:12:07,140 --> 00:12:12,120 We can see that in the read from possible, it checks that if the third length is larger than zero. 108 00:12:12,200 --> 00:12:20,060 However, in the write to possible, it checks if the third length is- is equal to zero but not if the third length is larger than zero. 109 00:12:20,100 --> 00:12:25,700 This will cause a mismatch occurs when the possible is written and read. 110 00:12:26,000 --> 00:12:33,880 So if you have a third length like minus uh like minus one, the mismatch will occur when the possible is written as a read. 111 00:12:33,880 --> 00:12:41,420 So this will lead to the bundle contain different objects after the deserialization, the serialization, and then deserialize again. 112 00:12:41,500 --> 00:12:50,540 Which will bypass the check intent check because actually now the system server that can measure uh service sees different intent as a settings. 113 00:12:51,140 --> 00:12:59,920 And uh this uh the detail is quite complex here and uh because this is not the core part of today's talk, we will not elaborate here. 114 00:13:00,220 --> 00:13:03,940 And uh for anyone who is interested in the next slide, give an overview. 115 00:13:03,940 --> 00:13:09,660 And uh this kind of possible mismatch box is largely exploited in the wild. 116 00:13:09,800 --> 00:13:17,540 So this uh figure is taken from the Google Android security team uh Hawker's Black Hat EU uh 2022 slide. 117 00:13:19,280 --> 00:13:32,720 And uh we can see that uh uh the bundle is uh deserialized and serialized in the system server and uh because a mismatch occurs, the system server and the settings see different intent. 118 00:13:32,860 --> 00:13:36,440 Which will lead to the launch anywhere vulnerability again. 119 00:13:36,780 --> 00:13:45,580 So this type of vulnerability uh is largely exploited in like billions of devices in previous years. 120 00:13:45,580 --> 00:13:50,640 And there are like more than 100 possible mismatch vulnerabilities in Android. 121 00:13:50,640 --> 00:13:59,820 And uh literally Google wrote out many mitigations and uh currently we think the possible mismatch vulnerability is not as effective as past. 122 00:14:00,240 --> 00:14:03,860 So now, we'll go to the third part of the talk. 123 00:14:03,860 --> 00:14:10,540 We'll go to the bad result vulnerability which is the uh CVEs we discovered. 124 00:14:11,040 --> 00:14:22,480 So uh recall that in the possible mismatch scenarios that uh we want to make the account manager service and the settings sees different intent to bypass the check. 125 00:14:22,520 --> 00:14:32,560 However, what if the account manager service, the system server, and the settings see same intent but the intent is actually resolved to different target activities. 126 00:14:32,760 --> 00:14:40,380 So we see the check from a different angle and uh we here we try to make the launch anywhere great again. 127 00:14:41,040 --> 00:14:53,220 So looking back in the fix, uh as I have mentioned earlier that this fix uh primarily checks the target of the intent resolution of the implicit intent and check the signature of the application. 128 00:14:53,600 --> 00:15:00,640 So uh we can see that it performs check here and literally the intent is used in the settings. 129 00:15:00,820 --> 00:15:06,340 So there are some ideas that flow on my mind that can we do a talk tool here? 130 00:15:09,000 --> 00:15:19,740 The core idea is that uh uh the system server checks the target user result activity and the same to the settings if the check parsed and then the settings will start its intent. 131 00:15:19,940 --> 00:15:24,700 And the start activity itself actually implicitly calls the resolve activity internally. 132 00:15:24,840 --> 00:15:30,420 So what if the draw solution result change between these resolves? 133 00:15:30,700 --> 00:15:33,240 Like is it possible for a risk condition? 134 00:15:33,820 --> 00:15:40,120 And we need to inspect the source to figure out that if there is something we can manipulate, we can risk with. 135 00:15:40,900 --> 00:15:53,080 So the lower part of this slide is uh illustration of the check and start uh check and start code of the between the activity manager service and the settings. 136 00:15:53,080 --> 00:16:07,340 We can see that uh uh if it possible so that we can make the when the check intent call the result activity, it will resolve to a benign activity which belongs to the attacker's application. 137 00:16:07,340 --> 00:16:16,840 However, in the second start activity, it will resolve to a privileged activity or protected protected activity that attacker wants to start. 138 00:16:17,000 --> 00:16:19,960 So can we like achieve this result? 139 00:16:20,820 --> 00:16:27,960 So if you want to like uh uh exploit or find or talk to a vulnerability, you need to find your primitives. 140 00:16:27,960 --> 00:16:31,020 What what things you can change or what can you control? 141 00:16:31,020 --> 00:16:43,280 The primitive here is that application is allowed to use the package manager set complement enable settings to enable or disable its own complement like activity, et cetera. 142 00:16:43,280 --> 00:16:44,860 It's in run time. 143 00:16:44,940 --> 00:16:50,740 And the disabled complement is considered to be vanished as if it had never existed. 144 00:16:51,220 --> 00:16:56,800 So can we utilize this primitive to manipulate the resolution results? 145 00:16:56,800 --> 00:17:08,940 For example, can we disable the result complement in the check run so that we can force the latter result point to a different result? 146 00:17:09,160 --> 00:17:14,400 So we can see the other time window here between the activity manager service and the settings. 147 00:17:14,420 --> 00:17:23,780 Like can we like disable the activity of our application so that in the first resolution, the result is our activity. 148 00:17:23,780 --> 00:17:29,000 However, when the second resolution, our activity is disabled so it cannot appear in the result list. 149 00:17:29,000 --> 00:17:34,460 And now the privileged activity or protected activity appears in the result list. 150 00:17:34,500 --> 00:17:37,760 So this is the basic idea of our TOCTO. 151 00:17:38,080 --> 00:17:45,020 However, we need to check if our TOCTO exploitation idea, is it feasible? 152 00:17:45,260 --> 00:18:01,380 As we have mentioned earlier, that intent can result to a single target or multiple targets because activities can declare similar intent filters and an implicit intent may result to a list of activities. 153 00:18:01,660 --> 00:18:21,920 So the first case is that when intent resolved to a single target is seen, whether it's an explicit intent or it's an implicit intent, when the intent resolved to a single target, if the target is disabled, the process fails and the exception is thrown. 154 00:18:22,860 --> 00:18:28,060 And of course, the explicit intent always resolved to a single target. 155 00:18:28,060 --> 00:18:32,520 Explicit means that a complement or the class field of this intent is set. 156 00:18:32,520 --> 00:18:42,460 However, the implicit intent may resolve to a single target if there is only one candidate in the intent resolution. 157 00:18:43,080 --> 00:18:59,760 So the lower figure illustrates that if the intent resolved to a single target and the target disappears, the target may be disabled, then exception will be thrown and the start activity will fail in the settings application. 158 00:19:01,340 --> 00:19:17,920 So after we dive deep into the resolution process and we draw out a figure of the functions called and we can see that the procedure is as follows. 159 00:19:18,520 --> 00:19:30,480 First, when the system server, the activity manager service start resolving on the intent, it will first check if the candidates is a single result. 160 00:19:30,480 --> 00:19:34,640 If the candidate is a single result, it will just return the single result. 161 00:19:34,640 --> 00:19:38,100 If there are multiple candidates, here comes a problem. 162 00:19:38,100 --> 00:19:48,920 If there are multiple candidates allowing the resolution of this implicit intent, it needs to find a single target or let the user choice. 163 00:19:48,920 --> 00:19:52,680 So it will first exclude the disabled ones. 164 00:19:52,680 --> 00:20:02,900 And then after this exclusion, if there is still multiple targets, it will decide that if the targets have different priorities. 165 00:20:02,900 --> 00:20:18,640 We know that developers can specify priorities in the intent filters and the resolution process will check is there an activity intent filter that contains the largest priority. 166 00:20:18,940 --> 00:20:26,800 There is a cork here that normal applications can only declare priority zero or lower than zero. 167 00:20:26,800 --> 00:20:33,240 It's a privilege of the platform application and system application to declare priority larger than zero. 168 00:20:33,500 --> 00:20:39,780 So if there is a candidate that holds a largest priority, this candidate will be returned. 169 00:20:39,940 --> 00:20:50,160 So if there are all candidates do not declare priority of the intent filters, it will try to find if there is a preferred target. 170 00:20:50,160 --> 00:20:52,020 What is a preferred attribute? 171 00:20:52,020 --> 00:20:59,120 The preferred attribute is we can see in the lower left, lower part of this slide, there is a pop-up here. 172 00:20:59,120 --> 00:21:13,900 For example, when an implicit intent resolves to different targets, different candidates, a pop-up of the chooser application will be given to the user and let the user decide which activity he or she wants to start. 173 00:21:13,900 --> 00:21:21,440 So if a user starts a candidate here and clicks on always, this activity will be marked as preferred. 174 00:21:22,040 --> 00:21:33,940 And this will be memorized and will survive the installation or will survive the update of this application and will be used in the next resolution process. 175 00:21:34,100 --> 00:21:37,820 So if there is a preferred one, this preferred one will be returned. 176 00:21:38,160 --> 00:21:47,100 And if there is still no preferred one and we still have multiple candidates available, then the chooser activity, the pop-up will appear. 177 00:21:50,850 --> 00:21:56,750 So we have introduced the flow of this resolution. 178 00:21:56,770 --> 00:22:00,990 So the following steps is summarized. 179 00:22:00,990 --> 00:22:05,750 Now we can see that first a disabled target won't be taken into consideration. 180 00:22:05,830 --> 00:22:11,330 And then the largest priority is chosen and returned. 181 00:22:11,330 --> 00:22:16,030 And if there is no largest priority, a preferred one will be chosen and returned. 182 00:22:16,030 --> 00:22:21,190 If neither is satisfied, a chooser dialogue is a pop-up for the user's confirmation. 183 00:22:22,110 --> 00:22:29,550 And however, from an attacker's perspective, which steps here we can affect or we can manipulate? 184 00:22:29,710 --> 00:22:39,610 The answer is that we cannot manipulate with the priorities because I have said earlier that normal applications cannot declare priorities larger than zero. 185 00:22:39,730 --> 00:22:55,470 And we cannot make this resolution point to a chooser application because the chooser application is a system platform application and it has different signatures than our attacker's application. 186 00:22:55,470 --> 00:23:03,810 So if you like the check intent finds that our intent is finally resolved to a chooser activity, it's not happy with it. 187 00:23:03,810 --> 00:23:07,650 Then we will like bail out and the check fails. 188 00:23:07,650 --> 00:23:14,810 So the only choice left here is that we need to make our activity a preferred one. 189 00:23:15,790 --> 00:23:35,610 So the whole idea is that it's like follows in the beginning of this resolution of this exploitation flow in the when the account manager service calls check intent and here we make our we supply an implicit intent and here the implicit intent will return multiple targets. 190 00:23:35,610 --> 00:23:39,890 However, we have already marked our activity as a preferred one. 191 00:23:39,890 --> 00:23:47,250 So here the check intent will happily find that this result is an activity that belongs to our application. 192 00:23:47,250 --> 00:23:49,790 So this check is passed. 193 00:23:49,790 --> 00:23:57,290 And then we disable our compliment during the time window of the account manager service and the settings application. 194 00:23:57,290 --> 00:24:11,610 So when the settings application accepts this bundle and retrieves intent from it, when it calls the start activity, it will find that there is only one candidate left because our candidate activity has already been disabled. 195 00:24:11,610 --> 00:24:12,570 It has vanished. 196 00:24:12,570 --> 00:24:22,250 So only one result is left and it will happily start the protected or privileged activity, the target activity the attacker wants to exploit. 197 00:24:22,270 --> 00:24:26,630 So here is the basic idea of our TOCTO attack flow. 198 00:24:26,630 --> 00:24:33,530 However, we know that there is another important factor in TOCTO exploiting TOCTO vulnerabilities. 199 00:24:33,530 --> 00:24:36,470 You need to check the time frame. 200 00:24:36,470 --> 00:24:41,210 Do you have enough time to manipulate the state of the compliment? 201 00:24:41,210 --> 00:24:42,870 Here we use a profetto. 202 00:24:42,870 --> 00:24:47,890 Profetto is a perf application that comes within the AOSP. 203 00:24:47,890 --> 00:24:57,410 It's a very useful application that it can that has inspect that the functionalities in the system server in the settings, how long do they take? 204 00:24:57,410 --> 00:25:00,010 For example, how long does the resolve intent take? 205 00:25:00,010 --> 00:25:02,130 How long does the start activity take? 206 00:25:02,190 --> 00:25:08,590 And this is crucial for our to deciding the time window of our TOCTO exploitation. 207 00:25:09,470 --> 00:25:17,530 And here using profetto, we see that there is actually two check intent calls in the system server. 208 00:25:17,530 --> 00:25:31,530 And after these two checks being passed and the start activity is called in the setting application and the start activity, we can see that it in itself calls the resolve activity internally. 209 00:25:32,510 --> 00:25:37,910 So it seems that we can just risk within this time window and we are good to go now. 210 00:25:38,330 --> 00:25:43,550 So actually, things are not as easy as we have thought here. 211 00:25:43,810 --> 00:25:56,230 And using profetto, we found that our time window is only one millisecond, which means that you can suddenly do anything in a one millisecond time window. 212 00:25:56,870 --> 00:26:03,070 And except if you are Superman or Flashman, you can like manipulate this compliment in one millisecond. 213 00:26:03,250 --> 00:26:09,510 However, so and we can see that the resolve intent here only takes like 0.5 milliseconds. 214 00:26:10,010 --> 00:26:13,710 So given this time frame, we cannot do anything meaningful. 215 00:26:13,710 --> 00:26:21,750 We need to find a way to like extend this time frame to extend to like at least tens or hundreds of milliseconds. 216 00:26:24,070 --> 00:26:32,630 So here that we have several ideas that we need to get a larger time window, but which direction should we take? 217 00:26:32,830 --> 00:26:38,150 Like, can we slow down the resolve intent and disable the compliment in this time frame? 218 00:26:38,250 --> 00:26:49,510 However, there is a question here that if we change the compliment states and the change of the compliment state is instantly reflected in the resolution result, we will still fail here. 219 00:26:49,570 --> 00:26:56,230 And can we like slow down the IPC between the system server and the settings application and disable the compliment in this time frame? 220 00:26:56,450 --> 00:27:01,010 So we have two ways here and finally we choose the formal way. 221 00:27:01,870 --> 00:27:08,570 To make the formal way work, we need to dive deeper into the resolve internals in the activity manager service. 222 00:27:10,090 --> 00:27:18,870 So actually, the compliment information query is done or fulfilled by the compliment resolver in the package manager service. 223 00:27:18,870 --> 00:27:31,170 It maintains a mapping of the four king cons, the activities service, broadcast reservers, content providers, their mappings from these compliments to the internal filters they declared. 224 00:27:31,230 --> 00:27:43,770 And this information is stored in the fields, in the activity internal resolver fields, the provider internal resolver fields, the receiver internal resolver fields, and the service internal resolver fields. 225 00:27:44,170 --> 00:27:49,670 And the actual resolution process is done in the computer engine. 226 00:27:49,670 --> 00:27:59,410 The computer engine is the M compliment resolver, the field of the computer engine is a snapshot of the compliment resolver. 227 00:27:59,410 --> 00:28:07,590 And this snapshot is fetched and updated when the package manager internal-based resolve intent is called. 228 00:28:07,910 --> 00:28:13,410 And then the queries are performed on this snapshot of this compliment resolver. 229 00:28:13,410 --> 00:28:18,550 The snapshot actually creates a copy of these big four mappings. 230 00:28:19,550 --> 00:28:24,450 So here in the right part of the slide, we can see this is a summary of this whole flow. 231 00:28:24,450 --> 00:28:40,750 The resolve internal helper, resolve internal internal calls the computer engine, query the component internals, and then call the component resolver query activity, which performs matching on a snapshot of these compliment mappings. 232 00:28:40,750 --> 00:28:49,210 And then it will call the choose best activity as we have explained the steps of choosing a candidate from a candidate list. 233 00:28:51,370 --> 00:28:55,630 So what is a snapshot in package manager service? 234 00:28:55,870 --> 00:29:01,350 A snapshot creates a read-only current state copy of the package infos. 235 00:29:01,670 --> 00:29:06,170 And the queries are done in the frozen compliment mappings and states. 236 00:29:06,350 --> 00:29:15,450 So once the snapshot is taken, any changes during the time frame of this resolve intent will not be taken into consideration. 237 00:29:15,670 --> 00:29:26,630 So we can see in the right part of the slide, the implementation of the resolve intent, the snapshot is created in the first argument of this resolve internal function call. 238 00:29:26,910 --> 00:29:39,210 So thank you snapshot here that we know the snapshot, once it's created, it will not be modified and we can manipulate everything we want in the time frame of this function call. 239 00:29:39,210 --> 00:29:46,790 And the result will not be affected by our operations because all queries are done in a frozen snapshot. 240 00:29:48,930 --> 00:30:06,330 So here, we have our idea of extending the time window of this resolve intent call, and we need to find some way to extend the time spent on searching the activities of this snapshot. 241 00:30:06,770 --> 00:30:10,290 Our solution here is to play with the Android manifest. 242 00:30:10,510 --> 00:30:25,030 So can we like declare lots of compliments, lots of attributes, lots of intent filters, which are lots of elements which will fill up the snapshot and increase like obstacles when it's performing a linear search on these compliments. 243 00:30:26,290 --> 00:30:30,030 And also, there's a very helpful flag here. 244 00:30:30,370 --> 00:30:48,990 The flag debug log resolution, and when it can be parsed, it is a flag of the intent, and if the flag of the intent is enabled, we see that a logging functionality is turned on when the intent is used in the activity manager service, package manager service, 245 00:30:48,990 --> 00:30:56,770 and it will do like a linear ON printing of all the categories of all the intent filters. 246 00:30:56,890 --> 00:31:18,270 So we can see, we can know that if we turn this flag on in the incoming intent, it will make this resolution process slow down much more altitude because it will print all the intent filters, all the elements, and this definitely will take up much time. 247 00:31:19,390 --> 00:31:28,330 So here we try to declare the intent filters with the large number of categories, and how many categories can we declare? 248 00:31:28,330 --> 00:31:30,490 What's the largest number we can declare? 249 00:31:30,590 --> 00:31:44,910 The upper bound here is limited by the timeout restriction of the package verification functionality in the package manager, and also it's limited by the format, the XML format of the Android manifest. 250 00:31:45,210 --> 00:32:12,250 So after some trial and error, and I found that also based on the code of these parsers, we found that the 10,000 or 40,000 categories in the intent filter is small enough to make both happy, to pass all the checks, and it can also slow down the resolve intent to like 50 or more than 400 milliseconds, 251 00:32:12,250 --> 00:32:15,230 and this is ideal for risk condition vulnerability. 252 00:32:16,230 --> 00:32:29,790 So in the lower part, the left part of the slide, we can see here's an example of the malformed manifest, the malformed intent filter, we declared with like 30 categories. 253 00:32:30,250 --> 00:32:44,970 We declared 30,000 different categories here in a single intent filter, and now the profiler shows us that the resolution process has been slowed down to like 400 milliseconds. 254 00:32:45,230 --> 00:32:48,030 This is a very ideal situation for us. 255 00:32:49,470 --> 00:32:56,570 So the final attack flow, the final outcome here in our profiler view is as follows. 256 00:32:56,590 --> 00:33:13,910 I can see attacker application triggers the add account functionality of the account manager service, and initialize this launch anywhere attack, and this now system server receives the intent, and it performs the first check on it. 257 00:33:13,910 --> 00:33:17,450 And then if the first check passed, it goes in the second check. 258 00:33:17,450 --> 00:33:34,990 However, there is a background thread started in the attacker application that in the second check, the time window of the second check, the thread disables the resolution target of the complement declared in the attacker application. 259 00:33:35,290 --> 00:33:42,290 So the second check also passed because the snapshot is taken in the beginning of this function. 260 00:33:42,290 --> 00:33:49,610 At the beginning of this function, we haven't disabled this complement, but we disabled this complement in the middle of this function. 261 00:33:49,790 --> 00:34:04,250 So after the first check and the second check is passed, this bundle and the intent is finally passed again to the settings application, which is the user of this bundle and intent. 262 00:34:04,250 --> 00:34:11,350 And here, the settings application will happily start the intent and call the launch anywhere vulnerability again. 263 00:34:13,170 --> 00:34:25,010 There is a small quirk here that system UI sometimes will crash on clicking the resolve activities dialogue due to the too large body of the intent filters. 264 00:34:25,010 --> 00:34:39,310 Remember that if we want to make our activity a preferred one, we need to trick the users to click on the always button, always label of the preferred activity of the chooser dialogue. 265 00:34:39,410 --> 00:34:46,270 However, if you declare a too large body of the intent filter, the system UI will crash here. 266 00:34:46,910 --> 00:34:57,290 And reinstalling the application can bypass this restriction because installing an update to an application will not clear the preferred activity's preferences. 267 00:34:57,390 --> 00:35:07,330 So the idea here is that we can install a normal version of the application and trigger the resolve and make the attacker's activity a preferred activity. 268 00:35:07,330 --> 00:35:14,370 And then we install an update to the exploit application with a larger number of categories and then trigger this vulnerability. 269 00:35:14,370 --> 00:35:17,990 This will give us an even larger time frame. 270 00:35:17,990 --> 00:35:30,610 However, this is not mandatory because we can declare like 10,000 of categories in a single intent filter and this will not crash the chooser dialogue. 271 00:35:30,810 --> 00:35:35,790 And this can still give us like 100 milliseconds of racing time. 272 00:35:36,110 --> 00:35:43,770 So this is just an exploitation technique here and you can take it or you may not need it. 273 00:35:45,230 --> 00:35:55,370 And this vulnerability here, the bad resolve vulnerability, has some limitations here because it is an implicit intent resolution. 274 00:35:55,370 --> 00:36:01,650 So it requires a target complement to have an intent filter with data element and it requires a target complement. 275 00:36:01,650 --> 00:36:10,890 The target complement we want to start the privileged or protected activity we want to start to have an intent filter with the category default declared . 276 00:36:10,890 --> 00:36:20,430 So we need to have a target to extend this ability, to expand the ability of this vulnerability , of this bad resolve series of vulnerabilities. 277 00:36:20,850 --> 00:36:29,370 And the idea is that here we first use this vulnerability to call the search trampoline activity with the controlled intent parameter. 278 00:36:29,530 --> 00:36:36,990 And in the onCreate function of the search trampoline activity, we can see that it has a very useful gadget here. 279 00:36:36,990 --> 00:36:46,270 It retrieves a string from this incoming intent and call the path UI on it, which creates an intent again from the incoming string. 280 00:36:46,310 --> 00:36:55,690 So here using this gadget, we can extend the functionality, extend the ability of the bad resolve vulnerability and the cause arbitrary activity at will. 281 00:36:56,630 --> 00:37:00,210 So there is another interesting detail here that we can see. 282 00:37:00,370 --> 00:37:05,130 Normally you cannot directly call the search trampoline activity because there is a permission check here. 283 00:37:05,130 --> 00:37:07,050 It will check the colors package. 284 00:37:07,050 --> 00:37:15,810 However, using bad resolve, the color package will be setting so you can easily bypass the check and use this gadget inside the search trampoline activity. 285 00:37:16,630 --> 00:37:22,030 The fix for this vulnerability in the activator service is quite simple. 286 00:37:22,030 --> 00:37:28,190 It just makes the implicit intent an explicit one using the set complement or set package. 287 00:37:28,190 --> 00:37:35,610 So this kills the tactile window, the whole tactile scenario of our attack. 288 00:37:36,790 --> 00:37:50,230 So digging this further and why I say this is a series of vulnerability because any code snippet that calls the start activity on intent after checking the resolution result can and will be vulnerable. 289 00:37:50,230 --> 00:38:01,030 And this previously discussed issue is already fixed and I have found like four other code snippets in the Android open source project that are found to have similar vulnerabilities and reported to Google. 290 00:38:01,030 --> 00:38:03,990 And there are two CVs assigned already. 291 00:38:06,960 --> 00:38:13,520 So for the aspiration technique, the key parameter here is a timeout before the disabling complement. 292 00:38:13,520 --> 00:38:22,620 So how much time will be spent in the resolve intent when we supply a malformed manifest, a malformed intent filter? 293 00:38:22,620 --> 00:38:25,240 It varies on high-end and low-end devices. 294 00:38:25,240 --> 00:38:33,100 It is understandable because on high-end devices, it will have higher CPU frequency and speed so it will take less time. 295 00:38:33,100 --> 00:38:35,240 It will give us less time for racing. 296 00:38:35,400 --> 00:38:41,360 And for example, on Pixel 7 Pro or Pixel 8 Pro, it is like 200 to 300 milliseconds. 297 00:38:41,640 --> 00:38:48,060 However, on an old phone like Galaxy S21, this can be extended to like one second. 298 00:38:48,600 --> 00:38:51,720 Anyway, we can continuously retry until we succeed. 299 00:38:53,180 --> 00:39:02,700 So here is the first demo that we use this vulnerability to call the log password, modify the protected activity or the settings. 300 00:39:05,100 --> 00:39:07,620 So it's quite straightforward. 301 00:39:07,620 --> 00:39:14,840 You just use the vulnerability to start the arbitrary protected activity to modify ping in the settings application. 302 00:39:15,000 --> 00:39:24,000 So here is another demo in the Android 16 Beta 3 and this is the newest version at the time of writing of this presentation. 303 00:39:24,940 --> 00:39:30,460 And I wrote a script to ease the exploitation of this vulnerability. 304 00:39:30,460 --> 00:39:36,180 And this is another similar vulnerability in the restriction fragment. 305 00:39:36,700 --> 00:39:42,560 And this exploitation calls the performance of phone call without any privilege. 306 00:39:42,820 --> 00:39:50,580 And here there is an interesting story here that previously we used our exploit to call 911. 307 00:39:50,800 --> 00:39:58,500 And after several submissions, we were told by the Android security team that please stop calling 911. 308 00:39:58,800 --> 00:40:00,880 Just call other phone numbers. 309 00:40:00,880 --> 00:40:03,300 But do not call 911 in your exploit. 310 00:40:08,860 --> 00:40:17,560 So we can go even further that there is still a problem with the search trampoline activity because the path UI does not support possible nested possible inside. 311 00:40:17,560 --> 00:40:25,800 And some windows, for example, like the owner devices, they removed this gadget in their application. 312 00:40:25,960 --> 00:40:29,520 So we found another gadget, the chooser activity, come to rescue. 313 00:40:29,520 --> 00:40:33,020 And the chooser activity draws a possible from intent and starts it. 314 00:40:33,440 --> 00:40:40,520 The chooser activity takes an actual intent from the input and launches using the start activity as caller. 315 00:40:40,600 --> 00:40:49,080 And the Android version of the chooser activity has a priority of 500, which means that it's not applicable for our bad result targets. 316 00:40:49,140 --> 00:41:01,460 However, Windows, they tend to implement their own version of choosers, like Xiaomi choosers, or like owner choosers, these kind of things. 317 00:41:01,460 --> 00:41:07,320 And this custom choosers mimics official chooser activity, but they do not have priorities specified. 318 00:41:07,340 --> 00:41:10,480 So they can be the target of the bad result. 319 00:41:11,000 --> 00:41:14,720 So does this custom choosers verifies targets? 320 00:41:14,760 --> 00:41:16,900 The answer is yes, but not enough. 321 00:41:17,380 --> 00:41:23,140 The right part of the slide is a summary of the different gadgets in different windows. 322 00:41:23,200 --> 00:41:29,120 We can see that in Android, we have the trampoline gadget, but we do not have the custom chooser gadget. 323 00:41:29,120 --> 00:41:34,600 However, on like a Xiaomi devices, we both have the trampoline gadget and the custom chooser gadget. 324 00:41:35,960 --> 00:41:46,620 So for example, on the Xiaomi devices, we can change the MIUI chooser activity here with the bad result vulnerability. 325 00:41:46,620 --> 00:41:50,400 And here we use bad result to start the MIUI chooser activity. 326 00:41:50,400 --> 00:42:01,240 The MIUI chooser activity verifies the caller has a permission to start the target intent it passed in, the target complement that the target intent resolved to. 327 00:42:01,240 --> 00:42:05,520 However, here that when we use bad result, the caller is a setting. 328 00:42:05,520 --> 00:42:17,800 So this check is passed and the MIUI chooser activity will happily start the actual intent passed in and starts the victim activity without any limitations. 329 00:42:18,560 --> 00:42:21,520 However, there are still like different chooser implementations. 330 00:42:21,520 --> 00:42:27,640 Some Windows chooser implementations verify the caller and also verify the target needs to be exported. 331 00:42:27,640 --> 00:42:30,360 So we need an additional hope here. 332 00:42:30,360 --> 00:42:35,640 For example, on Honor and the Huawei devices, we change another chooser activity. 333 00:42:35,640 --> 00:42:40,580 The official chooser of the Android of the AOSP here. 334 00:42:40,580 --> 00:42:58,700 And so the attack flow will be like attack application use bad result to start the HW chooser activity and the HW chooser activity verifies the caller has permission to start target and verifies target is exported because here the target is a chooser activity. 335 00:42:58,780 --> 00:43:00,680 These conditions are met. 336 00:43:00,680 --> 00:43:06,800 So it proceeds to a chooser activity and chooser activity verifies again that the caller has permission to start target. 337 00:43:06,800 --> 00:43:09,580 However, here the target is settings and chooser activity. 338 00:43:09,580 --> 00:43:11,800 So this check is also passed. 339 00:43:11,840 --> 00:43:19,340 So then the chooser activity calls that activity as caller and finally the victim privileged or protected activity is started. 340 00:43:20,720 --> 00:43:27,540 So the final part, I'm running a little bit out of time, so I'll go quickly here. 341 00:43:27,580 --> 00:43:30,720 How we can use LRM to find this kind of bugs? 342 00:43:31,540 --> 00:43:52,160 It's an interesting idea that maybe LRM is a better fit for finding bugs that bad result because as I have stated earlier that bad result is not a typical like data flow vulnerabilities that you can use static analysis to find. 343 00:43:52,200 --> 00:44:00,240 Maybe for this kind of flexible vulnerability, LRM has a better ability or idea to find them. 344 00:44:00,360 --> 00:44:04,460 And we design our system as illustrated in the figure. 345 00:44:04,460 --> 00:44:10,720 We have a manager agent which uses MCPs to fetch code from the Android USB codebase or the vendor codebase. 346 00:44:10,720 --> 00:44:14,220 In the vendor closed source codebase, we use the JEP. 347 00:44:14,240 --> 00:44:19,000 And I have a JEP here with a GitHub link and if you're interested you can use it. 348 00:44:19,080 --> 00:44:25,580 And the manager agent retrieves a possible vulnerable code and passes it to the auditor agent. 349 00:44:25,580 --> 00:44:29,900 The auditor agent has a prompt to check if the code is vulnerable to bad result. 350 00:44:30,100 --> 00:44:37,000 And the auditor agent, the result, the outcome of the auditor agent will be passed to the reviewer agent. 351 00:44:37,140 --> 00:44:44,440 The reviewer agent will double check if there is a false positive here or false negative here and then outcome the result. 352 00:44:45,420 --> 00:45:04,480 So here the LRM of course cannot directly consume all the USB codebase, so we need to search for APIs, the possible APIs that may appear in the possible vulnerable code, the result activity series, query intended series, and feed the functions and encoding classes into LRM. 353 00:45:04,480 --> 00:45:06,980 And we use different MCPs here. 354 00:45:06,980 --> 00:45:19,660 We have a quick and dirty prompt that you are Android expert, you need to input output in JSON, and you have a few short example that what is a bad result vulnerability, it's a total vulnerability. 355 00:45:19,940 --> 00:45:34,660 And to avoid false positive, do not consider it vulnerable if the intent has become a specific set and complement, set target, and the intent has been set an action or the intent is not used to start activity or start activity for result. 356 00:45:35,320 --> 00:45:55,480 So a quick observation here is that the LRM has false negatives but have a few false positives as there are hallucinations here on whether the intent is used to start activity and sometimes lack of knowledge of the tricky details of the Android security and sometimes lazy on querying call graph. 357 00:45:55,880 --> 00:45:58,280 So there is still additional work needed. 358 00:45:58,860 --> 00:46:09,880 So conclusion here is that we introduced the bad result vulnerabilities and how we support it and how we use the LRM to extend and search these kind of vulnerabilities. 359 00:46:11,300 --> 00:46:20,820 Yeah, so this is the reference credits and you can reach us at myxaccount and also our lab's xaccount. 360 00:46:20,980 --> 00:46:26,280 So I'm not sure if we have time for QA and here is all the slides. 361 00:46:26,280 --> 00:46:27,260 Thank you.