[00:00.000 --> 00:02.600] Okay, hello everyone. [00:02.600 --> 00:06.100] And I think this is the time for my talk. [00:06.100 --> 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. [00:18.900 --> 00:30.800] So the topic of my talk is Dem Made Alive Again, Bypassing Intended Destination Checks and Introducing Launch Anywhere Privilege Escalations. [00:30.820 --> 00:33.640] So a brief introduction about myself. [00:33.640 --> 00:38.280] I'm currently the Center Director and Chief Security Researcher at GD.com. [00:38.280 --> 00:47.260] I'm leading the Dawn Security Lab, which our lab is mainly doing anti-fraud, client security, security research, et cetera. [00:47.260 --> 00:56.500] And I'm previously a winner of the Pantone and Mobile Pantone competitions, and the 2022 Pony Awards Best Privilege Escalations. [00:56.620 --> 01:03.090] And I'm also a speaker at Black Hat, DEF CON, Consulate West, Recon, POC, and Hacking the Box. [01:04.220 --> 01:07.420] So today's agenda is as follows. [01:07.760 --> 01:10.220] My talk will be categorized into five parts. [01:10.220 --> 01:17.100] The first part is the Android security backgrounds for those who are not currently Android experts. [01:17.100 --> 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. [01:28.560 --> 01:31.240] And the third part is the core part of this talk. [01:31.240 --> 01:37.200] It's the battery resolve vulnerability series of CVs we have found in the newest Android system. [01:37.380 --> 01:42.700] And the fourth part is about using the power of ARM and MCP. [01:42.940 --> 01:45.160] The final part will be summary and QA. [01:46.860 --> 01:55.580] So for a quick introduction of backgrounds, I will talk about some knowledge about the intents in Android. [01:55.860 --> 01:57.200] So what is intent? [01:57.200 --> 02:01.960] Intents are actually the core of the IPC mechanism in Android. [02:01.960 --> 02:07.800] It's actually abstraction for messages sent within and between the applications containing the embedded data. [02:07.980 --> 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. [02:27.720 --> 02:31.500] And this API call will be processed by the Android system. [02:31.560 --> 02:35.260] And in particular, it's the activity manager service. [02:35.380 --> 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. [02:48.460 --> 02:53.280] So this is a basic flow of the activities communicating with each other using intents. [02:54.020 --> 02:59.560] So there are like 5 major parts, 5 parts of complements in Android applications. [02:59.560 --> 03:02.200] We usually call it like 5 King Kongs. [03:02.200 --> 03:07.360] And complements can be studied by intents and receive from- receive input from it. [03:07.360 --> 03:14.240] And complements can declare intent filters in the Android manifest about what kind of intents they are expecting. [03:14.480 --> 03:20.760] And the exception is the dynamic broadcast receiver and this is out of scope for today's talk. [03:20.960 --> 03:24.000] And the expected here means that it's not always enforced. [03:24.000 --> 03:32.500] It's only the intent filters criteria is only needed to be met when in the implicit intent resolving. [03:33.900 --> 03:39.280] So the lower part is the screenshots of the search trampoline activity in the Android manifest. [03:39.280 --> 03:42.380] I'm not sure if you can see it very clearly. [03:42.380 --> 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. [03:57.500 --> 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. [04:16.780 --> 04:22.920] And objects, the serializable and the possible, they can define their custom serialization scheme. [04:22.920 --> 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. [04:36.400 --> 04:42.600] So for the intent resolution, as we have mentioned earlier, intents can be explicit or implicit. [04:42.740 --> 04:48.480] The explicit intent target is deduced from the complement set within it. [04:48.680 --> 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. [04:58.060 --> 05:06.340] However, for implicit intent, it must go through the resolution process if there's no complement specified in this intent. [05:06.340 --> 05:15.640] The resolution process is currently defined in the resolve internal function of the resolve intent helper class of the android system. [05:15.640 --> 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. [05:26.460 --> 05:29.760] There are lots of details here and we will go back to it later on. [05:29.760 --> 05:34.740] The details are very important in the exploration of the bad resolve. [05:34.900 --> 05:47.220] And also, of course, security restrictions that a normal application cannot start the protected activity or unexplored activity of other applications. [05:47.220 --> 05:50.240] This is the security restrictions of the intent resolution. [05:50.920 --> 05:56.500] And in the right part of the slide, we can see an example of the implicit intent resolution. [05:56.620 --> 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. [06:07.180 --> 06:16.080] And this implicit action, this implicit intent is finally resolved to the privilege call activity of comp.android.phone. [06:16.280 --> 06:23.980] And we can see that this activity declares the matching intent filters, the intent actions, and the intent categories. [06:24.060 --> 06:28.400] And then the onCreate function of this activity is called. [06:28.400 --> 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. [06:38.360 --> 06:46.900] So in the following slides, we will see how we use the intent privilege escalations to bypass this restriction. [06:47.800 --> 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. [06:56.140 --> 06:59.320] So uh what's the non-launch anywhere? [06:59.600 --> 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. [07:09.760 --> 07:15.560] And these sensitive activities should be protected with permission or is always un-exported. [07:15.560 --> 07:21.820] So it cannot be accessed by a normal application uh uh application hold by attacker. [07:22.120 --> 07:29.220] However, I recall that intent can contain nasty intents which will lead to the intent reduction and injection vulnerability. [07:29.380 --> 07:35.160] For example, in the lower part of the slide, we can see that uh a victim application complements. [07:35.160 --> 07:43.160] It contains uh a secret action or privileged action and it actually commands from the intent income. [07:43.160 --> 07:46.680] However, this complement is usually protected or un-exported. [07:46.680 --> 07:51.000] So an attacking application cannot directly access this complement. [07:51.000 --> 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. [08:05.480 --> 08:12.860] And then the attacker application can use this breach uh breach application to attack the victim application. [08:12.860 --> 08:16.160] So this is an example of the intent redirection. [08:16.580 --> 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, [08:33.940 --> 08:39.640] the settings applications, they hold the privilege to call arbit- to call arbitrary activities. [08:41.180 --> 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. [08:52.040 --> 08:55.500] This is a very old bar, but a very typical example. [08:55.500 --> 08:56.720] Very classical. [08:56.960 --> 09:03.960] And uh in this uh bar, we can see that uh it's in the account management functionality of android. [09:03.960 --> 09:10.620] Uh the account management uh functionality android allows application to create an account. [09:10.620 --> 09:15.200] And uh when it creates an account, it need to ask the settings application. [09:15.200 --> 09:21.020] It sends an intent to the settings application and the settings application calls the account managers at account. [09:21.140 --> 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. [09:34.480 --> 09:36.660] And here we mean the attacker application. [09:36.680 --> 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. [09:46.940 --> 09:52.760] And the settings application just blindly take a possible intent from it and calls that- that activity on it. [09:52.760 --> 09:56.100] So this is a very classical example of a non-training weird. [09:57.380 --> 10:03.540] Of course, this vulnerability gets fixed very quickly and uh this is the first round of fix. [10:03.600 --> 10:05.880] And we will go back to it uh later on. [10:05.880 --> 10:08.720] This is a very important fix and with many details. [10:08.960 --> 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. [10:16.620 --> 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. [10:26.460 --> 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. [10:34.740 --> 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. [10:43.520 --> 10:47.240] And we can see that the check is mainly as follows. [10:47.240 --> 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. [10:58.280 --> 11:00.720] Uh which means the attacker application. [11:00.740 --> 11:08.760] So this check restricts that the attacker application can only use this functionality to start an activity of itself. [11:09.040 --> 11:15.780] And uh it is- it is disallowed to start other activities, other privileged activities of arbitrary application. [11:16.180 --> 11:18.540] So this is round one, right? [11:18.540 --> 11:19.800] Round one is not finished. [11:19.800 --> 11:21.260] We still have round two. [11:21.260 --> 11:28.280] And uh what if the account manager service, the system server, sees a different intent as settings? [11:28.640 --> 11:33.840] So maybe they see the different intents and the check will of course fail. [11:33.840 --> 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. [11:41.500 --> 11:46.920] So when developers create their own code, the things will really go wrong here. [11:47.020 --> 11:52.040] Uh here is an example, the CAE certificate info possible of the Samsung class. [11:52.080 --> 11:57.840] We can see that the developers implements a read from possible which is the deserialization function. [11:57.840 --> 12:00.920] And a write to possible which is a serialization function. [12:00.980 --> 12:07.120] And there's a tiny difference here that's uh on the possession of the third length, the integer. [12:07.140 --> 12:12.120] We can see that in the read from possible, it checks that if the third length is larger than zero. [12:12.200 --> 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. [12:20.100 --> 12:25.700] This will cause a mismatch occurs when the possible is written and read. [12:26.000 --> 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. [12:33.880 --> 12:41.420] So this will lead to the bundle contain different objects after the deserialization, the serialization, and then deserialize again. [12:41.500 --> 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. [12:51.140 --> 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. [13:00.220 --> 13:03.940] And uh for anyone who is interested in the next slide, give an overview. [13:03.940 --> 13:09.660] And uh this kind of possible mismatch box is largely exploited in the wild. [13:09.800 --> 13:17.540] So this uh figure is taken from the Google Android security team uh Hawker's Black Hat EU uh 2022 slide. [13:19.280 --> 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. [13:32.860 --> 13:36.440] Which will lead to the launch anywhere vulnerability again. [13:36.780 --> 13:45.580] So this type of vulnerability uh is largely exploited in like billions of devices in previous years. [13:45.580 --> 13:50.640] And there are like more than 100 possible mismatch vulnerabilities in Android. [13:50.640 --> 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. [14:00.240 --> 14:03.860] So now, we'll go to the third part of the talk. [14:03.860 --> 14:10.540] We'll go to the bad result vulnerability which is the uh CVEs we discovered. [14:11.040 --> 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. [14:22.520 --> 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. [14:32.760 --> 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. [14:41.040 --> 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. [14:53.600 --> 15:00.640] So uh we can see that it performs check here and literally the intent is used in the settings. [15:00.820 --> 15:06.340] So there are some ideas that flow on my mind that can we do a talk tool here? [15:09.000 --> 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. [15:19.940 --> 15:24.700] And the start activity itself actually implicitly calls the resolve activity internally. [15:24.840 --> 15:30.420] So what if the draw solution result change between these resolves? [15:30.700 --> 15:33.240] Like is it possible for a risk condition? [15:33.820 --> 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. [15:40.900 --> 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. [15:53.080 --> 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. [16:07.340 --> 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. [16:17.000 --> 16:19.960] So can we like achieve this result? [16:20.820 --> 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. [16:27.960 --> 16:31.020] What what things you can change or what can you control? [16:31.020 --> 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. [16:43.280 --> 16:44.860] It's in run time. [16:44.940 --> 16:50.740] And the disabled complement is considered to be vanished as if it had never existed. [16:51.220 --> 16:56.800] So can we utilize this primitive to manipulate the resolution results? [16:56.800 --> 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? [17:09.160 --> 17:14.400] So we can see the other time window here between the activity manager service and the settings. [17:14.420 --> 17:23.780] Like can we like disable the activity of our application so that in the first resolution, the result is our activity. [17:23.780 --> 17:29.000] However, when the second resolution, our activity is disabled so it cannot appear in the result list. [17:29.000 --> 17:34.460] And now the privileged activity or protected activity appears in the result list. [17:34.500 --> 17:37.760] So this is the basic idea of our TOCTO. [17:38.080 --> 17:45.020] However, we need to check if our TOCTO exploitation idea, is it feasible? [17:45.260 --> 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. [18:01.660 --> 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. [18:22.860 --> 18:28.060] And of course, the explicit intent always resolved to a single target. [18:28.060 --> 18:32.520] Explicit means that a complement or the class field of this intent is set. [18:32.520 --> 18:42.460] However, the implicit intent may resolve to a single target if there is only one candidate in the intent resolution. [18:43.080 --> 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. [19:01.340 --> 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. [19:18.520 --> 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. [19:30.480 --> 19:34.640] If the candidate is a single result, it will just return the single result. [19:34.640 --> 19:38.100] If there are multiple candidates, here comes a problem. [19:38.100 --> 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. [19:48.920 --> 19:52.680] So it will first exclude the disabled ones. [19:52.680 --> 20:02.900] And then after this exclusion, if there is still multiple targets, it will decide that if the targets have different priorities. [20:02.900 --> 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. [20:18.940 --> 20:26.800] There is a cork here that normal applications can only declare priority zero or lower than zero. [20:26.800 --> 20:33.240] It's a privilege of the platform application and system application to declare priority larger than zero. [20:33.500 --> 20:39.780] So if there is a candidate that holds a largest priority, this candidate will be returned. [20:39.940 --> 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. [20:50.160 --> 20:52.020] What is a preferred attribute? [20:52.020 --> 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. [20:59.120 --> 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. [21:13.900 --> 21:21.440] So if a user starts a candidate here and clicks on always, this activity will be marked as preferred. [21:22.040 --> 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. [21:34.100 --> 21:37.820] So if there is a preferred one, this preferred one will be returned. [21:38.160 --> 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. [21:50.850 --> 21:56.750] So we have introduced the flow of this resolution. [21:56.770 --> 22:00.990] So the following steps is summarized. [22:00.990 --> 22:05.750] Now we can see that first a disabled target won't be taken into consideration. [22:05.830 --> 22:11.330] And then the largest priority is chosen and returned. [22:11.330 --> 22:16.030] And if there is no largest priority, a preferred one will be chosen and returned. [22:16.030 --> 22:21.190] If neither is satisfied, a chooser dialogue is a pop-up for the user's confirmation. [22:22.110 --> 22:29.550] And however, from an attacker's perspective, which steps here we can affect or we can manipulate? [22:29.710 --> 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. [22:39.730 --> 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. [22:55.470 --> 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. [23:03.810 --> 23:07.650] Then we will like bail out and the check fails. [23:07.650 --> 23:14.810] So the only choice left here is that we need to make our activity a preferred one. [23:15.790 --> 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. [23:35.610 --> 23:39.890] However, we have already marked our activity as a preferred one. [23:39.890 --> 23:47.250] So here the check intent will happily find that this result is an activity that belongs to our application. [23:47.250 --> 23:49.790] So this check is passed. [23:49.790 --> 23:57.290] And then we disable our compliment during the time window of the account manager service and the settings application. [23:57.290 --> 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. [24:11.610 --> 24:12.570] It has vanished. [24:12.570 --> 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. [24:22.270 --> 24:26.630] So here is the basic idea of our TOCTO attack flow. [24:26.630 --> 24:33.530] However, we know that there is another important factor in TOCTO exploiting TOCTO vulnerabilities. [24:33.530 --> 24:36.470] You need to check the time frame. [24:36.470 --> 24:41.210] Do you have enough time to manipulate the state of the compliment? [24:41.210 --> 24:42.870] Here we use a profetto. [24:42.870 --> 24:47.890] Profetto is a perf application that comes within the AOSP. [24:47.890 --> 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? [24:57.410 --> 25:00.010] For example, how long does the resolve intent take? [25:00.010 --> 25:02.130] How long does the start activity take? [25:02.190 --> 25:08.590] And this is crucial for our to deciding the time window of our TOCTO exploitation. [25:09.470 --> 25:17.530] And here using profetto, we see that there is actually two check intent calls in the system server. [25:17.530 --> 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. [25:32.510 --> 25:37.910] So it seems that we can just risk within this time window and we are good to go now. [25:38.330 --> 25:43.550] So actually, things are not as easy as we have thought here. [25:43.810 --> 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. [25:56.870 --> 26:03.070] And except if you are Superman or Flashman, you can like manipulate this compliment in one millisecond. [26:03.250 --> 26:09.510] However, so and we can see that the resolve intent here only takes like 0.5 milliseconds. [26:10.010 --> 26:13.710] So given this time frame, we cannot do anything meaningful. [26:13.710 --> 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. [26:24.070 --> 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? [26:32.830 --> 26:38.150] Like, can we slow down the resolve intent and disable the compliment in this time frame? [26:38.250 --> 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. [26:49.570 --> 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? [26:56.450 --> 27:01.010] So we have two ways here and finally we choose the formal way. [27:01.870 --> 27:08.570] To make the formal way work, we need to dive deeper into the resolve internals in the activity manager service. [27:10.090 --> 27:18.870] So actually, the compliment information query is done or fulfilled by the compliment resolver in the package manager service. [27:18.870 --> 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. [27:31.230 --> 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. [27:44.170 --> 27:49.670] And the actual resolution process is done in the computer engine. [27:49.670 --> 27:59.410] The computer engine is the M compliment resolver, the field of the computer engine is a snapshot of the compliment resolver. [27:59.410 --> 28:07.590] And this snapshot is fetched and updated when the package manager internal-based resolve intent is called. [28:07.910 --> 28:13.410] And then the queries are performed on this snapshot of this compliment resolver. [28:13.410 --> 28:18.550] The snapshot actually creates a copy of these big four mappings. [28:19.550 --> 28:24.450] So here in the right part of the slide, we can see this is a summary of this whole flow. [28:24.450 --> 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. [28:40.750 --> 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. [28:51.370 --> 28:55.630] So what is a snapshot in package manager service? [28:55.870 --> 29:01.350] A snapshot creates a read-only current state copy of the package infos. [29:01.670 --> 29:06.170] And the queries are done in the frozen compliment mappings and states. [29:06.350 --> 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. [29:15.670 --> 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. [29:26.910 --> 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. [29:39.210 --> 29:46.790] And the result will not be affected by our operations because all queries are done in a frozen snapshot. [29:48.930 --> 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. [30:06.770 --> 30:10.290] Our solution here is to play with the Android manifest. [30:10.510 --> 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. [30:26.290 --> 30:30.030] And also, there's a very helpful flag here. [30:30.370 --> 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, [30:48.990 --> 30:56.770] and it will do like a linear ON printing of all the categories of all the intent filters. [30:56.890 --> 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. [31:19.390 --> 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? [31:28.330 --> 31:30.490] What's the largest number we can declare? [31:30.590 --> 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. [31:45.210 --> 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, [32:12.250 --> 32:15.230] and this is ideal for risk condition vulnerability. [32:16.230 --> 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. [32:30.250 --> 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. [32:45.230 --> 32:48.030] This is a very ideal situation for us. [32:49.470 --> 32:56.570] So the final attack flow, the final outcome here in our profiler view is as follows. [32:56.590 --> 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. [33:13.910 --> 33:17.450] And then if the first check passed, it goes in the second check. [33:17.450 --> 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. [33:35.290 --> 33:42.290] So the second check also passed because the snapshot is taken in the beginning of this function. [33:42.290 --> 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. [33:49.790 --> 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. [34:04.250 --> 34:11.350] And here, the settings application will happily start the intent and call the launch anywhere vulnerability again. [34:13.170 --> 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. [34:25.010 --> 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. [34:39.410 --> 34:46.270] However, if you declare a too large body of the intent filter, the system UI will crash here. [34:46.910 --> 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. [34:57.390 --> 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. [35:07.330 --> 35:14.370] And then we install an update to the exploit application with a larger number of categories and then trigger this vulnerability. [35:14.370 --> 35:17.990] This will give us an even larger time frame. [35:17.990 --> 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. [35:30.810 --> 35:35.790] And this can still give us like 100 milliseconds of racing time. [35:36.110 --> 35:43.770] So this is just an exploitation technique here and you can take it or you may not need it. [35:45.230 --> 35:55.370] And this vulnerability here, the bad resolve vulnerability, has some limitations here because it is an implicit intent resolution. [35:55.370 --> 36:01.650] So it requires a target complement to have an intent filter with data element and it requires a target complement. [36:01.650 --> 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 . [36:10.890 --> 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. [36:20.850 --> 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. [36:29.530 --> 36:36.990] And in the onCreate function of the search trampoline activity, we can see that it has a very useful gadget here. [36:36.990 --> 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. [36:46.310 --> 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. [36:56.630 --> 37:00.210] So there is another interesting detail here that we can see. [37:00.370 --> 37:05.130] Normally you cannot directly call the search trampoline activity because there is a permission check here. [37:05.130 --> 37:07.050] It will check the colors package. [37:07.050 --> 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. [37:16.630 --> 37:22.030] The fix for this vulnerability in the activator service is quite simple. [37:22.030 --> 37:28.190] It just makes the implicit intent an explicit one using the set complement or set package. [37:28.190 --> 37:35.610] So this kills the tactile window, the whole tactile scenario of our attack. [37:36.790 --> 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. [37:50.230 --> 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. [38:01.030 --> 38:03.990] And there are two CVs assigned already. [38:06.960 --> 38:13.520] So for the aspiration technique, the key parameter here is a timeout before the disabling complement. [38:13.520 --> 38:22.620] So how much time will be spent in the resolve intent when we supply a malformed manifest, a malformed intent filter? [38:22.620 --> 38:25.240] It varies on high-end and low-end devices. [38:25.240 --> 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. [38:33.100 --> 38:35.240] It will give us less time for racing. [38:35.400 --> 38:41.360] And for example, on Pixel 7 Pro or Pixel 8 Pro, it is like 200 to 300 milliseconds. [38:41.640 --> 38:48.060] However, on an old phone like Galaxy S21, this can be extended to like one second. [38:48.600 --> 38:51.720] Anyway, we can continuously retry until we succeed. [38:53.180 --> 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. [39:05.100 --> 39:07.620] So it's quite straightforward. [39:07.620 --> 39:14.840] You just use the vulnerability to start the arbitrary protected activity to modify ping in the settings application. [39:15.000 --> 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. [39:24.940 --> 39:30.460] And I wrote a script to ease the exploitation of this vulnerability. [39:30.460 --> 39:36.180] And this is another similar vulnerability in the restriction fragment. [39:36.700 --> 39:42.560] And this exploitation calls the performance of phone call without any privilege. [39:42.820 --> 39:50.580] And here there is an interesting story here that previously we used our exploit to call 911. [39:50.800 --> 39:58.500] And after several submissions, we were told by the Android security team that please stop calling 911. [39:58.800 --> 40:00.880] Just call other phone numbers. [40:00.880 --> 40:03.300] But do not call 911 in your exploit. [40:08.860 --> 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. [40:17.560 --> 40:25.800] And some windows, for example, like the owner devices, they removed this gadget in their application. [40:25.960 --> 40:29.520] So we found another gadget, the chooser activity, come to rescue. [40:29.520 --> 40:33.020] And the chooser activity draws a possible from intent and starts it. [40:33.440 --> 40:40.520] The chooser activity takes an actual intent from the input and launches using the start activity as caller. [40:40.600 --> 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. [40:49.140 --> 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. [41:01.460 --> 41:07.320] And this custom choosers mimics official chooser activity, but they do not have priorities specified. [41:07.340 --> 41:10.480] So they can be the target of the bad result. [41:11.000 --> 41:14.720] So does this custom choosers verifies targets? [41:14.760 --> 41:16.900] The answer is yes, but not enough. [41:17.380 --> 41:23.140] The right part of the slide is a summary of the different gadgets in different windows. [41:23.200 --> 41:29.120] We can see that in Android, we have the trampoline gadget, but we do not have the custom chooser gadget. [41:29.120 --> 41:34.600] However, on like a Xiaomi devices, we both have the trampoline gadget and the custom chooser gadget. [41:35.960 --> 41:46.620] So for example, on the Xiaomi devices, we can change the MIUI chooser activity here with the bad result vulnerability. [41:46.620 --> 41:50.400] And here we use bad result to start the MIUI chooser activity. [41:50.400 --> 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. [42:01.240 --> 42:05.520] However, here that when we use bad result, the caller is a setting. [42:05.520 --> 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. [42:18.560 --> 42:21.520] However, there are still like different chooser implementations. [42:21.520 --> 42:27.640] Some Windows chooser implementations verify the caller and also verify the target needs to be exported. [42:27.640 --> 42:30.360] So we need an additional hope here. [42:30.360 --> 42:35.640] For example, on Honor and the Huawei devices, we change another chooser activity. [42:35.640 --> 42:40.580] The official chooser of the Android of the AOSP here. [42:40.580 --> 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. [42:58.780 --> 43:00.680] These conditions are met. [43:00.680 --> 43:06.800] So it proceeds to a chooser activity and chooser activity verifies again that the caller has permission to start target. [43:06.800 --> 43:09.580] However, here the target is settings and chooser activity. [43:09.580 --> 43:11.800] So this check is also passed. [43:11.840 --> 43:19.340] So then the chooser activity calls that activity as caller and finally the victim privileged or protected activity is started. [43:20.720 --> 43:27.540] So the final part, I'm running a little bit out of time, so I'll go quickly here. [43:27.580 --> 43:30.720] How we can use LRM to find this kind of bugs? [43:31.540 --> 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. [43:52.200 --> 44:00.240] Maybe for this kind of flexible vulnerability, LRM has a better ability or idea to find them. [44:00.360 --> 44:04.460] And we design our system as illustrated in the figure. [44:04.460 --> 44:10.720] We have a manager agent which uses MCPs to fetch code from the Android USB codebase or the vendor codebase. [44:10.720 --> 44:14.220] In the vendor closed source codebase, we use the JEP. [44:14.240 --> 44:19.000] And I have a JEP here with a GitHub link and if you're interested you can use it. [44:19.080 --> 44:25.580] And the manager agent retrieves a possible vulnerable code and passes it to the auditor agent. [44:25.580 --> 44:29.900] The auditor agent has a prompt to check if the code is vulnerable to bad result. [44:30.100 --> 44:37.000] And the auditor agent, the result, the outcome of the auditor agent will be passed to the reviewer agent. [44:37.140 --> 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. [44:45.420 --> 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. [45:04.480 --> 45:06.980] And we use different MCPs here. [45:06.980 --> 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. [45:19.940 --> 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. [45:35.320 --> 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. [45:55.880 --> 45:58.280] So there is still additional work needed. [45:58.860 --> 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. [46:11.300 --> 46:20.820] Yeah, so this is the reference credits and you can reach us at myxaccount and also our lab's xaccount. [46:20.980 --> 46:26.280] So I'm not sure if we have time for QA and here is all the slides. [46:26.280 --> 46:27.260] Thank you.