Hello everyone, thank you very much for having me. Yes, today we're going to be talking about physical attacks against smartphones. So the crux of this talk is that I was seeing a huge number of different conference talks about extremely complex attacks against smartphones due to the high measures of security that are placed on them from the boot level all the way up to the high level OS. And despite this, there are still times when very simple techniques can be used to bypass the security on smartphones and escalate privileges or get unauthorized access in ways that you would consider very simple in a general sense. So we're going to be doing two 20 minute case studies for this. The first one is going to be gaining root access on a smartphone with no boot loader unlocking capability. This is where the manufacturer removes the ability to unlock the boot loader and root it by itself. And the second is going to be gaining code execution in the boot loader of a Samsung smartphone in order to bypass secure boot and execute your own kernel and do other malicious things. So case study one, rooting on a locked boot loader. Essentially I'd bought a brand new phone and wanted to root my old one so that I could use it for AppSec testing and that sort of thing, install my own certificates, add for reader, etc. However, on this particular device, the manufacturer had gone into the code of the boot loader and removed the checks to allow you to access the USB interface. This meant that I would never be able to get into the fast boot mode and unlock the boot loader, add root access and that sort of thing. OEMs very rarely do this and they usually just add restrictions onto the boot loader that requires them to um you to sign up with their services in order to do this properly. Um the target device was a smartphone from a Chinese OEM released in 2019 that used an OEM developed fork of Android which had it's own security features and other um tweaks to it that were going to be the target of this uh particular project. So while I say that it didn't have boot loader and unlocking capabilities in the traditional sense, what it did have was a special engineering app that permitted boot loader unlocking. This used a uh signature stored in a partition on the device um which was inaccessible to standard users but could then be used by the special engineering app with special permissions and written into it. And then when the device rebooted it would give other engineering level access. It was not publicly available although there were some leaks online and it required an approved user account which was a long winded process I didn't want to go through. Um so when boot loader unlocking isn't available it's obvious that you're going to need some kind of exploit in order to escalate privileges to the root. Um and with no direct access to the boot loader USB interface which is my standard approach for attacking a device like this, a vulnerability was needed in the Android fork itself. I didn't think I'd find anything in Android that would be um particularly actionable in this sense and I thought the changes that had made to it would be probably the area where I'd find the most critical vulnerabilities I could have used. What I found was the Android fork contained a high number of custom system and root level applications um which could be potentially exploited in different ways. Um so the Android fork had a service running at root as root at all times that was called by the system level applications um for the facilitation of cloud upload and archiving of um app data. So we would take uh the system level applications um for the um all the data from the uh users protected um application and cordoned off partitions and package it all together and upload it to the cloud where it could be downloaded again if needed. Um brief analysis of this binary found that it had a immediate command injection vulnerability where if you had a file within the file system with back ticks in the name you could execute commands within it. Um what would happen is you'd upload this file and then download it again and as it was restoring the file it would then execute whatever command was in the back ticks. So very basic. Unfortunately for me Android also employs SE Linux which is an extremely strong security measure to cordon off different components of the um operating system even if they are all running as root. This meant that even though I had root access superficially I only had access to the app data sections of the device rather than having the access to um other components I wanted to modify. Um I found that pretty much every instance of um a command injection I could find on the device had a similar issue. So I'd have to find an another way of getting ex uh escalated privileges. Um most app vulnerabilities are very similar to the ones that are limited by SE Linux um uh context could probably be bypassed with a kernel exploit. However a kernel exploit is a very complex thing to do and not something you want to be doing for a very basic simple project you're just doing in your spare time. Um and as the boot loader was locked down and the exploit OS exploits were out of the question I decided to go for my next best option which would be recovery mode on the device. So recovery mode uh uh mode on an Android device is traditionally is a very very simple menu which you use the volume buttons and the power button in order to navigate through it. Um the recovery mode on the navigate through it. I found that on this Android fork they've actually updated this to include Wi-Fi access, access to more parts of external storage and a few other options as well as having the touch screen enabled. Which I found was due to the fact that they'd taken their Android kernel and dumped it into the recovery partition meaning that if I'd gain access to it I'd have access to all the same hardware components the traditional Android operating system was. So I wanted to find an update image um for the um uh entire operating system of the device so that I could extract recovery and then find a simple vulnerability. Unfortunately I downloaded the updated um the update files for this device found that they never updated the recovery um partition meaning that I couldn't find it within the operating system. That meant that um I would have to work out any vulnerabilities blind and just guess and just try things until something worked. Um so yeah with no recovery image to reverse engineer I just tried very basic attacks to begin with. Um as the menu option included uh the option to load in these encrypted zip files the OTA update images I decided to attempt those first. So I decided to attempt those first. So as I found a command injection vulnerability in the high level operating system I thought I would probably find one in the recovery image as well. So I took a legitimate encrypted update file for the device and renamed it to contain backticks and sleep 30,000. What would happen is if I had successfully executed this command the phone would be spending a few hours trying to update itself with never succeeding. Um yes and this did indeed cause the update process to hang demonstrating that I'd found yet another command injection vulnerability in the device. Um I disclosed all the command injection vulnerabilities I'd found to the OEM who very very swiftly remediated them and updated new versions to the software. Um but as the recovery mode command injection was very likely to be running as root and have no restrictions on it this would be a good basis for me to then gain further root access to Android. So I started with root cause analysis just so I could get out of the way and found that it was a SHA1 sum check um for some logging that was checking um data on the uh uh the SHA1 sum of the update file um which was a very basic um as there was a command injection vulnerability in the file name um this could probably be used to update a more complex script. So if I wrote a more complex script a base 64 encoded it and piped it into a system bin SH um a shared shell script could then be loaded that's more complex from the file system and executed. So this um script here literally just cuts from the user data partition a much more complex script that can be used. Unfortunately, the file system that used by Android's user data does not support all special characters for instance the pipe character I would need to perform this exploit. So I would have to find a way around this. Luckily I found that they had modified the um recovery image to also support EXT4 file systems which is rare on Android. And usually when you put in an EXT4 um SD card into an Android device it says unsupported um file system and then tries to format it. Um luckily for me it didn't do that so I could just load my more complex update file onto that and execute it. So I wanted to get a more concrete shell on the device so I would have a look around and also work out what was going on in a more accessible manner. So what I did was I ran the ID command and ran it into the user data partition so that if I wanted to reboot the phone I would then find it was running ID root or ID system or whatever was going on. I also wanted to see if I could disable SC Linux to bypass all of the contacts that were there and found that that also worked. And then I also wanted to enable ADB on the device so I had a root shell into recovery which also worked quite well. Um so root access and recovery mode is great but you've then got a phone that's in a very not very fairly fleshed out mode. I can't access any apps from there, I can't modify my files in any real way and I can't usually access the internet, Bluetooth or anything like that. Um what I wanted to do was find a way to switch from recovery to Android without ever having to reboot the device and go to the bootloader. Because as soon as I got to the bootloader I had to reboot the device and go to recovery mode. And as soon as I do that I would lose my shell on the device because there was no persistence in an attack like this. My first port of call was to try to use KEXEC. Now KEXEC is a um kernel um component which allows you to load a new Linux kernel onto a Linux uh device and then execute that. Essentially switching from one Linux kernel to another. Um if I could do that that would be a very quick way for me to switch to the Android kernel and everything else. But unfortunately even compiling the module from scratch was blocked because it was using some um deny listed um uh code. Um so that was a very quick way for me to switch to the uh uh module components. So I just tried to do something, decided to try to do something that was in the user space rather than in the kernel itself. Luckily there was Ptrace. Now Ptrace is a system call allowing one process to observe and control another for debugging purposes. Um so typically this is for things like um logging and tracking and debugging on things that run on the operating system and doing things like you know the strace command within Linux. Um it can even um modify memory that is um write denied. Um it can even um modify memory that is um right denied um in the standard processes. Um which means you can modify running code even if they are not meant to be able to do that in the particular um ELF that you're working with. What I wanted to do was use Ptrace to essentially latch onto the init process and restart that but in the Android context. So init is um always process ID one um which uh means that it has some special privileges within Linux and also it has a lot of control over the rest of the system. Um what I wanted to do was use the execv key command which um executes a command um which um executes a command within one process that uses the same process ID to run more commands that would then get me to switch out init. Um luckily for me if I did this I could um execute uh init but never have to return back to it. I could just keep things going. There's one long process switching from one set of data to the other. Um and this could be very trivially done with a bit of uh um assembly code. So just moving in the parameters and then executing the service call. Um switch root is what's used during the boot process usually to switch from the init to the boot process. So the um the ram disc which contains some of the lower level stuff um for mounting the more complex file systems um into the new one. Uh it's a very common feature on Linux based devices and what I intended to do was switch from one init ram fs to the android init ram fs which would then load into the system operating system. Uh this could be very easily done if I just uh mounted a new ram disc and then loaded the data in and then hopefully I could then switch instead if I needed. So the process for uh uh uh uh uh uh uh uh uh uh uh uh uh uh uh uh uh uh uh uh oh init usually looks like this on Android. You do have the init process that starts as 1 then it sets up sc THEM warned me about annuance and then in its second stage which has all the hardware and everything and that's where the process sits most of the time. And essentially what I wanted to do was inject in a switch root command into init which would then start the whole process again killing the old recovery process and introducing the new one that was running android. Um there were a few caveats with this however because um the ones really intended to switch from one init ram fas to another and I've got a couple of and you're meant to reboot to get into other systems like this. So a core component of SwitchRoot is the remounting of mounted folders. However, most of the mounted folders that occur in Android at this point are shared. This means they're handled in slightly different ways than how you expect when it comes to things like moving the mounts to different places. However, this could be trivially resolved by just writing a small shell script that went through all the mounts, found out if they were shared, and made them private instead. And private means they could be moved around wherever I wanted within the file system. Also, I found that the init binary was checking prop command line within the file system for whether the image required SELinux to be enabled. And if it did, and it found it was disabled, it would enable SELinux, forcibly re-enabling it, even though I'd disabled it. Luckily for me, ptrace allows you to override system calls, so I modified the read system call whenever it touched the prop command line file to override the check for enforcing SELinux with one that allowed it to be disabled. I also found that this caused a lot of kernel panics, because init also does all the system hardware services set up. This includes things like saying the Wi-Fi interface, Bluetooth, etc. But the recovery operator side of things had already done this, so doing this again caused the kernel to not really know what to do. What I did was, in the same way as I've done with prop command line, just make it return empty files whenever it tried to access these .rc files. I did this because then I wouldn't have to modify them within the file system, which would require a lot of work. This would cause the device to not be able to work in a non-routed manner. I also found that when I tried to unlock my phone after getting through this entire process and getting it to boot, that I could no longer use my pin, because all of the security services were still running in the recovery context. Luckily for me, I could just kill all these processes and let init restart them again, right as I was starting this whole process up. While this is pretty much a read-only process, and if I rerouted the device, I'd lose all of this root access, what I could do was still overwrite it, and overwrite some read-only files. The system partition, which stores a lot of the system data, is a read-only file system, and it uses dm-verity to make sure it's got appropriate signatures working throughout the file system. However, if you use the mount-dash-dash bind command, you can override the files there temporarily with your own, meaning that if I wanted to modify, for instance, the frameworks which had root detection in and things like that, I just needed to do that temporarily, and it would work without damaging the device in any way. So, we're going to do a quick demo of this boot process now before we move on to the next one. So, hopefully this won't go to the next one. So, brilliant, sorry guys. As you can see, I've just pressed my little command there, and now it's now running through the init process. It then kills recovery, which was running the screen at that point, and starts the Android process booting up. So, then starting the full Android operating system and giving me root access. I also found that turning off the phone when I started this, I'd need to reboot the screen, otherwise I couldn't use the touch screen. And then, yeah, I have a telnet root backdoor into the device. Thank you. So, I observed something quite interesting afterwards. I was quite happy to have root access, but I realized that during the debugging process, I'd kept a BusyBox telnet server within the recovery context of the device. And when I'd remounted the new init RAMFS, I'd found that the old recovery one was still sitting in memory and accessible. So, there was a telnet service running in a file system that Android had no idea about. Switch root had deleted all the files within this file system because it was stored in RAM, but just using BusyBox, I could repopulate all the tools, and it gave me this, like, secret little section of the device which Android didn't really have access to. Because it was hidden from Android, I could do a lot of interesting things accessing the hardware and stuff, but I could also access the rest of Android itself without Android knowing that I was there. So, by CDing or shrooting into the directory proc1root, which was the root file system that the init process is using, recovery could access the Android root file system as root without Android knowing about it, which was fantastic. What I decided to do was expand this out, however, and add a whole Debian root file system, to the device, giving me a lot of debugging and testing tools I could also use to continue to compromise the device in further ways. So, in conclusion, root access by this method was very consistent. I left the thing running with the init parasite ptrace tool attached to it for days at a time without any crashes. It would just keep running and running and running and no problem whatsoever. I also found that just by rebooting the device, I had no real effects and it could operate normally, going back to a standard non-rooted device with no awareness that I'd manipulated in this way. And I also found that the biggest benefit for this whole project was having ptrace there. So, if you're compiling a kernel, do remove that if you need to. Now we move on to the second case study, which is a bit more technical and a bit more exciting, because we're not going for a device that I wanted to root for my own purposes, but I just wanted to exploit in some way. So, Exynos-based devices have had a significant amount of research done on them on this stage, and at Black Hat as well in previous years, but they all focused on the download mode of the bootloader. So, this is a high-level protocol used by Samsung to write and read files in different ways and debug the device and unbrick it in many ways. Because it all focused on the high-level download protocol, I decided to start a project to try and manipulate the low-level USB stack that was in use, to see if I could find a vulnerability that was as actionable as what had already been found. For this, I found the cheapest Samsung device I could that was still of decent quality and modern, which was a Samsung Galaxy A04s, which was actually quite a decent phone after I bought it. It was released in August 2022 and used an Exynos 850 chipset, and I knew that it would be quite an interesting target because it had a lot of the security features like Knox in place that more expensive, more modern, or more higher-end Samsung devices do. So, the secondary bootloader, which is what I was going for with this project, is called S-Boot in Samsung, and it facilitates a few things. It facilitates standard boot from the primary bootloader all the way up to Android. It facilitates download mode, which was the protocol we were just talking about. On my device, it also had fast boot mode, which is the standard Android administration's bootloader tool, and upload mode, which is what's usually found when you hit an unrecoverable error in some way. All of this was encompassed in a single firmware binary called S-Boot.bin, but because of this, I thought all three USB protocols, so download, fast boot, and USB, would probably be using the core USB stack underneath, which, if I could find a vulnerability in, I would have broken all of those in one go. So, when I'm talking about the core USB stack, I'm talking about USB control transfer. So, control transfers are used to send and receive, like, debugging information, or not debugging information, configuration information about the device. Sometimes it's used for more complex things, for instance, iPhones, DFU modes also use control transfers, but generally there's a very standardized approach for these, and they use standard parameters, which are BM request type, B request, W value, W index, buffer, and buffer size. So, what I really wanted to do was just fuzz it and find an actual exploit just by running a very basic fuzzer. Now, control transfers are mostly, extremely stateless, they do their own thing, you read and write data, and at a very high level, there's just not much else you need to do. And with this, you can just randomize all the parameters and send a randomized buffer size with randomized data in it, and see what happens. So, as you can see there, my very complex fuzzer, you know, way better than, you know, AFL, of rand, rand, rand, rand, rand for every parameter. And as you can see on the right, when I was running this, you'll see the minus nine errors, which are libUSB errors, which is where the device has gone, I don't know what the hell to do with this. All the ones without the minuses is where data has been transferred back and forth. So, very simple to keep track of. However, during my initial fuzzing attempts, I was sending purely random data, and it caused the device to reboot into a failure mode I couldn't recover from. Every time I tried to reboot, it said the same thing. An error has occurred updating the device software, and I thought I'd now got a brick on my hands. This occurred when the 0xf6 value was sent as the bRequest parameter, which was very interesting, because I didn't know why that would be, because it's not a standard command or anything like that. However, I found it was recoverable back to a working device by using the download mode tool. So I used the command line tool in Heimdall, which is an open source tool for manipulating download mode that's accessible on GitHub, and as soon as I tried to do anything with that tool, the device decided it was working again, so clearly it just didn't like my tool. So, I kept fuzzing and fuzzing and fuzzing for about half an hour, and found that the device would crash and reboot after a certain set of transfers. Luckily, I had a seed in this fuzzing, so I knew exactly what could be done, and I could just run the whole on-target fuzz again and see what happened. And what I did was essentially remove transfers in the sequence to see which ones were actually causing the crash in the first place. So, I essentially got that down to two control transfers after about 10,000, which was nice. So, the first transfer was a malformed get descriptor request, so in that instance it's got get, and it was sending data instead of receiving it. And the second was a valid get descriptor request, which was causing the crash. Now, get descriptor is a core component of the USB stack, and it's control transfers that retrieves descriptors about the device. These are configuration data, which includes things like strings about who manufactured the device, IDs, and also what the device does, which is very nice. In these descriptors, the first byte of the data is always going to be the size of the buffer itself, so you can see B length is 18, which is the size. And if you can overwrite this, you can then make your memory access push into the linked list next to it, which is where the other descriptors are stored, usually. So, what's interesting is most USB stacks don't check the control transfer direction. They're usually protected by how their own USB hardware works, so they have send and receive functions. So, for instance, in this case, this is the STM32 USB D stack, where if you send it a get device descriptor request, it will explicitly send a control send data request to its own hardware, meaning that it can't receive data back from it. However, in this instance, I could send data to it, meaning that I had full control overwriting data in memory, which was very nice. So, what I did was try to overwrite that first byte, just by sending data to the same memory that was there. However, this was ineffective, and it did change the byte. However, it didn't alter the size of the data received. Luckily for me, there was just a buffer overflow there anyway, so I was quite happy. Because of this, the data next to the buffer could be overwritten, but I didn't know what was there yet. But I could just try and guess. So, by sending a large buffer that caused the device to crash, I knew that I had a traditional buffer overflow hitting something. So, I decided to do a binary check until I found a data size that didn't cause the device to crash. Then I made that size one byte larger and saw if it crashed. And then, if it did crash, changed the value of that last byte, incrementing by one, until I found a value that didn't crash. Essentially, I was brute forcing my way up the adjacent memory. Until I found fully working memory that I could then manipulate if I wanted. What was excellent about this was that next to it was a linked list, which included pointers to other descriptors, which would then be overwritten themselves. And this had two key benefits to me. Number one, this could be used for a cold boot attack. So, for instance, if I had someone's Samsung phone and rebooted it, the memory wouldn't be cleared at that time. And I could dump the entirety of memory, EL1, so all of the external RAM, and then get their secrets out of it, something they'd been typing, anything that was stored in RAM at that time. The second thing I could do was write all of that data as well, including to the bootloader. So, the first thing I did was dump memory of the device, so I knew the memory layout of the bootloader itself, so I could then manipulate it later. So, I found that all of the pointers I was looking at were between OXF9 and the six zeros, and OXF8 and six zeros. So, I made a memory dump of a bit of data right before that, just to see if I could find the code of the bootloader itself right next to the RAM, which is what I expected. Luckily for me, the bootloader co-starter, OXF88 and five zeros, which meant that I could then dump it and just statically analyze it in Ghidorah if I needed to. What I really wanted to do was get code execution, so I could then modify the functionality of the device to pass secure boot, and get a bit more access to things, modify the kernel, etc. But I found that they'd actually implemented DEP on the device, so data execution prevention, meaning that I couldn't overwrite the code in the bootloader in RAM, because the memory management unit had disabled this. When I tried this, it caused the device to hang, because it hit a hardware error, implying that it was configured well. However, I found that attempting to execute code outside of the code that had been allocated for the bootloader was possible. So, if I just dumped a bunch of code just outside of what had been mapped already, I could execute code from anywhere at the same exception level as the bootloader itself. So, with this, I could patch in new functions if I wanted to, and when I'm writing even next-works for bootloaders, I like doing this in C. And just by using the GCC static no lib flags, and using object copy, you can create a raw binary of any functions you're writing, as long as you're not using standard libraries. So, you would have to re-implement memcopy, but you've still got a lot of ease over writing ARM assembly all day. And because I could write these directly into memory, if I wanted to then write into the stack to point to them, that would be very easy as well, but I had another idea instead. So, fastboot mode was used as the basis of this exploit, because I just really like fastboot mode, but also because it uses string-based commands for all of its administration. So, what you'll find on bootloaders using fastboot, is there will be a table of strings for the commands themselves, and then pointers to specific functions. And this is usually stored in writable RAM, regardless of where it is, because they're loaded in via other functions. And by modifying this table, it would allow me to have easy code execution, without modifying the stack, without having to do other complex things. I found that fastboot in this instance wasn't really used for administration, it only had two commands, which were get variable, which had system variables, and reboot, which would reboot the device. So, I chose get variable, because it was easier. So, the table usually looks like this, so you have an address pointing to the string, so reboot, and then address pointing to the function itself. This would mean that if there were any really complex things like stack canaries in place, where I could still bypass them very easily, they wouldn't be a problem at this point, because I was actually going to see someone loading in the address itself and execute them. Because I had code execution, it meant that secure boot bypass would be possible. So, I could then modify the kernel without hopefully tripping knocks, and add malicious code into someone's phone when it was booting, and do other interesting things. However, I found that none of the USB-based modes, so fastboot, download, et cetera, had the capability of just booting the phone itself, which would be a good thing to hook into for this particular attack. What I would have to do was call into the boot functionality that was already there for the standard boot mode. However, I found that this crashed the phone itself, which meant that I would actually have to implement boot function functionality in a bootloader myself. So, there are two options for re-implementing the boot process. The first was to copy the entirety of working memory from the bootloader and put it somewhere where I could modify as I wanted to, or just re-implement the boot functionality from scratch, calling in functions that I needed to, to things like set up the hardware, set up the TE, et cetera, et cetera. I chose the latter because it would be a lot easier for me to debug things, but also because there was a lack of writable memory at this point, because of all I was doing. So, functions in the bootloader could trivially be called by apps, and actually addresses in C. So, in C, you can literally say, I want to call a function at this address, and it will load it in and branch into them. And you can give it parameters, and that's what I wanted to do, so that I could just load in and check things that didn't work right, et cetera, or change parameters, or just remove functionality I didn't need. For instance, if the bootloader had already executed certain hardware setup, I wouldn't have to modify that anymore. So, I could literally cut down everything until I had the bare bones of a boot process for myself. What was really lucky for me was that the bootloader contained a huge number of print tests throughout it for debugging, saying things like, oh, we're setting up this, this has failed, et cetera, which were all written into RAM address 0xf0070s. By comparing my boot implementation to one that had worked legitimately, I could literally do a one-to-one comparison of what was broken, and then check down the until I had a boot process that looked almost identical superficially from the spring's perspective, which was really nice. Then, at the end of this whole boot process, of course, it would have to jump into the kernel. I found that on the bootloader, it was using KSLR, so it was putting the kernel at a randomized address within memory, but I also found that that randomized address was stored at a static pointer, which I could just load off and then execute into it, which was nice and easy. However, I found that even booting into the kernel had some problems. So, after I'd patched in all of what I thought were the appropriate functions, I wanted to execute the kernel. However, it started at the start of the process, it showed the boot screen and looked like it was going to start, and then hung and never started Android. However, I realized that because I'd already been modulating it, and modified the boot code like this, and because the MMU was still in a position where the kernel code was writable, I could modify the kernel after it started in order to see what was going on and remove security components or harder initialization components to see what was actually going on and hopefully find the thing that was causing a crash. After doing a bit of analysis by knocking out functions within the kernel itself, I found that the device was freezing after the kernel reinitialized the MMU, a key component of the kernel is it reinitializes a lot of the hardware registers that the bootloader has already done because they're not necessary anymore. And so as soon as it was reinitializing the MMU with its own rearrangement of the memory, so setting up things like for kernel memory protection and things, it was causing the rest of the device to hang. And the reason for that was most likely going to be that the bootloader itself had other threads going on that were accessing memory that would no longer be accessible at this point. So, most Android bootloaders use a single thread for all functionality. They start up, they have some interrupts, and then they've maybe got a USB interface, but literally all they want to do is get from A to B, which would be starting up to loading Android and executing. However, SBOOT was found to implement an RTOS, which was much more fully featured and handled things like a much more complex graphics setup and a much more fully featured thing for the debugging and addressing, etc. As you saw, there were a lot of print tests and things. There was a background process that was allowing this to be written into memory, etc., and it was really nice. And because the kernel was altering the MMU page tables, they were showing to execute unmapped memory, which was causing the hardware errors. So, there were three threads that were identified on the device. There was the background tasks, which I just talked about. There were the USB control transfers, which were what we were exploiting. And there was the high-level USB communication, which was the download mode, the fast boot mode, etc. we were talking about. And as each one was constantly polling for the next interrupt it wanted and things, it was that that was causing the issue. And I also felt that because I didn't know much about how the RTOS was working, there was no trivial way for me to disable them individually. So, I needed to come up with a much simpler solution for myself just to kick them over and get myself into a position where there were no threads running. So, a simple solution for me was going to be to throw an exception. When you throw an exception, all the threads sort of hang waiting for that exception to occur because they're usually doing something that's very timing or security critical. And also, recovering from the exception wouldn't be required because we were trying to execute against the kernel, which would then resettle off the exception and registers and things. So, I could literally just dump the kernel bootstrapping code into there, hopefully, and get where I wanted to be. So, vbyel1, which was the table that you just saw in the last slide, is a register that points to a table in memory which includes sequences of different exceptions, which are stored in 128 byte chunks. So, every 128 bytes is a different exception type. I didn't really want to work out which exception was what. So, what I ended up doing was doing a knob sled throughout the entirety of the exception table into my bootstrapping code at the end of it. And I did that by using a node of memory, which was then executed. So, even with the kernel booting like this, and it did work, it's got further down the line, Android was still failing to start, reverting to a special recovery mode that was telling me that the file system manager was failing. The error message that I saw suggested that it was due to the user data partition not being decrypted. So, on most Android devices now, user data is encrypted and using hardware key, which needs to be set up during boot to make sure that you can access your files. What this means is that, what this implied to me is that I'd messed up somewhere and that the key storage or something else was not being enabled properly or had been broken in some manner by my bootstrapping. So, analyzing the logs prior to boot found that there were multiple hardware initializations I'd missed or ignored because I was being quite lazy with this project. And this was due to the fact that they'd already been initialized by fastboot that required them for other purposes. This included things like reading data and setting other things up. But essentially, I was running the same functions twice before setting up the TE, etc. By looking at the logs, I could see the error messages. For instance, key storage in it failed and tgris register handler minus one, meaning that I'd have to do something to bypass this. So, both of these particular functions were enabled by a very, very large and complex function that would take a long time to modify or bring back from scratch. However, I did end up doing that by fully re-implementing it by checking for every if statement throughout the function for different self-hardware initializations and ignoring the code paths that I didn't think it would hit. However, with these errors removed, the phone could then complete booting to Android. So, I'm going to do another demo now, hopefully. So, here's the phone in fastboot mode and you'll see it very quickly go into the boot screen before switching back. So, that screen you just saw was the one that happens when you just hold the power button on and turn on the phone. But as part of the boot process, it required it. It then shows the secured by knock screen, which I'm not quite sure is true anymore at this point in the process. You'll see a flicker occasionally in the screen where the kernel is rewriting that secured by knock screen and then you'll see that disappear. Now, at this point, I was very excited because this was meaning that we'd bypassed all of the hardware issues, all the other issues I'd had in this process and we were now getting to the point where I was executing my custom modified kernel, which I was peeking and poking into through this process. So, in a second, we'll see the... the home screen and we'll know that my modified kernel was executing, which I was very happy with. Perfect. So, there's a lot of things that can be done with kernel code execution. You can disable some security features and things like that, but you have to be very careful because Samsung do put a lot of effort into making sure that there are checks in place that don't... that if you... do too many scary things, Knox will blow a fuse and permanently the device will say it can't be secured in the same manner because someone's been messing with it. But, very easily, I could modify the kernel... proc version just to show what happens in the strings. Now, I did modify this further to remove things like SELinux checks, regardless of whether it had SELinux in place, but I thought just a demonstrative picture of the version being modified was a good start for this. So, some final notes on this case study. Because the exploit can now be triggered by producing an exception, it would be much easier for me to re-implement it in the download mode, which is much more common on Samsung devices, which would mean that the exploit would be much more far-reaching if I implemented it on a more expensive device. And while code execution was possible, as I just said, there was still a risk of triggering Knox. However, I didn't manage to do that during my analysis of this device. So, in conclusion of the two case studies we've discussed today, the initial vulnerability was disclosed to... Sorry, we're doing disclosures first. I'm getting my slides mixed up. The initial vulnerability was disclosed to Samsung in December 2022, and they provided constant updates on progress and patched the finding within three months across all their devices, which was extremely impressive, considering the complexity of debugging this kind of thing. So, the target device that I had after recording my demos for DEF CON was updated, and I found it to no longer be vulnerable to the discrete probe write vulnerability, meaning code execution in this manner was no longer possible. I'll be releasing the tools for this on my GitHub, but you'll be able to find the link to my Twitter, where I'll announce this, in the slides, which you'll find on the DEF CON media server. So, now conclusion. So, most devices, regardless of how much effort people put into protecting them, still have exploitable vulnerabilities that can be exploited simply, despite there is resources. And even with basic vulnerabilities, the effort required sometimes to go from a proof of concept to a full exploit is really rewarding. For instance, you saw that there was two very basic vulnerabilities in both of those case studies. Which then took a certain amount of effort to actually make into a complete attack chain. And, last of all, even on targets which had a huge amount of research put on them, there'll still be a factor no one else has tried. So, shoot, you should try it first. Thank you very much. I think we have time for questions, and there's a microphone at the back of the room. I'm also happy for people to just shout at me, or I'll be outside in the hallway after this talk. So, whatever works for everyone. Thanks.