1 00:00:05,920 --> 00:00:11,560 Thank you everybody for coming to Game Changing Advances in Windows shellcode analysis. 2 00:00:12,840 --> 00:00:18,260 So shellcode, it's always out there lurking somewhere, causing problems. 3 00:00:18,700 --> 00:00:27,600 And a problem until very, very recently is there just has not been adequate tooling to address shellcode. 4 00:00:27,600 --> 00:00:32,760 Well, we have aimed and succeeded in changing that. 5 00:00:32,960 --> 00:00:34,800 And we're thrilled to show you how. 6 00:00:35,580 --> 00:00:36,960 So a little bit about ourselves. 7 00:00:37,320 --> 00:00:38,900 My name is Dr. Bramwell-Brizendine. 8 00:00:39,080 --> 00:00:41,980 I am a professor, former director of the Verona Lab. 9 00:00:42,320 --> 00:00:44,880 And I've created quite a number of different tools. 10 00:00:45,280 --> 00:00:54,240 Joprocket, Shell Wasp, co-creator of Sharem, and also Roprocket, which we'll be presenting on Sunday. 11 00:00:55,000 --> 00:00:57,580 I do have a PhD in cyber operations. 12 00:00:57,600 --> 00:01:00,320 From Dakota State, which is a highly technical degree. 13 00:01:01,240 --> 00:01:05,540 And now we will let one of my former students, Jake, introduce himself. 14 00:01:07,580 --> 00:01:08,360 Hey, everyone. 15 00:01:08,480 --> 00:01:09,160 I'm Jake. 16 00:01:09,320 --> 00:01:14,640 I'm a recent college grad now working as a reverse engineer at the Johns Hopkins University Applied Physics Laboratory. 17 00:01:15,180 --> 00:01:19,660 I worked on the Sharem project as a graduate researcher in Dr. Brizendine's Verona Lab. 18 00:01:19,820 --> 00:01:22,240 And I'm still an active contributor to the project now. 19 00:01:23,020 --> 00:01:23,780 Here's Max. 20 00:01:26,700 --> 00:01:27,220 Hello. 21 00:01:27,600 --> 00:01:28,060 Hello, everybody. 22 00:01:28,260 --> 00:01:29,400 My name is Max Gerson. 23 00:01:29,520 --> 00:01:30,840 I go by the nickname of Libra. 24 00:01:30,940 --> 00:01:33,080 I work for Trellix in the Advanced Research Center. 25 00:01:33,260 --> 00:01:35,960 And I like to write blogs about the research I do. 26 00:01:36,080 --> 00:01:38,720 I'm a malware analyst and reverse engineer by trade. 27 00:01:38,940 --> 00:01:42,040 I do that both as a personal hobby and for work. 28 00:01:42,420 --> 00:01:49,240 And in here I'm representing Trellix and presenting the JITR script that relates to this. 29 00:01:55,620 --> 00:02:01,680 So first, let's talk about why shellcode is a topic of interest to us and why we decided to develop the Sharem project in the first place. 30 00:02:02,340 --> 00:02:05,440 So we see shellcode quite frequently in the world of malware and exploitation. 31 00:02:06,280 --> 00:02:09,380 The common objective of malware is to remain hidden and obfuscated. 32 00:02:09,700 --> 00:02:11,820 So shellcode makes a great tool for these objectives. 33 00:02:12,100 --> 00:02:15,100 Its inherent obscure nature makes it difficult to statically analyze. 34 00:02:16,120 --> 00:02:18,860 An example of such a challenge is Windows API identification. 35 00:02:20,120 --> 00:02:25,760 When examining a normal piece of malware, like a PE file executable, you'd expect to see labeled Windows API calls. 36 00:02:26,780 --> 00:02:29,540 But this isn't a luxury we have when we're dealing with shellcode. 37 00:02:29,780 --> 00:02:32,940 Shellcode has to manually go in and resolve API addresses manually. 38 00:02:33,480 --> 00:02:38,160 So what you'll wind up with is something like a call EDI instead of a nice clean call win exec. 39 00:02:39,020 --> 00:02:41,560 So this call EDI isn't much for us to go off of. 40 00:02:41,700 --> 00:02:44,520 So we have to go in and perform a bunch of static or dynamic analysis. 41 00:02:44,940 --> 00:02:46,880 And then this challenge doesn't scale well either. 42 00:02:46,880 --> 00:02:54,320 If there's many shellcode APIs called, then this is going to take a ton of time for us to go in and find out. 43 00:02:55,720 --> 00:03:01,760 So issues like this and some of the other headaches when dealing with shellcode are why we decided there's a need for more tooling to solve these challenges. 44 00:03:02,640 --> 00:03:04,020 Which is where Sharem comes in. 45 00:03:04,120 --> 00:03:06,060 Our game-changing solution to shellcode analysis. 46 00:03:08,140 --> 00:03:09,080 So what is Sharem? 47 00:03:09,340 --> 00:03:13,420 Sharem aims to be the complete all-in-one comprehensive solution to Windows shellcode analysis. 48 00:03:13,960 --> 00:03:16,520 It's loaded with a bunch of features that we'll cover in this talk. 49 00:03:16,880 --> 00:03:19,340 We have a shellcode emulator that's built on Unicorn. 50 00:03:19,560 --> 00:03:24,800 This helps us deal with some of those Windows API identification problems I was mentioning earlier. 51 00:03:25,160 --> 00:03:31,420 And then we have a few other unique features such as complete code coverage that helps us unravel unexplored paths of shellcode. 52 00:03:32,460 --> 00:03:37,000 We also include a fully accurate disassembler that's labeled and enhanced by our emulation results. 53 00:03:37,480 --> 00:03:44,820 Then we have a few other features that are helpful for us unraveling deceptive shellcode encoding and obfuscation. 54 00:03:45,940 --> 00:03:46,860 This tool is really useful. 55 00:03:46,860 --> 00:03:51,020 It supports for Windows shellcode only, but we include support for both 64-bit and 32-bit shellcodes. 56 00:03:51,320 --> 00:03:56,660 And now we're revealing for the first time at this presentation a brand new Ghidra plugin that was developed by Max at Trellix. 57 00:03:59,060 --> 00:04:00,900 Alright, so let's talk about Sharem's emulator. 58 00:04:02,260 --> 00:04:05,080 Sharem's emulator is built with Unicorn's CPU emulation framework. 59 00:04:05,420 --> 00:04:09,880 It's able to hook and log over 20,000 Windows APIs across over 60 DLLs. 60 00:04:10,060 --> 00:04:13,540 And it wouldn't be a shellcode emulator unless we also supported syscalls as well. 61 00:04:13,780 --> 00:04:16,600 We baked in a support for about 99% of those. 62 00:04:17,660 --> 00:04:22,220 Sharem does analysis on raw .bin files as well as the hex byte representation of shellcode. 63 00:04:22,620 --> 00:04:27,540 One of the highlights of this tool is its use for high-level indicator of compromised analysis. 64 00:04:28,340 --> 00:04:32,400 Running a shellcode in emulation provides a detailed summary of what the shellcode is doing. 65 00:04:33,020 --> 00:04:39,600 You'll be able to see things like what Windows APIs were used, what file paths were accessed, or what URLs were reached out to. 66 00:04:40,440 --> 00:04:45,500 Also great is that all of the knowledge we gather from emulation is leveraged elsewhere in the Sharem tool. 67 00:04:47,680 --> 00:04:53,080 So with the high-level details out of the way, I want to dig a step deeper and talk about some of the implementation details of our emulator. 68 00:04:53,700 --> 00:04:58,040 So Unicorn's bare-bones framework that kind of just gives us the essentials needed to emulate code. 69 00:04:58,540 --> 00:05:02,700 The shellcode wouldn't get very far into emulation if you just tried to run it with vanilla Unicorn. 70 00:05:02,940 --> 00:05:09,420 There's a bunch of stuff we had to do to set up, to make sure our emulation looked and behaved like an actual Windows process. 71 00:05:10,760 --> 00:05:13,000 So an example of this is pebwalking. 72 00:05:14,260 --> 00:05:16,840 The peb is an internal Windows structure that's built into a shellcode. 73 00:05:16,840 --> 00:05:19,640 It is used to resolve DLL address, base addresses. 74 00:05:20,080 --> 00:05:23,540 But as the name implies, this technique is heavily reliant on the peb structure. 75 00:05:25,280 --> 00:05:30,400 So structures like the peb had to be implemented in high fidelity for our code to, emulated code to get anywhere. 76 00:05:31,980 --> 00:05:40,940 So now that our shellcode is able to walk the peb and find a DLL address, the next step is to parse the DLL and loop through the tables until we find the DLL we're looking, API we're looking for. 77 00:05:42,140 --> 00:05:45,820 So in our emulation, what's the shellcode actually parsing as a DLL? 78 00:05:45,820 --> 00:05:48,000 The answer is actual DLLs. 79 00:05:48,120 --> 00:05:55,640 We load the DLL straight into memory from disk and apply a special formula to get them to execution size. 80 00:05:56,180 --> 00:05:59,760 As we're loading them into disk, we create references to them in a dictionary. 81 00:05:59,920 --> 00:06:02,720 So we'll be able to look them up at runtime once an API is called. 82 00:06:04,640 --> 00:06:06,400 Which gets us into API emulation. 83 00:06:06,720 --> 00:06:09,620 So now our emulation is able to locate a Windows API. 84 00:06:09,840 --> 00:06:11,960 What happens once the API is actually called? 85 00:06:12,260 --> 00:06:15,800 Our emulator will log the invoked API along with all the parameters that it needs. 86 00:06:17,020 --> 00:06:21,560 Once the API emulation finishes, this information is printed out to the screen for the user to see. 87 00:06:22,180 --> 00:06:26,340 This information is very useful as it can give you a really good idea of what the shellcode is doing. 88 00:06:27,080 --> 00:06:30,300 In the example on the right here, we have a metasploit shellcode. 89 00:06:30,560 --> 00:06:36,820 And it's really obvious to see here that this is a bind shellcode that's opening a bind interface over port 8721. 90 00:06:40,120 --> 00:06:43,020 So now what goes on underneath the hood during an emulated API call? 91 00:06:43,560 --> 00:06:45,800 For some APIs, it's not enough to just simply log in. 92 00:06:45,820 --> 00:06:47,960 You can simply log the call, then return an arbitrary value. 93 00:06:48,420 --> 00:06:49,920 Take virtual alloc, for example. 94 00:06:50,220 --> 00:06:53,500 The virtual alloc API goes and creates a usable region of memory. 95 00:06:54,000 --> 00:06:57,480 But the shellcode's probably expecting to actually do something with that memory. 96 00:06:57,640 --> 00:06:59,500 Probably read, write, and or execute. 97 00:07:00,120 --> 00:07:03,360 If the emulation doesn't actually go out and create that usable region of memory, 98 00:07:03,580 --> 00:07:05,780 the shellcode will probably fail to emulate properly. 99 00:07:06,560 --> 00:07:12,260 So for essential functions like this, we wrote out handwritten hooks that will go out and perform whatever steps necessary 100 00:07:12,260 --> 00:07:15,320 to keep the high fidelity representation of shellcode emulation alive. 101 00:07:16,120 --> 00:07:20,600 So for our virtual alloc example here, our API hook will use Unicorn's memmap 102 00:07:20,600 --> 00:07:23,080 to actually go out and create more memory space for us. 103 00:07:23,500 --> 00:07:26,760 Currently, we have support for over 600 of these API hooks. 104 00:07:29,420 --> 00:07:33,760 Now, doing manual written hooks for this for over 20,000 APIs is a big undertaking. 105 00:07:34,140 --> 00:07:37,140 So we've implemented as many as we could for all the security-relevant APIs 106 00:07:37,780 --> 00:07:39,340 that shellcode would likely want to play with. 107 00:07:39,920 --> 00:07:43,820 We built dictionaries that will look up the required parameters for each API as well as their types. 108 00:07:43,820 --> 00:07:47,480 Also determined through this lookup dictionary is an appropriate default return value 109 00:07:47,480 --> 00:07:49,100 based on the return type for the API. 110 00:07:49,780 --> 00:07:52,640 Default return values can also be specified through config options. 111 00:07:53,220 --> 00:07:56,980 So now turning over to Dr. Brizendine for some more information on how we emulate syscalls. 112 00:08:05,860 --> 00:08:07,720 Alright, thank you very much, Jake. 113 00:08:08,060 --> 00:08:13,340 So Windows syscalls are something that until very recently, 114 00:08:15,140 --> 00:08:24,400 had not been supported whatsoever in terms of these types of what we're doing. 115 00:08:24,700 --> 00:08:35,800 So Windows syscalls have become very popular, very trendy in the last few years. 116 00:08:36,060 --> 00:08:40,420 But up until about 2018, that had not been the case. 117 00:08:40,760 --> 00:08:41,560 Previously, 118 00:08:43,860 --> 00:08:51,020 virtually the only Windows syscall had, in terms of shellcode, had been egg hunters. 119 00:08:51,300 --> 00:08:54,860 Egg hunters were where you can go and search through process memory 120 00:08:54,860 --> 00:08:57,720 for something like a tag such as woot woot. 121 00:08:57,920 --> 00:09:03,620 Once you find that tag, then you can redirect control to that particular location. 122 00:09:04,040 --> 00:09:11,820 So we had assumed naturally that there would be many other Windows syscalls out there being used in shellcode. 123 00:09:12,340 --> 00:09:13,800 But the reality was, 124 00:09:13,820 --> 00:09:15,460 that was simply not the case. 125 00:09:16,080 --> 00:09:18,560 Instead, it was just simply egg hunters. 126 00:09:19,020 --> 00:09:20,900 Now as part of this research, 127 00:09:21,060 --> 00:09:27,140 we actually received a $300,000 NSA research grant to develop this. 128 00:09:27,380 --> 00:09:35,240 And so we wanted to make sure that we were able to successfully emulate Windows syscalls. 129 00:09:35,640 --> 00:09:37,780 So since that really hadn't been done, 130 00:09:38,040 --> 00:09:41,860 we went and developed our own techniques and tooling 131 00:09:41,860 --> 00:09:43,840 to help facilitate that. 132 00:09:44,000 --> 00:09:45,960 That was a previous DEF CON talk, 133 00:09:46,240 --> 00:09:47,840 which we also expanded, 134 00:09:48,080 --> 00:09:49,620 very much so, 135 00:09:49,860 --> 00:09:52,320 at Hack in the Box 2023. 136 00:09:57,700 --> 00:10:02,800 So how exactly do we emulate these Windows syscalls? 137 00:10:03,980 --> 00:10:06,940 Now in terms of something like stack cleanup, 138 00:10:07,080 --> 00:10:08,480 when we have Windows APIs, 139 00:10:08,840 --> 00:10:10,100 it is necessary to, 140 00:10:10,920 --> 00:10:11,520 internally, 141 00:10:11,720 --> 00:10:12,840 do the stack cleanup. 142 00:10:12,940 --> 00:10:13,900 But Windows syscalls, 143 00:10:14,500 --> 00:10:16,000 the opposite is true. 144 00:10:16,180 --> 00:10:19,640 So the shellcode author is responsible for that cleanup. 145 00:10:19,760 --> 00:10:22,120 So we do not do that ourselves. 146 00:10:23,180 --> 00:10:26,140 And for those of you who are familiar with Windows syscalls, 147 00:10:26,520 --> 00:10:28,620 the way in which we invoked them is, 148 00:10:28,680 --> 00:10:32,500 we will provide a particular value in the EAX register, 149 00:10:32,880 --> 00:10:37,260 such as hex 18 for NT allocated virtual memory. 150 00:10:37,600 --> 00:10:40,020 And for every different OS build, 151 00:10:40,100 --> 00:10:40,880 of Windows, 152 00:10:41,300 --> 00:10:44,080 these SSNs will change. 153 00:10:44,620 --> 00:10:47,440 And so in order to emulate them, 154 00:10:47,560 --> 00:10:51,180 we need to specify the particular Windows OS 155 00:10:51,180 --> 00:10:52,320 that we are wanting to do, 156 00:10:52,460 --> 00:10:54,640 to make sure we get accurate results. 157 00:10:56,180 --> 00:10:57,760 In this example here, 158 00:10:58,000 --> 00:11:01,940 we see that we have NT allocate virtual memory. 159 00:11:03,500 --> 00:11:07,440 And the particular OS build is identified. 160 00:11:08,560 --> 00:11:09,520 With that, 161 00:11:09,520 --> 00:11:11,100 we will turn it over to Jake. 162 00:11:17,360 --> 00:11:18,940 So in analyzing SHRM's output, 163 00:11:19,140 --> 00:11:21,080 we try to make things as easy on the user as possible 164 00:11:21,080 --> 00:11:23,060 to understand the various parameters and values. 165 00:11:23,560 --> 00:11:24,480 So for example, 166 00:11:24,560 --> 00:11:25,800 it may not be immediately obvious 167 00:11:25,800 --> 00:11:29,060 what a value of 0x40 means for an FL protect parameter, 168 00:11:29,620 --> 00:11:32,440 but page execute read write is a lot more useful. 169 00:11:33,180 --> 00:11:36,020 SHRM will also try to parse structures and strings whenever necessary. 170 00:11:36,520 --> 00:11:37,980 So here in the bottom screenshot, 171 00:11:37,980 --> 00:11:40,600 we have a call to win exec with calc.exe. 172 00:11:41,400 --> 00:11:43,460 You'll see that calc.exe is printed 173 00:11:43,460 --> 00:11:46,120 instead of the address that points to it. 174 00:11:47,960 --> 00:11:50,000 Another thing we do to make parsing the output easier 175 00:11:50,000 --> 00:11:51,280 is include some artifacts 176 00:11:51,280 --> 00:11:53,180 that are extracted from regular expressions. 177 00:11:53,920 --> 00:11:55,640 Under the artifact section of output, 178 00:11:55,880 --> 00:11:57,120 you can find IOC information, 179 00:11:57,380 --> 00:11:58,260 such as commands run, 180 00:11:58,520 --> 00:11:59,540 files and paths references, 181 00:11:59,860 --> 00:12:00,720 and URL addresses. 182 00:12:01,460 --> 00:12:03,160 Here we have another shellcode example. 183 00:12:03,500 --> 00:12:04,220 In this one, 184 00:12:04,240 --> 00:12:05,920 you can see that a bunch of commands were run, 185 00:12:06,080 --> 00:12:07,580 one to stop Windows Defender, 186 00:12:07,580 --> 00:12:09,440 a couple other malicious actions, 187 00:12:09,740 --> 00:12:11,820 and then we can see a Chrome updates dot back 188 00:12:11,820 --> 00:12:13,720 artifact interacted with as well. 189 00:12:16,180 --> 00:12:18,060 So one optional feature we also include 190 00:12:18,060 --> 00:12:20,280 is the ability to pull live artifacts from over the web. 191 00:12:20,760 --> 00:12:23,140 Suppose the malicious shellcodes reaches out over HTTP 192 00:12:23,140 --> 00:12:25,100 to grab some sort of second stage 193 00:12:25,100 --> 00:12:26,200 or other external dependency, 194 00:12:26,660 --> 00:12:29,900 you may want to actually go and grab this file as well. 195 00:12:30,220 --> 00:12:32,280 This option is there to support that. 196 00:12:32,740 --> 00:12:33,500 If successful, 197 00:12:33,660 --> 00:12:35,560 an MD5 hash will automatically be performed 198 00:12:35,560 --> 00:12:37,440 on this download as well. 199 00:12:39,240 --> 00:12:40,540 Here's an example of that in action. 200 00:12:40,900 --> 00:12:42,020 Here we have a shellcode 201 00:12:42,020 --> 00:12:43,340 that pulls down an executable file 202 00:12:43,340 --> 00:12:44,880 called some payload dot exe. 203 00:12:45,460 --> 00:12:47,080 Sherm will actually issue a get request 204 00:12:47,080 --> 00:12:48,060 to pull down that file, 205 00:12:48,180 --> 00:12:49,920 then load it into memory if necessary, 206 00:12:50,040 --> 00:12:50,940 if it's interactive with later. 207 00:12:51,700 --> 00:12:53,960 You can also see that an MD5 hash of the file 208 00:12:53,960 --> 00:12:55,140 is included as part of the output. 209 00:12:58,040 --> 00:12:59,940 Another nice part about Sherm's emulation output 210 00:12:59,940 --> 00:13:01,500 is its ability to apply structure 211 00:13:01,500 --> 00:13:02,620 to parameters in APIs. 212 00:13:03,440 --> 00:13:05,820 For parameters that pass entire structures 213 00:13:05,820 --> 00:13:07,500 instead of just standalone values, 214 00:13:07,580 --> 00:13:09,200 Sherm will enumerate through 215 00:13:09,200 --> 00:13:10,800 and label all members of the structure. 216 00:13:13,260 --> 00:13:14,380 Here's an example of that. 217 00:13:14,780 --> 00:13:16,680 Instead of just a pointer value 218 00:13:16,680 --> 00:13:18,280 for these two structures, 219 00:13:18,560 --> 00:13:20,500 you'll see an expanded list 220 00:13:20,500 --> 00:13:22,400 of all the members of the structure included. 221 00:13:25,960 --> 00:13:27,920 Not only does it enumerate and label structures, 222 00:13:28,280 --> 00:13:29,900 but it also labels nested structures 223 00:13:29,900 --> 00:13:30,900 while it's recursive. 224 00:13:31,320 --> 00:13:33,960 For this LP time zone information structure, 225 00:13:34,240 --> 00:13:35,540 you'll see the standard date 226 00:13:35,540 --> 00:13:37,560 and daylight date nested structures as well. 227 00:13:41,580 --> 00:13:44,460 There's also instances where APIs will use unions, 228 00:13:44,720 --> 00:13:45,840 which is essentially a parameter 229 00:13:45,840 --> 00:13:47,700 that shares the same memory space. 230 00:13:48,460 --> 00:13:50,180 Sherm is verbose enough to delineate 231 00:13:50,180 --> 00:13:51,940 this level of information in its output. 232 00:13:54,920 --> 00:13:57,380 The Windows Registry is another area of interest 233 00:13:57,380 --> 00:13:58,080 for shellcode, 234 00:13:58,220 --> 00:13:59,480 which is why we also developed 235 00:13:59,480 --> 00:14:01,020 a Registry Manager for our emulation. 236 00:14:01,680 --> 00:14:03,940 The Sherm Registry Manager helps us track 237 00:14:03,940 --> 00:14:06,060 and stub out actions for our emulated registry. 238 00:14:06,980 --> 00:14:07,560 The Registry Manager helps us track 239 00:14:07,580 --> 00:14:07,760 the actions we see on the registry. 240 00:14:07,760 --> 00:14:10,040 The Registry Manager maps hex values 241 00:14:10,040 --> 00:14:10,920 to actual paths 242 00:14:10,920 --> 00:14:14,480 so when registry addresses are printed as output 243 00:14:14,480 --> 00:14:16,160 you'll see the full registry path 244 00:14:16,160 --> 00:14:18,120 instead of just some random address. 245 00:14:20,780 --> 00:14:22,520 We have a bunch of custom hooks 246 00:14:22,520 --> 00:14:24,020 written for the registry-related APIs 247 00:14:24,020 --> 00:14:26,420 and try to simulate some sort of success action 248 00:14:26,420 --> 00:14:27,100 whenever possible. 249 00:14:27,500 --> 00:14:29,700 This includes having our Sherm Registry Manager 250 00:14:29,700 --> 00:14:32,060 update various things in its faked-out registry 251 00:14:32,060 --> 00:14:33,580 that the shellcode can interact with. 252 00:14:34,040 --> 00:14:35,820 For output related to a registry, 253 00:14:36,060 --> 00:14:37,440 we also have some special parter 254 00:14:37,580 --> 00:14:42,340 mechanisms based on the MITRE framework to pick out any sort of registry actions that are security 255 00:14:42,340 --> 00:14:48,320 relevant to us. Here we have an example of one that does registry persistence for an executable 256 00:14:48,320 --> 00:14:56,000 file. Again, like the rest of our output, it's formatted in such a way that it's easy to parse 257 00:14:56,000 --> 00:15:01,400 for the end user. So for all references to H key, instead of just hex values, you'll actually see 258 00:15:01,400 --> 00:15:09,820 the full registry keys and paths and data. And all of these registry related things don't just 259 00:15:09,820 --> 00:15:14,640 apply to APIs. There's also support included for syscalls as well. This is an example of the NT 260 00:15:14,640 --> 00:15:20,220 create syscall for current version slash run to set up persistence. Again, this is immediately 261 00:15:20,220 --> 00:15:27,900 obvious due to the way that the output is labeled. So one final part of SHRM's output is 262 00:15:28,600 --> 00:15:31,380 timeless debugging information. This is essentially the way that we're going to use the 263 00:15:31,400 --> 00:15:36,800 log of every CPU instruction that we emulated along with register values. This is useful if you 264 00:15:36,800 --> 00:15:41,760 want to go back and review any of the instructions that were executed and evaluate the registers at 265 00:15:41,760 --> 00:15:46,100 that state. There's also an option to view a selected number of bytes from the stack as well. 266 00:15:48,000 --> 00:15:51,300 So this is what that timeless debugging log looks like. Here you can see all of the 267 00:15:51,300 --> 00:15:55,100 instructions and all of the registry values before and after each execution. 268 00:15:58,820 --> 00:16:01,300 So when developing this tool, we conducted a lot of research 269 00:16:01,400 --> 00:16:07,860 from public sandboxes and shellcode repositories. We found that 64-bit shellcode is a lot less 270 00:16:07,860 --> 00:16:13,740 common than 32-bit. But rest assured, we also have support for 64-bit shellcode emulation as well. 271 00:16:14,540 --> 00:16:18,120 So we have different but similar DLLs and internal Windows structures for this. 272 00:16:19,020 --> 00:16:23,160 So yeah, anything you can do in 32-bit, you can do in 64-bit for our tool. 273 00:16:24,020 --> 00:16:27,620 All right. Now turning back over to Dr. Brizendine for complete code coverage. 274 00:16:42,240 --> 00:16:49,440 Thank you for that. So this is one of the most important game changing aspects of all of this. 275 00:16:49,500 --> 00:16:56,180 Now some of you may be familiar with the idea of code coverage, but this is a very different twist 276 00:16:56,180 --> 00:17:01,160 on that concept. So with complete code coverage, we are going to, 277 00:17:01,160 --> 00:17:07,380 to all but guarantee that virtually every single code path is going to be executed. 278 00:17:09,180 --> 00:17:14,400 How do we achieve this functionality? Well, we instantiate it at the assembly level, 279 00:17:15,200 --> 00:17:23,180 and it works very well. So whenever we encounter an opportunity where we could go left, 280 00:17:23,260 --> 00:17:29,120 we could go right, we have a jump table, whatever the case may be, we can capture 281 00:17:31,160 --> 00:17:38,360 a particular location, including a snapshot of the stack. And we will maintain a list 282 00:17:38,360 --> 00:17:44,400 of all of these locations. Once the shellcode is about to terminate, 283 00:17:44,420 --> 00:17:50,580 if there are any unvisited code paths, then the shellcode will simply restart. 284 00:17:51,200 --> 00:17:59,300 And because we were able to save the CPU register state alongside a snapshot of the stack, 285 00:18:01,160 --> 00:18:08,940 and get the confirmation by doing that, we were able to capture APIs and log them that we otherwise 286 00:18:08,940 --> 00:18:16,040 would not have been able to, to do. So to give an example of why that is important. 287 00:18:16,640 --> 00:18:24,800 So this could be considered a form of dynamic analysis. So we could do dynamic analysis with a debugger. 288 00:18:24,960 --> 00:18:30,080 We possibly could tweak things a little bit to maybe cause it to, 289 00:18:31,160 --> 00:18:35,780 Just go on this direction that it went otherwise or we could detonate something 290 00:18:36,540 --> 00:18:38,060 in a piece of 291 00:18:38,900 --> 00:18:41,260 or detonate a shell code and a 292 00:18:41,260 --> 00:18:48,380 C style harness in a sandbox and just see what happens but with complete code coverage 293 00:18:48,950 --> 00:18:56,500 We can guarantee that we will see all of the possible code paths not simply those that would have been 294 00:18:58,070 --> 00:18:59,180 For that particular 295 00:19:00,040 --> 00:19:01,500 instance in the sandbox 296 00:19:03,320 --> 00:19:06,900 So to the left there you can see a shell code that was 297 00:19:07,960 --> 00:19:15,160 Written by a student of mine, and there are only two api's that are identified now one of these is get computer name a 298 00:19:15,160 --> 00:19:22,660 So it's looking for a very specific computer name, and if it's able to to get that computer name then 299 00:19:23,540 --> 00:19:26,060 It's going to do reg 300 00:19:26,720 --> 00:19:28,140 Set key value 301 00:19:28,140 --> 00:19:29,000 and 302 00:19:29,000 --> 00:19:29,160 it's 303 00:19:29,160 --> 00:19:34,060 Going to establish terminal server so unless we have that particular computer 304 00:19:34,820 --> 00:19:39,400 Name we should never be able to see that but with complete code coverage 305 00:19:39,400 --> 00:19:42,600 We are able to capture not only the api 306 00:19:42,600 --> 00:19:44,140 but all of the 307 00:19:44,780 --> 00:19:45,380 Correct 308 00:19:46,260 --> 00:19:48,480 parameters that would have been there otherwise 309 00:19:51,540 --> 00:19:59,100 So self-modifying code is also an important aspect of shell code so a lot of times our shell code 310 00:19:59,100 --> 00:20:03,940 May be encoded and the shell code will simply decode itself in memory 311 00:20:03,940 --> 00:20:11,040 I don't have a decoder stub to help facilitate that process and we can actually identify that through the use of 312 00:20:11,040 --> 00:20:13,680 fuzzy hashing in 313 00:20:13,680 --> 00:20:15,800 particular SS deep and 314 00:20:15,800 --> 00:20:23,400 So if we are able to identify that then we will simply take the decoded form and then that decoded form is what we will then 315 00:20:23,400 --> 00:20:27,860 Perform our analysis on and then we will also send that to the disassembler 316 00:20:28,260 --> 00:20:30,380 So at the bottom there you can see the 317 00:20:31,160 --> 00:20:33,640 Serum has identified successfully 318 00:20:34,860 --> 00:20:37,800 That this is indeed self-modifying code 319 00:20:39,120 --> 00:20:44,560 And this is an example of a shell code that is actually encoded 320 00:20:44,560 --> 00:20:52,740 But lo and behold we are seeing the actual api's that are being called we are seeing the parameters 321 00:20:53,600 --> 00:20:57,740 so really this is very much a game changer if you're 322 00:20:57,860 --> 00:20:59,600 dealing with encoded shellcode. 323 00:21:00,080 --> 00:21:03,440 You know, maybe somebody gives you a piece of shellcode 324 00:21:03,440 --> 00:21:06,840 and you're not quite sure what that is. 325 00:21:07,040 --> 00:21:10,080 Now, your options could be, I'm going to take that, 326 00:21:10,160 --> 00:21:11,840 I'm going to put it in a C-style harness, 327 00:21:12,540 --> 00:21:13,720 I'm going to debug it. 328 00:21:13,880 --> 00:21:17,840 Now, some parts of shellcode may be very repetitive. 329 00:21:18,280 --> 00:21:20,700 So, there could be loops that may occur 330 00:21:20,700 --> 00:21:22,880 hundreds or even thousands of times. 331 00:21:22,880 --> 00:21:27,420 And also, the fact that it's decoding itself in memory, 332 00:21:27,620 --> 00:21:29,180 it can be very, very tedious. 333 00:21:29,680 --> 00:21:32,080 But with ShareRum, we can instantly see 334 00:21:32,780 --> 00:21:35,240 what is going on inside of that shellcode. 335 00:21:36,300 --> 00:21:39,420 So, maybe a friend gave you a piece of shellcode, 336 00:21:39,660 --> 00:21:41,600 you're going to do that for some particular type 337 00:21:41,600 --> 00:21:46,320 of exploitation, but they snuck a little something extra 338 00:21:46,320 --> 00:21:49,280 in there, well, you could easily identify that. 339 00:21:50,660 --> 00:21:52,520 And so, this is the exact same 340 00:21:52,520 --> 00:21:54,260 shellcode in IDA Pro. 341 00:21:54,600 --> 00:21:58,420 And it's absolutely correct, but what we're seeing 342 00:21:58,420 --> 00:22:01,300 is a series of encrypted bytes, 343 00:22:02,140 --> 00:22:04,840 so it's pretty much absolutely meaningless 344 00:22:05,520 --> 00:22:08,440 for the human analyst who's trying to go through this 345 00:22:08,440 --> 00:22:10,840 and figure out what's going on. 346 00:22:11,340 --> 00:22:15,480 Accurate, but just not very helpful, unfortunately. 347 00:22:17,780 --> 00:22:19,840 So, the decoder stub is going to be part 348 00:22:19,840 --> 00:22:21,680 of the encoded shellcode. 349 00:22:21,900 --> 00:22:22,500 It will decode. 350 00:22:22,500 --> 00:22:30,980 decode itself in memory. And it can perform one or even multiple or many operations to decode it 351 00:22:30,980 --> 00:22:38,040 byte by byte. To the left you can see IDA Pro and to the right you have SHAREM which provides a 352 00:22:38,040 --> 00:22:52,480 little bit more information. So at this time we're going to take a brief demo. So we're going 353 00:22:52,500 --> 00:23:17,240 to go ahead and ... So we are in SHAREM right now. Let's go ahead and emulate this. So it'll take 354 00:23:17,240 --> 00:23:22,300 just a small amount of time to emulate it. Right now it's breaking out of some very long 355 00:23:22,300 --> 00:23:29,400 loops. We got some output. We have been able to identify a number of APIs as well as the 356 00:23:29,400 --> 00:23:35,140 parameters. And various other artifacts have been identified. SHAREM identifies itself modifying 357 00:23:35,140 --> 00:23:41,300 codes. So that's very useful. And then now we've generated disassembly. And so we can see 358 00:23:41,300 --> 00:23:47,180 that printed to the screen. So that can be very useful. We have our APIs identified. We have 359 00:23:47,180 --> 00:23:51,840 our data down below at the bottom there. And then we're going to take a look at the 360 00:24:08,320 --> 00:24:12,120 disk. So what's going to work here is we're going to look at the best-of-the-kind 361 00:24:12,120 --> 00:24:13,300 disk. And so what we see is we've got a very nice assembler. We're going to update it a 362 00:24:13,300 --> 00:24:22,280 Click here. So you see that the disk is now on the PC now. Now we're going to choose to load the disk. So that's the main thing. We're going to do a little bit of bloom for our disk. So we're 363 00:24:22,300 --> 00:24:27,720 like IDA pro or Ghidra they were to put it simply very much inadequate 364 00:24:28,580 --> 00:24:34,480 sometimes there'd be as much as 60 or 70 percent only that was correct so meaning 365 00:24:34,480 --> 00:24:40,120 40 percent that was wrong and the root cause of a lot of this was simply 366 00:24:40,120 --> 00:24:47,920 misclassification of data is instructions or alternatively a cascading 367 00:24:47,920 --> 00:24:53,840 effect of that is some instructions were would start disassembling it in an 368 00:24:53,840 --> 00:25:02,140 incorrect offset simple things like strings would be just disassembled is 369 00:25:02,140 --> 00:25:11,220 instructions so in order to address this I came up with some static analysis 370 00:25:11,220 --> 00:25:17,840 methods to and call that disassembly analysis engine so in x86 371 00:25:17,920 --> 00:25:23,160 you can have instructions and data that are freely intermixed and also with 372 00:25:23,160 --> 00:25:30,300 shellcode you can play fast and loose with certain conventions so in order to 373 00:25:30,300 --> 00:25:35,600 help deal with this Shario map will actually utilize multiple analysis phases 374 00:25:35,600 --> 00:25:42,220 in order to try to achieve more accurate disassembly of shellcode 375 00:25:42,220 --> 00:25:47,560 and if we're able to accurately distinguish between instructions 376 00:25:47,560 --> 00:25:55,180 deductions in data, then we should get vastly superior disassembly, hypothetically even 377 00:25:55,540 --> 00:26:03,760 perfect disassembly. So what SHAREM will do is it will maintain complex metadata about 378 00:26:03,760 --> 00:26:17,540 each and every byte of shellcode. Now, SHAREM does work exclusively with shellcode. And 379 00:26:17,540 --> 00:26:24,480 it's very much empirical, very much based on experimentation with actual true shellcodes. 380 00:26:24,680 --> 00:26:31,920 So I have a large collection of shellcode with where I actually possess the source code. 381 00:26:32,220 --> 00:26:38,480 And the process was to try to scrutinize it very closely. And if I noticed at one particular 382 00:26:38,480 --> 00:26:43,800 location that something was incorrect, I would try to identify the root cause as to why that 383 00:26:43,800 --> 00:26:47,120 was the case. And if I could identify the root cause, 384 00:26:47,540 --> 00:26:53,640 then I could try to then remediate it. And I would remediate it not for that particular 385 00:26:53,640 --> 00:26:57,300 with that one instance, but for all other similar types. 386 00:26:57,960 --> 00:27:05,080 The end result was a very much improved disassembly. Now it could never be perfect, 387 00:27:05,340 --> 00:27:12,460 but it was markedly better than what would be produced by ITAPRO or by Ghidra. 388 00:27:15,040 --> 00:27:17,520 So some of these can be a little“ 389 00:27:19,140 --> 00:27:20,800 A bit much to discuss. 390 00:27:21,040 --> 00:27:23,780 There is a white paper that does discuss them 391 00:27:23,780 --> 00:27:25,880 in more detail if you wish, 392 00:27:26,040 --> 00:27:27,520 but just very briefly, 393 00:27:27,660 --> 00:27:32,180 a few of the things that we do to help with this, 394 00:27:32,360 --> 00:27:35,580 if we can find repeating data bytes, 395 00:27:36,240 --> 00:27:37,920 then we can label those as data, 396 00:27:38,040 --> 00:27:44,720 for instance, long repeating instances of zeros or Fs. 397 00:27:44,720 --> 00:27:47,620 We also might check for valid jump destinations. 398 00:27:47,980 --> 00:27:51,920 If a shellcode is trying to jump to offset 3,000 399 00:27:51,920 --> 00:27:53,920 and it's only 200 bytes long, 400 00:27:54,240 --> 00:27:54,860 well, guess what? 401 00:27:55,100 --> 00:27:57,060 Offset 3,000 doesn't exist, 402 00:27:57,380 --> 00:27:59,320 so that's incorrect, 403 00:27:59,640 --> 00:28:02,080 so we try to then address that. 404 00:28:02,440 --> 00:28:05,940 Can locate hidden calls and jumps, 405 00:28:06,660 --> 00:28:09,400 and in this particular case, 406 00:28:09,500 --> 00:28:12,240 we're looking for the particular opcodes 407 00:28:12,240 --> 00:28:14,180 or bytes that produce these, 408 00:28:14,180 --> 00:28:16,760 and then we make sure that they are formed, 409 00:28:17,220 --> 00:28:18,960 they form the correct disassembly 410 00:28:19,340 --> 00:28:25,100 if there is a valid branching destination that exists. 411 00:28:26,260 --> 00:28:27,780 Something like strings, 412 00:28:28,000 --> 00:28:31,780 we can easily identify those with Unicode or ASCII. 413 00:28:34,920 --> 00:28:38,440 So you can see one of the most important aspects of this 414 00:28:38,440 --> 00:28:44,120 is we are able to identify functions in our shellcodes. 415 00:28:44,180 --> 00:28:48,420 And this is really the only way in which you can do that. 416 00:28:48,520 --> 00:28:52,540 So if you were to open this up in IA Pro or Ghidra, 417 00:28:52,680 --> 00:28:55,020 you would not see any of these functions identified. 418 00:28:56,220 --> 00:28:59,600 You would simply see call EAX, call EDX, 419 00:29:00,360 --> 00:29:03,720 and some type of variation to that effect. 420 00:29:05,520 --> 00:29:08,420 Now, ShareM, we are able to identify 421 00:29:09,340 --> 00:29:12,540 more than 20,000 of these Windows APIs, 422 00:29:12,820 --> 00:29:13,800 as well as virtually 423 00:29:13,800 --> 00:29:15,940 all Windows syscalls. 424 00:29:20,180 --> 00:29:23,960 We also are able to identify disassembly annotations, 425 00:29:24,200 --> 00:29:27,940 things such as getPC to self-locate in memory, 426 00:29:28,260 --> 00:29:30,520 push-threads, Heaven's Gate, 427 00:29:30,740 --> 00:29:32,240 and those can be labeled for us. 428 00:29:32,780 --> 00:29:33,660 PAB identification, 429 00:29:34,280 --> 00:29:36,240 so walking the process environment block. 430 00:29:36,540 --> 00:29:39,780 That's something that each and every shellcode needs to do. 431 00:29:39,880 --> 00:29:43,000 It's one of the first steps of dynamically resolving, 432 00:29:43,000 --> 00:29:45,240 runtime API addresses. 433 00:29:45,720 --> 00:29:50,220 And so we will call out all of those particular PAB features. 434 00:29:50,840 --> 00:29:51,860 API tables. 435 00:29:52,160 --> 00:29:53,900 So one common thing the shellcode does 436 00:29:54,300 --> 00:29:59,640 is it's able to identify a particular location 437 00:30:01,820 --> 00:30:04,080 as being a place where a shellcode 438 00:30:04,080 --> 00:30:06,720 or a Windows API pointer will be written. 439 00:30:06,880 --> 00:30:08,720 So for instance, delete file A, 440 00:30:08,880 --> 00:30:11,860 that may always be at that particular offset. 441 00:30:11,860 --> 00:30:17,580 So you might have call EDX plus some offset to access that. 442 00:30:19,020 --> 00:30:21,640 So let's look at IDA Pro versus ShareM 443 00:30:21,640 --> 00:30:23,460 in terms of disassembly. 444 00:30:23,460 --> 00:30:26,680 IDA Pro, it cannot determine APIs. 445 00:30:26,940 --> 00:30:28,000 How tragic. 446 00:30:28,420 --> 00:30:29,960 You pay thousands of dollars 447 00:30:29,960 --> 00:30:32,400 and it just doesn't have that information. 448 00:30:32,980 --> 00:30:37,680 But we look inside of ShareM and no cost, 449 00:30:37,800 --> 00:30:40,980 but you're able to have the APIs identified. 450 00:30:44,300 --> 00:30:46,120 Strings, thank you. 451 00:30:48,580 --> 00:30:52,040 Now strings are pretty obvious, ASCII, Unicode. 452 00:30:52,120 --> 00:30:55,920 We'll identify those and also things like push stack strings. 453 00:30:56,400 --> 00:31:00,700 We can have those identified very nicely with our comments. 454 00:31:02,880 --> 00:31:09,800 Now one thing that we do do is we utilize 455 00:31:11,860 --> 00:31:16,740 emulation data as a way to enhance our disassembly. 456 00:31:18,660 --> 00:31:23,420 So now the way in which we do this is very unique. 457 00:31:24,460 --> 00:31:28,740 So if we were able to start emulating a shellcode 458 00:31:28,740 --> 00:31:30,980 at a particular offset, then we know definitively 459 00:31:30,980 --> 00:31:34,300 at this location we have this instruction 460 00:31:34,900 --> 00:31:36,680 and it's size two bytes. 461 00:31:37,500 --> 00:31:39,440 So we will preserve that information. 462 00:31:41,860 --> 00:31:44,040 If we go and produce the disassembly, 463 00:31:44,480 --> 00:31:47,700 then to put it simply, that would override 464 00:31:47,700 --> 00:31:49,360 what would be determined statically. 465 00:31:49,700 --> 00:31:53,320 And for things like data, the data will also 466 00:31:54,600 --> 00:31:57,640 be identified with memory reads and writes 467 00:31:57,640 --> 00:32:02,620 and so that information can be clearly labeled for us. 468 00:32:07,000 --> 00:32:11,840 Now, self-modifying codes, you might say, well, gee, God. 469 00:32:11,840 --> 00:32:13,660 Golly, self-modifying code. 470 00:32:13,940 --> 00:32:17,620 Each byte is going to be both data and instructions. 471 00:32:17,680 --> 00:32:19,280 How can we cope with that? 472 00:32:20,060 --> 00:32:23,300 Well, what you actually could do is you could say, OK, 473 00:32:23,560 --> 00:32:26,200 we recognize that data, everything 474 00:32:26,200 --> 00:32:30,100 is going to be data at least once, so in this case, 475 00:32:30,140 --> 00:32:32,500 we will not classify it as data unless it's 476 00:32:32,500 --> 00:32:36,380 accessed, read to, or written to more than once. 477 00:32:38,460 --> 00:32:40,920 Distinguishing between data and instructions. 478 00:32:41,840 --> 00:32:44,700 So at the top there, that's the actual disassembly 479 00:32:44,700 --> 00:32:45,800 of instructions. 480 00:32:46,120 --> 00:32:48,640 We have call EAX, we're calling virtual alloc, 481 00:32:48,840 --> 00:32:51,200 we're creating a region of memory, 482 00:32:52,180 --> 00:32:55,740 and the page execute read write is labeled for us. 483 00:32:56,420 --> 00:32:59,640 And then down below everything there is data. 484 00:32:59,940 --> 00:33:03,520 Now, if this was in Ghidra or IDA Pro, 485 00:33:03,780 --> 00:33:07,720 it would just be simply misclassified as instructions, 486 00:33:08,660 --> 00:33:11,160 but instead we have our API pointers 487 00:33:11,160 --> 00:33:13,800 that are labeled, we have strings that are labeled, 488 00:33:14,040 --> 00:33:17,680 and then other D words, which we can surmise maybe things 489 00:33:17,680 --> 00:33:23,760 like checksums, which could help us to resolve those APIs. 490 00:33:26,200 --> 00:33:28,800 So the way in which we integrate our emulation data, 491 00:33:33,300 --> 00:33:35,240 now we take three different forms. 492 00:33:35,400 --> 00:33:37,820 We have the starting form, so if something is encoded, 493 00:33:37,920 --> 00:33:39,720 we'll take a snapshot of that. 494 00:33:39,720 --> 00:33:43,260 And then we do, at a byte by byte basis, 495 00:33:44,200 --> 00:33:48,220 every time a particular set of bytes are executed 496 00:33:48,220 --> 00:33:54,580 is instructions, we will take a snapshot of that. 497 00:33:54,960 --> 00:33:58,960 And then finally, we'll take a snapshot of the final form 498 00:33:59,380 --> 00:34:02,580 of the shellcode after it has decoded itself in memory. 499 00:34:03,640 --> 00:34:05,880 And then we will merge these together, 500 00:34:06,060 --> 00:34:08,300 and it's a very novel way of merging it. 501 00:34:08,300 --> 00:34:11,700 So if I was a very clever shellcode author, 502 00:34:12,100 --> 00:34:14,860 and I wanted to try to conceal what I was doing, 503 00:34:15,040 --> 00:34:17,560 I might have the shellcode re-encode itself 504 00:34:18,120 --> 00:34:19,600 after it decoded itself. 505 00:34:20,080 --> 00:34:24,060 Now, that doesn't typically happen, but it could. 506 00:34:24,940 --> 00:34:28,860 And if somebody were trying to protect 507 00:34:29,200 --> 00:34:33,080 the intellectual property of their shellcode by doing that, 508 00:34:33,300 --> 00:34:35,600 we would still be able to see what that was, 509 00:34:35,660 --> 00:34:37,220 because we are going to prioritize 510 00:34:37,220 --> 00:34:40,880 the executed form of the shellcode 511 00:34:40,880 --> 00:34:43,980 when we merge these together. 512 00:34:44,300 --> 00:34:47,680 Next, we then prioritize the final form, 513 00:34:48,270 --> 00:34:51,940 and then finally, we prioritize the starting form. 514 00:34:53,980 --> 00:34:57,660 So there is the result of all that madness. 515 00:34:58,150 --> 00:35:00,900 We can see a decoded shellcode 516 00:35:01,330 --> 00:35:03,520 with the APIs very clearly labeled. 517 00:35:03,860 --> 00:35:06,380 The parameters are immediately easy. 518 00:35:07,220 --> 00:35:10,000 It's just a C, and it's not just hex values, 519 00:35:10,180 --> 00:35:13,760 but the human readable equivalence that we can see, 520 00:35:13,900 --> 00:35:17,560 things like, well, in this particular case, 521 00:35:17,820 --> 00:35:20,660 we can see that it's downloading an evil.hta, 522 00:35:21,300 --> 00:35:23,520 and then doing WinExec on that. 523 00:35:27,800 --> 00:35:28,900 In terms of reporting, 524 00:35:29,280 --> 00:35:31,200 SHRM has a lot of verbose reporting, 525 00:35:31,540 --> 00:35:33,920 of all kinds of very useful information, 526 00:35:35,140 --> 00:35:37,200 and it has many different types. 527 00:35:37,200 --> 00:35:39,680 Types of outputs that it provides for us, 528 00:35:40,270 --> 00:35:43,240 ASCII representation of bytes, raw binary, 529 00:35:43,580 --> 00:35:48,520 text format, JSON, so if you want to run SHRM headless, 530 00:35:49,470 --> 00:35:52,180 and maybe integrate that into some kind of web server, 531 00:35:52,360 --> 00:35:55,720 or web service, then absolutely you could do so. 532 00:35:56,040 --> 00:35:59,060 It'll also generate a C-style tester, 533 00:35:59,520 --> 00:36:01,180 so if you want to then compile that, 534 00:36:01,420 --> 00:36:05,400 and run that in a debugger, it's just very easy to do. 535 00:36:07,200 --> 00:36:11,000 All right, so this time we will hand it off to, 536 00:36:14,580 --> 00:36:16,060 this is the time right there. 537 00:36:18,240 --> 00:36:19,960 All right, let me adjust this. 538 00:36:22,900 --> 00:36:26,400 So, since I'm a major user of GDRA in my day-to-day work, 539 00:36:26,840 --> 00:36:29,580 during malware analysis, and I also encounter shellcode, 540 00:36:29,780 --> 00:36:32,600 I like the SHRM framework. 541 00:36:32,820 --> 00:36:35,560 I figured I would combine the best of both worlds. 542 00:36:35,780 --> 00:36:36,880 Now it's a, kind of, 543 00:36:36,880 --> 00:36:40,720 an open secret I unironically like Java to write in. 544 00:36:41,040 --> 00:36:43,240 It's kind of an open secret that the rest of the world 545 00:36:43,240 --> 00:36:44,660 kind of hates Java to write in, 546 00:36:44,740 --> 00:36:46,580 so I consider this a win-win, 547 00:36:46,740 --> 00:36:48,860 where I wrote the script in Java for everybody to use, 548 00:36:49,000 --> 00:36:50,760 so you don't have to, but you can still use it. 549 00:36:51,320 --> 00:36:54,080 Now, for those unaware, GDRA is a framework 550 00:36:54,080 --> 00:36:56,600 for reverse engineering published by the NSA. 551 00:36:56,840 --> 00:36:57,620 It's open source. 552 00:36:58,520 --> 00:37:01,520 And you can also analyze shellcode with this. 553 00:37:03,140 --> 00:37:05,040 Now, you can extend this framework 554 00:37:05,040 --> 00:37:06,600 after you've loaded your shellcode, 555 00:37:06,600 --> 00:37:07,360 and analyzed it. 556 00:37:07,480 --> 00:37:10,040 You can go to the display's script manager, 557 00:37:10,280 --> 00:37:12,400 which is the green play button in the top bar, 558 00:37:12,960 --> 00:37:16,420 and it will open the script manager for you. 559 00:37:16,560 --> 00:37:17,980 Now, you can go to the hamburger menu, 560 00:37:18,200 --> 00:37:19,380 and once you open that, 561 00:37:19,480 --> 00:37:21,700 you will see the folders where your scripts are located, 562 00:37:21,880 --> 00:37:23,280 and you can select any location. 563 00:37:24,420 --> 00:37:26,520 Alternatively, your home directory 564 00:37:26,520 --> 00:37:28,260 will contain a folder called GDRA scripts. 565 00:37:28,500 --> 00:37:29,840 You can put the script in there. 566 00:37:30,680 --> 00:37:33,000 And afterwards, you can simply double-click it by running. 567 00:37:34,260 --> 00:37:36,360 Now, once you do this, it will call, 568 00:37:36,600 --> 00:37:37,780 share them in the background, 569 00:37:38,040 --> 00:37:40,880 and it will allow you to see the scripting console, 570 00:37:41,760 --> 00:37:44,720 which is located by default in GDRA's bottom. 571 00:37:45,080 --> 00:37:47,240 And it will see where comments are placed. 572 00:37:47,460 --> 00:37:49,980 You'll see the hexadecimal address afterwards. 573 00:37:50,380 --> 00:37:52,380 And given that the disassembly view 574 00:37:52,380 --> 00:37:54,380 and decompiler view from GDRA are linked, 575 00:37:55,340 --> 00:37:58,260 double-clicking on these addresses will jump towards it, 576 00:37:58,300 --> 00:38:00,160 and will highlight that in your overview. 577 00:38:00,520 --> 00:38:03,300 Now, the comments in here allow you to have 578 00:38:03,300 --> 00:38:06,260 a quick and easy overview as to what was added by the script. 579 00:38:06,600 --> 00:38:11,480 And navigate towards interesting parts of the shellcode. 580 00:38:12,460 --> 00:38:15,560 Now, it's a brief flowchart as to how does this work. 581 00:38:16,160 --> 00:38:18,580 You run the script, which runs share them in the background. 582 00:38:18,840 --> 00:38:19,900 Share them can run headless. 583 00:38:20,100 --> 00:38:23,100 The script for GDRA itself is written in such a way 584 00:38:23,100 --> 00:38:26,220 that it requires no graphical user interface elements, 585 00:38:26,480 --> 00:38:29,300 so you can also run the script headless in GDRA, 586 00:38:29,380 --> 00:38:30,760 which then runs share them headless. 587 00:38:31,380 --> 00:38:34,620 It loads the output once share them is done in its execution, 588 00:38:35,200 --> 00:38:36,320 which is the JSON default. 589 00:38:36,320 --> 00:38:37,420 It's called this JSON file. 590 00:38:37,720 --> 00:38:39,560 And it will load that JSON converted 591 00:38:39,560 --> 00:38:40,780 into plain Java objects. 592 00:38:41,100 --> 00:38:45,020 It will iterate over all of those, add comments 593 00:38:45,020 --> 00:38:47,480 wherever possible based on the output. 594 00:38:47,740 --> 00:38:49,400 It will update the disassembly. 595 00:38:49,720 --> 00:38:54,900 We just saw the explanation as to why share them 596 00:38:54,900 --> 00:38:57,280 is able to catch more than, for example, GDRA. 597 00:38:57,600 --> 00:39:00,280 And it will also assign, or reassign, 598 00:39:00,280 --> 00:39:01,880 if there was already a datatype. 599 00:39:01,940 --> 00:39:04,820 So it's preferring share it and output over GDRA's own analysis, 600 00:39:05,060 --> 00:39:06,300 in any type of U bek series, like a four Creams text. 601 00:39:06,300 --> 00:39:08,160 along the script's execution. 602 00:39:08,660 --> 00:39:11,080 It will log those changes in the script console 603 00:39:11,080 --> 00:39:12,720 at the bottom and it will finish the execution. 604 00:39:14,880 --> 00:39:16,460 Now, how does that look like? 605 00:39:16,640 --> 00:39:19,320 So I have a overview here of a piece of shell code 606 00:39:19,320 --> 00:39:20,920 that I received from Bramwell, 607 00:39:21,540 --> 00:39:26,160 and this is the default way that Jira shows it to you. 608 00:39:26,520 --> 00:39:28,200 Now, if you were to run the script, 609 00:39:29,200 --> 00:39:30,880 then you will get information. 610 00:39:31,180 --> 00:39:32,160 Now, based on the emulation, 611 00:39:32,400 --> 00:39:35,120 you suddenly see that specific offsets 612 00:39:35,120 --> 00:39:38,080 or memory locations refer to, in this case, for example, 613 00:39:38,200 --> 00:39:41,220 on line 25, six, and seven, you see load library A, 614 00:39:41,620 --> 00:39:43,440 but not only do you know this function, 615 00:39:43,600 --> 00:39:45,820 and based on MSDN, you know the parameters 616 00:39:45,820 --> 00:39:48,380 and the use case offset function, 617 00:39:48,620 --> 00:39:50,880 you also know the value of the argument, 618 00:39:51,020 --> 00:39:53,460 so not only the type of argument, but the actual value. 619 00:39:53,580 --> 00:39:55,460 So in this case, we know that URLmon is loaded 620 00:39:56,000 --> 00:39:58,700 by the shell code, and we can see that get proc address 621 00:39:58,700 --> 00:40:00,860 is used to get URL download to file A. 622 00:40:03,180 --> 00:40:04,300 As for data types, 623 00:40:05,260 --> 00:40:08,480 Jira tends to try and guesstimate 624 00:40:09,100 --> 00:40:11,340 whatever you have in front of you. 625 00:40:11,500 --> 00:40:14,500 In this case, you have unknown bytes. 626 00:40:14,780 --> 00:40:18,720 These are, well, they're nothing constructible. 627 00:40:18,900 --> 00:40:21,720 However, during emulation, you will see 628 00:40:22,720 --> 00:40:26,740 that the API pointers, checksums, and strings reside here. 629 00:40:27,120 --> 00:40:28,940 Now, the strings themselves might be found 630 00:40:28,940 --> 00:40:33,440 by Jira initially, but maybe the ending null byte 631 00:40:33,440 --> 00:40:34,900 is or is not included. 632 00:40:37,540 --> 00:40:39,520 Jira generally assumes it is, 633 00:40:39,680 --> 00:40:42,640 and that byte might be useful for the next part. 634 00:40:42,880 --> 00:40:44,440 Maybe it's alignment or padding afterwards. 635 00:40:44,740 --> 00:40:46,360 Kinda depends on what you're looking for. 636 00:40:46,540 --> 00:40:48,260 So this gives you an easy overview 637 00:40:48,260 --> 00:40:50,160 as to what you're looking for. 638 00:40:50,320 --> 00:40:52,600 If you see any checksums or magic values, 639 00:40:52,780 --> 00:40:55,120 you might try and find those online to get more information, 640 00:40:55,380 --> 00:40:58,940 and if you see references in the code towards that data, 641 00:40:59,100 --> 00:41:00,900 you also know the size of the data 642 00:41:00,900 --> 00:41:02,400 rather than just being one byte. 643 00:41:04,280 --> 00:41:08,780 As for the disassembly, it wasn't really clear in screenshots 644 00:41:08,780 --> 00:41:11,140 if I did more than just one instruction, 645 00:41:11,480 --> 00:41:14,320 so I manually patched the first line, offset five, pop ex. 646 00:41:14,720 --> 00:41:17,560 Once you run the script, this changes to pop edx, 647 00:41:17,640 --> 00:41:21,020 which was originally, but this shows that the emulation 648 00:41:21,020 --> 00:41:24,060 from Jira and the changes in there are reworked 649 00:41:24,060 --> 00:41:25,960 in whatever you see in here. 650 00:41:27,540 --> 00:41:28,880 Now, as for a demo, 651 00:41:34,680 --> 00:41:37,080 we can see here that we started offset five. 652 00:41:43,880 --> 00:41:45,980 Now you can also see it starts at offset five. 653 00:41:47,540 --> 00:41:48,480 Otherwise, it's just me. 654 00:41:49,060 --> 00:41:50,860 And you can see that it has pop ex. 655 00:41:51,740 --> 00:41:54,440 Once we go down, we can see that function calls, 656 00:41:54,600 --> 00:41:57,980 for example, are to a memory address. 657 00:41:58,180 --> 00:42:00,000 We don't know what we're looking at necessarily, 658 00:42:00,780 --> 00:42:02,380 and if we go all the way down, 659 00:42:02,380 --> 00:42:05,160 we can see the bytes that are not classified, 660 00:42:05,460 --> 00:42:08,500 and we can see the strings that are found by Jira. 661 00:42:08,820 --> 00:42:10,780 Opening up the script manager and running it, 662 00:42:10,880 --> 00:42:15,240 we'll see in the bottom the log showing us 663 00:42:15,240 --> 00:42:17,340 what we can use and what has been added. 664 00:42:17,640 --> 00:42:20,440 So this allows us to, in one single overview, 665 00:42:20,580 --> 00:42:21,400 see what we need. 666 00:42:21,580 --> 00:42:25,160 We can see that the pop ex has changed into pop edx. 667 00:42:27,000 --> 00:42:29,200 And once we go down to the function call, 668 00:42:29,320 --> 00:42:32,120 we again see the annotation in both the disassembly listing, 669 00:42:32,120 --> 00:42:33,420 and in the decompiler view, 670 00:42:33,620 --> 00:42:36,220 where we have both the API, 671 00:42:36,480 --> 00:42:38,800 but also the value of the arguments. 672 00:42:39,100 --> 00:42:41,280 And we can see that in both views. 673 00:42:42,960 --> 00:42:44,580 Moving down, we see the 674 00:42:48,740 --> 00:42:50,720 checksums located at the bottom. 675 00:42:55,040 --> 00:42:55,920 Thank you. 676 00:43:03,480 --> 00:43:05,220 This also marks the end of the presentation. 677 00:43:05,580 --> 00:43:09,940 You can download and try SHAREM on the address on the top, 678 00:43:10,080 --> 00:43:13,040 and you can find the Jira address on the Trilux GitHub 679 00:43:13,040 --> 00:43:14,400 located at the bottom. 680 00:43:15,360 --> 00:43:18,680 There was an NSA grant used for the research for SHAREM, 681 00:43:18,720 --> 00:43:19,780 which is listed at the bottom. 682 00:43:19,920 --> 00:43:20,980 Thank you very much for your attention.