00:00:00.000-->00:00:06.340 >>Next up we’re going to have some fun with some low level rootkits kind of stuff. Um now 00:00:06.340-->00:00:11.578 Alexandre Borges? >>Yes >>Doing my best here. Um is uh in all the way from Brazil and he is a 00:00:11.578-->00:00:13.580 first time speaker so we want to give him a special recognition so let’s give him a round of 00:00:13.580-->00:00:15.582 applause. [applause from audience] Have a wonderful time. >>Hello everybody. Good 00:00:15.582-->00:00:17.584 afternoon. My name is Alexandre Borges. Uh I am a security researcher at Blackstorm 00:00:17.584-->00:00:19.586 Security and let’s talk about Rootkits. First about two things. English is not my native 00:00:19.586-->00:00:21.588 language so if you don’t understand something please signal to me. And these 00:00:21.588-->00:00:26.593 professionals deserve my sin-sincere thank you and deep respect for their researches 00:00:48.382-->00:00:53.387 about this same theme. Let’s start. Honestly I was expecting only 10 or 12 people here. 00:01:26.053-->00:01:35.362 [Speaker chuckles. Audience laughs] This is a table of contents. I I will talk about uh 00:01:35.362-->00:01:50.243 two topics Ring 0 and advanced malware uh ring minus 2. First Rootkits Ring 0. Malicious 00:01:50.243-->00:01:58.585 drivers have been using the same tricks every single day to affect systems uh but uh no 00:01:58.585-->00:02:07.461 doubts callback methods or kernel callback functions is a good one because eh it is a kind 00:02:07.461-->00:02:13.867 of uh modern rooks used by antivirus programs for monitoring an-and alerting the 00:02:13.867-->00:02:25.045 kernel modules about a specific event occurrence. Uh and uh kernel callback methods are good 00:02:25.045-->00:02:34.654 trick for evading defenses. Kernel callback methods provide uh notification when a process, 00:02:34.654-->00:02:41.361 a library and kernel a memory is mapped in-into memory, when a fire system become available, 00:02:41.361-->00:02:57.177 when a system is going too long, before a system crash, when a sss a thread starts or ends or 00:02:57.177-->00:03:08.922 finish, when a process starts or finish, when some uh registry entries are modified or removed. 00:03:08.922-->00:03:19.499 For example, I have uh seen some malwares using this specific callback uh methods in cache to 00:03:19.499-->00:03:27.340 callback for checking if if there are persistence entries are kept and just uh an analyzer 00:03:27.340-->00:03:37.484 or software or uh programmer remove it so the malware is able to adding back is uh nice trick 00:03:37.484-->00:03:46.059 to keep the purse strings. To find the number of callback methods is so easy using window 00:03:46.059-->00:03:56.136 back. The first command there and running a couple of commands we have a very nice way to list 00:03:56.136-->00:04:06.513 the callback methods. For example, uh, PSCreateProcessNotifyRoutine 00:04:06.513-->00:04:14.721 adds that kind of uh list of callback routines to be colored when a process is created or 00:04:14.721-->00:04:22.996 deleted. So in this case it’s so easy to find the number of installed callbacks. The first 00:04:22.996-->00:04:33.306 command that uh window back and a very easy to achieve command at the middle to list all the 00:04:33.306-->00:04:42.716 callback methods that uh are installed. In the last few weeks I have seen several malwares 00:04:42.716-->00:04:52.692 using this specific callback method PS SetLegoNotifyRoutine kernel callback to register a 00:04:52.692-->00:04:58.064 malicious routine and that’s called during the thread termination in this case. Uh the 00:04:58.064-->00:05:07.707 malware change the key thread the LegoData uh to provide uh malicious address in the routine 00:05:07.707-->00:05:17.217 redirects the execution flow to the malicious code is a very nice and different trick. Here 00:05:17.217-->00:05:28.762 we have the output from the last slide about the about the uh callback methods I showed you 00:05:28.762-->00:05:40.140 create process. And here we have the signature of uh key thread in the LegoData Field that is 00:05:40.140-->00:05:48.882 changed by the malware. Windows offers different uh types of drivers such as uh legacy 00:05:48.882-->00:05:57.991 drivers, filter drivers and minifilter drivers. All of them are developed by using R dot DM 00:05:57.991-->00:06:07.234 or R dot DF frameworks. Basically, a drive is composed by one or more objects and each 00:06:07.234-->00:06:20.180 object is associated to a driver object. So most ring 0 malwares malwares install filter drivers 00:06:20.180-->00:06:28.755 for modify aspects and behavior of existing drivers, filtering filtering of operations, add new 00:06:28.755-->00:06:39.232 malicious uh features for example keyloggers. The trick is always the same. Uh we have uh 00:06:39.232-->00:06:50.076 drivers stick and the malware uh first create an unnamed device object by using just first 00:06:50.076-->00:07:00.887 function AddDevice. And the second thing the malware adds the unnamed device object on the 00:07:00.887-->00:07:11.564 top of the stack by using this function IOAttachDevice. All communications in the drive 00:07:11.564-->00:07:23.977 stack is only by using IRP packets uh in each IRP packet is processed by a dispatch routine 00:07:23.977-->00:07:32.652 that’s retrieved from the MajorFunction Table. Uh the IRP parameters are retrieved from uh 00:07:32.652-->00:07:40.327 the IO stack location by using this function IoGetCurrentIrpStackLocation. 00:07:40.327-->00:07:49.736 Additionally, it’s possible to pass down the IRP parameters to the next layer by using 00:07:49.736-->00:07:58.511 IoSkipCurrentStackLocation or copy them by using IoCopyIrpStackLocation. 00:07:58.511-->00:08:07.520 Alternatively, IRP packets can be passed down to the layered driver by using this specific 00:08:07.520-->00:08:17.530 call, IoCallDriver. Here we have uh very nice trick. Some malwares try to pass the IRP 00:08:17.530-->00:08:24.738 package to the lowest driver by passing the middle of drivers and so avoiding should be the 00:08:24.738-->00:08:34.447 tactic for by monitoring tools and hooking tools so uh it’s very nice uh nice trick to evade 00:08:34.447-->00:08:49.929 the faces. Here I show you uh a complete picture about each uh at left we have the driver 00:08:49.929-->00:09:02.242 stack. At right we have the associated device objects to each driver. Pay attention that 00:09:02.242-->00:09:11.518 uh the IoCallDriver function is going to to pass down the IRP packets to the next layer. At 00:09:11.518-->00:09:21.694 bottom we have completer routines that are called in the reverse order so uh the 00:09:21.694-->00:09:30.970 completion routine is the function that do tha-that does the job. Often they are managed 00:09:30.970-->00:09:45.685 by the IoCompleteRequest function at right. Here we have the IRP structure composed by I 00:09:45.685-->00:09:54.194 static parts and I dynamic parts. The main part is composed by IO stack locations. So each 00:09:54.194-->00:10:03.269 uh IRP is created by calling the IO a locate IRP function and as I mentioned it before this 00:10:03.269-->00:10:12.178 function and the other 3 in your hat uh are interesting functions to be analyzed uh when you uh if 00:10:12.178-->00:10:21.554 you ever see a malware. At right bottom we have the IO stack location structure composed by 00:10:21.554-->00:10:30.196 the major function. The major function is uh holds the pointers to dispatch routines. 00:10:30.196-->00:10:38.538 Uh parameters field and completational chains field. Parameters fields uh depends uh 00:10:38.538-->00:10:45.979 on the major and minor functions. So in this slide we have the uh the uh uh structure 00:10:45.979-->00:10:55.288 of the parameters field. And on the next slide we have the complete list of IRP types. So 00:10:55.288-->00:11:04.864 easy Here we have uh complete relationship be-between the uh IO stack location structure, 00:11:04.864-->00:11:12.539 device object structure, and driver object structure. It’s a good logic to read tomorrow 00:11:12.539-->00:11:25.652 night. Here I show you uh a step by step investigation about a potential malicious driver named 00:11:25.652-->00:11:37.730 aborges. Uh with some commands in window back. And pay attention this specific malware 00:11:37.730-->00:11:48.708 made some spectral changes such as create, read, close, write, and device control. It’s so 00:11:48.708-->00:11:58.117 usual to see things like that when you’re analyzing malicious drivers. Here uh more complete 00:11:58.117-->00:12:10.263 overview. Uh showing you uh the relationship between the code driver object and spectral 00:12:10.263-->00:12:20.607 change. In this slide I started an investigation about a potential malicious filtered 00:12:20.607-->00:12:33.319 drive by using some commands anywhere in the back. Naturally, as closest uh a-at bottom of 00:12:33.319-->00:12:43.429 device stack occurs the infection, the more it should be easy uh i mean. Most uh most 00:12:43.429-->00:12:52.171 monitoring tools a hooking tools try to check the middle of the stack so if the infection happen 00:12:52.171-->00:13:01.447 at the bottom you are skipping all these tools and evading the defences. Some malwares try to 00:13:01.447-->00:13:09.756 intercept requests such as read write operations by manipulating the MajorFunction array. For 00:13:09.756-->00:13:20.233 example, MG Device Control and IRP Internal Control callback meth- dispatch routines. 00:13:20.233-->00:13:30.610 Rootkits try to protect itself from being removed by modifying functions such as IRP MJ Device 00:13:30.610-->00:13:38.918 Control and hooking requests going to the disk uh is other kind of tricks. Some malwares 00:13:38.918-->00:13:45.591 try to hook the uh uh DriverUnload routine for preventing the rootkit of being 00:13:45.591-->00:13:55.268 removed. Another trick. However, most malicious drivers or most malicious uh uh malwares trying 00:13:55.268-->00:14:03.342 to avoid touching areas protected by patch guard because uh patch guard is so tough to 00:14:03.342-->00:14:13.119 circumvented. Here we have uh we have a list of protection service by patch guard. I think 00:14:13.119-->00:14:24.731 strong action is good bye this comment. Most time, uh malwares have been starting their 00:14:24.731-->00:14:32.839 payloads and configurations en-encrypt hidden file systems and uh additionally they have uh 00:14:32.839-->00:14:41.214 create the random device objects names during the boot trusted stage uh strategy the special 00:14:41.214-->00:14:52.458 file system. Some malwares composed by executable A drivers have been using APLC advanced 00:14:52.458-->00:14:58.664 local procedure call to perform the communication between the user codes and the driver codes 00:14:58.664-->00:15:09.776 instead of using IO control commands. It’s another smart trick. Some malwares don’t 00:15:09.776-->00:15:17.216 choose the uh any specific driver for injection but try to randomly pick up a driver by 00:15:17.216-->00:15:29.662 parsing just last structure there key lego data table entry. Certainly, hooking device can 00:15:29.662-->00:15:41.374 access so easy here I show you complete list of of APIs it’s so easy to do that. Few malwares uh 00:15:41.374-->00:15:49.782 have been hooking the specific API Z dot create for intercepting all opened requests 00:15:49.782-->00:15:59.058 sent to devices it’s a ver-uh nice trick because it is antivirus use the same tricks. 00:15:59.058-->00:16:06.566 Some malwares after infecting a system by dropping device by dropping kernel drivers try to 00:16:06.566-->00:16:18.044 force a reboot by calling Z dot raise hard error function is uh very special malware trick. 00:16:18.044-->00:16:31.557 Other malwares try to use uh the last routine here in red IO Register Shutdown Notification 00:16:31.557-->00:16:37.330 for restoring uh the malicious drivers in the next reboot so if you try remove it uh they back. 00:16:37.330-->00:16:47.306 Fortunately most malwares have been using uh ExAllocatePoolWithTag function 00:16:47.306-->00:16:53.079 try to locate member pool but these so easy to find them because we have the volatility 00:16:53.079-->00:17:03.389 here. We can find indeed by using item crawl as you already know or using key command and 00:17:03.389-->00:17:15.668 window back. Finally, most malicious drivers have been using APC injection to inject 00:17:15.668-->00:17:22.875 some malicious code instead of using CreateRemoteThread so my recommendation is to pay 00:17:22.875-->00:17:43.696 attention uh at uh these three last functions in red. Now I’m talking about advanced malwares 00:17:43.696-->00:17:56.776 basically rootkits minus ring minus 2. We’re going to be talking about ring minus 2 00:17:56.776-->00:18:07.753 malwares the context is so different. Most most malwares uh act changes viral attack MBR, 00:18:07.753-->00:18:17.196 VBR, UFI, for example some malwares alter the BPB, BIOS parameter block, to change the 00:18:17.196-->00:18:27.306 execution flow to another place for this case. This kind of malware alters uh this less 00:18:27.306-->00:18:38.784 filtered hidden sectors. To change to uh another address and uh execute the malicious code 00:18:38.784-->00:18:50.830 instead of executing the IPL. Here we have uh real keys about uh malwares such as TDL4 or 00:18:50.830-->00:19:03.409 Petya which equip and infect the MBR so it stays the trick is try to load a good MBR and a bad one 00:19:03.409-->00:19:14.553 in the IDA pro and emulate them uh using box simulator so I try to compare to make my my 00:19:14.553-->00:19:28.501 analysis easier. MBR modifications and VBR modifications are effective ways 00:19:28.501-->00:19:34.040 to bypass KCS, Kernel Mode Code Signing Policy. KCS is responsible for validating the 00:19:34.040-->00:19:44.683 drive signature. So there are some ways to bypass KCS. Disable it booting in test mode but in 00:19:44.683-->00:19:50.790 this case secure boot must be disable. Change the kernel memory it’s so easy. Or even 00:19:50.790-->00:19:59.465 trying to find a flaw in the firmware in this case again secure boot must be disabled. 00:19:59.465-->00:20:09.475 Here we have a real case about a trojan banker. Uh well the malware is putting Windows in 00:20:09.475-->00:20:18.250 test mode in this case it goes into uh force in the near future to load the unsigned malicious 00:20:18.250-->00:20:30.296 driver. Here I show you um more complete overview composed by BIOS that here we have the boot 00:20:30.296-->00:20:44.610 process composed by BIOS, MBR, VBR, Boot Manager, and look at the left now. There we have the 00:20:44.610-->00:20:53.953 Winload easy many bootkits try to attack the before loading the kernel and ELAM protection it is 00:20:53.953-->00:21:03.796 uh not that uh smart uh trick to bypass the face. Malwares have been uh infect boot manager. 00:21:03.796-->00:21:09.435 Boot manager is responsible to switch the processor execution uh from real mode to protected 00:21:09.435-->00:21:15.808 mode so some malwares have been using some roots to act as the drive to patch modules and load 00:21:15.808-->00:21:28.120 malicious drivers. At bottom I show you some uh some tasks how to say to show ring integrity uh 00:21:28.120-->00:21:36.428 it enable the protect mode check the modules integrity and loaded the kernels, loads several DLLs 00:21:36.428-->00:21:47.173 and ELAM protection, and finally loads drivers and system register data. Therefore 00:21:47.173-->00:21:55.915 integrity checking uh of in window load uh is critical and uh if it is subverted everything 00:21:55.915-->00:22:04.623 fall because the integrity control don't doesn’t exist anymore so pay attention here. 00:22:04.623-->00:22:13.999 All the protections are based on digital certificates and digital signatures so it’s critical. 00:22:13.999-->00:22:21.974 Most advanced rootkits as I mentioned remove easily start their payloads and um 00:22:21.974-->00:22:30.282 configuration in uh encrypted hidden file systems by using some special up codes. As you 00:22:30.282-->00:22:42.361 know SMM mode is a kind of magical mode or god mode that’s perfect place to hide a malware. 00:22:42.361-->00:22:58.010 Here I show you uh a first approach composed by SPI Flash, SMM, UEFI services, MBR, VBR, 00:22:58.010-->00:23:08.687 the OS loader, and OS. Uh pay attention here malwares can attack any block here so you are 00:23:08.687-->00:23:23.402 not safe. Here uh quick reminder about the UEFI phases. So is. Here I show you uh more computer 00:23:23.402-->00:23:30.643 reveal about which process composes by hardware and the UEFI phases and thing like that. 00:23:30.643-->00:23:40.419 Again malwares can attack everywhere here but we have good protections such as Boot Guard, 00:23:40.419-->00:24:02.975 UEFI Secure Boot, OS Secure Boot and and some more. Remember, the SPI Flash is composed by 00:24:02.975-->00:24:13.185 descriptors, gigabit ethernet, management engine, ACPI and BIOS. So for example the Boot 00:24:13.185-->00:24:20.025 Guard controlled by management engine is responsible for validating the boot process uh 00:24:20.025-->00:24:30.235 by flashing a public key uh into the intel management engine. Uh of course for a perfect working 00:24:30.235-->00:24:37.276 of the Boot Guard, the SPI flash region must be locked and the Boot Guard configuration must be 00:24:37.276-->00:24:48.887 set and protected against SMM rootkits. Here I show you uh quick picture about the Boot 00:24:48.887-->00:24:59.164 Guard blocks. Basically each block verifies the next one. Uh it’s kind of certificate chain. 00:24:59.164-->00:25:12.244 Another very interesting process uh protection is the BIOS Guard uh which runs within the SMM and 00:25:12.244-->00:25:18.317 protects the platform against unauthorized SPI Flash, BIOS update, boot infection and 00:25:18.317-->00:25:26.392 corruption, and basically uh BIOS Guard only allows trusted modules to modify the SPI flash 00:25:26.392-->00:25:35.501 memory. Secure Boot is responsible for protecting the entire path against bootkit 00:25:35.501-->00:25:42.941 infection, protects the key components during the kernel load, mm key drivers and 00:25:42.941-->00:25:50.582 important system files, uh and at end Secure Boot prevents any uh uh loading of uh a strange 00:25:50.582-->00:26:00.459 code without any valid uh additional signature. Two things so two essential items in the 00:26:00.459-->00:26:07.433 Secure Boot are the Platform Key. The Platform Key establish a relationship between the 00:26:07.433-->00:26:15.040 platform owner and the platform firmware. And it’s responsible uh for verifying the exchange 00:26:15.040-->00:26:21.680 key. And at bottom KEK exchange key establish a trust relationship between the 00:26:21.680-->00:26:31.256 platform firmware and OS. Additionally, the key exchange key verifies the authorized 00:26:31.256-->00:26:37.629 database which contains authorized sss signing certificates and digital uh 00:26:37.629-->00:26:43.135 signatures. And Forbidden Database which contains the forbidden certificates and 00:26:43.135-->00:26:50.809 digital signatures. Obviously, if the Platform Key is corrupted everything fall because the 00:26:50.809-->00:26:58.016 Secure Boot must be or can be disabled. Unfortunately some vendors uh store uh important 00:26:58.016-->00:27:07.159 Secure Boot settings into UEFI variables. However if some uh uh root key exploit these variables 00:27:07.159-->00:27:20.072 Secure Boot can be disabled. UEFI BIOS supports uh Terse Executable format. However, 00:27:20.072-->00:27:27.112 Terse Executable format doesn’t support signatures and remember uh what uh what I told you all 00:27:27.112-->00:27:34.119 the modern protections are basically on digital signature and digital certificates so in 00:27:34.119-->00:27:41.994 this case if a rootkit uh is able to re-replace the typical uh PL loader by uh Terse 00:27:41.994-->00:27:56.742 Executable so uh Secure Boot can be disabled. Fortunately, new uh releases of Windows 10 00:27:56.742-->00:28:05.584 introduced uh a very interesting feature uh about SSM protections know as Windows SMM Security 00:28:05.584-->00:28:11.790 Mitigation Table. Uh in Windows 10 the firmware executing SSM must be authorized and trusted 00:28:11.790-->00:28:22.200 by VBS so it’s uh an uh extra protection service. SSM protection flags uh in Windows 00:28:22.200-->00:28:33.545 can be uh be configured for your use. Uh here I show you some flags. Finally, I I’m showing 00:28:33.545-->00:28:42.821 here uh protocol keys uh real keys about the customer in Brazil. In this case the system 00:28:42.821-->00:28:54.933 uh is not protects against BIOS writing. You see the second one BIOS read write permission so 00:28:54.933-->00:29:09.915 it’s terrible. In the same system BIOS was enabled is set is terrible too because any 00:29:09.915-->00:29:19.625 malware uh can write a malicious code there. The BIOS lock enable isn’t set. It’s terrible too 00:29:19.625-->00:29:27.899 because this is a kind of notification bit. The SMM BIOS write protection is disabled, 00:29:27.899-->00:29:41.613 horrible again. At bottom right the protection range registers are disabled too so in this case 00:29:41.613-->00:29:50.789 we have here complete exposed machine, complete exposed system. Here I’m using chip sec 00:29:50.789-->00:30:06.672 uh to perform my analysis, my checking. Here we have the flash configuration lockdown is 00:30:06.672-->00:30:14.079 enabled. That’s ok however it doesn’t matter because this section protects the protection 00:30:14.079-->00:30:31.096 range registers which are disabled so it’s not matter. Here the BIOS stop swap mode is 00:30:31.096-->00:30:38.737 disabled. That’s okay because in this case it’s impossible to redirect the chipsec vector to 00:30:38.737-->00:30:50.048 uh pick up block so it’s impossible to execute the malicious code. Finally, the SMM 00:30:50.048-->00:30:58.724 range is enabled. It’s a good one it’s a good news so it’s impossible to access the SMM 00:30:58.724-->00:31:12.938 from uh no SMM mode. My conclusion are most security professionals are not ready to 00:31:12.938-->00:31:22.481 analyze malicious drivers because the theory is huge and not easy. And I know that. Real 00:31:22.481-->00:31:28.920 customers real world are not aware about uh ring minus 2 threats and they know they don’t 00:31:28.920-->00:31:41.733 know how to update the firmwares uh most customers don’t know how to do that. And finally remember 00:31:41.733-->00:31:48.006 uh all the protections are based on integrity. For example digital certificate and 00:31:48.006-->00:31:56.615 signature. However I leave you a question here. What would happen if these algorithms were broken? 00:31:56.615-->00:32:08.393 For example using quantum computation. Uh this talk here is dedicated to my wife and for 00:32:08.393-->00:00:00.000 you who reserve some time to be here. Thank you for attending my talk. [audience applause]