Next up we are going to have some fun with some low level root kits kind of stuff. Now, Alexandre Borges, I'm doing my best here, is all the way from Brazil and he is a first time speaker. So we want to give him a special recognition. So let's give him a round of applause. Have a wonderful time. Hello everybody. Good afternoon. My name is Alexandre Borges. Uh, I'm a malware and security researcher at BlackStorm Security. And let's talk about root kit. Uh, first of all, two things. Uh, English is not my native language. So if you don't understand something, please send me an email. And, uh, uh, I'll help you out. These professionals deserve a, my sincere thank you and a deep respect for their researchers of both the same thing. Let's start. Honestly, I was ex- expecting only ten or twelve people here. I just wanted to make This is a table of contents. I, I will talk about, uh, two topics, ring zero and advanced malware, uh, ring minus two. First, rootkits ring zero. Malicious drivers have been been using the same tricks every single day to infect systems. Uh, but, uh, no doubts. Call back methods or kernel call back functions is a good one because, uh, it's a kind of, uh, modern routes used by antivirus programs for monitoring and alerting the kernel models about, uh, a specific event occurrence. Uh, and, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, kernel call back methods are, uh, good trick to evade defenses. Kernel call back methods provide us, uh, notification when a process, a library, and a kernel memory is mapped into memory. When a file system become available. When a system is going to down. Before a system crash. When a, when a thread starts or ends or finish. When a process starts or finish. When some, uh, registry entries are modified or removed. For example, I have, uh, seen some malware using this specific, uh, call back method, cm registry call back, for checking if the, uh, if there are persistency entry are kept and just an analyst or software or a programmer remove it so the malware is able to adding back. It's a nice trick to keep the persistence. To find the number of callback methods is so easy using win the back, the first command there and running a couple of comments we have a very nice way to list the callback methods. For example, PS set creates process notify routine as a kind of list of callback routines to be called when a process is created or deleted. So in this case it's so easy to callback the process. It's so easy to find the number of installed callbacks, the first command at win the back and a very easy intuitive command at the middle to list all the callback methods that are installed. In the last few weeks I have seen several malware using this specific callback methods. PS set creates process notify routine as a kind of list of all the callback methods. PS set creates legal notify routine callback methods to register a malicious routine that is called during the thread termination. In this case, uh, the malware changed the key thread dot Lego data, uh, to provide a malicious address and the routine redirects the execution flow to the malicious code, is a very nice and different trick. Here we have a pretty useful example of an have the output from the last slide about the about the uh callback methods associated to create process. And here we have the structure of uh key thread in the legal data field that is changed by the malware. Windows offers different uh types of software. Windows offers drivers such as uh legacy drivers, future drivers and many future drivers. All of them are developed by using our WDM or WDF frameworks. Basically a drive is composed by one or more device objects and each object is associated to a driver object. So most ring zero malwares malwares uh install future drivers for modify aspects and behavior of the existing drivers, filtering result of operations, add new malicious uh features for example keyloggers. The trick is almost the same. Uh we have uh driver stack and the malware uh first creates uh unnamed device object and then we have a driver stack and then we have a driver stack. Uh by using this first function, add device. And secondly, the malware adds the unnamed device object on the top of the stack by using this function I o attach device. All communications in the drive stack is done by using IRP packets. IRP packets are used by the driver stack to let's say uh uh DB server loss Manufacturing server. Anyways by by using stop package, and each IRP package is processed by a dispatch routine that's retrieved from the major function table. Uh the IRP parameters retrieved from uh the I-ostech location by using this function I get current I-O-K stagnation. Additionally, it's possible to pass down the IRP parameters to the next layer keeping this карat because you get the table牠p on your by using IO skip current stack location or copy them by using IO copy current IRP stack location. Alternatively, IRP packets can be passed down to the layer drive by using this specific call, IO call driver. Here we have a very nice trick. Some hours try to pass the IRP packet to the lowest driver by passing the middle of drivers and so avoid it to be detected for by monitoring tools and hooking tools. So it's a very nice and smart trick to evade defenses. Here I show you uh a complete picture about it. Uh I'm going to show you at left we have the driver stack. At right we have the associated device objects to each driver. Pay attention that uh the IO call driver function is called to pass down the IRP packet to the next layer. At bottom we have complete routines. We have the driver stack, the driver stack, the driver stack that are called in the reverse order. So uh uh the complete routine is the function that do that that does the job. All of them are managed by the IO compete request function at right. Here we have the um IRP structure composed by a stack part and the idynamic part. The dynamic part is composed by a stack locations. So uh each uh IRP is created by calling the IO allocates IRP function. And as I mentioned it before, this function and the other three in your hand, are interesting functions to analyze when you to reverse a malware. At right by all of them are components, even for the software So uh you can see the IRP♥, which we bottom. We have the IO stack location structure composed by the major function. The major function we uh uh holds the pointers to dispatch routines. Uh parameters field and completation routines field. Parameter fields uh depends uh on the major and minor functions. So, in this slide we have uh their uh uh its structure uh of the parameters fields. Uh in the next slide we have a complete list of IRP types. So easy. Here we have uh complete relationship with between the uh IO stack location structure, device object structure, and driver object structure. It's a good slide to read tomorrow night. Here I show you uh a step by step investigation about a potential malicious driver named A. Borges. Uh with some comments in the back. And pay attention. This specific malware use some dispatch routines such as uh uh uh uh uh uh uh uh uh test, create, read, close, write, and device control. It's uh so usual to see things like that when you are analysing malicious drivers. Here uh more complete overview. Uh showing you uh the relationship between the reversed code, driver object, and dispatch routine. Let's chains. In this slide, I started an investigation about, uh, potential malicious filter drive by using some commands in the back. Naturally, uh, as close as the, uh, bottom of the device stack occurs the infection, the more effective it is. Or, uh, I mean, most, uh, most monitoring tools and hooking tools try to check the middle of the stack. So, if the infection happened at the bottom, you are skipping all these tools and evading the defenses. Some marers try to intercept requests. Such as read and write operations, uh, by manipulating the module function array. For example, uh, MG device control and IRP, uh, internal control, uh, callback, uh, uh, dispatch routines. Rootkits try to protect itself from being removed by modifying functions such as IRP, MG device control and hooking requests going to the disk. So, uh, these are other kinds of tricks. Uh, some marers try to hook the driver load routine for preventing their rootkit of being removed. Another trick. However, most malicious drivers or most malicious, uh, uh, marers try to avoid touching areas protected by patchguard. Uh, because PetGuard is so tough to circumvent it. Here, we have, uh, we have, uh, a list of protected areas by PetGuard. Uh, thanks to Alex Jonesco by this common. Most time, uh, mowers have been storing, uh, their payloads and configurations and encrypted hiding file systems. And, uh, additionally, they have, uh, created random device object names during the boot to associate, uh, to the, the special file system. Some mowers, composed by executable drivers, have been using APLC, advanced local procedure call, to perform the communication between the user code and the mowers. And, uh, we have, uh, a list of protected areas by PetGuard. Uh, another, uh, smart trick. Some mowers don't use, uh, any specific driver for injection, uh, but try to randomly, uh, pick up a driver by parsing this this last structure there. Key, loader, data, table entry. Certainly, uh, hooking the file system access is so easy. Here, I show you a complete list of, uh, APIs. It's so easy to do that. Few hours, uh, have been hooking this specific API, ZWQH, for intercept all open requests sent to devices. It's a very, uh, smart trick because AVs, antivirus, uh, use the same tricks. Some hours after infecting, uh, a system by dropping device, uh, by dropping kernel drivers, try to, uh, force a reboot, uh, by calling ZW raise hardware function. It's, uh, very special error, uh, trick. Other malwares, try to use, uh, the last routine here in red. Uh, your register shut down notification for restoring, uh, the malicious drivers in the next reboot. So, if you try to remove it, uh, they back. Fortunately, most malwares have been using, uh, X allocate pool with tag function to allocate memory pool, but it's so easy to find out because we have the volatility here. We can find it by using IDAPRO, as you already know, or execute a command and win the back. Finally, most malicious drivers, uh, have been using APC injection to inject some malicious code instead of using create in most threads. So, my recommendation is to pay attention, uh, at, uh, these three last functions in red. Now, I'm talking about advanced malwares. Basically, the rootkits in my network, uh, are, uh, uh, ring, uh, ring minus two. When we talk about, uh, ring minus two malwares, uh, the context is so different. Uh, most, most malwares, uh, actually in this level, uh, attack MBR, VBR, UEFI, for example. Some malwares alter the BBB bias parameter blockers. Uh, the block. To change the execution flow to another uh place for in this case this kind of malware alters uh this last field hiding sectors. To change it to uh another address and uh execute the malicious code instead of executing the IPL. Here we have a real case uh uh about uh mirrors uh such as Tdl4 or Petya uh which encrypts uh and infects the MBR. So in this case the trick is try to load uh good MBR and a bad one in the IDA pro and emulate then uh using box emulator. So I try to compare to make my my analysis easier. So uh if the field is safe I can make a render and the data is secure. MBR modifications and VBR modifications are effective ways to bypass KCS, kernel mode code sign policy. KCS is responsible for validating the driver signature. So uh there are same ways to bypass KCS. Disabled. Put windows in test mode but in this case security boot must be disabled. To disabled, change the kernel memory, it's so easy, or even trying to find a flaw in the firmware. In this case again, SQL boot must be disabled. Here, we have a real case about a Trojan Banker, uh, where the malware is put in Windows in test mode. In this case, the goal is to, uh, force in a near future to load, uh, unsigned malicious driver. Here, I show you, uh, more complete overview. Composed by BIOS, here we have the boot process. Composed by BIOS, MBR, VBR, boot manager, and look at the left down. This is the boot manager. This is the boot manager. Uh, there we have the win load easy. Many bootkits try to attack the before load the kernel in Elan protection. Uh, it's, uh, another smart, uh, trick to bypass defense. Malwares have been, uh, infecting boot manager. Boot manager is responsible to switch the process execution, uh, from real mode to protect mode. So, malwares have been using some interrupts, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh. To access the driver, to patch models, and load malicious drivers. Uh, at the bottom I show you some, uh, some task associated to win load easy. Uh, it, uh, enabled the protected mode. Check the model's integrity and load the Windows kernel. Load several DOLs and Elan protection. And finally, load drivers and system registered data. Therefore, integrity checking, uh, of in-window load, uh, is critical and, uh, if it is subverted, everything's fall because the integrity control don't, doesn't exist anymore. So, pay attention here. All modern protections are based on digital certificates and digital signatures. So, it's critical. Most advanced rootkits, as I mentioned, previously, store their payload and, um, configuration and, uh, encrypt hide and file system by using, uh, some special opcodes. As you know, SM mode is a kind of magical mode or god mode. Uh, that's a perfect place to hide a malware. Here, I show you, uh, uh, first approach composed by SPI flash, SMM, UEFI services, MBR, VBR, the OS loader and OS. Uh, pay attention here. Uh, malware can attack any block here, so you are not safe. All of you are safe. Uh, you can't here uh quick reminder about the UFI phases so easy. Here uh I show you uh more complete overview about the boot process composed uh by hardware and the UFI phases and things like that. Again, mowers can attack everywhere here but we have good protection such as uh boot guard, UFI secure boot, OS secure boot and and so on. Remember? The SPI flash is composed by descriptors, gigabit ethernet, managing genie, ACPI and BIOS. Now let's look at the boot process. So, for example, the boot guard controlled by managing genie is responsible uh for validating the boot process uh by flashing a public key uh into the Intel managing genie. Uh obviously, for a perfect working of the boot guard, the SPI flash region must be locked and the boot guard configuration must be uh set and protected against the SEM rootkits. Here, I show you a quick picture uh about the boot guard blocks. Basically, each block verify the next one. Uh it's kind of a certificate chain. Another uh very interesting process uh uh protection uh is the BIOS guard uh which runs the uh the uh within the SMM and protects the platform against the not authorized uh the SPI flash, BIOS update, boot infection and corruption. And basically uh BIOS guard only uh allows stress models to modify the SPI flash memory. Secure boot is responsible uh for protecting the entire path against boot uh kit infection, protects the key components during the boot uh kernel load, um key drivers and important uh system files. Uh and at the end secure boot prevent any uh uh loading of uh strange code without a valid digital signer. Two essential uh two essential items in the secure boot are the platform key. The platform key establish a relationship between the platform owner and platform firmer. And it is responsible, uh, for verifying the key exchange key. And at bottom, key exchange key establish a trust relationship between the platform firmer and OS. Actually, uh, the key exchange key verifies the authorized database which contains authorizing signing certificates and digital, uh, signatures and forbidden database which contains the forbidden certificates and digital signatures. Obviously, if the platform key is corrupt, everything falls because the security boot must be or can be disabled. Uh, unfortunately, some vendors, uh, store, uh, important, uh, security boot settings into F5 variables. However, if some, uh, root kit is one of the variables, security boot can be disabled. UEFI BIOS supports, uh, test formal. However, doesn't support signatures. And, remember, uh, what, uh, what I told you, uh, all the modern protections are based on, uh, digital, uh, sign, uh, and digital certificates. So in this case, if a rootkit uh is able to re-replace the typical uh PL loader by a terse executable, so uh secure boot can be disabled. Fortunately, new uh release of Windows 10 introduced a uh very interesting feature uh about uh SMM protections uh known as Windows SMM Secret Mitigation Table. Uh in Windows 10, the firmware executing SMM must be authorized and trusted by VBS. So it's uh is an additional protection for us. SMM protection flags uh in Windows uh can be con- uh configured for your use. Uh uh uh uh uh uh uh uh uh uh uh uh uh and uh here I show you some flags. Finally, I I'm showing here uh practical case, uh real case about a customer in Brazil. In this case, the system uh is not protected against BIOS writing. You see the second one uh BIOS read write permission. So it's terrible. So it's uh really terrible. In in the same system, BIOS write enable is set, it's terrible too because uh anymore uh can write a malicious code there. The BIOS lock enable is unset. It's terrible too because this is a kind of notification bit. The SMM BIOS write permission, it's protection is disabled, horrible again. At bottom right, the protection range register are disabled too. So in this case, we have complete exposed machine, complete exposed system. Here, I am using chipset to perform my analysis, my checking. Here, we have the flash configuration lockdown is enabled. That's okay. However, it doesn't matter because the settings protects the protection range in the image. So, in this case, we are going to use, is this registers which are disabled, so it doesn't matter. Here the biostop swap mode is disabled, that's okay because in this case it's impossible to redirect the resetting vector to a backup boot block, so it's impossible to execute a malicious code. Finally, the SMM range is enabled. It's a good one, it's a good news, so it's impossible to access the SMM run from a non-SMM mode. My conclusion are, most security professionals are not ready to analyze the code, they don't know how to analyze malicious drivers because the theory is huge and not easy, and I know that. Real customers, real worlds, are not aware about the wing-2 threats and they don't know how to update the firmware. Most customers don't know how to do that. And finally, remember, all modern protection systems are based on a general actions are based on the integrity. For example, digital certificates and signature. However, I leave a question here. What would happen if these algorithms were broken? For example, using quantum computation. This talk is dedicated to my wife and for you who reserved some time to be here. Thank you for attending my talk.