We got a talk here on weaponizing hypervisors by Oli and Dan. Um and we have a little tradition here at DEF CON for those that are new to speaking at DEF CON and do you, does anybody know what that uh what that is? So this is called shoot the noob um and uh you know those of you who can cheer them on as we uh do our shot here for the first time speakers. Hey guys, thank you for coming. Uh really excited to be here. Uh it's our first time as you saw. Um I am Ali Islam. I am the co-founder and CEO of Neumann. I am the founder and CEO of Neumann. Uh I've been in the cyber security industry from last uh 13 plus years and for a long time I I was working for a company called FireEye. It's another cyber security company. So um that's yeah. Dan do you wanna? Hey guys uh my name is Dan Regalado. Um I'm so excited to be here because you know it's the first time in DEF CON so so glad and and blessed. Y quiero agradecer a mi esposa, a mis hermanos, a los amigos, a esa banda mexicana, a esa banda mexicana que esta aqui seƱores. DEF CON speaks Spanish. Cool. Okay let's uh let's get started. So here's a quick uh overview of like uh how we organize our talk. So we're gonna introduce some some of the basic concepts. Uh these concepts are really important uh and kind of a foundation upon which we build our uh later detection cases and and you know a lot of the other policies. Uh apart from that uh then we're gonna explain the embedded, whole embedded environment, the journey you know setting up the board and uh the environment that we play in. And then we're gonna talk about the very important uh VMI on ARM. Uh I'll explain shortly what VMI is. And uh finally we'll discuss about uh different attacks uh use cases and some of the recommendations. Uh okay. So uh let's get started. So let's get started. So let's get started. So uh why is hypervisor so important and relevant? Uh as you can see uh all of the major players automotive great Linux, Renaissance, uh Denso, and Alibaba NXP, uh Peron Robotics, uh you I mean there there are many uh Greenhill, Intel, they are all have now the hypervisor in their architecture. And uh the traditional use case for hypervisor is basically the user interface. So uh the efficient utilization of the resources. And uh probably the isolation use case. Uh however um not many people have explored hypervisor uh for security in terms of uh you know how you can use hypervisor to build a really good security system. Uh isolation is there but not the VMI uh that we're gonna talk about. Okay. So um the beauty of hypervisor is that it exposes uh an engineer's interface which is called uh you know the introspection interface it's also called virtual machine introspection. What it does uh or it allows you to do is um you can monitor the whole system from the outside. Uh that's really powerful and uh we haven't seen many people using it especially on the ARM um so you know we were very very excited to start on it and it was a long very hard journey because uh there's not much out there there are like few projects or papers out there um so traditionally the anti-virus we all know that it has a lot of issues it sucks um but mainly uh you know when the any advanced malware comes into the system uh the first thing uh it does is uh basically check if there is an agent inside or if some somehow it's being monitored and um uh if you're sitting outside of the printing system you solve that very important problem automatically. So you so basically you have that sophisticated invisibility. Uh apart from that uh not having anything inside the operating system also helps with uh you know uh the different certifications because you're not messing up with the device functionality imagine you know you're securing a car infotainment and then you know certainly you know there's a bug in your software which kind of messes up everything right so you don't want that. Ok so let's get started on the uh on the VMI. So what is what is VMI or what what kind of uh interface hypervisor expose? Basically what you have is raw memory and uh you take the raw memory and you use some of the OS specific knowledge to actually make sense out of it. For example you you should really know like where kernel is storing what and um and then uh you know you kind of like build your logic around it to really make sense out of it. For example if you if you uh take the uh the uh the uh the uh the uh the uh the raw memory and you know where the uh Linux tasklist is stored in the memory you can go to those offsets and then you can start decoding and you know finally as you can see here uh you can uh decode this task from the uh raw memory. Uh to give you an example uh for example if you have to read a kernel simple value from the uh raw memory you know it looks like a simple thing if you are inside the operating system. However, from a VMI uh it's a very complex uh process. So what will happen is um first of all uh you know once you say hey you know I re- I wanna read the va- value of this virtual address. First of all VMI uh by the way we are using uh libvmi uh we highly recommend uh it's an open source project. It kind of provides the basic functionality uh that you need and on top of that we build our own functionality. Some of the basic functionality might be like the you know uh I'll explain you shortly like once this is done for example the caching and and some of those uh capabilities. So uh we really recommend using libvmi. So what will happen uh let's say if you have to read the value uh you'll get the virtual address libvmi will first uh go and check with the system map uh to see uh you know where the virtual address is. And then um uh take that and then uh map it to the page directory. And uh the page directory will uh be added to the some of the bytes from the virtual address to map to the page table. And finally to the actual physical location in the memory. And then it will come back and give that value back to the VMI application. So that's the that's the general flow of how uh you know you can uh get the value value out. Uh also uh here you can see that once you go through this process you're not gonna do that again for this particular uh virtual address. So that's where again libvmi comes in. It has a very efficient caching mechanism. You can do on your own also but you know in in case you want to avoid some of that work you can uh just simply use the libvmi. Okay another very important uh concept that is critical to uh you know what what we're gonna show you today is single stepping. Uh because uh you know if you're gonna show you eventually how you can uh get the system calls out uh by staying outside of the operating system through VMI and from the raw memory. So I'm sure you have uh all used uh debuggers and single stepping in your own use cases including reversing. However uh there there there there are other uh single stepping and break point mechanism that I wanna quickly touch you on. The hardware break points is basically uh uh uh uh uh uh uh uh uh uh uh uh uh uh are mainly used for uh code that sits in the room. Uh so basically uh when the code is not in the RAM you cannot overwrite the break point instruction. So what you do is uh you have these uh special registers provided by ARM and Intel. For example on Intel it's D0 to D3 um and you stores those uh locations memory location values in those registers. And then uh when program counter comes to that particular memory location or that instruction it just halts the execution and then you can analyze the whole system. Um another is the software break points uh you know is the most common one. CPU assisted that we use in debuggers uh for example you will set the TRAF flag in the E-flags register and then you'll uh uh let the CPU do the work uh once the break point hits the CPU automatically do the single stepping. But what really is single stepping uh you know when we say single stepping. Uh when we say single stepping we're talking about a single step. So what happens in the back end? Uh so in the back end what happens is there is a special instruction uh for example called INT1. Um when the break point hits you know you you do the whole analysis. However in the back end that instruction uh the CPU makes sure that it also executes the original instruction and then move on and then move on. So that's very important. And now the third one is the software break points with no CPU assistance. So we're going to use that uh in our implementation and there are reasons for that. Uh there are reasons for that uh that I will explain you once we are done with the basic concepts. But just keep that the concept the single stepping concept in your mind. Uh apart from that uh in our implementation as I said right you're playing with the live raw memory. So you really need to know how the kernel internals uh and how the kernel is you know organizing the memory and how everything is uh working inside. So you have you need to have that uh basic knowledge. So uh we all know that uh from quite some time we now have the paging the virtual addressing uh since 2.8.6 where the real real addressing mode ended. Um and then this is a typical uh two level uh paging we also call it SLAT, second level address translation or you know the uh and and it is implemented using the extending page table and the virtualization extens- uh extensions that the newer architectures provide nowadays. Uh so to quickly uh go back a little bit to the uh the follow the flow uh like I was saying for example if you are going to read a value this is how it looks like. So basically you take the first 10 bytes uh add it to the CR3. CR3 is a special register which stores the base of the page directory. And you add that uh 10 bytes to the CR3 and then uh it takes you to the base of the page table entry. And where uh then you're going to pick the next 10 bytes and then you add them to get to the right page table and find a value. So basically you add that 12 uh 12 bytes which are the offset into a specific memory page uh from which then you fetch the value. Okay this is a uh this is uh another view of just what- I just uh explained uh so two levels of translation. First from uh virtual machine to the VM physical uh w- VM virtual to VM physical address. And then from VM physical to machine physical. So basically you have this hardware uh VM virtual to VM physical address and this is the on uh running right on top of the, by the way we're talking about the bare metal, the type 1 hypervisor right? So so you have this uh hardware, the hypervisor sitting right on top of it and then you know there are there are like different domains or the VMs. Um so the second level of translation is uh handled by uh a table called extended page tables and there's a pointer E-P-T. Uh for example Zen hypervisor stores that uh per VM and it is used to uh do the translation. Uh E-P-T there's something very interesting about E-P-T. So what E-P-T as you guys can see what E-P-T is doing is it is eventually giving you the value from the memory right? It it points to the eventual physical location where the where the value is. And uh the newer uh virtualization extensions um are uh are uh are uh are uh are uh are uh are uh are uh are uh for example Intel and ARM uh they have um a way where you can store multiple E-P-T uh pointers uh per VM. Now that is very powerful uh because, one you can uh for uh each page table there are permissions right? So you can assign different permissions to it and uh that way you know for example if you assign permission execute to one page and then read write to another page you know you can play with those permissions uh and I'm gonna show you uh later in the in our talk uh some of the use cases uh but for now I think it's very uh critical to you know what we're gonna do uh or what we have implemented in our implementation. The second uh uh interesting fact about EPT is like you can as I said you can store more EPT pointers apart from uh partition what you can do is you can actually point a EPT to a different memory location. Now what that means is basically for example if you are uh you have to translate one virtual address right? Uh you can play with that last level of translation and then you know at one time you are uh giving one value at the other time you are giving another value. So basically you are using the same code but you are using the same code but you are using the same code you are creating two different behaviors uh which is very powerful um and there are many use cases for it and uh you can see the code snippet in the Xen where it stores the and the permissions also. Uh yeah that's the one I was talking about like for example uh the second EPT is actually pointing to uh another uh memory location and uh I'll I'll also talk to some of the implementation details um you know it's it looks it looks easy but it's not that easy. So for example you have to create uh all of the pages in the memory yourself uh well Xen uh Xen hypervisor for example have do have APIs so uh but they are not very well documented so you have to play with them and you create for example increase reservation is one that you can use to create pages. So once you create the pages you have to maintain all the mappings but uh you know Xen provides the uh functionality to switch between different pointers. And uh uh I think another very uh important aspect of this is like um you know uh this switching between different EPTs or you can call them the memory views because essentially what you are doing is you are creating different views of of the memory so you can present one view to one user and other view to other user and you know by user a user can be a malware also. Uh the the the best part is that uh the VM exit uh VM exit is a very uh expensive operation. It's a very expensive operation. Uh what what why VM exit means is like when uh you know you're running your domain on top of hypervisor and suddenly the control has to be transferred to the hypervisor. What what that means is hypervisor has to store all of the virtual CPUs inside that domain the context of all those virtual CPUs and then get out and get take the give the control to the hypervisor. But uh switching between these EPTs there is no VM exit. So it's very fast and I I will explain later like why performance is very critical to uh anything you're doing especially building a detection system using VMI. So okay guys so uh once we understand the basics uh we started playing with an environment right? We need to have a board to play with this whole uh implementation. In in our case we didn't have a specific board so we went to LinkedIn we used Google uh Xilinx. You know Xilinx? You know Xilinx? You know Xilinx? You know Xilinx? You know Xilinx? FPGA creators and turns out that these guys has a pretty cool uh board uh which is uh NPSock CCU 102. The problem was that that board is $2,500 just a starter kit. So we talk to those guys we tell them hey you know what we have this project in mind and kudos to Xilinx they just ship us ship ship the board to our house and then uh we started playing with with the whole environment. So this is the board it's just a pretty uh standard uh uh uh uh uh uh uh uh uh uh uh uh uh uh uh an input and output so we have an SD card to root the rootFS we have Ethernet UART is JTAG and and we have uh QuadCore A53's that are the ARM CPU's dual core R5F so this is the board that is very expensive but don't worry the uh WHAT WIRAP presented this is can be used in the any other board. So the first thing that we were learning guys because in well I I am a like the reverser you know exploits related person, so um I was like enter and uh and where it's going so I am a like a reverser you know exploit related anyway guy this kind of board I never played with it. It was very challenging because we are running same hypervisor on it and there is no implementation on this board with the VMI introspection on it. So it was kind of hard for us because there is no support. So we learned that there is a peta Linux project which basically helps you to uh uh deploy the whole uh uh information into the board so that you can boot it up. It's pretty cool. The only problem is that um it works with the specific images. So we have our own same hypervisor custom uh deployment. So it was a problem for us. That's the first thing. Second thing is peta Linux is for Xilinx right? What if tomorrow we want to deploy the same environment in Renesas, NXP, others. So we don't want to just tie to Xilinx related stuff. So then we we went to Jocto. You know many of you guys know Jocto very well. Well in my case was like uh I don't have an idea. It turns out pretty cool. Uh the only problem was that the root fs at the end was busy box related. That was a pain in the ass for us because uh once we have it everything up and running we really need python libraries to run our machine learning stuff. And it was a pain to just compile a single library. Like tensor flow for example machine learning. So it was pretty cool pretty easy to run but at the end of the day a busy box root fs root fs it was a pain for us. So we end up choosing the bootstrap the bootstrap allows you to have a root fs in this case ARM 64 Debian based flavor. So you have apt-get you can download all the libraries. So it was the way for us to go. Very recommended instead of the the previous one. Now in the dev environment guys so you don't want to push everything on the board right? Because the board is like the production environment. So you really want to have a test environment. So in our case uh we we pick a ch s ch root which is a wrapper for ch root. It's pretty cool because we have our Ubuntu Intel x64 environment as you can see in the picture in the in the bottom. So with this uh intel based environment via ch root you can you know uh using chemo you can ch root into the environment. You can you do your testing, install libraries, connect to internet. Everything like you were in the board but once you test everything then you can jump into the board. Pretty convenient for us. Uh now let's boot the board right? So what do we need to boot the board? So Xilinx has a specific uh debugger which is called Xilinx system debug client. What it basically does it reads a TCL file. That TCL file just you guys to have an idea what basically it's doing is gonna boot four different files. The PNUFW which is just to set up the pro- the clock and the platform management on the board. Then the the first uh stage bootloader which is gonna initialize U-boot. And then U-boot which is gonna allow us to boot the hypervisor in this case same hypervisor. Then the Linux kernel. And then the uh the uh the uh the uh the and finally the rootfs. Uh and the VL31 which is ARM trusted firmware. We didn't play with these components uh we just used them with the versions of Xilinx. Important to mention that if you combine versions uh it will never boot the board. So we have a lot of pain uh trying to play with different versions and it was not booting. So once you reach uh this initial stage of JTAG you get into the U-boot prompt and now let's boot the board right? So the first thing is you know the data device 3 blob. Uh that's where all the configuration from the board is is located. So the first thing is the root uh location right? Where is your rootfs uh that you wanna boot on? In our case it's an SD card partition as you can see there. Then the second thing is uh we have our same hypervisor we just convert it into U-boot format with that command line. And then you start booting up the system. You know this is the typical U-boot uh commands. So the first thing is U-boot uh uh uh uh uh uh uh uh uh uh uh uh uh uh uh uh uh uh the same DTV which is the device 3 blob. In a specific uh location. Then you pull the uh the Linux Cardinal. That Linux Cardinal you see the 80,000 address. That uh must be exactly the same address that you have in the DTV. Otherwise when it is booting up it doesn't it's not gonna find the Linux Cardinal address and therefore it's not it's not going to boot. And then you load the same hypervisor and finally you run the boot m, which is basically telling you okay so boot the board uh in the address you know 1 40. It has an IP address so that you uh uh you uh 100,000 which is uh the same hypervisor then the hyphen in the middle is telling that you need to grab the root fs direct uh path from the DTV and finally you have a uh the same DTV. With this uh we can boot it to the world. This take this same uh specific steps guys for us uh it took us many days and months because it was a lot of issues booting the same hypervisor. Uh another important point here guys is that those addresses that you see they're loading if you don't have enough space between them they are gonna overlap and then your board is gonna crash. So suddenly we were just you know booting up it was crashing and turns out that uh you need to have enough space for every single memory address but there is no validation on it. So you need to make sure that whatever the same hypervisor is loaded in memory the linux kernel that has enough space so that you don't overlap uh and you don't you know you you you don't get a kernel panic or or same hypervisor problem. So let's get the damn syscalls out huh. Uh basically um I don't know I mean it's it's it was uh it was kind of uh almost became a dream for us to see this ARM syscalls on the screen because you know we've been going back and forth we tried different things we always got got stuck because you know as I said it's it's it's it's it's it's it's it's it's it's it's it's it's it's not very well documented and you know uh there are a few research papers out there so we were like just trying different things playing with the memory and finally you know we figured out um uh or we did our own implementation. So as you guys remember I was I was mentioning about what single stepping and you know this why single stepping is very important and why you know we we've been we're gonna use the uh known CPU assisted single stepping. Uh the reason is like uh since we were using the Zen hypervisor and Zen hypervisor does not support single stepping on ARM. So we have to figure out our own way of doing what normally a CPU does. And uh we found a a very interesting paper online uh we talked to that guy also Sergey from Germany uh so and then we reviewed some other techniques online and we finally uh decided to use this technique. It's it's a very fascinate a fascinating one uh so remember EPT helps you create uh a single stepping you create different views of the memory right? And so first the first step is uh basically you create two views of the memory. By views I mean like um you just take the whole memory take all the pages you create the copy of those pages and then you know you have these two copies in your memory uh for those pages. And then uh since Zen hypervisor provided this support to have multiple EPTs so you point one EPT you know let's just call one your default view and then uh the other the single stepping view. So you have two EPTs now uh one is the default view, default view is the one where you know you'll you you you're gonna run by default when the system starts that is the view where you're gonna the control will be and the execution will happen and then you have another view in the memory waiting uh if you wanna switch to that one. So we have these two views and uh I'm talking uh remember I'm now I'm talking in context of the the sys calls so the goal is to uh start monitoring the memory sys calls uh or the operating system system calls on an ARM platform right? So so think of it like okay you wanna monitor a particular system call it the code is in in the memory somewhere so you find the location of that mem uh uh that that EPI uh in the memory. So you for the uh at the first instruction you put uh one breakpoint and on ARM is uh oh sorry. So you put uh one breakpoint and so on ARM uh the breakpoint is this uh D4003 it's also called SMC it's a special instruction on Intel it's INT3 so uh you can use the same for Intel also but you don't have to use the this one for Intel uh just to mention that because uh Zen actually supports uh single stepping on Intel so you can just use that one. Um so on the the first instruction uh you put one breakpoint in the data of the fault view and then uh on the second instruction you put another breakpoint but in the single stepping view. Now what will happen uh in the the control is in the default view and uh you know you just uh once the first breakpoint hits uh what you do is you do your analysis you wanna get the sys call you know you note down the parameters what process to call, let sys call, whatever analysis you wanna do, right? And then you know you switch the the view. You switch the view and the control will go to the instruction one in the second view. The instruction one will get executed and then the second breakpoint will hit. When the second breakpoint hits again you get the control, you switch back to the default view and then the second instruction gets executed. So basically that's how you single step uh on ARM if you're using the Xen hypervisor and not many hypervisors support ARM so Xen is probably your best choice on or unless you want to build your own hypervisor from scratch that is an option too. So uh this technique is is very fascinating and and you know as I was saying this is one of the applications of the views that the underlying architecture uh provides through what the virtualization extensions. So that's how we we single step uh on ARM in our implementation. And so let's take a look overall how do you now um as a detection on ARM uh how do you know or as a monitoring system using VMI how do you monitor from the outside right? So using all the concept that we have uh so far shared right? So what you will do is um uh first of all you will um put a hook on any every function or every API uh in the memory that you wanna really analyze or for example you might wanna always uh analyze sleep. The malware use sleep a lot. Um so the first step is to uh put that break point go to that memory location and put that instruction uh and in combination you have to register an event. Now a good hypervisor always provides uh event mechanism right? So you you wanna you wanna monitor something it provides you an event mechanism and Xen does the same. So you register your event and then you also register your callback. So that's the second most important because with the callback function that you're gonna register what it does is you're telling the hypervisor hey anytime my break point is going to hit you you know give me the control and execute this function. So in this function you're gonna do everything for example you're gonna extract once the break point hits you're gonna extract the parameter values of the function you know the function name process name or whatever you wanna do you do in this function. The single stepping functionality that I showed you uh in the previous slide you will also do in this function. So that's the second uh most important step. Uh the third step is obviously you know you need to single step. Remember so if you don't single step what will happen? Uh the break point will hit you don't single step the control will stay there it will continue to execute the same instruction the system will get into a very unstable state and you know imagine you're protecting a car infotainment and then you will you will crash the system. So it's very important to make sure you know you properly single step. And finally you know once you're done monitoring uh make sure you're monitoring uh make sure you remove all your hooks from the memory and uh you know you you know you do a very clean exit. So that's how you basically uh do uh the syscall monitoring through VMI and uh on ARM especially it was challenging because uh you know as I mentioned there was no single stepping and there was no documentation so it took us some time but you know finally we're very happy that you know we achieved this. So let me let me now show you how it looks like uh our moment of uh happiness when you first saw this so I hope it okay so how do I show uh click escape in the okay escape escape the presentation yeah yeah so this is our Xilinx board uh we have our introspection framework we call it Neumann introspection framework and uh uh yeah these are these are how the syscall looks like you know the process name and everything uh now see you know we're typing and then you see all the syscalls being log uh logged on the upper right and then now I type top and then you can see the process name top being tracked this is happening everything happening from the raw memory outside of the operating system so that's pretty cool and now finally you know we do a we do a sleep and then uh you're gonna see the sleep being uh shown and not only shown because we have other components uh it's it's also being monitored as I highlighted here so uh not only we get these syscalls out we also uh send it to our machine learning model to to monitor it so that was our uh it took us quite some time to achieve that one and yeah that was the Okay guys so let's get to the phone part because uh uh after this whole efforts as you can see now we know the basics we know how to arm uh use uh VMI to introspect into a machine learning uh sorry into the machine and now we we are able to have the board everything right now let's see what we can do uh from a tax perspective and detection with these components uh in in the board right so the first approach is a typical typical malware coming into a car, into a medical device right? How can we tackle that problem from BMI? So if you have been working on antivirus companies or sandbox related companies is is the typical way to do it is very common but keep in mind here guys we are out of the box we don't have an agent inside and that's a totally different different beast. So let's see the first example. For example we have a malware running so what we do in this specific scenario is we we're gonna use machine learning in order to detect attacks. So what we do is we get let's say the infotainment from the car and we profile it. Get all the processes running we feed it into into our uh autoencoder which is neural network uh based uh approach and and what it's gonna do is it's gonna learn how a healthy system how a healthy system looks like all the processes all the different syscalls being executed so once it learns that uh when we when it is running like this it's gonna be able to run it. And then it's gonna be able to run the process in the infotainment. It's gonna grab that profile which is in the left side the actual profile. That is gonna be feed into the autoencoder and then he the autoencoder is gonna create a new profile based on his learning experience. Once it generated if the similarity between the reconstructed profile and the and the actual profile that was running in the in the in the device is is has really low error which means is very similar is when we know we are dealing with a benign process. But what what happened was that the uh the uh the uh the uh the uh the request didn't work so we decided to over deal with the other one and then we have a maliceous process. So the same process happens we have this maliceous process we profile it and we create the actual profile, feed it into the autoencoder, the autoencoder is gonna create his own reconstruction of the profile and is gonna realize that the sequence and the syscalls been used is totally off is the error level is really really high and that way is easy for us with via machine learning to detect that there is an anomaly inside the device. That's a pretty simple step one. Second approach guys, let's say that we have a an exploit going on right? In the left side you can see an application running and the list of all the syscalls going on there. So you are gonna see always the way it executes. But what happen if suddenly that application is compromised? So if you see in the right side uh uh at the end in the in the red uh uh bot in the red square uh you will see that comparing the two applications the benign one with the bin exploited is gonna exit the program but when you look at the second one is gonna call execv. Why execv? Obviously because it's gaining a shell. So in this case we don't need we don't really need machine learning to realize that the flow has been affected right? We call it sequence based, people call it control flow same sh sh it. So at the end of the day uh you just need to measure the sequence based and realize if there is any alteration. And in this case one exit properly and the second one called execv so it is easy to detect. Uh now let's talk about the delay. Uh you if you guys are familiar with antivirus and uh and sandboxes right? Uh one of the techniques of of of the APTs for example is to delay execution so that it executes and then it's gonna wait for execution so that an antivirus needs to take a decision in milliseconds to know if it is malicious or not right? It doesn't it cannot be scanning the process all the time. So by delaying the execution those engines are gonna give up and they are gonna stop monitoring it and that's a way to bypass it. So that scenario is a pain always in the in in in the enterprise with antivirus. In our case it's the same issue but how we tackle it uh comparing with them. So in our case for example we have this pretty simple delay in ARM uh and it's just a simple loop that is gonna you know delay execution for 8 seconds, 8 minutes and then after 8 seconds it's gonna delay execution for 8 seconds, 8 minutes and then after that it's gonna trigger the shell. If you remember the previous slide uh in that one we have all the execution at at the end we have the execv to be called. In this case what happened is that the execv is is never gonna be called and therefore we're not gonna see any anomaly. So that's a pretty pretty challenging ch-challenge that people have. So what the people does for example in the sandboxes they hook all these sleep or nano sleep or those syscalls and once they see this syscall triggering let's say that in there's an syscall triggering let's say that they sleep for 5 minutes they will change at run time the 5 minutes to 0 so that they force the malware to execute. Right? That's one technique but that is a cat and mouse game because today it's a sleep, tomorrow it's nano sleep and there's gonna be multiple techniques all the time so you need to keep updating these techniques so that anytime there's a new way to bypass it you need to update it. Uh in this case for example we don't even use an sleep uh we don't use a syscall so in this case it's just a code that's gonna delay execution so you don't you cannot rely on hooking syscalls. So uh this is a challenge for everyone. In our case uh we tackle it in a different way. Uh one way is you don't wanna uh monitor these executions all the time right? We were talking about we are in a car we don't wanna delay execution can you imagine the GPS just slowing down or any application in the car so we need to decide quickly but if this application is running and it's sleeping we cannot wait forever. So we have a way to hack the process so that when the process start running suddenly goes to sleep we stop executing and then we monitor it in a way that uh we can uh uh know when the the malware wakes up. Uh there is a way to do it via profile based approach that Ali is gonna explain in a second but from BMI perspective uh same challenge but we don't wanna follow the syscall implementation in order to understand when there is a delay. In our case we tag it the process we just you are sleeping we sleep we don't we don't know when the process will start. So we have to do a lot of work to do any performance issue but as soon as you wake up we wake up. So that's a profile based uh policy that we're gonna explain in a second. Now Ali was explaining us that his technique right? Uh sorry the technique that he was explaining to hook into the memory so he was telling us that you know you need to put a D4003 as an MC hook right? So that's pretty cool uh but it's pretty easy to bypass so uh I mean uh if I have a kernel module I can just go to the syscall the first four bytes and then get the the the the the SMC there and for me as a malware I'm gonna be able to detect right away that I'm being monitored right? Uh and that moment I'm gonna say you know what man I have this SMC hook I'm being monitored so I'm not gonna execute anything I wanna wipe the system or even worse I can overwrite if if the memory uh the page allow me I can overwrite that SMC hook to the to put it in the in the original state and then I can just totally bypass the hooks in the system and then this hook is going to be able to do the whole thing. So the whole technique being shown by Ali is totally screwed because it's pretty easy to identify so I don't know how come Ali come up with this technique but anyways. Okay so let me think how we can uh answer Dan. So you remember the views right? And I keep saying the views are very powerful so here's another use case and we'll we'll see how we can uh answer Dan's question. Um in this case what we're doing is we're uh we're uh we're doing is again we are creating uh you know two views actually you know you don't need to create um uh the the whole the whole memory pages what what we're essentially doing is we are um assigning different permissions to different uh EPT's so we have two EPT's uh one is going to be the execute only the other is going to be the read write only now what will happen? So let's say by default we are in the execute only view right? And the malware comes and tries to do a read the hooks that we have placed in the memory um since the page is execute only there will be an exception the control will be transferred to me and I will see that the malware is trying to be smart so what I will do is I will switch the view uh which is the clean view by the way there is no hooks hook hook in uh in this view so that's the that's the trick so I have this view where there's no hook I'll I'll switch the view I'll let the malware read the memory pages in this view and then it's uh read request will be satisfied the malware will get know you know that there are any hooks or it's being monitored so that's how and then once the the that read request is done uh we'll switch back to the execute view so you saw the previous application where you know we created these views um to do the single stepping now you saw another one where you know we use the same capability that you know upacle built into the app um from them. So the intel and the arm provides to uh bypass uh or trying you know malware detecting us uh we bypass that. Okay guys so let's see another uh other examples. Um in this case we have an anti-VMM you know hypervisors are known to be virtual machine monitors is another name. So what we have here is uh I'm again I'm a malware right? So I wanna know if I'm being monitored if I'm in I'm I'm being monitored so I'm gonna stop executing. So in this case uh since we're switching views as we explained that has a cost has a time in terms of performance. So what a malware can do uh and we do we just do a proof of concept here is we measure as a baseline without without having the page views switching we just measure the time. In this case it's 38 nanoseconds and then once we do that we now measure the time that it takes to write into the memory. And you will see in that red line you can see that the time that it takes to write uh color that the time is highly significant so that you will realize that uh the time to write into memory is totally different to the baseline and this is another technique that we can use to detect that we are being monitored. Just by measuring the time that it takes to write into memory we can realize it's taking too much time at the baseline and and and this is uh another way to to find a ways to bypass uh to to understand that we are being monitored. Now uh let's talk about process killing guys. So when we when we kill a process right uh we all know how it works right uh uh if you wanna implement it on on code you will just need to call the syscall kill and you pass the PID and the way you wanna kill it right dash nine if you wanna force it. So that's the way it works normally in a user mode scenario and we all know. But what happened here is uh what happened if we wanna implement a simple killing process in BMI. Keep in mind that we don't have any agent inside so people or people don't have any agent inside. So we don't have any agent inside. So people or other people are other companies what uh what they do is they just drop an agent inside they call kill in the user mode and then you just kill the process. But in our case guys we don't have a an agent inside and and we don't wanna have an agent inside. We wanna keep being out of the box. So how a simple kill process can be done from BMI. So we have a way to do it here uh it doesn't need to be the perfect solution but the idea here is that you guys can see the challenge when you wanna just kill a simple process that is very easy to do but from the hypervisor. So we have a way to do it here. So what we do is let's say that we wanna kill the process ID 300. So what we do is in the kernel because this whole BMI guys is being executed in the kernel. We are not using user mode syscalls because it's too high too consuming it's a lot of performance issues so we are just hooking in the kernel. So when this 300 process is running what we are gonna do from BMI is we're we're gonna monitor all the syscalls. So when the syscalls come in from that process what we're gonna do is we're we're gonna mess with the stack. That's what we're gonna do from BMI is we're gonna get the uh information that you see in the green is the full stack dumped from uh from all from one syscall. So what we do is you know there is something that that is called a safe user state registers. So when you transfer from user mode to kernel mode those registers in user mode are stored in the kernel so that when the kernel resumes execution in user mode those registers are used again right? So what we do in kernel is that we get that stack content we get those safe registers which are not being used by the kernel and we just nullify them. What what's gonna happen guys is that when the syscalls come back into the user mode since those registers are totally nullified it's gonna cause an exception and it's gonna exit the process. As you can see it's totally a different way it's it's not a traditional one but to taking advantage of BMI we are able to mess up with the stack and then force the process to kill. Important to mention that it's not easy to do because uh in this example you see the yellow box uh if you mess with any kernel related information which is in the lower addresses you're gonna get a crash in the in the device. So you wanna make sure that you are really uh overriding only uh the user mode uh register information. So we learned that from experience and then we come up with this specific offset that is calculated dynamically so that we always overwrite only uh user mode registers. Uh and the way it works guys is that every time we get a we set to the to the device a kill PID 300 it's gonna grab all the syscalls every time we grab it it's gonna mess up with the stack. Sometimes in the first syscall it it it get the exception and kills it. Some sometimes in the second and the third one so sometimes it is it sometimes it needs to take like five or seven syscalls to be called in order to in order to be killed. But this simple example guys as I said uh is totally different beast as you can see. So it's it's totally different beast as you can see. It's not it's not easy to do it at at the VMI if you wanna be totally a-less. So let's see a quick example of of of uh how we kill it uh in in in the device. So here we have our our system so So what we're going to do guys is in the upper left we're going to run a simple malware like Mirai which is very very common one. In the upper right we have our inspector monitoring it. Here is the Mirai. We're going to execute it. As soon as we execute it Mirai deletes itself and spawn a busy box process pretending to be normal and it is in the 336 PID. So let's go back to the virtual machine that we're monitoring. We search for that process 336 and we can see that it is there running. Right? 336 is there. We click it on it and then we can see that the busy box is is showing up. Right? There is busy box. Now let's try to kill it from BMI. So we go to our front end. We go and try to find the 336 process. We find it there and then we click on kill button. That's gonna be from BMI sending a a a signal to kill it. So then we go back to the BMI and search for the Mirai which is gone already. You know it disappears as we said. And now let's search for the 336 and you can see that it's totally killed. Eh this eh it's totally eh eh clean. We don't crash the system and this way to do it which is not the best way eh eh it works for us ah ah and that way we are able to kill from BMI perspective. Okay. Okay so. So um just wanna quickly mention that you know once you get hold of BMI you understand it ah its pretty cool and you can do a lot of other things eh with it, eh its very powerful. So eh one of the things that we did additional in addition to detection is the policy. So not only eh you can do the detection with BMI but you can also implement policies. Again not putting anything inside the operating system and still maintain these policies. One of the example that I want to quickly share with you is eh a lot of ah infotainment or any IOT device, for example medical device, there are certain processes very limited which are responsible for going out to the internet. So what you can do is you can, you know the task list that I showed you, you can continuously monitor that from the outside and you know since socket is a special file, you can just simply see if there is another uh socket being opened. That might be slow because you're actively traversing uh alternately what you can do is you can hook a connect or a uh network API and then you know when events that API gets called you will see if this process is allowed to communicate outside or not. So here's you know just a quick uh view of uh how it uh it looks like in our system. Uh like Dan was mentioning uh remediation is another uh topic that we are tackling aspect. Once we detect something we need to kill, it's not easy to kill from outside, we always have that option to put an agent inside but we don't want to do that, we want to be totally out of the box. So you want to try, I mean the method that we showed you, is not one of the, I mean we we figured that out on our own but we we have another one, you know that's that's that we're exploring right now. So you can try different things, you can make the parameters null and try try some of those things. Quickly want to share some of the recommendations with you guys for an end to end system. Let's say you're working with some other hypervisor like in our case, you know XANA is just the start, we are already working with some you know another hypervisor uh and that's a custom one. So you really need to have good way of putting the breakpoints, FNs, you know you need to have good way of putting the have an efficient single stepping mechanism. Uh the event mechanism, now we didn't talk too much about event mechanisms because Zen provides a really good even mechanism but if you're working with some other hypervisor, you want to make sure you know you have a good even mechanism. Anything that you translate using those page, page, page tables or the page walk uh you know you want to make sure uh you cache those in an efficient hash tables. Uh multiple views is awesome as you can see I mean we have few other use cases which are patent pending we cannot to talk about it uh we combine the views uh in you know with other techniques uh to really really improve the performance and VMI in VMI monitoring system performance is the key and finally the permission management. Uh finally guys uh we are releasing some uh tools uh for you guys to play with um you can see the the drop box you can go and check them out so we have the ARM and Intel VMI monitoring tools that you know you can play with um uh we have all the files that we have used to you know uh boot up the Xilinx board and finally we have the uh one malware ARM 64 base malware that you can use to do an end to end scenario so do check that out and and uh you know play with it. Uh ok so finally the the takeaways uh in today's world of advanced malware we really need to make sure you know we make the hypervisor smart hypervisor is everywhere so you know you want to make sure you know you you make it smart and uh you know agentless is the way to go because we know that you know anytime you have an agent inside it's it's a it's a losing game. ARM syscall monitoring is obviously was a great achievement for us but it's just a start I mean we there's uh now there's a lot we can do so don't just stop at the you know syscall monitoring you know think of new use cases and you know especially switching between views is very powerful so you can also think of new use cases around that. And finally performance is the key we have a patent pending Neumann Adaptive uh uh you know we have a patent uh monitoring and then we we we use that um uh in our system we're gonna talk about it right now we need another talk for that. Ok finally I really want to thank um uh Saqib, Matt, Stefano, Waleed, I don't know if you guys are here uh but still uh these guys really helped us along uh uh with our journey and um it wouldn't have been possible what we have achieved without these guys so thank you guys, thank you. Captions by GetTranscribed.com