1 00:00:01,640 --> 00:00:10,640 Okay. How is everybody? I need your energy, right? Yeah. Okay. I drank some. Okay. So 2 00:00:10,640 --> 00:00:16,440 welcome to our talk, Defender Pretender, when Windows Defender updates become a security 3 00:00:16,440 --> 00:00:23,780 risk. We'll introduce ourselves first. My name is Tomer Bar and I am the VP of security 4 00:00:23,780 --> 00:00:29,780 research at SafeBridge. Actually, we spoke ten different talks at Black Hat USA and this 5 00:00:29,780 --> 00:00:36,380 is our ninth in DEFCON. And I've been around for the last 20 years. I presented in many 6 00:00:36,380 --> 00:00:42,640 global security conferences and this year I was qualified to speak to talks at Black Hat and 7 00:00:42,640 --> 00:00:51,980 one at DEFCON. Hey, guys. So my name is Tomer Bar. I'm a security researcher at SafeBridge. I 8 00:00:52,520 --> 00:00:58,680 have over six years of experience in cybersecurity, especially in low level and vulnerability 9 00:00:58,680 --> 00:00:59,420 research. 10 00:00:59,780 --> 00:01:08,640 And I'm also a technology and science enthusiast. So let's kick it off. Okay. We will 11 00:01:08,640 --> 00:01:15,540 introduce our research motivation and goal and then we'll describe in details Defender 12 00:01:15,540 --> 00:01:22,220 Pretender process and the vulnerability we discovered. We will demo different super 13 00:01:22,220 --> 00:01:28,720 interesting attack vectors and we'll finish our talk with important takeaways before leaving time 14 00:01:28,720 --> 00:01:29,660 for Q and A. 15 00:01:29,780 --> 00:01:38,080 Let's begin. So in this session, we are going to walk you all through the process of how we turn 16 00:01:38,080 --> 00:01:48,640 defender to defender pretender. And our motivation originated from used by probably state 17 00:01:48,640 --> 00:01:55,480 sponsored threat actor and exploited the Windows update process using a sophisticated man in the 18 00:01:55,480 --> 00:01:59,760 middle attack. Flame was able to hijack the Windows and the Azure reform. The first one was the recent 19 00:01:59,780 --> 00:02:05,940 Windows update mechanism by posing as a legitimate Microsoft update server, allowing it to 20 00:02:05,940 --> 00:02:14,140 deliver malicious updates and maintain persistence on the target system. Our goal was to 21 00:02:14,140 --> 00:02:21,500 achieve similar capabilities, but running without admin privileges, without possessing a 22 00:02:21,500 --> 00:02:28,260 forged certificate, and with no requirements of men in the middle, and still achieve full 23 00:02:28,260 --> 00:02:36,080 takeover on defend ore workflow. So let's start to analyze the defender update process and 24 00:02:36,080 --> 00:02:44,040 understand what happens locally during an update. So defender checks with the Microsoft update 25 00:02:44,040 --> 00:02:51,620 center for new updates. We found out that the updates are returned as a single executable. The 26 00:02:51,620 --> 00:02:58,060 file full name is pretty long. It's called Microsoft protection anti-malware front end. So 27 00:02:58,060 --> 00:02:58,240 it's the same as the defender update. We can only use it as a single update, for example. If we 28 00:02:58,240 --> 00:03:01,260 So we will refer to it as MPAM from now on. 29 00:03:02,800 --> 00:03:09,520 And we downloaded this MPAM file, analyzed it, and found that it has a CAB resource and 30 00:03:09,520 --> 00:03:16,740 then we manually extracted the resource and got six files, two executable files, MP engine 31 00:03:17,020 --> 00:03:23,980 and MP six tab, and four files with unfamiliar VDM extension, at least for us. 32 00:03:24,980 --> 00:03:33,300 So when we tried to execute this MPAM file, we observed that it was executed the MP six tab as a 33 00:03:33,300 --> 00:03:40,320 child process using the command line in red. After the execution, we saw the defender was 34 00:03:40,320 --> 00:03:50,980 updated. So it seems like the stab's role is to initiate the update process. The VDM files are 35 00:03:50,980 --> 00:03:53,960 loaded to the defender's main process. And the VDM files are loaded to the defender's main 36 00:03:53,980 --> 00:04:02,380 function as you can see here. MP engine DLL was also used by the process and this DLL exports 37 00:04:02,380 --> 00:04:11,680 defender's core functionality. Let's investigate a little bit more about these VDM files. So the 38 00:04:11,680 --> 00:04:17,940 VDM files are actually portable executable files, meaning the application. However, they cannot 39 00:04:17,940 --> 00:04:23,960 be executed as they have no code logic at all. So we assume that they are certain tasks. As we've 40 00:04:23,960 --> 00:04:31,260 special data files that contains the detection signatures. Furthermore, we observed that the 41 00:04:31,260 --> 00:04:36,760 two of them are labeled with the keyword base and the other two are labeled with the keyboard 42 00:04:36,760 --> 00:04:44,580 delta. With the main difference being their sizes. The base file are significantly larger than 43 00:04:44,580 --> 00:04:51,160 the delta files and we speculate that this is due to incremental updating for efficiency 44 00:04:51,160 --> 00:04:58,840 reasons because you probably don't want to send the entire database each time you have to have a 45 00:04:58,840 --> 00:05:07,540 small update, right? It's not efficient. And the base file is a major version of 391 and zero 46 00:05:07,540 --> 00:05:16,160 minor version and the delta file has the same major version and 3508 as the minor version. And 47 00:05:16,160 --> 00:05:20,740 it's important and I'm telling you that because the delta version represent the current 48 00:05:20,740 --> 00:05:21,140 version and the delta file represent the current version and the delta file represent the 49 00:05:21,140 --> 00:05:27,460 current version of defender security intelligence. So it may indicate that the delta files are 50 00:05:27,460 --> 00:05:36,740 related to the signature data. But a quick check reveals that all six files are digitally signed 51 00:05:36,740 --> 00:05:43,940 by Microsoft which probably indicates that the update process was designed against tempering. 52 00:05:44,650 --> 00:05:50,720 However, let's continue to explore furthermore before reaching a definitive answer to this 53 00:05:50,720 --> 00:05:59,560 speculation. So to summarize the update process to the ones that come in right now, the MPAM file is 54 00:05:59,560 --> 00:06:05,420 fetched from the internet and upon execution it triggers an update and the following three 55 00:06:05,420 --> 00:06:13,760 step occur. MPAM extract the video files, MP engine and MP6 tab from itself into the update 56 00:06:13,760 --> 00:06:20,700 payload folder located at the temporary direction, directory, sorry. And MPAM, the update files, the 57 00:06:20,700 --> 00:06:25,400 update of the 6th tab and then executes the 6th tab in order to perform the update. And finally, 58 00:06:25,520 --> 00:06:32,820 6th tab takes the video files and MP engine DLL and uses them to update Windows Defender. So easy 59 00:06:33,160 --> 00:06:41,100 right until now. So now that we have gained eye level knowledge about the update process, we can 60 00:06:41,100 --> 00:06:50,620 start to play around with the files involved. If we will be able to modify MP engine DLL to our 61 00:06:50,620 --> 00:06:57,240 our own fake DLL, it will be a game over for Defender resulting in local privilege escalation, 62 00:06:57,320 --> 00:07:05,540 right? So we modified a valid update payload that we have downloaded from the Internet and 63 00:07:05,540 --> 00:07:12,760 replace only the original MP engine DLL as you can see with our fake DLL even though the DLL 64 00:07:12,760 --> 00:07:18,840 was digitally signed by Microsoft, the original one. And then we executed this tab executable 65 00:07:18,840 --> 00:07:25,940 with the appropriate command line and of course this attempt failed. During a kernel debugging 66 00:07:26,460 --> 00:07:33,700 we got this exception at the top that tells us that the DLL is not signed. This protection is 67 00:07:33,700 --> 00:07:40,340 implemented since Defender main process is a protected process, a PPL process which cannot 68 00:07:40,340 --> 00:07:48,460 load unsigned DLLs. So in that point we thought is this the end of our research lead? We 69 00:07:48,460 --> 00:07:56,560 decided not to give up and focus on the VDM files. What will happen if we update Defender using a 70 00:07:56,560 --> 00:08:02,780 modified older VDM file so we decided to modify only the file version which is embedded inside 71 00:08:02,780 --> 00:08:09,580 the file so making Defender believe it's a newer version but without modifying the data itself. 72 00:08:10,220 --> 00:08:18,200 Of course this modification will turn the VDM to be unsigned because it's embedded in the file but we decided to give it a shot anyway. 73 00:08:19,060 --> 00:08:25,980 And for our surprise the update attempt succeeded we actually update an older version 74 00:08:25,980 --> 00:08:33,260 they tended to be a newer version and most importantly using unsigned files with the low privileged user, 75 00:08:33,360 --> 00:08:48,100 unprivileged user. So this was the first clue that something is fishy. But when we tried to modify additional random byte in this VDM data itself and not just the file version 76 00:08:48,460 --> 00:08:56,460 execute a second update, we got an error. So we understood it won't be that simple and we have to 77 00:08:56,460 --> 00:09:04,440 learn more about the update process. So let's summarize what we accomplished so far. We 78 00:09:04,440 --> 00:09:11,100 understood in high level Windows Defender update process and we have become familiar with the 79 00:09:11,100 --> 00:09:16,900 involved file, right? We attempted to modify MP Engine to use our own fake DLL but were 80 00:09:16,900 --> 00:09:25,300 unsuccessful in doing so. However, we did successfully modify an older update payload to 81 00:09:25,300 --> 00:09:32,140 appear as a new update payload by modifying the video files but finally got an error when we 82 00:09:32,140 --> 00:09:40,560 updated using video file with modified data. So we left with the question, how does a low 83 00:09:40,990 --> 00:09:46,880 privileged user can replace files managed by Defender protected process? So the first thing we 84 00:09:46,880 --> 00:09:56,280 did was we began to analyze MP6 step. After a bit of reversing, we understood that MP6 step 85 00:09:56,720 --> 00:10:03,800 communicate with MSMP engine which is the main process of Defender via RPC, remote procedure 86 00:10:03,800 --> 00:10:10,400 calls. But at that point in time, we were unable to find a specific RPC interface which was 87 00:10:10,400 --> 00:10:16,760 used and the challenge was even more difficult since RPC tools that we all use like RPC 88 00:10:16,880 --> 00:10:24,580 review could not display the RPC data due to involved protected process. So we did manual reverse 89 00:10:24,580 --> 00:10:31,120 engineering and revealed that the RPC guide which belongs to MPSVC DLL and that the 90 00:10:31,120 --> 00:10:38,320 function number parameter was 42 corresponding to a function name server MP update engine 91 00:10:38,320 --> 00:10:46,860 signature which by its name indeed seems like the function we were looking for. After the RPC data 92 00:10:46,880 --> 00:10:54,060 is done, the execution will continue from Defender main process on the right and will reach 93 00:10:54,060 --> 00:11:01,420 init engine context function which start the update process by calling the R signal function in 94 00:11:01,420 --> 00:11:08,380 our MP engine DLL. So now we are ready for dynamic kernel debugging to understand the rest of 95 00:11:08,380 --> 00:11:16,520 the execution flow. And as you can see, the execution flow is pretty long, right? We will skip to 96 00:11:16,880 --> 00:11:24,380 the interesting part in the load database function which is called for each VDM file. So now we 97 00:11:24,380 --> 00:11:34,060 know for sure that the VDM is indeed contains the update database. Let's analyze the database 98 00:11:34,060 --> 00:11:41,380 format. So we will be able to modify the data in much smarter way than we did before like in random 99 00:11:41,380 --> 00:11:46,860 data modification. As we mentioned, the VDM file is Windows VDM file. So we will be able to modify 100 00:11:46,860 --> 00:11:53,700 both portable executable files with no code logic but it also includes a resource section and this 101 00:11:53,700 --> 00:12:03,280 resource section contains compressed data that start with RMDX magic bytes. And the signature in 102 00:12:03,280 --> 00:12:12,440 both the base and the delta files are compressed with Zlib but Zlib magic bytes are absent. So by 103 00:12:12,440 --> 00:12:16,840 simply adding these two bytes at the bottom and then adding the data to the database, the data is 104 00:12:16,840 --> 00:12:23,380 compressed and running this simple command, it can be decompressed. And we were very surprised to 105 00:12:23,380 --> 00:12:30,220 see that the signatures are not even encrypted. So in a brief look over the base file, we could 106 00:12:30,220 --> 00:12:37,480 literally see where signatures begins and ends and probably the actual unique strings Defender 107 00:12:37,480 --> 00:12:46,820 searches in order to detect, for this example, the Conti ransomware. But the delta file format is 108 00:12:46,840 --> 00:12:56,860 a bit more complex. And we have decided to prioritize understanding it to a later time. So now we 109 00:12:56,860 --> 00:13:02,860 are going to focus on the base file. And the base file as we assume has the most of the signature 110 00:13:02,860 --> 00:13:08,900 logic because it's larger. And it seems easier to understand its format. So let's see what we 111 00:13:08,900 --> 00:13:16,820 discovered. So each signature has a four byte signature header which contains signature type and 112 00:13:16,840 --> 00:13:24,960 size. The type is one byte long and the size is three byte long. And the signature data begins just 113 00:13:24,960 --> 00:13:31,500 right after the signature header. So simple structure. And instead of reversing each signature 114 00:13:31,500 --> 00:13:38,020 type, we search on Google and for some relevant information and found this comprehensive list of 115 00:13:38,020 --> 00:13:46,820 signature types. Each threat starts with a signature type 5C. A threat is a signature type that is 116 00:13:46,840 --> 00:13:53,540 a collection of signatures. These signatures are simply unique strings or byte sequences which 117 00:13:53,540 --> 00:14:00,100 belong to a malware family. You can see several strings from the Conti threat. And the collection 118 00:14:00,100 --> 00:14:10,580 of the signatures always ends up with threat and signature 5D type at the bottom. The base file is 119 00:14:10,580 --> 00:14:16,820 actually a sequence of threats. When one threat ends, the next threat starts and so on. So 120 00:14:16,820 --> 00:14:24,580 So using this knowledge, we were able to extract more than 2.5 million signatures from the base file. 121 00:14:26,860 --> 00:14:29,800 We figured out most of the members of the signature. 122 00:14:29,980 --> 00:14:34,640 For example, the threat name, its category, and severity of the threat. 123 00:14:35,420 --> 00:14:44,700 Now, we can conduct an experiment in order to verify if we can modify it in a more smarter way than we did at the beginning of the research. 124 00:14:44,700 --> 00:14:55,320 So, we extracted the strings from the VDM files, copied them to a Visual Studio environment, and compiled a simple executable containing these strings. 125 00:14:55,660 --> 00:15:02,040 But, as you can see, without any logic, as you can see it's line 16, the main function is empty. 126 00:15:03,000 --> 00:15:08,180 And then we copied this executable to a virtual machine with Defender. 127 00:15:08,320 --> 00:15:14,620 And in a minute, immediately, it triggered Defender, even though there is no malicious code at all. 128 00:15:14,700 --> 00:15:21,740 And, as expected, the threat alert name is the name of the threat we investigated, Conti, as you can see at the top. 129 00:15:23,260 --> 00:15:29,900 Then, we modified just the threat name associated with the signature from Conti to a different name, 130 00:15:30,720 --> 00:15:36,220 recompressed the VDM file, and tried to update Defender using this modified version. 131 00:15:37,140 --> 00:15:43,380 Unfortunately, this attempt was unsuccessful and resulted in unexplained error. 132 00:15:44,700 --> 00:15:51,320 We assume that the error is due to validation mechanism, and Omer will speak about those validations. 133 00:15:54,460 --> 00:16:01,560 Okay, so, we went back to the drawing board and reverse-engineered the update process, 134 00:16:02,520 --> 00:16:08,760 with the goal of identifying the point where the update failed and why it failed. 135 00:16:10,500 --> 00:16:13,420 So, a quick reminder, for each VDM file, 136 00:16:13,420 --> 00:16:18,360 load database is called, and then checks the validity of the file, 137 00:16:18,520 --> 00:16:22,500 and then calls to ConsumeInputCompress function. 138 00:16:24,600 --> 00:16:31,960 ConsumeInputCompress function is a huge function that performs a lot of operations on the VDM files. 139 00:16:33,260 --> 00:16:40,780 Also, we suspected the function to be the function that returned the error code we saw in the logs. 140 00:16:41,660 --> 00:16:43,400 So, we focused deeply on the VDM file. 141 00:16:43,420 --> 00:16:46,700 We focused deeply on the internals of these two functions, 142 00:16:47,000 --> 00:16:50,740 and specifically on ConsumeInputCompress function. 143 00:16:52,300 --> 00:16:56,020 We did it by dynamically debugging the update execution. 144 00:16:56,960 --> 00:16:59,360 So, let's see what we got from debugging. 145 00:17:01,380 --> 00:17:08,160 The debugging led us to figure out two important structures that contained in each VDM file. 146 00:17:08,700 --> 00:17:11,860 The first one is the RMDX header, 147 00:17:13,420 --> 00:17:16,940 which is in the beginning of every VDM resource data. 148 00:17:18,620 --> 00:17:24,280 One of the important members of the RMDX header is the data offset, 149 00:17:24,640 --> 00:17:28,460 which points to a second header called Zilib header, 150 00:17:29,180 --> 00:17:30,720 which we can see marked in blue. 151 00:17:32,200 --> 00:17:37,900 The Zilib header actually contains the Zilib compressed data of the VDM, 152 00:17:37,940 --> 00:17:41,100 and also consists of two vars, 153 00:17:41,100 --> 00:17:48,300 and the second vars is suspected to be the CRC of the compressed data. 154 00:17:49,160 --> 00:17:53,120 So, we tried to calculate the CRC value of the compressed data, 155 00:17:53,820 --> 00:17:55,940 but we didn't get the expected value. 156 00:17:56,720 --> 00:17:58,800 So, maybe this is not the CRC. 157 00:18:00,160 --> 00:18:04,920 So, we tried to locate the point where this value is accessed, 158 00:18:05,140 --> 00:18:11,080 and discovered that it's compared to a variable calculated using CRC. 159 00:18:11,080 --> 00:18:14,580 Using an algorithm similar to a CRC calculations. 160 00:18:16,280 --> 00:18:19,560 So, after searching on Google, 161 00:18:19,800 --> 00:18:25,440 we found out that this is a specific CRC algorithm called GemCRC, 162 00:18:25,660 --> 00:18:29,360 which is calculated by one minus the CRC value. 163 00:18:31,100 --> 00:18:34,900 So, we were confident that we could modify the VDM 164 00:18:34,900 --> 00:18:39,680 and fix the expected CRC value that appears in the headers, 165 00:18:39,680 --> 00:18:44,800 and by doing so, the update would be validated successfully, 166 00:18:45,300 --> 00:18:47,740 and we would be able to take down Defender. 167 00:18:49,180 --> 00:18:51,220 But the update was unsuccessful, 168 00:18:51,700 --> 00:18:56,120 even though we fixed the CRC value of the compressed data. 169 00:18:57,280 --> 00:18:59,880 Likely, there are additional validation checks, 170 00:19:01,080 --> 00:19:04,700 and we thought, where do these validation occurs, 171 00:19:04,960 --> 00:19:06,820 and what they validate. 172 00:19:06,980 --> 00:19:08,580 So, let's find them out. 173 00:19:10,060 --> 00:19:11,980 The modification was simple. 174 00:19:12,340 --> 00:19:17,340 We just opened up the base file and tried to modify the signatures, 175 00:19:17,680 --> 00:19:21,120 and after the modification, we wrapped up the base file 176 00:19:21,120 --> 00:19:23,600 and tried to do an update attempt. 177 00:19:24,480 --> 00:19:28,600 But it turned out to be quite more complicated than we thought. 178 00:19:29,260 --> 00:19:32,280 We completely ignored the Delta file. 179 00:19:32,680 --> 00:19:37,040 And we assumed that the error we got related to the relationship 180 00:19:37,040 --> 00:19:39,660 between the base file and the Delta file 181 00:19:39,680 --> 00:19:39,940 and the Delta file. 182 00:19:41,780 --> 00:19:44,040 There are two pairs of VDMs. 183 00:19:44,340 --> 00:19:49,040 The first pair contains the antivirus definitions of Defender, 184 00:19:49,180 --> 00:19:53,620 and the second pair actually contains the spyware definitions. 185 00:19:54,580 --> 00:19:59,440 Each of these pairs is identical in terms of the format of the file 186 00:19:59,440 --> 00:20:00,400 and the signatures. 187 00:20:00,780 --> 00:20:05,420 So, all the findings and the conclusions we will show now 188 00:20:05,420 --> 00:20:07,640 apply to each of these VDM pairs. 189 00:20:09,680 --> 00:20:09,900 Okay. 190 00:20:10,620 --> 00:20:13,760 So, as we mentioned earlier, we ignored the Delta. 191 00:20:14,360 --> 00:20:18,680 But now, it's time to focus on the purpose of the Delta file. 192 00:20:19,680 --> 00:20:24,360 During an update, both the base and the Delta files are involved. 193 00:20:25,500 --> 00:20:30,820 The merge takes the base file and the Delta simply defines the changes 194 00:20:30,820 --> 00:20:33,040 to be made to this base file. 195 00:20:34,180 --> 00:20:38,640 The resulting output file will represent the updated version 196 00:20:38,640 --> 00:20:39,720 from the Delta. 197 00:20:40,320 --> 00:20:44,100 And this update process is referred to as incremental. 198 00:20:45,360 --> 00:20:49,740 To modify base signatures, we need to supply a Delta file 199 00:20:49,740 --> 00:20:54,760 that precisely patches the base file with the intended changes. 200 00:20:55,320 --> 00:21:02,040 But to do that, we need to understand the entire merge process internals 201 00:21:02,320 --> 00:21:06,580 and identify any other validations that we encountered. 202 00:21:08,820 --> 00:21:12,800 So, now we will delve into the merge process. 203 00:21:14,220 --> 00:21:15,120 Oh, sorry. 204 00:21:15,800 --> 00:21:19,080 So, we have talked about the VDM file format 205 00:21:19,080 --> 00:21:22,460 and specifically the base file format, 206 00:21:22,660 --> 00:21:25,800 which contains threats and their signatures. 207 00:21:26,800 --> 00:21:29,800 Now, let's look into the Delta format 208 00:21:29,800 --> 00:21:35,340 and how it combines with the base file to create new file with new signatures. 209 00:21:36,620 --> 00:21:40,320 So, we went back to the decompressed Delta file 210 00:21:40,320 --> 00:21:45,240 and we figured out that the Delta is a signature base file too. 211 00:21:46,380 --> 00:21:49,440 We saw that the Delta always contain two signatures. 212 00:21:50,280 --> 00:21:54,220 The second signature is blob signature type 213 00:21:54,220 --> 00:21:57,240 and we ignored the blob rec info signature 214 00:21:57,240 --> 00:22:02,220 as we assume all the essential data contained in the blob signature. 215 00:22:03,700 --> 00:22:05,900 So, right after the signature header, 216 00:22:05,900 --> 00:22:09,900 we have two numbers which we were not sure about their purpose. 217 00:22:10,400 --> 00:22:12,540 So, we will call them unknown for now 218 00:22:12,540 --> 00:22:14,960 and we will come back to them later on. 219 00:22:17,640 --> 00:22:22,100 The rest of the data right after these numbers is actually the actions, 220 00:22:22,880 --> 00:22:26,680 which define the actions done by the merge algorithm. 221 00:22:27,440 --> 00:22:29,660 How do they define the actions? 222 00:22:30,260 --> 00:22:32,360 Now, we will answer this question. 223 00:22:33,580 --> 00:22:35,260 So, we spotted the point 224 00:22:35,900 --> 00:22:37,780 where Defender parsed the actions. 225 00:22:38,620 --> 00:22:43,480 And this block of code shows where actually the action parsed start. 226 00:22:44,100 --> 00:22:47,020 And we reverse all the merge process 227 00:22:47,020 --> 00:22:51,420 and figured out how the merge works. 228 00:22:51,840 --> 00:22:54,180 So, let's delve into the internals. 229 00:22:56,020 --> 00:22:59,100 So, we identify two action types, 230 00:22:59,520 --> 00:23:02,100 copy from Delta and copy from base. 231 00:23:03,000 --> 00:23:06,060 Copy from Delta used to copy size bytes 232 00:23:06,060 --> 00:23:09,380 from the Delta file into the merge file. 233 00:23:09,780 --> 00:23:13,520 And copy from base used to copy size bytes 234 00:23:13,520 --> 00:23:18,100 from an offset within the base file into the merge file. 235 00:23:18,720 --> 00:23:23,580 Let's see exactly the format of each of these signatures. 236 00:23:24,100 --> 00:23:26,940 So, to parse the actions, 237 00:23:27,100 --> 00:23:31,440 we first need to read two bytes representing the action header. 238 00:23:32,100 --> 00:23:36,660 The first bit within the action header indicates the action type. 239 00:23:37,360 --> 00:23:41,260 Zero for copy from Delta and one for copy from base. 240 00:23:42,080 --> 00:23:46,700 And the rest of the action header is dependent on the action type. 241 00:23:47,140 --> 00:23:52,280 So, first let's take a look at copy from Delta action. 242 00:23:53,200 --> 00:23:55,120 Here we have an action example. 243 00:23:55,930 --> 00:23:59,940 And the first thing to do is to read the first two bytes 244 00:23:59,940 --> 00:24:01,740 and check the MSB. 245 00:24:02,100 --> 00:24:04,160 To identify which type of action is it. 246 00:24:05,360 --> 00:24:10,280 The MSB is zero means this action is actually copy from Delta. 247 00:24:10,820 --> 00:24:17,840 Then it means that the next 15 bits represented the size variable 248 00:24:17,840 --> 00:24:21,280 which tells us how many bytes to read. 249 00:24:22,820 --> 00:24:26,400 So, the size variable is set to one in this case. 250 00:24:26,560 --> 00:24:29,500 So, we read one byte right after the action header. 251 00:24:29,760 --> 00:24:30,920 So, in this case, 252 00:24:30,920 --> 00:24:35,920 we will read 5C and place it into the new merge file. 253 00:24:36,960 --> 00:24:37,560 Okay. 254 00:24:37,700 --> 00:24:41,480 Now that we understand how to parse copy from Delta action, 255 00:24:41,740 --> 00:24:43,960 let's move on to copy from base action. 256 00:24:45,460 --> 00:24:48,120 So, when we look at copy from base action, 257 00:24:48,360 --> 00:24:50,600 we can see that the MSB is on. 258 00:24:51,300 --> 00:24:52,800 But in this case, 259 00:24:52,900 --> 00:24:55,960 after reverse engineer of consume input compress function, 260 00:24:56,760 --> 00:24:58,900 we found out that in this case, 261 00:24:59,000 --> 00:25:00,040 the size variable, 262 00:25:00,040 --> 00:25:02,340 calculated in the following way. 263 00:25:02,840 --> 00:25:07,440 Firstly, we take the two bytes and turn off the MSB by 264 00:25:08,040 --> 00:25:10,980 and bitwise with 7FFF. 265 00:25:11,580 --> 00:25:14,980 And then add to this result 6, 266 00:25:15,120 --> 00:25:16,920 which result the size variable. 267 00:25:17,740 --> 00:25:20,120 We now know how many bytes to read, 268 00:25:20,300 --> 00:25:22,980 but the question is where we will read them from. 269 00:25:24,580 --> 00:25:26,940 So, copy from base action type 270 00:25:26,940 --> 00:25:29,840 consists also the offset variable, 271 00:25:29,840 --> 00:25:32,900 the next D word right after the action header 272 00:25:32,900 --> 00:25:36,260 indicates the offset within the base file 273 00:25:36,260 --> 00:25:38,140 we should read the bytes from. 274 00:25:38,340 --> 00:25:39,900 So, in this example, 275 00:25:40,040 --> 00:25:43,020 the size is equal to 8005. 276 00:25:43,640 --> 00:25:47,920 And we should read them from the offset one of the base file. 277 00:25:48,240 --> 00:25:52,040 And eventually place them into the new merge file. 278 00:25:53,560 --> 00:25:55,600 So, to summarize the Delta file, 279 00:25:55,740 --> 00:25:59,320 so to summarize the Delta file contains compressed data. 280 00:25:59,320 --> 00:26:01,820 And by decompressing this data, 281 00:26:02,000 --> 00:26:04,120 we can extract the blob signature. 282 00:26:05,080 --> 00:26:07,200 The blob contains actions, 283 00:26:07,400 --> 00:26:12,520 and the actions tells how to build the new updated file, 284 00:26:12,700 --> 00:26:15,740 depending on the current version of the base file. 285 00:26:16,380 --> 00:26:18,860 And all this occurs in memory. 286 00:26:20,380 --> 00:26:22,100 So, following our knowledge, 287 00:26:22,320 --> 00:26:25,880 we developed a script that do that merge 288 00:26:25,880 --> 00:26:29,300 between the base file and the Delta file. 289 00:26:29,320 --> 00:26:33,200 We ran our code and got a merge stream 290 00:26:33,200 --> 00:26:37,180 that actually seems like a base with signatures, 291 00:26:37,380 --> 00:26:38,660 but with some modifications. 292 00:26:40,360 --> 00:26:43,640 Here we can see a diff between base signatures 293 00:26:43,640 --> 00:26:44,860 to emerge signatures. 294 00:26:45,480 --> 00:26:49,160 The bytes that marked in yellow are the modified bytes, 295 00:26:49,400 --> 00:26:52,780 and the size of the data got bigger. 296 00:26:54,300 --> 00:26:58,160 Probably the merge process added some new signatures. 297 00:26:59,280 --> 00:27:04,060 And here things are starting to reveal a clear image of what happening. 298 00:27:04,960 --> 00:27:06,340 As we said before, 299 00:27:07,000 --> 00:27:09,980 we will talk about the unknown numbers we mentioned before. 300 00:27:10,920 --> 00:27:13,380 So, we started to investigate the merge properties 301 00:27:13,380 --> 00:27:16,520 like the size of the merge and the CRC of the merge. 302 00:27:17,920 --> 00:27:22,180 And we looked up for a correlation to the unknown numbers. 303 00:27:23,080 --> 00:27:25,300 And Eureka, we got it. 304 00:27:25,300 --> 00:27:29,200 The first number represents the size of the merge data, 305 00:27:29,420 --> 00:27:33,960 and the second number is actually the CRC of the merge data. 306 00:27:34,680 --> 00:27:37,740 These two numbers are the expected values 307 00:27:38,080 --> 00:27:40,000 that Defenders compares with. 308 00:27:41,100 --> 00:27:45,260 And the numbers is actually one more layer of validations. 309 00:27:46,720 --> 00:27:50,240 So, I want to recap the three validations we discovered. 310 00:27:51,020 --> 00:27:53,700 The first validation simply checks 311 00:27:53,700 --> 00:27:56,380 if the Zlib compressed data isn't changed. 312 00:27:56,620 --> 00:27:58,700 And how does Defender check this? 313 00:27:59,320 --> 00:28:03,760 By comparing the expected CRC value within the Zlib data header 314 00:28:03,760 --> 00:28:07,020 to the calculated CRC of the Zlib data. 315 00:28:08,420 --> 00:28:11,440 The next validation are the ones we just mentioned. 316 00:28:12,140 --> 00:28:16,060 Merge size validation ensures the size of the merge data, 317 00:28:16,260 --> 00:28:21,720 and merge CRC validation validates the CRC of the merge data. 318 00:28:21,720 --> 00:28:26,120 These checks confirm the success of the merge algorithm. 319 00:28:27,360 --> 00:28:31,960 So, we wondered if now we have all the knowledge we need 320 00:28:31,960 --> 00:28:33,200 in order to fake an update. 321 00:28:33,900 --> 00:28:37,580 So, we tried to change the delta actions in such a way 322 00:28:37,580 --> 00:28:39,580 that the merge will result with a difference. 323 00:28:40,720 --> 00:28:41,820 And it worked. 324 00:28:42,340 --> 00:28:46,600 We managed to update Defender with a fake unsigned database 325 00:28:46,600 --> 00:28:48,360 using unprivileged user. 326 00:28:49,380 --> 00:28:50,320 It's crazy. 327 00:28:51,720 --> 00:28:53,940 Let's see what we can do with this capability. 328 00:28:54,520 --> 00:28:57,340 We will explain three attack vectors. 329 00:28:58,960 --> 00:29:01,560 We have developed a fully automatic tool 330 00:29:01,560 --> 00:29:03,160 called WDPretender, 331 00:29:03,400 --> 00:29:07,380 which stands for Windows Defender Pretender. 332 00:29:08,800 --> 00:29:11,760 This tool supports all the attack vectors 333 00:29:11,760 --> 00:29:13,720 that we are going to present. 334 00:29:14,100 --> 00:29:17,040 And we will share the GitHub link at the end of the talk. 335 00:29:17,960 --> 00:29:20,180 So, as we explained earlier, 336 00:29:20,180 --> 00:29:23,400 the signatures of Defender resulted from merging 337 00:29:23,400 --> 00:29:25,380 the delta file and the base file. 338 00:29:25,940 --> 00:29:29,640 The database files of Defender are composed of threats, 339 00:29:29,940 --> 00:29:32,180 and each threat has its name, 340 00:29:32,260 --> 00:29:36,740 and we can infer from the name the purpose of the threat, right? 341 00:29:37,980 --> 00:29:42,220 Now, what will happen if we will delete all the threats 342 00:29:42,220 --> 00:29:46,100 that contain the keyword lasagna, for example, in their names? 343 00:29:47,520 --> 00:29:48,260 Let's see. 344 00:29:48,260 --> 00:29:52,740 We will show how deletion of threat resulting with bypass 345 00:29:52,740 --> 00:29:56,140 and with successful execute lasagna tool. 346 00:29:56,560 --> 00:29:57,400 Let's see. 347 00:29:58,520 --> 00:30:02,680 So now, we see that we are unprivileged user. 348 00:30:06,840 --> 00:30:10,540 And we will try to download lasagna tool. 349 00:30:11,500 --> 00:30:14,780 And it immediately triggered Defender. 350 00:30:15,400 --> 00:30:18,180 And Defender will delete this tool. 351 00:30:18,180 --> 00:30:22,040 Now, we will run WD Pretender 352 00:30:22,040 --> 00:30:28,680 and delete all the threats that contain the lasagna name 353 00:30:28,680 --> 00:30:29,980 in their threats name. 354 00:30:30,940 --> 00:30:33,620 The tool will export the VDM files, 355 00:30:33,900 --> 00:30:37,380 and we will run an update attempt with this tab. 356 00:30:39,030 --> 00:30:45,400 And we will see in a sec that the update executed successfully. 357 00:30:45,400 --> 00:30:50,240 And now, we will try to download lasagna tool again. 358 00:30:51,960 --> 00:30:53,200 Let's see what we get. 359 00:30:57,140 --> 00:30:57,840 Perfect. 360 00:30:58,220 --> 00:30:59,480 The tool downloaded, 361 00:30:59,560 --> 00:31:03,520 and we will execute successfully lasagna. 362 00:31:03,680 --> 00:31:03,960 Bingo. 363 00:31:07,540 --> 00:31:08,520 Thank you. 364 00:31:11,480 --> 00:31:12,180 Okay. 365 00:31:12,180 --> 00:31:15,640 Now, Tomer will present the next demos. 366 00:31:22,940 --> 00:31:23,660 Okay. 367 00:31:23,900 --> 00:31:28,480 So, one of the signature type seems very, very interesting. 368 00:31:28,740 --> 00:31:32,420 The name that Microsoft named it is friendly file signature. 369 00:31:32,760 --> 00:31:36,120 And with hash algorithm like 256, 370 00:31:36,960 --> 00:31:39,700 as you can see on the left, on red, 371 00:31:39,700 --> 00:31:44,800 so we wonder what do Microsoft means by friendly files. 372 00:31:45,240 --> 00:31:49,960 So, parsing all the friendly file signatures from the VDM files 373 00:31:50,680 --> 00:31:54,760 revealed us a very, very long list of sorted list of hashes. 374 00:31:54,900 --> 00:32:01,240 The hash marked in green on the right belongs to Oracle VirtualBox runtime library, 375 00:32:01,460 --> 00:32:03,200 and the others belongs to other files. 376 00:32:03,540 --> 00:32:08,980 And we assume that this signature is probably an allow list implementation, 377 00:32:08,980 --> 00:32:15,040 probably to reduce false positives caused by, example, this Oracle file. 378 00:32:15,680 --> 00:32:21,540 And what will happen if we replace the hash value of Oracle file 379 00:32:21,540 --> 00:32:25,080 with the Mimikatz known hash value? 380 00:32:25,180 --> 00:32:27,440 We didn't change the Mimikatz from the internet. 381 00:32:28,000 --> 00:32:29,860 Will it be allowed to run? 382 00:32:30,480 --> 00:32:33,500 Can we create a friendly Mimikatz file? 383 00:32:34,740 --> 00:32:35,880 Let's see a demo. 384 00:32:39,240 --> 00:32:42,380 Okay, so we'll try to download Mimikatz. 385 00:32:42,660 --> 00:32:44,780 It is detected as Mimikatz on the right. 386 00:32:45,060 --> 00:32:47,900 So, Defender is working. 387 00:32:48,100 --> 00:32:49,740 Now we will execute on the left. 388 00:32:50,160 --> 00:32:52,140 Again, Windows pretender Defender. 389 00:32:53,020 --> 00:32:54,060 Defender pretender, sorry. 390 00:32:54,240 --> 00:32:57,400 And with the hash of Mimikatz, the known hash, 391 00:32:57,660 --> 00:32:59,120 then we will update. 392 00:32:59,320 --> 00:33:01,980 And you will see on the right that the update was successful. 393 00:33:02,380 --> 00:33:04,700 From unprivileged user, unsigned files. 394 00:33:05,560 --> 00:33:08,620 And you can also see that the logs are 395 00:33:08,980 --> 00:33:11,140 saying the same, that the update was successful. 396 00:33:12,380 --> 00:33:16,700 Now we will try to download Mimikatz from the same place. 397 00:33:17,940 --> 00:33:19,460 And let's see if it runs. 398 00:33:19,780 --> 00:33:20,340 Yeah, it runs. 399 00:33:20,660 --> 00:33:24,480 Let's see if we can extract all credentials from the memory of Alsace. 400 00:33:26,200 --> 00:33:26,720 Yeah. 401 00:33:27,360 --> 00:33:27,880 Right? 402 00:33:29,740 --> 00:33:30,500 Thank you. 403 00:33:35,540 --> 00:33:37,860 And now for our final demo, 404 00:33:37,860 --> 00:33:39,500 we saved the best for last. 405 00:33:39,520 --> 00:33:41,100 It's going to be very, very cool. 406 00:33:41,200 --> 00:33:41,680 Trust me. 407 00:33:42,120 --> 00:33:47,700 We are going to force Defender to delete all the PE files in the PC 408 00:33:48,300 --> 00:33:51,000 by modifying existing signature 409 00:33:51,780 --> 00:33:54,340 to include the DOSMOD stop string, 410 00:33:54,560 --> 00:33:57,960 which appears in all of the portable executable 411 00:33:58,780 --> 00:34:00,660 as a new malicious signature. 412 00:34:01,020 --> 00:34:03,440 And when Defender will find this string, 413 00:34:03,680 --> 00:34:07,460 this program cannot be run in DOSMOD since the 80s, right? 414 00:34:07,860 --> 00:34:11,280 In OS files, it will automatically say, 415 00:34:11,420 --> 00:34:12,620 I'm going to delete you, 416 00:34:12,780 --> 00:34:15,480 and causing permanent denial of service. 417 00:34:18,780 --> 00:34:22,200 So we run our tool, generated database. 418 00:34:22,720 --> 00:34:25,580 We are going to copy it to a machine, replace it, 419 00:34:25,740 --> 00:34:28,260 and we'll do an update after that. 420 00:34:29,840 --> 00:34:33,140 That's the user that is unprivileged user. 421 00:34:34,180 --> 00:34:35,640 And we'll run the update. 422 00:34:36,540 --> 00:34:39,600 And on the left, you will see the update succeed. 423 00:34:40,620 --> 00:34:41,100 Okay. 424 00:34:42,020 --> 00:34:44,180 Now we'll wait, like, a few seconds. 425 00:34:44,260 --> 00:34:45,540 It's not edited at all. 426 00:34:46,940 --> 00:34:50,580 And Defender started to say something about a lot of files 427 00:34:50,580 --> 00:34:52,480 detecting them as emoted. 428 00:34:52,860 --> 00:34:54,200 And it keeps going. 429 00:34:54,620 --> 00:34:55,320 It keeps going. 430 00:34:55,400 --> 00:34:56,540 If I add sound right now, 431 00:34:56,680 --> 00:34:59,400 you will see, like, a lot of concert, you know? 432 00:34:59,660 --> 00:35:01,900 And Defender said, what's going on? 433 00:35:02,780 --> 00:35:03,620 Restart the computer. 434 00:35:03,960 --> 00:35:05,300 But we are not going to do it. 435 00:35:05,300 --> 00:35:08,820 We are going to scan the driver folder under system 32. 436 00:35:10,280 --> 00:35:11,140 Thank you. 437 00:35:11,340 --> 00:35:11,680 Thank you. 438 00:35:13,720 --> 00:35:15,080 And let's see. 439 00:35:17,320 --> 00:35:18,480 Let's see what happens. 440 00:35:18,920 --> 00:35:24,420 And we'll show you that all the drivers and DLL files 441 00:35:25,260 --> 00:35:28,620 and processes and registry keys and everything. 442 00:35:29,020 --> 00:35:31,360 And, of course, we can do it also on user files 443 00:35:31,360 --> 00:35:33,440 that contain a specific code, like DEFCON. 444 00:35:33,560 --> 00:35:35,280 Any file that contains DEFCON, 445 00:35:35,300 --> 00:35:37,060 we can delete it and so on. 446 00:35:37,180 --> 00:35:41,920 And trust me, Windows cannot load without drivers. 447 00:35:42,220 --> 00:35:43,200 It won't work. 448 00:35:43,500 --> 00:35:44,540 So we tried. 449 00:35:44,700 --> 00:35:45,140 We tried. 450 00:35:45,380 --> 00:35:47,260 We have a second restart attempt. 451 00:35:47,440 --> 00:35:49,260 But believe me, it won't work. 452 00:35:49,380 --> 00:35:50,540 So it's a permanent denial of service. 453 00:35:52,260 --> 00:35:56,500 And this demo was recorded on an older version of Defender. 454 00:35:56,660 --> 00:35:58,580 It was version 3.2.1. 455 00:35:59,220 --> 00:36:02,400 And the newest version at the time of the check, 3.8.1, 456 00:36:02,540 --> 00:36:04,680 implements few additional checks. 457 00:36:04,680 --> 00:36:09,280 For example, we had to remove all the signature type trusted publisher 458 00:36:10,000 --> 00:36:13,360 to make Defender delete benign drivers and OS executables. 459 00:36:13,520 --> 00:36:14,280 But it works. 460 00:36:15,580 --> 00:36:17,960 Let's speak a little bit about future work. 461 00:36:18,140 --> 00:36:19,060 And it's very interesting. 462 00:36:19,280 --> 00:36:25,460 We found out that the signature database file also includes 30,000 Lua scripts. 463 00:36:26,420 --> 00:36:30,740 Microsoft used a little bit of modified Lua header for them. 464 00:36:30,820 --> 00:36:33,840 But we were able to overcome the modification. 465 00:36:33,840 --> 00:36:40,200 And to decompile and extract the source code of 30,000 Lua scripts 466 00:36:40,200 --> 00:36:44,140 that control all of the remediation process of Defender. 467 00:36:44,360 --> 00:36:52,220 So, for example, a Lua rule to detect suspicious files masquerading as legit Windows files. 468 00:36:52,500 --> 00:36:57,340 The rule simply checks if a file has the same name of OS executable, 469 00:36:57,500 --> 00:36:59,640 but not in the legit OS path. 470 00:37:00,440 --> 00:37:03,720 What will happen if we change this rule code? 471 00:37:03,720 --> 00:37:04,720 We changed the code to our own code. 472 00:37:04,900 --> 00:37:07,880 And we tried to use Lua libraries, but failed. 473 00:37:08,040 --> 00:37:11,600 Since Microsoft probably limits the usage of Lua libraries. 474 00:37:11,860 --> 00:37:18,540 But we still think that we might be possible to achieve LPE, local privilege escalation, 475 00:37:18,660 --> 00:37:24,040 using Microsoft remediation library, which we saw used in some of the other Lua scripts. 476 00:37:24,560 --> 00:37:28,220 But we had to leave it for future work because of lack of time. 477 00:37:28,360 --> 00:37:31,340 But we encourage you to do it and please update us if you can do it. 478 00:37:31,400 --> 00:37:33,480 We will try to after DefCon. 479 00:37:33,720 --> 00:37:36,260 So, a little bit about takeaways. 480 00:37:36,660 --> 00:37:39,120 Of course, trust no one. We are DefCon, right? 481 00:37:39,340 --> 00:37:46,480 Even the most reliable security controls might be used as a loophole by adversaries 482 00:37:46,480 --> 00:37:53,600 and the architecture and work process should check and verify in continuous security validation process. 483 00:37:54,060 --> 00:38:00,500 Secondly, using digitally signed files does not always necessarily mean totally secure. 484 00:38:00,820 --> 00:38:03,700 Security vendors should always verify 485 00:38:03,720 --> 00:38:07,740 in any step of the process that the trust was not broken. 486 00:38:08,300 --> 00:38:13,900 And finally, signature update process of security control is probably a new attack vector. 487 00:38:14,180 --> 00:38:17,320 And we believe additional research is very important. 488 00:38:18,540 --> 00:38:23,320 We reported to Microsoft, which released a patch and assigned DCVAD. 489 00:38:24,380 --> 00:38:30,160 Please make sure that you are using the version of malware protection platform or above. 490 00:38:33,720 --> 00:38:34,600 Keep your cameras. 491 00:38:34,740 --> 00:38:38,740 This is the Windows Defender pretended GitHub QR code and link. 492 00:38:39,520 --> 00:38:43,740 I will wait a few seconds for those of you who would like to follow it. 493 00:38:45,080 --> 00:38:48,480 And this past research helped us a lot. 494 00:38:48,680 --> 00:38:51,960 And we built our research based on their initial findings. 495 00:38:52,100 --> 00:38:53,100 So, thank you. 496 00:38:53,840 --> 00:38:55,400 And thank you all. 497 00:38:55,520 --> 00:38:56,520 Thank you all for joining.