1 00:00:00,000 --> 00:00:05,040 Or more specifically, how .NET attacks are not so hidden from us. 2 00:00:06,800 --> 00:00:09,360 So, just a minor introduction about myself. 3 00:00:10,040 --> 00:00:15,680 I'm a threat hunter at Countercept, F-Secure company, whereby we are a consultancy firm. 4 00:00:16,080 --> 00:00:18,920 I am in the detection and response team. 5 00:00:19,080 --> 00:00:22,100 So, my job is literally detection and response. 6 00:00:22,460 --> 00:00:27,180 For the detection part, I do something known as hypothesis-driven threat hunting, 7 00:00:27,300 --> 00:00:29,780 whereby I look through all my client data. 8 00:00:30,470 --> 00:00:34,180 In the events where I find something suspicious, I respond to it. 9 00:00:34,240 --> 00:00:39,260 I investigate them, such as using process logs, event logs, MFT. 10 00:00:39,540 --> 00:00:42,780 So, you could think of it more like real-time incident response. 11 00:00:44,100 --> 00:00:47,660 I do quite a bit of attack detection research as well. 12 00:00:47,880 --> 00:00:53,800 So, part of me being a defensive security person, I constantly need to make sure that I'm on par with the offensive guys. 13 00:00:54,060 --> 00:00:56,620 And that's where I do some form of attack detection research. 14 00:00:57,160 --> 00:00:59,860 And if it's interesting and big enough, I blog about them. 15 00:01:00,000 --> 00:01:03,360 So, you could find some of my blog posts on the Countercept website, actually. 16 00:01:04,720 --> 00:01:07,780 I am sort of a little code junkie as well. 17 00:01:07,880 --> 00:01:09,160 I like to automate stuff. 18 00:01:09,460 --> 00:01:12,200 I like to write scripts to automate some of my daily works. 19 00:01:12,340 --> 00:01:16,700 And it helped me a lot with my job as well, as I need to filter out lots of data at times. 20 00:01:17,680 --> 00:01:19,500 And lastly, I'm a Netflix edit. 21 00:01:19,600 --> 00:01:24,100 I like to just relax in my home and sit down and just watch TV. 22 00:01:25,060 --> 00:01:26,860 So, yeah, just four things about myself. 23 00:01:27,120 --> 00:01:29,980 And let's move on to the agenda, which is why we are here. 24 00:01:30,000 --> 00:01:30,220 So, why are we here today? 25 00:01:31,760 --> 00:01:34,760 Firstly, I'm going to discuss the importance of downlight detection. 26 00:01:35,240 --> 00:01:36,920 Why do we actually need to do it? 27 00:01:37,100 --> 00:01:39,880 And how do we actually do the detection itself? 28 00:01:40,580 --> 00:01:44,400 So, I'm just going to start off with why the importance of downlight detection. 29 00:01:46,180 --> 00:01:51,340 So, as a chat hunter myself, I have faced quite a bit of chat actors and adversaries. 30 00:01:51,620 --> 00:01:53,700 And I have seen my fair share of investigation. 31 00:01:54,600 --> 00:01:59,980 And some of these attacks, most of these chat actors, what they like to use is something known as script-based attack. 32 00:02:00,600 --> 00:02:05,640 Whereby they are typically run in processors that are commonly installed on a Windows Enterprise machine, 33 00:02:06,300 --> 00:02:11,460 such as PowerShell, where I've seen PowerShell invoking a download string against a C2 channel, 34 00:02:11,680 --> 00:02:15,420 invoking Mimikatz, VBScript, enumerating user drive, 35 00:02:15,620 --> 00:02:21,380 or even those pescalated macros that you see attempting to trick people into clicking them to get a free iPhone. 36 00:02:22,680 --> 00:02:27,220 And out of all these attacks, PowerShell is a hot favorite, I realize. 37 00:02:27,520 --> 00:02:29,880 Well, probably because it's really powerful. 38 00:02:30,000 --> 00:02:34,380 You could do quite a bit of activities with PowerShell, such as loading shellcode into memory, 39 00:02:34,800 --> 00:02:38,960 calling upon the .NET API, which is basically what PowerShell is based on, 40 00:02:39,120 --> 00:02:41,480 and even calling upon the Windows native API. 41 00:02:42,300 --> 00:02:47,000 And if you think about it, it's quite easy to actually POC something with PowerShell. 42 00:02:47,080 --> 00:02:50,020 All you need to do is pop up a console and test your code there. 43 00:02:50,520 --> 00:02:55,140 And if you just pop up a search engine, do a quick search on PowerShell frameworks, 44 00:02:55,440 --> 00:02:59,980 you can probably get a lot of hits from GitHub that gives a wide variety of PowerShell. 45 00:03:02,060 --> 00:03:05,380 But as defenders, we are also getting better. 46 00:03:05,840 --> 00:03:09,800 As compared to in the past, it's not that hard to detect bad PowerShell anymore. 47 00:03:10,320 --> 00:03:15,000 With the rise of EDR agents, we can actually analyze parent-child process relationship, 48 00:03:15,420 --> 00:03:19,200 and this gives us a spread of visibility on enormous PowerShell execution. 49 00:03:19,720 --> 00:03:24,920 For example here, we see Microsoft Word or Excel spreadsheet spawning a PowerShell process. 50 00:03:25,420 --> 00:03:29,800 And that is quite anonymous, because you would not expect a Word document 51 00:03:29,800 --> 00:03:32,800 or an Excel spreadsheet to spawn a PowerShell process. 52 00:03:33,240 --> 00:03:38,720 I mean, those are mainly for, like, working stuff, editing your spreadsheets and all. 53 00:03:38,900 --> 00:03:45,120 Although, to be frank, I've seen legitimate instances of this in my clinic state, but it's very rare. 54 00:03:45,240 --> 00:03:49,240 So you expect something like this to be rather anonymous and probably malicious. 55 00:03:50,520 --> 00:03:55,520 We can also see the common line arguments tagged to a newly spawned PowerShell process, 56 00:03:56,180 --> 00:03:59,260 such as here, we can actually see what the PowerShell code was doing. 57 00:03:59,800 --> 00:04:04,140 In this case, what the PowerShell code was doing was simply printing out an evil command. 58 00:04:04,420 --> 00:04:05,600 So, nothing too malicious. 59 00:04:06,020 --> 00:04:10,540 But from here, I hope that you guys can actually understand that with this level of visibility, 60 00:04:11,040 --> 00:04:16,000 as defenders ourselves, we are able to determine whether a bad PowerShell is actually being run. 61 00:04:17,040 --> 00:04:23,740 And there are other defenses as well, such as MZ, which can assist antivirus with script-based attack detection. 62 00:04:24,340 --> 00:04:29,560 So, take for example with this image here I have, where I enter MZ tools into the console. 63 00:04:29,800 --> 00:04:31,900 The antivirus actually stops and blocks it. 64 00:04:32,240 --> 00:04:35,440 So, this occurs because MZ acts as an interface. 65 00:04:35,760 --> 00:04:44,320 When a command is entered to the PowerShell console, MZ will act as an interface which will send the command to the antivirus for scanning. 66 00:04:44,620 --> 00:04:49,520 If a signature has been created, the antivirus will then stop the command from being executed. 67 00:04:50,860 --> 00:04:56,340 There are other defenses as well, such as PowerShell script-based logging, whereby for PowerShell version 5 and above, 68 00:04:59,800 --> 00:05:02,100 the process would be logged into the event logs. 69 00:05:02,300 --> 00:05:05,920 And this gives another visibility for defenders to actually leverage on. 70 00:05:07,580 --> 00:05:12,080 So, all in all, I guess as an industry as a whole, defenses have improved. 71 00:05:12,400 --> 00:05:15,280 We are given more opportunities to detect bad PowerShell. 72 00:05:16,020 --> 00:05:19,720 And the adversaries, the bad guys, they are aware of it. 73 00:05:19,940 --> 00:05:23,820 They know that PowerShell is not as easy as it was in the past. 74 00:05:24,000 --> 00:05:28,460 And some of them have migrated different tooling and techniques, such as .NET. 75 00:05:29,180 --> 00:05:34,620 Whereby you invoke the .NET core instead of choosing something like PowerShell, for example. 76 00:05:35,760 --> 00:05:37,260 And why .NET, though? 77 00:05:37,360 --> 00:05:39,920 If you think about it, it's very similar to PowerShell. 78 00:05:40,020 --> 00:05:41,560 You have powerful functions. 79 00:05:42,680 --> 00:05:44,520 It's installed by default on Windows machine. 80 00:05:44,760 --> 00:05:46,060 But with one key difference. 81 00:05:46,580 --> 00:05:50,080 There is currently a lack of telemetry regarding towards .NET. 82 00:05:51,340 --> 00:05:54,280 So, I'm just going to do a quick demonstration here. 83 00:05:54,940 --> 00:05:57,920 Whereby I'm going to compare a PowerShell and a .NET. 84 00:05:58,460 --> 00:06:00,800 Both of them are going to do exactly the same thing. 85 00:06:01,200 --> 00:06:05,840 Firstly, they're going to write a registry key through the use of a .NET API. 86 00:06:06,860 --> 00:06:10,900 Secondly, they're going to pop a message box with the use of a Windows native API. 87 00:06:11,640 --> 00:06:15,340 So, native API is essentially a Windows library. 88 00:06:15,480 --> 00:06:22,500 Whereby we are actually importing functions from Windows library such as user32.dll, kernel32.dll. 89 00:06:23,520 --> 00:06:27,200 So, I have a demonstration here. We shall start. 90 00:06:28,460 --> 00:06:30,780 So, right here I have two HTA scripts file. 91 00:06:30,940 --> 00:06:34,520 A PowerShell HTA file and a .NET HTA file. 92 00:06:34,900 --> 00:06:37,400 Both of them will run within the MSHTA process. 93 00:06:38,400 --> 00:06:40,580 So, let's click on the PowerShell process first. 94 00:06:43,600 --> 00:06:46,600 So, I'm going to click on the button to execute my PowerShell code. 95 00:06:47,040 --> 00:06:50,680 And as you see, I pop a message box from kernel32. 96 00:06:51,720 --> 00:06:54,100 And I actually return a registry key as well. 97 00:06:56,580 --> 00:06:58,440 So, we're going to look at the indicator. 98 00:06:58,440 --> 00:07:00,680 The indicators related to this attack now. 99 00:07:01,420 --> 00:07:03,180 So, we are going to look at the process logs. 100 00:07:03,420 --> 00:07:08,160 And from here, we can actually see a PowerShell process being spawned. 101 00:07:08,320 --> 00:07:13,580 And it was being created from a parent process which is mshj.exe. 102 00:07:13,840 --> 00:07:15,580 So, this is quite suspicious by itself. 103 00:07:17,060 --> 00:07:21,620 And furthermore, we can actually look at the common arguments here. 104 00:07:22,100 --> 00:07:25,660 So, we have this bunch of encoded base64 PowerShell code. 105 00:07:25,880 --> 00:07:28,260 Which I'm going to decode in front of you now. 106 00:07:33,460 --> 00:07:36,980 So, I'm just going to base64 decode it. 107 00:07:39,340 --> 00:07:42,800 And from here, we can actually see the entire PowerShell code that was being run. 108 00:07:43,160 --> 00:07:48,040 So, as a defender myself, now I know what is being executed on this stack state. 109 00:07:48,180 --> 00:07:49,840 And I know how to remediate against it. 110 00:07:51,060 --> 00:07:53,640 So, let's delete all my artifacts now. 111 00:07:53,780 --> 00:07:56,900 And we're going to demonstrate the .NET HTA file. 112 00:07:56,900 --> 00:08:00,360 I'm going to show you the level of visibility we have on .NET HTA currently. 113 00:08:00,560 --> 00:08:04,200 And why is it harder as compared to PowerShell. 114 00:08:09,960 --> 00:08:12,660 So, same thing. I'm going to execute the .NET code directly. 115 00:08:13,680 --> 00:08:15,780 And now, I pop a message box. 116 00:08:18,220 --> 00:08:19,980 I've written a registry key. 117 00:08:24,460 --> 00:08:26,540 And if you look at my process log now. 118 00:08:26,900 --> 00:08:28,360 There is only one indicator. 119 00:08:28,660 --> 00:08:33,280 Which is an MSH TA process running a HTA file. 120 00:08:34,260 --> 00:08:40,900 And with that, we don't really have a lot of visibility on how to further investigate such a problem. 121 00:08:47,860 --> 00:08:51,720 So, just a quick summary of what I actually did. 122 00:08:52,420 --> 00:08:54,280 Firstly, for the PowerShell process. 123 00:08:54,280 --> 00:08:58,020 I used the MSH process to spawn a PowerShell code process. 124 00:08:58,280 --> 00:09:03,820 Which, thereafter, called upon the PowerShell code to write a registry key and pop a message box. 125 00:09:05,640 --> 00:09:08,160 For the .NET portion, I did the same thing. 126 00:09:08,360 --> 00:09:14,060 I used a MSH process to call upon the .NET code directly to perform exactly the same task. 127 00:09:14,560 --> 00:09:16,020 And here's the question though. 128 00:09:16,220 --> 00:09:17,920 How did I actually achieve this? 129 00:09:18,100 --> 00:09:20,700 Because an MSH HTA process 130 00:09:20,700 --> 00:09:24,300 typically is not able to actually invoke the .NET library. 131 00:09:26,300 --> 00:09:30,320 So, I achieved this with something known as an in-memory assembly loading. 132 00:09:31,200 --> 00:09:37,820 Whereby, firstly, on the victim's machine, I will compile a C-sharp code into a .NET assembly. 133 00:09:38,600 --> 00:09:43,240 I will then serialize it and embed it within a delivery mechanism. 134 00:09:43,840 --> 00:09:46,500 In my case, I used a HTA delivery mechanism. 135 00:09:46,700 --> 00:09:49,240 But technically, you could use any delivery mechanism. 136 00:09:50,700 --> 00:09:57,400 With that, I will deliver my payload to the attacker's machine and load it into the victim's machine memory. 137 00:09:58,600 --> 00:10:04,100 And once it's in the victim's machine memory, I will deserialize it back to the .NET assembly. 138 00:10:04,560 --> 00:10:12,480 And once it's deserialized, I will use reflection to actually reference this assembly and create an instance out of it. 139 00:10:13,920 --> 00:10:19,680 So, this entire flowchart, basically, what is it trying to replicate is something like this. 140 00:10:20,700 --> 00:10:23,340 For those of you who are aware of object-oriented programming, 141 00:10:23,780 --> 00:10:27,680 you realize that this entire flowchart is attempting to replicate this behavior. 142 00:10:28,040 --> 00:10:30,440 Whereby, you're attempting to reference an assembly. 143 00:10:30,680 --> 00:10:35,220 And with the reference assembly, you invoke the class constructor to create an object. 144 00:10:35,460 --> 00:10:37,160 And with that object, you can call its method. 145 00:10:39,020 --> 00:10:41,240 And what can this loaded object do? 146 00:10:41,960 --> 00:10:44,520 Basically, anything that PowerShell can do, it can do. 147 00:10:45,440 --> 00:10:49,100 So, just to give a midpoint check summary of what we have discussed, 148 00:10:50,700 --> 00:10:53,880 if we run a C-sharp object through the use of in-memory assembly loading, 149 00:10:54,360 --> 00:10:59,460 this object is capable of doing anything that PowerShell can do with one key difference. 150 00:10:59,960 --> 00:11:02,420 There's currently a lack of telemetry to detect it. 151 00:11:02,820 --> 00:11:03,940 And here's our challenge today. 152 00:11:04,540 --> 00:11:05,940 Can we actually detect this? 153 00:11:06,840 --> 00:11:12,420 And that is where I'm going to talk about now, the actual detection portion of .NET attacks. 154 00:11:14,740 --> 00:11:20,000 So, first, I'm going to do some form of initial triage, initial investigation with Process Hacker. 155 00:11:20,700 --> 00:11:25,100 Process Hacker is a tool which allows you to analyze the process behavior. 156 00:11:25,460 --> 00:11:29,420 You can look at the process threads, the module it loads, the string that it has. 157 00:11:29,760 --> 00:11:37,000 And I'm going to use it to analyze the MSHA process, which was responsible for running the .NET code. 158 00:11:39,860 --> 00:11:43,100 So, right here, we see something interesting here. 159 00:11:43,380 --> 00:11:48,580 For the MSHA process, we actually see some interesting module loads here. 160 00:11:48,580 --> 00:11:53,080 Which are actually module loads related to the .NET runtime engine DLL. 161 00:11:53,800 --> 00:11:55,980 And this is quite interesting. 162 00:11:57,180 --> 00:12:05,760 And this is quite interesting because MSHA actually requires this engine to execute the .NET assembly code. 163 00:12:06,260 --> 00:12:10,080 But it's also very dodgy, if you think about it, very suspicious. 164 00:12:10,640 --> 00:12:18,560 Why would MSHA require such a .NET runtime DLL engine when typically it only runs HTML or JavaScript code? 165 00:12:20,580 --> 00:12:24,320 So, this analogy can be hold true for other binary as well. 166 00:12:24,540 --> 00:12:29,020 You will not expect Microsoft Word, Microsoft PowerPoint to execute .NET code. 167 00:12:29,200 --> 00:12:33,500 So, such runtime engine DLLs should not actually be within this process. 168 00:12:34,060 --> 00:12:37,240 So, with this, we can actually think of an interesting hypothesis to hunt. 169 00:12:37,600 --> 00:12:42,480 Whereby, for example, we can hunt for processes that typically do not execute .NET code. 170 00:12:42,600 --> 00:12:47,220 And hunt to see whether these binaries contain a runtime engine DLL. 171 00:12:48,580 --> 00:12:51,440 But unfortunately, this hypothesis is not perfect. 172 00:12:51,840 --> 00:12:54,940 What if a binary that was related to .NET was used? 173 00:12:55,160 --> 00:13:02,500 Such as msbuild.exe, which is an application that is used to build .NET applications. 174 00:13:03,560 --> 00:13:10,900 Or perhaps a third-party application such as SQL Server, in which it allows a user to run C-sharp code on it. 175 00:13:11,560 --> 00:13:18,440 So, if you think about applications like this, it's not uncommon for them to actually have a .NET runtime DLL being loaded into it. 176 00:13:19,860 --> 00:13:21,980 So, we're going to need something better than this. 177 00:13:22,140 --> 00:13:26,160 And fortunately for us, the answer actually lies deep within Process Hacker. 178 00:13:27,140 --> 00:13:34,660 Within Process Hacker, there is a section that only appears when it detects events related to assembly load. 179 00:13:34,800 --> 00:13:37,360 And these assembly loads have to be .NET assembly loads. 180 00:13:38,240 --> 00:13:44,080 And what's interesting about this section here is that you can actually detect any event related to a .NET assembly load. 181 00:13:44,080 --> 00:13:52,580 And if you look closely at one of the assembly loads, one of them is without a path as compared to the other three. 182 00:13:53,060 --> 00:13:57,200 So, lack of a path potentially indicates some form of in-memory assembly loading. 183 00:13:57,480 --> 00:14:05,280 Which is what I was trying to do in my previous flowchart, whereby I was trying to load an assembly through the use of in-memory. 184 00:14:08,060 --> 00:14:12,040 And one question is, how did Process Hacker actually achieve this? 185 00:14:13,160 --> 00:14:19,220 We realized that deep within Process Hacker code, they actually leverage on a set of ETW providers. 186 00:14:19,820 --> 00:14:25,680 And right here in front of us, there is a great wealth of information that we can potentially leverage on. 187 00:14:26,440 --> 00:14:37,260 And with this information, we at Countercept, we wrote up a Python proof-of-concept code to consume these .NET ETW events with the help of FireEye's ETW tracing library. 188 00:14:39,380 --> 00:14:43,980 So, with this information, let's try to detect the attack that I did in my demonstration earlier. 189 00:14:44,440 --> 00:14:50,540 Let's try to find indicators related to in-memory assembly load, which we saw covered earlier with Process Hacker. 190 00:14:51,280 --> 00:14:56,220 Let's try to find indicators related to registry creation through the use of .NET API. 191 00:14:56,920 --> 00:15:01,480 And finally, let's try to find indicators related to the invoking of native API. 192 00:15:02,840 --> 00:15:06,080 So, let's continue our discussion on in-memory assembly loads. 193 00:15:07,260 --> 00:15:14,680 Firstly, with Process Hacker, we're actually able to use events related to the loading of .NET assembly to flag out such various events. 194 00:15:15,240 --> 00:15:20,580 There's another event we can use, and this is something known as the JIT compiler, just-in-time compilation. 195 00:15:21,780 --> 00:15:28,920 So, before I dive deep into just-in-time compilation, we need to first understand the .NET code compilation architecture. 196 00:15:29,780 --> 00:15:36,720 A .NET code is essentially a managed code whereby they run within a virtualized environment. 197 00:15:37,260 --> 00:15:39,640 With something known as the Common Language Runtime. 198 00:15:40,040 --> 00:15:43,040 So, a .NET code doesn't compile directly to native code. 199 00:15:43,340 --> 00:15:51,240 What happens is, when a .NET code compiles, it compiles to something known as the Common Intermediate Language, within the CLR. 200 00:15:51,940 --> 00:16:02,240 And when it's going to be executed, basically when you double-click it, it will go to something known as the JIT compilation, which will compile this to the Windows native code. 201 00:16:02,900 --> 00:16:06,160 Once the code has been compiled to a native code, it will be cached. 202 00:16:06,160 --> 00:16:07,940 And the JIT compiler will not be used. 203 00:16:09,000 --> 00:16:15,240 And this is interesting to us because when the JIT compiler is used, an event will be generated. 204 00:16:15,800 --> 00:16:19,740 Which means that an event will be generated whenever a .NET method is first utilized. 205 00:16:20,640 --> 00:16:23,920 Subsequently, it will not be generated because the code will have been cached. 206 00:16:25,800 --> 00:16:30,860 So, with this, we actually have two events that we can use to detect in-memory assembly load indicators. 207 00:16:31,560 --> 00:16:35,760 Firstly, the event related to the loading of .NET assembly. 208 00:16:36,160 --> 00:16:38,300 As well as event related to JIT compilation. 209 00:16:40,040 --> 00:16:44,920 So, what I have here is an output snippet from my Python POC code. 210 00:16:45,600 --> 00:16:50,360 So, firstly, we can detect the loading of my assembly without a path. 211 00:16:50,680 --> 00:16:52,740 And that is through the events of assembly load. 212 00:16:53,160 --> 00:16:57,220 And secondly, we can actually attempt to trace what the assembly was doing. 213 00:16:57,320 --> 00:17:01,560 In this case, we see that the assembly was trying to call upon the constructor class. 214 00:17:01,560 --> 00:17:05,680 And if you look back at what I was trying to achieve previously with my flowchart, 215 00:17:05,900 --> 00:17:09,960 I was actually trying to reference an assembly and load an instance out of it. 216 00:17:11,960 --> 00:17:17,360 So, to sum it up, we actually are able to detect indicators related to in-memory assembly loads. 217 00:17:19,060 --> 00:17:21,180 So now, let's look at another indicator. 218 00:17:21,740 --> 00:17:25,400 We're going to look at indicators for .NET API related to the registry creation. 219 00:17:27,480 --> 00:17:30,960 So, we used JIT compilation was quite useful for us previously. 220 00:17:31,560 --> 00:17:32,480 So, can we use this? 221 00:17:34,780 --> 00:17:39,480 Unfortunately, we can't because JIT compilation doesn't occur for native .NET assembly. 222 00:17:40,260 --> 00:17:42,240 And what I mean by native .NET assembly? 223 00:17:42,560 --> 00:17:46,740 I mean libraries like system.txt whereby as a C-sharp programmer, 224 00:17:47,140 --> 00:17:51,600 you'll reference system.txt to allow you to call upon the console.WriteLine function 225 00:17:51,600 --> 00:17:55,300 to print out statements to the, to output out statements to the console. 226 00:17:56,580 --> 00:18:00,680 And this happens because when a .NET framework is installed, 227 00:18:01,560 --> 00:18:04,460 the .NET, native .NET assemblies are installed as well. 228 00:18:04,960 --> 00:18:09,120 And once they're installed, they'll actually be compiled to native code and cached 229 00:18:09,120 --> 00:18:12,580 by something known as the native image generator, NGEN. 230 00:18:12,680 --> 00:18:18,120 So, essentially, it compiles the .NET assembly to native images and it will cache them. 231 00:18:19,280 --> 00:18:23,860 And because of this, because they are cached, JIT compilation will not occur. 232 00:18:24,860 --> 00:18:30,900 And because of that, we are not really able to actually detect indicators related to 233 00:18:30,900 --> 00:18:34,220 the use of native .NET APIs for registry creation. 234 00:18:35,440 --> 00:18:38,800 So, let's move on to our final indicator. 235 00:18:39,160 --> 00:18:42,180 Indicators related to the invoking of native API. 236 00:18:44,660 --> 00:18:50,760 So, we can use an ETLV event known as InteropEvents to help us with this. 237 00:18:52,540 --> 00:18:59,160 So, these are essentially events generated whenever a .NET assembly makes a call towards the Windows native API. 238 00:19:00,960 --> 00:19:03,300 And this is an example of a native code. 239 00:19:03,440 --> 00:19:10,160 As you have seen earlier from my message box, it was actually a native function that I imported from the User32 DLL library. 240 00:19:11,960 --> 00:19:14,680 And with that, we're actually able to detect an event towards it, 241 00:19:14,780 --> 00:19:19,400 whereby you're able to see my assembly call invoking the message box. 242 00:19:20,120 --> 00:19:22,180 So, native API is very useful. 243 00:19:22,340 --> 00:19:30,160 Like, you could use it to do a lot of interesting activities such as you could use a native API to send an outbound network connection. 244 00:19:30,160 --> 00:19:32,880 But, track actors can also abuse this. 245 00:19:33,200 --> 00:19:35,660 Track actors can use it to do key logging. 246 00:19:36,160 --> 00:19:41,580 They can use it to extract credentials from memory and any other malicious activities that you can think of. 247 00:19:42,460 --> 00:19:45,860 So, us having visibility on this is really useful as well. 248 00:19:47,040 --> 00:19:51,380 So, to sum it up, we're actually able to detect two out of three. 249 00:19:51,620 --> 00:19:53,320 So, pretty good, I would say. 250 00:19:54,560 --> 00:19:58,280 Now, let's use what we have learned on an actual demonstration. 251 00:19:58,980 --> 00:20:03,860 We're going to demonstrate our indicators on a real-world example, Silent Trinity. 252 00:20:04,560 --> 00:20:12,560 So, Silent Trinity is a post-exploitation framework which is coded in Ion Python. 253 00:20:13,180 --> 00:20:17,660 So, Ion Python is essentially Python that is tightly coupled towards the .NET library. 254 00:20:18,400 --> 00:20:21,900 And with that, we're going to do two things. 255 00:20:22,100 --> 00:20:23,640 We're going to launch a .NET assembly, 256 00:20:23,820 --> 00:20:26,940 which will be responsible for launching 257 00:20:26,940 --> 00:20:30,900 all the other assemblies, like all the Silent Trinity assemblies. 258 00:20:32,100 --> 00:20:33,960 And we're going to launch Safety Cats. 259 00:20:34,140 --> 00:20:35,460 We're going to do something malicious now. 260 00:20:35,720 --> 00:20:38,600 We're going to launch Safety Cats, a credential extraction tool. 261 00:20:41,560 --> 00:20:47,780 So, on my right, right here is a console which basically holds my stager, 262 00:20:47,900 --> 00:20:48,940 my Silent Trinity stager. 263 00:20:49,080 --> 00:20:53,960 It's an XML file which will be built by msbuild.exe. 264 00:20:54,960 --> 00:20:56,560 And on the left here, 265 00:20:56,560 --> 00:21:01,300 is my Python POT script that is mainly used for the event tracing. 266 00:21:04,540 --> 00:21:07,240 So, I'm going to execute the Python script first 267 00:21:07,240 --> 00:21:09,400 before executing the Silent Trinity stager. 268 00:21:18,360 --> 00:21:19,960 So, I've executed the Python script, 269 00:21:20,140 --> 00:21:22,580 and now I'm going to execute the Silent Trinity. 270 00:21:22,880 --> 00:21:26,160 As you can see, there's a whole bunch of output coming out now, 271 00:21:26,160 --> 00:21:27,620 because these are ATW events. 272 00:21:27,820 --> 00:21:29,040 There's a whole lot of information. 273 00:21:29,440 --> 00:21:32,060 So, we're going to ignore all this information for now, 274 00:21:32,200 --> 00:21:34,740 and we're going to move towards my attacker's machine, 275 00:21:36,060 --> 00:21:37,160 which is right here. 276 00:21:37,580 --> 00:21:39,200 And I'm going to run Safety Cats. 277 00:21:41,360 --> 00:21:44,200 I'm going to extract user credentials from my victim's machine. 278 00:21:45,460 --> 00:21:48,300 As you can see here, I grab out a bunch of user credentials. 279 00:21:51,000 --> 00:21:53,800 And now, let's move back to our victim's machine. 280 00:21:56,160 --> 00:21:58,180 And as you can see, we're still getting so much output here. 281 00:21:58,340 --> 00:22:01,200 And frankly, most of them aren't probably going to be very useful. 282 00:22:01,460 --> 00:22:05,540 So, I'm going to ignore this, and I'm going to minimize it. 283 00:22:05,880 --> 00:22:09,980 So, I've actually filtered out a bunch of necessary information for us to look at. 284 00:22:10,100 --> 00:22:12,240 And that is what you expect to do in the real world. 285 00:22:12,420 --> 00:22:16,720 In the real world, your base Windows telemetries are a whole bunch of data, 286 00:22:16,840 --> 00:22:17,840 and as defenders ourselves, 287 00:22:18,300 --> 00:22:21,080 we have to know how to filter the necessary data for us to look at. 288 00:22:22,140 --> 00:22:26,000 So, firstly, what I have right here is a bunch of assembly loading. 289 00:22:26,000 --> 00:22:27,360 of IMPython assemblies. 290 00:22:27,640 --> 00:22:30,660 And as you can see here, there is no path tag towards it, 291 00:22:30,740 --> 00:22:32,180 which is quite suspicious. 292 00:22:33,040 --> 00:22:35,100 IMPython by itself is not malicious, 293 00:22:35,380 --> 00:22:37,940 but it loading with a path is very anonymous, 294 00:22:38,260 --> 00:22:42,400 and most organizations typically will not execute IMPython on their state. 295 00:22:42,640 --> 00:22:47,280 So, having visibility of this will definitely give some form of anonymous activity. 296 00:22:49,120 --> 00:22:51,440 So, other than the in-memory assembly loads, 297 00:22:51,660 --> 00:22:53,900 we're going to see what it was actually doing. 298 00:22:57,720 --> 00:22:59,480 So, as you can see below here, 299 00:23:00,940 --> 00:23:03,760 several interesting native API calls were actually made, 300 00:23:03,900 --> 00:23:07,680 such as load library, virtual-alloc, get-proc-address. 301 00:23:07,920 --> 00:23:09,800 So, probably legitimate stuff, 302 00:23:10,020 --> 00:23:13,400 but there are actually activities that can be used to do code injection as well. 303 00:23:14,420 --> 00:23:16,940 And there's one more native API that is quite interesting, 304 00:23:17,060 --> 00:23:19,880 which will be more specific to what we're actually looking at. 305 00:23:21,840 --> 00:23:25,000 And it's something known as the mini-write-dump, 306 00:23:25,000 --> 00:23:26,800 which I will show you now. 307 00:23:27,840 --> 00:23:30,160 So, for extracting credentials from memory, 308 00:23:30,340 --> 00:23:33,140 typically you would target a process such as lsess, 309 00:23:33,360 --> 00:23:35,400 and you would dump its contents out. 310 00:23:35,760 --> 00:23:39,860 Mini-dump-write allows a user to grab a handle towards a process, 311 00:23:40,080 --> 00:23:42,940 and dump its contents to a file. 312 00:23:43,140 --> 00:23:45,260 And that is essentially what is happening here. 313 00:23:46,180 --> 00:23:49,220 So, having all this visibility actually helped us in trying to determine 314 00:23:49,220 --> 00:23:51,360 whether a bad .NET code was being run. 315 00:23:53,380 --> 00:23:54,980 So, just to sum up, 316 00:23:55,000 --> 00:23:58,420 all the telemetry that I have discussed. 317 00:24:00,480 --> 00:24:02,220 Firstly, .NET Runtime DL. 318 00:24:03,540 --> 00:24:09,280 So, basically, we can hunt for binaries that do not execute .NET code, 319 00:24:09,400 --> 00:24:12,560 and we see that this binary contains a .NET Runtime DL, 320 00:24:12,780 --> 00:24:16,020 there is something suspicious that we can potentially leverage on. 321 00:24:17,440 --> 00:24:19,740 We can also look at .NET ETW events, 322 00:24:19,900 --> 00:24:23,700 and with ETW events, it's a wealth of information for us to look through 323 00:24:23,700 --> 00:24:24,980 to actually determine whether or not 324 00:24:25,000 --> 00:24:27,300 what the .NET code was attempting to run. 325 00:24:29,840 --> 00:24:32,020 And we have other telemetries as well. 326 00:24:32,340 --> 00:24:33,900 If we base on a cyber queue chain, 327 00:24:34,540 --> 00:24:39,320 you expect a .NET code to occur at the execution phase, 328 00:24:40,660 --> 00:24:43,860 and typically you can argue that a .NET code could be executed 329 00:24:43,860 --> 00:24:45,980 at the persistent phase, the control phase, 330 00:24:46,140 --> 00:24:47,940 but all these leave different indicators. 331 00:24:49,340 --> 00:24:50,500 At the persistent phase, 332 00:24:50,700 --> 00:24:53,660 you can hunt for registry locations, scheduled tasks. 333 00:24:53,660 --> 00:24:55,200 At the control channel, 334 00:24:56,240 --> 00:24:59,700 an attacker can use a .NET code to communicate with the C2 channel, 335 00:24:59,840 --> 00:25:01,380 but that will leave network indicators. 336 00:25:01,760 --> 00:25:03,340 You could find, within a day, 337 00:25:03,480 --> 00:25:06,060 how many outbound connections towards a particular IP address, 338 00:25:06,720 --> 00:25:09,020 and how about before even the .NET code was being executed? 339 00:25:09,260 --> 00:25:10,500 How was it even delivered? 340 00:25:11,040 --> 00:25:13,500 What are the delivery mechanisms used to actually deliver it? 341 00:25:13,600 --> 00:25:14,760 We can hunt for such behavior, 342 00:25:14,900 --> 00:25:16,620 and with all these indicators put together, 343 00:25:16,960 --> 00:25:20,760 we actually paint a whole complete picture on how to detect a bad .NET code, 344 00:25:20,880 --> 00:25:23,140 which allows us to determine what actually happened. 345 00:25:23,660 --> 00:25:26,460 So, having a robust detection strategy like this 346 00:25:26,460 --> 00:25:30,200 aids us in trying to actually determine, 347 00:25:30,460 --> 00:25:32,660 in trying to detect bad track actors. 348 00:25:35,760 --> 00:25:38,740 So, I guess to wrap it up on what I've discussed, 349 00:25:39,540 --> 00:25:44,220 PowerShell is still a very good weapon of choice for track actors, 350 00:25:44,420 --> 00:25:48,400 but defenders have gotten better at detecting them. 351 00:25:48,680 --> 00:25:51,840 There are more opportunities to detect bad PowerShell code, 352 00:25:51,960 --> 00:25:52,560 so, 353 00:25:53,660 --> 00:25:54,700 as compared to what it was in the past, 354 00:25:54,860 --> 00:25:56,280 it's not as hard as it was before. 355 00:25:57,980 --> 00:25:59,340 And, attackers being attackers, 356 00:25:59,900 --> 00:26:02,000 they're always moving to different techniques and tooling, 357 00:26:02,180 --> 00:26:05,160 and one of them is .NET attacks. 358 00:26:05,560 --> 00:26:07,060 But, as I have shown here, 359 00:26:07,780 --> 00:26:09,740 .NET attacks aren't that invincible themselves. 360 00:26:10,140 --> 00:26:11,180 We can actually detect them. 361 00:26:11,880 --> 00:26:13,240 And lastly, more importantly, 362 00:26:13,400 --> 00:26:14,440 is to try all this yourself. 363 00:26:15,000 --> 00:26:16,560 All the things that I've demonstrated here, 364 00:26:16,680 --> 00:26:17,660 they are all open source. 365 00:26:18,180 --> 00:26:21,380 The Python POC code that I was demonstrating earlier, 366 00:26:21,940 --> 00:26:23,640 you can actually find it on countless sites, 367 00:26:23,660 --> 00:26:24,140 such as Github. 368 00:26:24,380 --> 00:26:26,540 Silent Trinity, you can also find on Github. 369 00:26:26,580 --> 00:26:30,460 Process Hacker is also an open source tool. 370 00:26:31,860 --> 00:26:34,780 So, I guess this marks the end of my presentation. 371 00:26:35,120 --> 00:26:36,700 So, any questions? 372 00:26:40,880 --> 00:26:41,320 Okay. 373 00:26:41,780 --> 00:26:42,500 All right, then. 374 00:26:43,160 --> 00:26:43,760 Thank you. 375 00:26:44,000 --> 00:26:44,940 Oh, wait, is there a question? 376 00:26:45,420 --> 00:26:45,980 All right. 377 00:26:54,140 --> 00:26:54,780 I'm sorry. 378 00:26:55,020 --> 00:26:56,200 All right. 379 00:26:57,180 --> 00:26:57,820 . 380 00:26:57,820 --> 00:26:58,280 . 381 00:26:58,280 --> 00:26:58,600 . 382 00:26:58,600 --> 00:26:58,740 . 383 00:26:58,740 --> 00:26:58,820 . 384 00:26:58,820 --> 00:26:59,020 . 385 00:26:59,020 --> 00:26:59,340 . 386 00:26:59,340 --> 00:26:59,540 . 387 00:26:59,540 --> 00:27:00,100 Thanks for watching!