1 00:00:00,000 --> 00:00:01,540 Hey, this is Alex. 2 00:00:01,540 --> 00:00:02,560 This is Dan. 3 00:00:02,780 --> 00:00:05,040 And I got something really cool to talk about. 4 00:00:08,120 --> 00:00:09,680 How are you guys doing? 5 00:00:10,520 --> 00:00:12,000 Last talk of the day. 6 00:00:12,040 --> 00:00:15,180 Then you guys are going to go to bed right after this, I imagine. 7 00:00:17,060 --> 00:00:18,540 Thanks for coming out, guys. 8 00:00:18,540 --> 00:00:20,140 This is pretty exciting for us. 9 00:00:20,140 --> 00:00:21,400 My name is Alex Levenson. 10 00:00:21,400 --> 00:00:22,580 I've got Dan here. 11 00:00:22,860 --> 00:00:26,140 Today we're going to go through a tool that we wrote the agenda today. 12 00:00:26,260 --> 00:00:29,820 We're going to talk about droppers and stagers, as some of you might call them. 13 00:00:30,140 --> 00:00:32,760 Not really going to get pedantic about the terminology there. 14 00:00:32,980 --> 00:00:34,400 And how we kind of got here today. 15 00:00:34,400 --> 00:00:37,920 After that, we're going to go into this technology that we built and how it works. 16 00:00:37,920 --> 00:00:42,780 And we'll talk about some of the real world applications and then we'll give you a demo which will inevitably fail. 17 00:00:42,780 --> 00:00:45,080 But, you know, we'll see how that goes. 18 00:00:45,280 --> 00:00:47,400 First off, just an introduction for us. 19 00:00:47,400 --> 00:00:48,820 My name is Alex Levenson. 20 00:00:49,000 --> 00:00:52,640 I'm a senior security engineer at Uber. 21 00:00:52,800 --> 00:00:54,420 I've been there for a couple of years. 22 00:00:54,480 --> 00:00:57,380 My specialty is really in tool development and red teaming. 23 00:00:57,620 --> 00:01:04,380 I am a core red team member at the national CCDC and also the western regional CCDC as well. 24 00:01:04,680 --> 00:01:05,640 Thank you. 25 00:01:06,600 --> 00:01:07,760 Hey guys. 26 00:01:09,340 --> 00:01:10,520 I'm Dan Borges. 27 00:01:10,520 --> 00:01:12,880 I'm a senior red team operator and dev. 28 00:01:13,420 --> 00:01:17,200 I also partake in national CCDC on the red team. 29 00:01:17,480 --> 00:01:20,580 And Alex and I play a lot of cyber competitions together. 30 00:01:20,800 --> 00:01:23,000 So we're just here to show you some of our cool tools. 31 00:01:23,580 --> 00:01:25,680 So we got to go back a little bit. 32 00:01:26,600 --> 00:01:31,100 We are going to talk about what is a dropper, what is this classification thing we're talking about. 33 00:01:31,420 --> 00:01:35,780 In our little hyper local kill chain right here, we have an exploit. 34 00:01:35,780 --> 00:01:37,060 This is your initial vector. 35 00:01:37,060 --> 00:01:39,000 This is how you're getting on the server. 36 00:01:39,360 --> 00:01:42,040 This is usually like a memory corruption attack, something like that. 37 00:01:42,120 --> 00:01:44,280 Next attackers usually move to some kind of stager. 38 00:01:44,280 --> 00:01:46,960 This is moving from memory to their next tool. 39 00:01:47,320 --> 00:01:50,400 Often this can reach out and download more shell code, do something like that. 40 00:01:50,680 --> 00:01:53,040 And then this is really where we're going to focus on. 41 00:01:53,040 --> 00:01:55,040 This is your stage one. 42 00:01:55,040 --> 00:01:57,220 Some people call it the stage one, the stage two. 43 00:01:57,220 --> 00:01:58,020 This is the dropper. 44 00:01:58,020 --> 00:02:01,300 You're moving from your exploit to bringing over your tools. 45 00:02:01,300 --> 00:02:03,660 This is what's going to bring over your malware. 46 00:02:03,660 --> 00:02:08,020 It's going to put your persistence on the box, your deep slow stuff. 47 00:02:08,220 --> 00:02:09,880 And then finally you have your own malware. 48 00:02:09,880 --> 00:02:15,040 These are your custom applications, maybe your specific TTPs that you want to put on a box. 49 00:02:15,180 --> 00:02:23,540 And again, using a dropper here is important because you can protect your TTPs, your tools and tactics and procedures by using the dropper. 50 00:02:24,040 --> 00:02:25,540 So where are droppers used? 51 00:02:25,620 --> 00:02:28,380 We're trying to emulate what we see in the wild. 52 00:02:28,400 --> 00:02:37,400 What we see is a lot of third party crime where people use these exploit kits and then between the exploit kit and their own private malware, they'll usually lever some kind of dropper. 53 00:02:37,460 --> 00:02:45,740 They can do this as a form of packing to either bundle it with other executables or just as a way to get their malware on to the system. 54 00:02:46,260 --> 00:02:50,600 We can also use a dropper to be contextually aware and have contextually aware implants. 55 00:02:50,680 --> 00:02:52,080 This is kind of like Stuxnet. 56 00:02:52,140 --> 00:02:54,380 Do you want to land on this system? 57 00:02:54,380 --> 00:02:55,880 Do I want to deploy my payload? 58 00:02:55,880 --> 00:02:57,740 Sometimes you don't want to infect this host. 59 00:02:57,740 --> 00:03:02,720 That's a good thing for a dropper to say and back off and not put the malware down. 60 00:03:02,780 --> 00:03:05,720 We use it a lot in our red team operations for CCDC. 61 00:03:05,720 --> 00:03:07,200 We like to go fast and hard. 62 00:03:07,380 --> 00:03:10,780 This is the perfect tool for us to lay on the pain fast. 63 00:03:11,820 --> 00:03:14,760 So a little bit of history about how we arrived here. 64 00:03:15,560 --> 00:03:19,820 Back in the day on the CCDC red team, all these people would be bringing these super cool kits. 65 00:03:19,820 --> 00:03:21,360 We'd have really advanced techniques. 66 00:03:21,360 --> 00:03:25,760 And they'd be going against a single team and they'd be using this technique on this team. 67 00:03:26,240 --> 00:03:30,380 And what we wanted to do is we wanted to apply this pain to everybody equally. 68 00:03:30,380 --> 00:03:41,100 So we started wrapping it in shell scripts, in PowerShell, bash and all these great techniques to really just kind of drop six, seven implants, up to ten on a single team. 69 00:03:41,100 --> 00:03:44,640 So now each team is not getting just one implant made specially for them. 70 00:03:44,640 --> 00:03:46,960 They're getting all ten implants we made for everybody. 71 00:03:47,020 --> 00:03:48,180 So we can really share. 72 00:03:49,880 --> 00:03:54,240 And then around 2015 , 2016, we moved to these, like I said, these scripts. 73 00:03:54,240 --> 00:03:55,680 But they started to have drawbacks , right? 74 00:03:55,680 --> 00:03:59,360 They had like forensic drawbacks, right? 75 00:03:59,360 --> 00:04:05,260 People could find the scripts on the systems , PowerShell script lock logging and they could tell exactly what we were doing. 76 00:04:05,260 --> 00:04:08,600 They could get our source code, which was pretty dangerous for us as operators. 77 00:04:09,640 --> 00:04:15,380 So in late 2016, early 2017, we moved a lot of our tool chain to Golang. 78 00:04:15,460 --> 00:04:19,940 We did this for a number of reasons, mostly because you get natively compiled executables. 79 00:04:19,940 --> 00:04:24,060 So you can get a binary that runs specifically on an architecture. 80 00:04:24,520 --> 00:04:26,240 This means you have to disassemble it. 81 00:04:26,240 --> 00:04:29,300 It's hard to decompile, which means you can't get that source code back. 82 00:04:29,300 --> 00:04:31,120 It's difficult to reverse. 83 00:04:31,420 --> 00:04:35,440 And while we were doing this, we also started looking at what is a dropper? 84 00:04:35,460 --> 00:04:38,280 This had all of our tactics built into it. 85 00:04:38,280 --> 00:04:45,420 And we really wanted to say, let's abstract our specific techniques out and make a pure dropper that we can put any technique into. 86 00:04:46,260 --> 00:04:57,700 And at 2017 at a national CCDC, we had a few friends, Virus, Lucas, and they put together this thing called Genesis, where we had an SMB share, and you could just drop binaries in it. 87 00:04:57,700 --> 00:05:00,880 And we bundled them all into one executable and ran it on the disk. 88 00:05:00,880 --> 00:05:03,160 It would run everything you put into the SMB share. 89 00:05:03,160 --> 00:05:04,440 Just a native executable. 90 00:05:05,120 --> 00:05:06,180 This was really cool. 91 00:05:06,180 --> 00:05:07,060 This was really good. 92 00:05:07,060 --> 00:05:08,500 But it had a few drawbacks. 93 00:05:08,620 --> 00:05:14,300 Instead of just running everything together, we wanted to specifically instrument them in a certain way. 94 00:05:15,020 --> 00:05:25,920 So I think it was late 2017 into the 2018 CCDC season, Alex started working on this prototype of G script, the Genesis scripting engine, which we'll get to. 95 00:05:26,120 --> 00:05:26,840 And we used it. 96 00:05:26,840 --> 00:05:29,040 We used it all through this last CCDC season. 97 00:05:29,040 --> 00:05:30,300 It was really successful. 98 00:05:30,340 --> 00:05:32,700 We dropped it on every single team at nationals. 99 00:05:32,700 --> 00:05:33,980 Everybody felt the pain. 100 00:05:34,280 --> 00:05:40,740 And then between then, which was April 2018 and now, we've added a ton of cool new features. 101 00:05:40,740 --> 00:05:42,120 Like really sweet stuff. 102 00:05:42,120 --> 00:05:43,560 And that's what we're going to get into today. 103 00:05:45,140 --> 00:05:45,700 Woo! 104 00:05:45,700 --> 00:05:46,720 Thank you, Dan. 105 00:05:47,140 --> 00:05:56,200 Yeah, as Dan said, today we are going to show the world, you guys, the awesome information security community that we're part of. 106 00:05:56,480 --> 00:06:05,320 Basically what we've done cumulatively over the last several years, but also some really awesome features that even if you were at CCDC, you really didn't get a chance to play with. 107 00:06:05,320 --> 00:06:10,740 But from now on, I'd like to introduce the Genesis scripting engine, or as we call it, G script. 108 00:06:11,360 --> 00:06:12,680 What is G script? 109 00:06:12,680 --> 00:06:14,140 Dan covered sort of this thing. 110 00:06:14,140 --> 00:06:15,140 It's this dropper. 111 00:06:15,140 --> 00:06:19,740 It lets us take malware and bundle it together and tape it up in a big ball and throw it at somebody. 112 00:06:20,380 --> 00:06:21,660 Great, that's a good explanation. 113 00:06:21,660 --> 00:06:22,480 But how do you use it? 114 00:06:22,480 --> 00:06:24,840 What does it look like to you as the red teamer? 115 00:06:25,120 --> 00:06:26,500 It's really easy. 116 00:06:26,560 --> 00:06:28,020 You have your payloads. 117 00:06:28,060 --> 00:06:29,760 You write a script for your payload. 118 00:06:30,000 --> 00:06:32,900 You use the G script compiler on the command line. 119 00:06:33,000 --> 00:06:34,560 You get out a native binary. 120 00:06:35,120 --> 00:06:37,220 It couldn't be more simple than that. 121 00:06:37,560 --> 00:06:39,900 I use this all over our documentation. 122 00:06:39,900 --> 00:06:45,780 G script is a framework that allows you to rapidly implement custom droppers for all three major operating systems. 123 00:06:46,580 --> 00:06:51,140 So let's talk about what makes up G script, right? 124 00:06:51,140 --> 00:06:53,180 So first off, there's the engine. 125 00:06:53,400 --> 00:07:03,900 The engine is the thing that is inside of that native binary that you made that actually runs and executes the logic that you've specified in your script. 126 00:07:04,000 --> 00:07:05,320 There's the compiler. 127 00:07:05,320 --> 00:07:10,320 The compiler takes your script and turns it into that native binary. 128 00:07:10,440 --> 00:07:16,560 There's an obfuscator that's hooked into the compiler that we wrote to try and make it a little bit harder for you blue team folks out there. 129 00:07:16,980 --> 00:07:20,600 We really do like you, but, you know, we want to make you mad sometimes. 130 00:07:21,460 --> 00:07:22,920 We've got a standard library. 131 00:07:22,920 --> 00:07:25,800 These are functions that you can use inside of your Genesis scripts. 132 00:07:25,880 --> 00:07:27,260 We've got a command line tool. 133 00:07:27,260 --> 00:07:29,820 That's how you interact with the compiler and other things. 134 00:07:29,820 --> 00:07:38,300 And we also have an interactive debugger to help you develop these scripts in a more reliable way, let you test them out ahead of time so you're not doing stuff live. 135 00:07:38,840 --> 00:07:41,140 A high level walkthrough, here's what happens. 136 00:07:41,780 --> 00:07:56,280 When you use the compiler and that three step process we just showed, what ends up happening very first is the compiler goes and creates essentially representations of engines within memory for each of the scripts that you pass into it. 137 00:07:56,280 --> 00:08:11,120 The next thing it's going to do is every one of the payloads that you gave into it, we'll have an interpreter payload, we'll have some shell code, we'll have some, you know, SSH keys that we're going to drop somewhere, it encrypts and embeds them directly into that virtual machine that it's got in memory. 138 00:08:11,300 --> 00:08:14,720 After that, it's going to take all in number of virtual machines. 139 00:08:14,720 --> 00:08:17,860 Remember, it has a virtual machine isolated for each script. 140 00:08:17,960 --> 00:08:21,940 It's going to take all in number of those and it's going to sew it all together. 141 00:08:21,940 --> 00:08:27,700 It's like with needle and thread into an actual executable for whatever platform you're targeting. 142 00:08:27,940 --> 00:08:36,200 And then when that executable is run, that main that it sewed up together is going to launch every one of those run times in parallel. 143 00:08:36,820 --> 00:08:39,160 So let's do just a quick, quick walkthrough. 144 00:08:39,160 --> 00:08:40,940 You all know what, thank you. 145 00:08:41,360 --> 00:08:47,820 So a quick walkthrough of this, just to kind of hopefully illuminate you guys on how easy this is to use. 146 00:08:48,080 --> 00:08:49,840 So I've got a little example here. 147 00:08:50,100 --> 00:08:54,320 The example isn't, isn't crazy, it's really simple. 148 00:08:54,540 --> 00:08:56,780 So we're going to write a script, it's eight lines. 149 00:08:56,940 --> 00:08:59,240 There's some important things to note in this, though. 150 00:08:59,240 --> 00:09:09,740 It looks like JavaScript, for all intents and purposes it is JavaScript, we've sprinkled some syntactic sugar in the form of comment macros, so compiler macros that you see in the very first line there. 151 00:09:09,740 --> 00:09:17,520 That import statement is telling the G script compiler, I want you to import this file off my disk when we go to bundle this together. 152 00:09:17,920 --> 00:09:22,560 The next line, line three, is just a normal variable declaration like you would call in JavaScript. 153 00:09:23,020 --> 00:09:26,300 And then lines five through eight there is a function called deploy. 154 00:09:26,660 --> 00:09:37,960 Now when I talked before about when you run main, it launches all those virtual machines, the JavaScript VMs essentially need an entry point to launch when that happens, that's what it launches. 155 00:09:37,960 --> 00:09:39,740 It launches the deploy hook. 156 00:09:39,960 --> 00:09:46,300 So every one of your G scripts, no matter what you're doing in it, will always have a function deploy with something defined in it. 157 00:09:46,300 --> 00:09:48,060 What's defined in ours here? 158 00:09:48,180 --> 00:09:59,500 We get the payload dot text, the data that was in that file, we get it as a string called payload data, and then we write that to the destination file which we defined in line three. 159 00:09:59,900 --> 00:10:03,880 So very quick, very easy G script that anybody can write. 160 00:10:04,400 --> 00:10:07,980 But hey, this is not just for one script, this can be for multiple things, right? 161 00:10:07,980 --> 00:10:09,320 So let's write another one. 162 00:10:09,480 --> 00:10:10,500 What's this one doing? 163 00:10:10,500 --> 00:10:15,500 It's simply writing a file, second underscore file dot text with the string rect. 164 00:10:16,540 --> 00:10:17,780 So what do we do now? 165 00:10:17,980 --> 00:10:24,920 Step three, just use the compiler, one command, G script compile with an output file, star dot GS. 166 00:10:25,000 --> 00:10:29,280 GS is our file extension for G script. 167 00:10:30,640 --> 00:10:31,540 That's it. 168 00:10:31,540 --> 00:10:32,620 And what did we get? 169 00:10:33,220 --> 00:10:35,860 At the top, we got dropper dot bin. 170 00:10:36,040 --> 00:10:37,480 What is dropper dot bin? 171 00:10:37,480 --> 00:10:41,140 It's a 64 bit Mocko executable, I'm doing this on OSX. 172 00:10:41,900 --> 00:10:46,200 What else is in ‑‑ I run it on the bottom of the first box there. 173 00:10:46,440 --> 00:10:47,720 And then what happens? 174 00:10:47,720 --> 00:10:52,360 All of a sudden you see desk dot text and second file dot text in that directory. 175 00:10:52,420 --> 00:10:53,220 What's in those? 176 00:10:53,220 --> 00:10:56,520 Exactly the contents that we had placed in them initially. 177 00:10:58,100 --> 00:11:00,200 All of you guys seem pretty quiet. 178 00:11:00,200 --> 00:11:01,360 Was that too easy? 179 00:11:02,080 --> 00:11:03,140 Thank you. 180 00:11:03,900 --> 00:11:04,540 All right. 181 00:11:04,540 --> 00:11:05,860 So let's just talk about that. 182 00:11:05,860 --> 00:11:09,980 That seemed, you know, why couldn't you do that with PowerShell or shell script or something like that? 183 00:11:10,160 --> 00:11:12,660 Well, first off, you're getting a native binary. 184 00:11:12,900 --> 00:11:17,620 You're getting a native binary that I could have written the first script, Dan could have written the next one. 185 00:11:17,700 --> 00:11:22,100 And if Dan messed his up or I messed mine up, it's not going to take down the entire binary. 186 00:11:22,100 --> 00:11:23,440 It's going to keep executing. 187 00:11:23,440 --> 00:11:27,560 That's the whole point of this is to be robust and resilient in the case of failure. 188 00:11:27,560 --> 00:11:39,840 When you do these large scale red team ops and you have many people contributing code, you don't necessarily have the luxury of constantly testing to make sure that somebody's payload isn't going to mess up something in your process. 189 00:11:39,840 --> 00:11:48,780 So we really wanted to give the people writing the payloads the ability to come up with their logic on how they wanted this to be bundled in to the actual final binary. 190 00:11:48,780 --> 00:12:00,420 So you've got your native binary, you've got your isolated G script engines, you've got the user defined logic in those scripts that is actually encrypted and embedded just like the assets are into the binary. 191 00:12:00,800 --> 00:12:03,620 And then you've got the embedded assets in their payloads. 192 00:12:03,700 --> 00:12:08,460 Those all get bundled together into one container inside of your native binary. 193 00:12:09,120 --> 00:12:11,260 So let's talk about some of the features here, right? 194 00:12:11,460 --> 00:12:16,000 So first off, number one feature we saw was that you get to do this in JavaScript. 195 00:12:16,260 --> 00:12:26,120 Now, I'm not a JavaScript developer, but I think that we need to be making tools that are as easy for the broadest selection of us to use, right? 196 00:12:26,120 --> 00:12:31,460 So I know a lot of people in here probably see programmers, a lot of people in here do a lot of low level stuff. 197 00:12:31,460 --> 00:12:34,280 I wanted to make something common that people were familiar with. 198 00:12:34,280 --> 00:12:36,360 There's a lot of people that do web pin testing. 199 00:12:36,460 --> 00:12:40,860 JavaScript seems pretty familiar right now to a lot of people, so let's just go ahead and go with that. 200 00:12:40,940 --> 00:12:45,840 So it's easy to write, it's easy to learn, there's good documentation on how to write JavaScript well. 201 00:12:45,920 --> 00:12:47,820 Next thing is it's resilient to failure. 202 00:12:47,820 --> 00:12:51,920 As we talked about, if script 2 failed, script 1 would have kept on going. 203 00:12:52,540 --> 00:12:54,740 Third, it's highly customizable. 204 00:12:55,140 --> 00:13:03,660 So things like order of operations of your script, timeouts, all of the stuff you can customize with those compiler macros that we showed you, right? 205 00:13:03,660 --> 00:13:06,220 We showed you one, but there's many more you can go with. 206 00:13:06,380 --> 00:13:07,800 So how is this cross-platform? 207 00:13:07,800 --> 00:13:09,020 It's written in Go. 208 00:13:09,700 --> 00:13:19,420 Essentially, this whole thing is sort of leveraging the power of the Go compiler to make cross-platform malware for anybody to be using here. 209 00:13:19,720 --> 00:13:21,380 Number 5, it's secure. 210 00:13:21,500 --> 00:13:28,660 We ran into this at CCDC where we had our droppers essentially be reverse engineered very easily by just looking at the PowerShell logs. 211 00:13:29,080 --> 00:13:35,380 I'm excited to release this today because I'm excited to see how hard it is for somebody to actually reverse engineer one of these binaries. 212 00:13:35,380 --> 00:13:36,340 That is a challenge. 213 00:13:36,340 --> 00:13:36,980 Let me know if you do. 214 00:13:36,980 --> 00:13:38,100 I'd love to see it. 215 00:13:39,000 --> 00:13:47,020 And the number one thing that is new to anybody who has seen Genesys in the past is now you can actually call native Go from within your JavaScript. 216 00:13:47,360 --> 00:13:48,280 We'll get into that. 217 00:13:48,280 --> 00:13:49,960 I know that sounds kind of wacky. 218 00:13:51,160 --> 00:13:57,020 So we talked about this initially, but this diagram kind of gives you a little bit more context as to what happens. 219 00:13:57,400 --> 00:14:00,080 You've got your main of your final binary. 220 00:14:00,080 --> 00:14:07,240 And when that gets run, you have all of these engines that are in their own isolated namespace essentially get created. 221 00:14:07,240 --> 00:14:10,060 They initialize the JavaScript virtual machine within them. 222 00:14:10,060 --> 00:14:16,040 They inject the scripts, all the assets and any libraries, native Go libraries that you've called into it. 223 00:14:16,040 --> 00:14:20,680 And then it calls that deploy function, that entry point, if you will, on each of those. 224 00:14:20,680 --> 00:14:25,200 And that happens pending any custom order of operations with your macros. 225 00:14:25,200 --> 00:14:27,000 That happens all concurrently. 226 00:14:27,200 --> 00:14:29,480 So what does Gscript really let you do? 227 00:14:29,480 --> 00:14:38,360 It lets you focus on what your stager is doing, not how am I going to implement this for OSX even though I don't really know OSX or Windows or Linux. 228 00:14:39,480 --> 00:14:42,240 So this has been a process for us, right? 229 00:14:42,240 --> 00:14:50,480 I'm not a computer science, you know, master's student who's studied the deep internals of how software is made. 230 00:14:50,480 --> 00:14:52,760 I would like to say I was, but I definitely wasn't. 231 00:14:52,760 --> 00:14:56,580 I started to take an operating systems class in college and I was way over my head. 232 00:14:56,980 --> 00:14:59,100 So this has been a learning experience for me. 233 00:14:59,440 --> 00:15:03,960 And this is sort of some of the technology that I've figured out and implemented here within Gscript. 234 00:15:03,960 --> 00:15:07,260 So when you go to do a compile, what happens? 235 00:15:08,140 --> 00:15:14,440 Straightforward, the first thing that happens is it looks through all your scripts and gets a essentially a mapping of all the macros that you've defined. 236 00:15:14,660 --> 00:15:26,980 The next thing it's going to do is it's going to walk the abstract syntax tree of your JavaScript, notating things like, oh, you imported a Go library with this macro and then you called it down here. 237 00:15:27,120 --> 00:15:30,600 And registers, you know, things like how many arguments are you calling with it? 238 00:15:30,600 --> 00:15:32,440 What might the type be? 239 00:15:32,440 --> 00:15:34,640 What can I infer the type might be of that argument? 240 00:15:34,880 --> 00:15:39,880 It then goes through all the Go packages that you've included in that as well and does the same thing. 241 00:15:39,880 --> 00:15:45,200 Walks all the AST there looking for places where functions are defined that you've called from your JavaScript. 242 00:15:45,920 --> 00:15:48,740 Next, it's going to start marrying those together. 243 00:15:48,840 --> 00:16:03,040 It's going to essentially create foreign function interface wrappers in Go on the fly for all of the functions that you've called in JavaScript that are instrumented in native Go so that you're, and then inject those into the VM that we're bundling itself together. 244 00:16:04,300 --> 00:16:11,360 That's a probably another three talks worth of material to get into, but if you'd like to, it's definitely on GitHub, you can go check it out. 245 00:16:11,800 --> 00:16:15,240 After that, we embed all the assets, we encrypt them. 246 00:16:15,240 --> 00:16:20,360 Each VM has its own encryption key that all the assets get embedded with. 247 00:16:20,540 --> 00:16:25,800 And the assets themselves don't actually get decrypted until you call them within your script. 248 00:16:25,800 --> 00:16:30,940 So until you retrieve the asset, the asset isn't sitting in memory unencrypted. 249 00:16:31,440 --> 00:16:36,160 And then the final step, optional, but we do enjoy it, is the obfuscation step. 250 00:16:36,160 --> 00:16:40,640 So we do the obfuscation both before and after native compilation. 251 00:16:41,120 --> 00:16:45,240 And we've got some interesting stuff we'll kind of cover as to how that works there. 252 00:16:45,500 --> 00:16:48,340 So creating these standalone executables, right? 253 00:16:48,600 --> 00:16:49,940 How do we go about doing that? 254 00:16:49,940 --> 00:16:52,500 Well, I said we leverage the Go compiler to do that. 255 00:16:52,600 --> 00:17:09,720 Now, what's interesting about this is, if you can kind of see up here on this, on the picture, we take your scripts and payload, and we actually write out an entire Go program that contains the logic and everything needed that we just covered it into this Go program. 256 00:17:09,720 --> 00:17:11,340 Now, there's flags in our compiler. 257 00:17:11,340 --> 00:17:14,000 You can go look at that code and see what that looks like. 258 00:17:14,000 --> 00:17:15,740 It's incredibly unreadable. 259 00:17:16,180 --> 00:17:19,300 We needed to make it that way for security, right? 260 00:17:19,900 --> 00:17:28,120 But it's been a really interesting thing to consider that, you know, we're in a place in time where it's no longer enough to just write malware. 261 00:17:28,120 --> 00:17:32,120 You have to write code that writes code that writes your malware, right? 262 00:17:32,960 --> 00:17:36,320 So we talked about this before, too, and now I want to dive into this. 263 00:17:36,320 --> 00:17:38,420 Linking JavaScript and native Go. 264 00:17:39,260 --> 00:17:43,020 I was called crazy a couple times in the process of this. 265 00:17:43,020 --> 00:17:44,680 This was definitely one of those. 266 00:17:45,000 --> 00:17:46,580 And I still think it might be crazy. 267 00:17:46,580 --> 00:17:52,260 It's probably not the safest thing you can be doing in the world, but it is crazy. 268 00:17:52,260 --> 00:17:52,960 Thank you. 269 00:17:55,380 --> 00:17:56,980 It's an interesting thing, right? 270 00:17:56,980 --> 00:18:01,980 You've got two languages on completely opposite ends of the spectrum in terms of how they work. 271 00:18:02,240 --> 00:18:13,540 And figuring out a way for a user to almost not know the difference between them is a fascinating endeavor for me and Dan for us to kind of implement this and somebody in the back who shall remain nameless. 272 00:18:15,220 --> 00:18:17,020 So here I've got a little example, right? 273 00:18:17,020 --> 00:18:20,420 So we use the Go import macro, the compiler macro we talked about. 274 00:18:20,800 --> 00:18:22,320 We're going to import Redis. 275 00:18:22,580 --> 00:18:30,000 We're going to import Redis because as far as I know, other than Node.js, there's really just not an easy Redis library for JavaScript. 276 00:18:30,000 --> 00:18:31,440 There certainly isn't one for G script. 277 00:18:31,440 --> 00:18:33,720 You can't import Node.js modules into this. 278 00:18:33,780 --> 00:18:37,140 So how are we going to interact with Redis and G script? 279 00:18:37,140 --> 00:18:40,160 We're going to import the Go package for Redis. 280 00:18:40,160 --> 00:18:41,700 So we import that. 281 00:18:42,660 --> 00:18:45,980 And from there, you import it, as you see there, as Redis. 282 00:18:45,980 --> 00:18:53,080 That as blank, blank is equal to the namespace within the JavaScript program that you're defining here in your G script. 283 00:18:53,340 --> 00:18:56,040 So on the next one, I call the functions directly. 284 00:18:56,040 --> 00:19:02,540 So Redis.parseURL is actually a exported function within that Go package. 285 00:19:02,560 --> 00:19:04,920 And I can call it just like I would in Go. 286 00:19:05,640 --> 00:19:10,840 Now, one thing to note, there's no multiple assignment in JavaScript. 287 00:19:12,080 --> 00:19:14,900 We're in ES5, not ES6. 288 00:19:14,900 --> 00:19:17,880 So in this version, there's no multiple assignments. 289 00:19:17,880 --> 00:19:21,580 So if you look on line 5, you'll see R0. 290 00:19:21,820 --> 00:19:38,360 R0 is because in our linker that we do, when we see that you're calling a Go function that's returning multiple assignment, we actually make a dynamic array of that and give you back the return of that inside a single object that is an array of various types. 291 00:19:38,360 --> 00:19:44,200 So R0 in that is going to actually be the Redis client, the Redis connection URL. 292 00:19:44,720 --> 00:19:47,040 So line 5, we create a Redis client. 293 00:19:47,040 --> 00:19:52,380 And line 6, we simply interact with it as we would any Go program, right? 294 00:19:52,380 --> 00:19:57,600 And then down there, you look at the script, we compiled it normally and ran it and boom. 295 00:19:57,940 --> 00:20:03,580 Got the, was able to interact with Redis right from G script using this native bridge. 296 00:20:04,140 --> 00:20:14,620 So I wouldn't give you something incredibly, incredibly unsafe without some way to at least play around with it and see how it worked and test your stuff, right? 297 00:20:14,620 --> 00:20:17,780 So we spent a lot of time on an interactive debugger. 298 00:20:18,480 --> 00:20:20,080 It's pretty nice and easy to use. 299 00:20:20,080 --> 00:20:27,460 So at any time after you've installed G script, you can simply do G script shell and it will drop you into a REPL right there. 300 00:20:27,580 --> 00:20:31,420 The REPL has the entire standard library which we'll get into bundled into it. 301 00:20:31,660 --> 00:20:33,720 And you can do kind of some various things. 302 00:20:33,720 --> 00:20:35,840 So for example, we talked about macros. 303 00:20:35,840 --> 00:20:39,500 How do you get a macro into the shell when it's something the compiler knows? 304 00:20:39,500 --> 00:20:44,060 Well, in G script shell, you can just pass the dash into it with macros. 305 00:20:44,060 --> 00:20:46,700 You can pass multiple as many as you'd like into it . 306 00:20:46,700 --> 00:20:54,100 And then when it drops into that shell, it says if you've dropped into the deploy function with that VM instrument. 307 00:20:55,000 --> 00:20:58,160 Other things you can do is you can step through your code. 308 00:20:58,160 --> 00:21:10,940 So in this, you can see that I'm essentially doing the exact same thing that we were in the previous demonstration of the native linking except now I've got some functions that as I'm stepping through help me understand a little bit more about what's going on. 309 00:21:10,940 --> 00:21:16,400 So the function type of, you can see is the third function I'm calling there. 310 00:21:16,400 --> 00:21:23,600 It's actually showing me that under the hood in JavaScript, this is actually a pointer to a Redis client object in Go's namespace. 311 00:21:25,060 --> 00:21:29,520 And that's a pretty nice thing to have to be able to use here as well. 312 00:21:29,520 --> 00:21:44,900 Also, any time you're in a script, if you want to compile your binary for yourself but then be able to drop into a debugger, we have a compiler flag enable debugging and you can just use the function debug console just like you would debugger in Chrome or anything like that. 313 00:21:44,900 --> 00:21:50,200 And when you run your binary, it will drop you into the same console right where you're at in the context of your script. 314 00:21:51,060 --> 00:21:57,280 Outside of that, as I mentioned before, type of, we have a bunch of specialty functions that are only available from within the debugger. 315 00:21:57,820 --> 00:22:06,380 That's been something we've expanded on in the last several weeks to try and make the native linking a lot more easy for people to do. 316 00:22:06,760 --> 00:22:08,280 Another one is symbol table. 317 00:22:08,280 --> 00:22:17,180 So you can call the symbol table function in the interactive debugger and that's actually going to go through and show you all the functions within Go's namespace that you've imported in there. 318 00:22:17,180 --> 00:22:19,900 Our standard library is actually instrumented in Go. 319 00:22:19,900 --> 00:22:21,820 You don't have to import it as a Go module. 320 00:22:21,820 --> 00:22:25,120 The compiler is smart enough to know, oh, you're calling a standard library function. 321 00:22:25,120 --> 00:22:26,540 I need to link against that. 322 00:22:27,280 --> 00:22:29,700 So we talked about how cool it is. 323 00:22:29,780 --> 00:22:33,240 There are some limitations and we'll just get these out of the way real quick. 324 00:22:33,480 --> 00:22:35,860 First thing, no free VSD support. 325 00:22:36,100 --> 00:22:42,820 I know that some of you neck beards in the crowd, I'm looking front row here, are going to be real upset about that. 326 00:22:43,460 --> 00:22:46,500 But I don't think it's impossible. 327 00:22:46,500 --> 00:22:51,520 It's just something where it was on a medium priority list for us to go and get done. 328 00:22:51,520 --> 00:22:58,800 I think as Go becomes more free VSD compliant in things like its OS and user lib, we'll be able to extend support to this as well. 329 00:22:59,040 --> 00:23:04,640 One of the other limitations that kind of people I've seen have issues with is these are large binaries. 330 00:23:04,640 --> 00:23:11,920 If you've ever worked with Go before, you know that Go binaries are never known to be the smallest, tiniest payloads in the world. 331 00:23:12,460 --> 00:23:15,020 Another limitation is the regular expressions. 332 00:23:15,020 --> 00:23:23,240 If you're going to do any regular expressions in JavaScript, they need to be essentially compliant with the RE2 library that Go uses. 333 00:23:23,320 --> 00:23:28,100 So things like look ahead and stuff like that, you're not going to have compatibility in that. 334 00:23:28,100 --> 00:23:29,100 So you've got to be careful. 335 00:23:29,100 --> 00:23:31,840 You can't use crazy complex regular expressions in it. 336 00:23:32,800 --> 00:23:35,840 Another thing that's been kind of difficult for us has been versioning. 337 00:23:36,340 --> 00:23:42,540 Go's versioning story has not been the greatest part of the language as it's evolved over the years. 338 00:23:42,700 --> 00:23:46,760 And that made it hard for us to do things like lock you into a specific version of it. 339 00:23:46,760 --> 00:23:56,880 So as Dan and I have done this, Dan will go write a bunch of G scripts and I'll come around and make a compiler change that will break all his scripts and he'll be like, oh, why can't I still stick with the old version? 340 00:23:57,220 --> 00:24:00,700 Well, a lot of that has been tied to this Go versioning problem. 341 00:24:00,760 --> 00:24:06,060 In the future, Go is releasing in 1.11 their new Go mod support. 342 00:24:06,260 --> 00:24:16,120 I think in the next major version of G script will actually release with an ability to lock your engines to a specific version of G script and be able to have backwards compatibility. 343 00:24:16,520 --> 00:24:20,240 As we said before, ES5 is the only thing we support right now. 344 00:24:20,240 --> 00:24:25,380 Working on ES6 support, there's complicated reasons why that's difficult for us. 345 00:24:25,380 --> 00:24:31,260 But something we'd like to do as we talk to people that write a lot of JavaScript, they seem to think that would have been a really nice feature for us. 346 00:24:31,260 --> 00:24:32,480 So we're working on that. 347 00:24:33,020 --> 00:24:38,060 Also something that we don't have is a lot of the JavaScript concurrency primitives that you guys might be used to. 348 00:24:38,420 --> 00:24:40,680 Just like in ES6 you have async. 349 00:24:40,680 --> 00:24:42,380 We don't have that stuff right now. 350 00:24:42,380 --> 00:24:50,640 Because our virtual machine is actually instrumented in native Go, we have to do all of this concurrency actually outside of that virtual machine's namespace. 351 00:24:51,320 --> 00:24:54,320 But as I mentioned before, we have the standard library. 352 00:24:54,320 --> 00:24:59,020 You don't need to be a Go programmer to know how to use this on a basic level. 353 00:24:59,400 --> 00:25:04,980 We've got libraries that cover almost every type of basic OS functionality you'll need. 354 00:25:04,980 --> 00:25:06,840 They're entirely cross platform. 355 00:25:07,020 --> 00:25:08,320 They're supported by us. 356 00:25:08,320 --> 00:25:11,320 If there's ever a bug in one of these that you find, please file it against us. 357 00:25:11,320 --> 00:25:12,860 We will fix it immediately. 358 00:25:13,260 --> 00:25:28,600 It is exactly the type of stuff where as we sat down and used G script in our jobs and at CCDC, we were able to say, there's some parts of Go that are just complicated and maybe not straightforward for the normal person. 359 00:25:28,600 --> 00:25:35,140 So let's just go kind of wrap that basic functionality in our standard library and present that to users for ease. 360 00:25:35,880 --> 00:25:37,560 So with that, I'm going to hand it back to Dan. 361 00:25:37,560 --> 00:25:43,400 Dan's going to talk about some of the ways that we've used this in the real world and why it just has really been powerful for us. 362 00:25:46,390 --> 00:25:53,110 So like Alex was saying, one of the number one reasons we use it is because we encounter a wide array of systems. 363 00:25:53,270 --> 00:25:55,090 Windows, Linux and Mac. 364 00:25:55,090 --> 00:25:59,430 And we didn't want to keep rewriting our techniques for these different operating systems. 365 00:25:59,430 --> 00:26:00,710 It was really kind of a pain. 366 00:26:00,890 --> 00:26:03,210 So we really like the cross platform features of it. 367 00:26:03,210 --> 00:26:15,530 You can actually write G scripts completely system, you can write them completely cross platform where the binary itself will determine which operating system it's on using Go and then execute according to that. 368 00:26:15,530 --> 00:26:18,850 Obviously you have to compile it to a specific architecture. 369 00:26:19,010 --> 00:26:21,190 So at the compilation time, there's always that. 370 00:26:21,190 --> 00:26:25,270 And when you're embedding assets, you still need to embed assets that can run on that specific architecture. 371 00:26:25,450 --> 00:26:27,370 But the platform itself is cross platform. 372 00:26:27,370 --> 00:26:28,290 So I love that. 373 00:26:29,190 --> 00:26:31,070 It's also really easy to use. 374 00:26:31,150 --> 00:26:38,930 Originally we were considering like having people write the Golang for that original Genesis dropper and then use that to embed their stuff. 375 00:26:38,930 --> 00:26:42,750 And it was a really hard kind of ask for people to learn Golang. 376 00:26:42,750 --> 00:26:46,690 So instead we decided to roll this out because now all they have to do is learn JavaScript. 377 00:26:46,770 --> 00:26:48,490 And JavaScript is really forgiving. 378 00:26:48,770 --> 00:26:52,250 Unlike Golang where it's really opinionated and you have to handle all your errors. 379 00:26:52,250 --> 00:26:55,690 So we think the barrier to entry with JavaScript is a lot lower than Golang. 380 00:26:55,790 --> 00:27:04,550 Another neat feature of that is when we added the Golang native linking, now it's also a good like gateway to learn Golang, right? 381 00:27:04,550 --> 00:27:13,730 You can start with JavaScript, you can play around in the debugger and eventually you can just start writing your own Golang native libs and then call them from G script, which is pretty cool. 382 00:27:14,610 --> 00:27:20,490 Just like I was saying, where you can call any Golang native library like off of GitHub, which is really freaking sweet. 383 00:27:20,490 --> 00:27:22,830 You can also wrap your existing tools. 384 00:27:22,830 --> 00:27:27,250 So you don't really have to change any of your existing tactics or any of your existing methodology. 385 00:27:27,330 --> 00:27:29,690 You can just instrument them now with G script. 386 00:27:30,050 --> 00:27:35,290 Which leads me to my next point, which is this is now like persistence and techniques as code. 387 00:27:35,290 --> 00:27:36,590 It's very auditable. 388 00:27:36,610 --> 00:27:41,410 We can give somebody this script that says this is exactly what it's going to do when it hits disk. 389 00:27:41,730 --> 00:27:53,450 Which is really nice because as you'll see, we've been building a community around documenting all of these different G scripts or I'm sorry, documenting miter attack techniques in G script. 390 00:27:53,510 --> 00:27:57,370 So now if you're familiar with miter attack, we have these small little atomic techniques. 391 00:27:57,390 --> 00:28:03,050 We've been writing G scripts such that you can compile native unsigned binaries with these techniques. 392 00:28:03,050 --> 00:28:15,190 It's kind of neat because this way you can see can I detect an unsigned binary doing this from a blue team perspective as opposed to like a script doing this, which might be easier or harder depending on your instrumentation. 393 00:28:16,310 --> 00:28:21,970 So like I was saying, we've been writing a ton of G scripts and we've been writing them to the miter attack framework. 394 00:28:22,130 --> 00:28:24,830 I try to make them as atomic as possible. 395 00:28:24,830 --> 00:28:30,670 So I try to keep the techniques as small as I can because you can compile N number of G scripts into a single binary. 396 00:28:31,050 --> 00:28:35,730 So the idea is you have a bunch of little techniques that all play well together . 397 00:28:36,270 --> 00:28:39,190 And again, we really want people to contribute stuff. 398 00:28:39,190 --> 00:28:45,950 We want to continue to catalog that miter attack framework such that we can compile it to these native binaries. 399 00:28:47,290 --> 00:28:50,710 So again, this tool was really built with a community in mind. 400 00:28:50,710 --> 00:28:56,170 This tool was built with multiple red teamers contributing payloads to build a single binary. 401 00:28:56,170 --> 00:29:01,770 It's really collaborative post exploitation is the idea. 402 00:29:01,770 --> 00:29:08,650 We want everybody to contribute a G script and we're going to run them all on the victim because we're a team. 403 00:29:11,290 --> 00:29:14,850 So here's a quick little example just showing some stuff. 404 00:29:15,610 --> 00:29:19,630 Up here we have a go import of a native package which is OS. 405 00:29:19,630 --> 00:29:22,510 We're going to use this to create a temp directory later. 406 00:29:22,790 --> 00:29:27,390 But we also import a special library we made called the X library. 407 00:29:27,710 --> 00:29:30,650 We had a lot of help with an unnamed person in the back. 408 00:29:31,010 --> 00:29:38,250 And this is an amazing library because these are the functions that yes, they're platform specific, but we would be remiss to leave them out. 409 00:29:38,250 --> 00:29:40,050 This is Windows registry editing. 410 00:29:40,050 --> 00:29:41,510 This is process injection. 411 00:29:41,510 --> 00:29:44,490 This is kind of that fancy stuff that is platform specific. 412 00:29:44,890 --> 00:29:49,090 And again, we move that into the X library because the core of G script is supposed to be cross platform. 413 00:29:49,630 --> 00:29:52,850 And below that, we're embedding this croissant.xc. 414 00:29:59,530 --> 00:30:06,430 This is so first thing we're doing is in this first block, this is just prepping the asset. 415 00:30:06,430 --> 00:30:16,470 This is just saying we have an embedded asset from compile time and we're just going to create this random temp directory string and that's where we're going to write this asset at execution. 416 00:30:16,690 --> 00:30:21,590 Here we're actually using the standard library just to write that file to a path. 417 00:30:21,730 --> 00:30:22,710 We're dropping a file. 418 00:30:22,710 --> 00:30:25,270 This is a great detection exercise. 419 00:30:25,630 --> 00:30:32,490 And then here is a run once key and we're just adding this to show this persistence method. 420 00:30:32,490 --> 00:30:39,210 So the idea here is we're creating persistence as code and we're abstracting the implant from it, right? 421 00:30:39,210 --> 00:30:45,830 So now you have this arbitrary persistence technique and you can just persist any old implant. 422 00:30:45,870 --> 00:30:49,610 And it's great for detection ops because do we detect persistence technique? 423 00:30:51,070 --> 00:30:53,330 It's also really cool for hunting ops. 424 00:30:53,330 --> 00:31:05,910 One thing that I really like is this idea of compiling a G script with multiple techniques in it like a technique A and a technique B and we can run this and then later a blue team can find this, they can dissect this and they can understand the techniques in it. 425 00:31:05,910 --> 00:31:07,370 Then they can hunt on those techniques. 426 00:31:07,370 --> 00:31:14,450 Let's say they had an alert for technique A, they reverse it and they learn about technique B, then they can hunt their data for technique B. 427 00:31:14,470 --> 00:31:20,490 Then we can play these games where we also compile a binary with technique B and technique C and do they find that, right? 428 00:31:20,490 --> 00:31:22,370 Something they may not have the alert for. 429 00:31:22,390 --> 00:31:27,610 So it's kind of cool for these like advanced hunt operations if you can get there in your organization. 430 00:31:28,750 --> 00:31:31,730 So kind of just like why do we really love this? 431 00:31:31,730 --> 00:31:38,190 If I could give you one line, N number of techniques, we keep the techniques really small and auditable. 432 00:31:38,190 --> 00:31:40,990 We wrap our existing tools so nothing really changes. 433 00:31:40,990 --> 00:31:45,910 We still use our C2s, we still use all of our favorite tools on disk or in memory. 434 00:31:46,510 --> 00:31:51,510 But we can codify the techniques of how we're instrumenting them and run them with a single click. 435 00:31:51,530 --> 00:31:53,370 So like what's not to love? 436 00:31:54,690 --> 00:31:56,590 So this always works, right? 437 00:31:58,790 --> 00:32:09,990 One really cool part about CCDC, Dave Cohen is like the grand master and he has this great strategic vision and at the end of day two at some point he really like, he unleashes the hounds. 438 00:32:09,990 --> 00:32:11,530 He kind of like lets us go, right? 439 00:32:11,530 --> 00:32:13,410 And we get to burn things down. 440 00:32:14,190 --> 00:32:17,230 So like taking down services is pretty straightforward, right? 441 00:32:17,230 --> 00:32:19,670 Like service, whatever, stop. 442 00:32:19,670 --> 00:32:21,150 Pretty basic and boring. 443 00:32:21,210 --> 00:32:23,590 So you want to get creative with it and have some fun. 444 00:32:23,970 --> 00:32:29,010 So one thing we like to do is make these troll payloads or trollware, if you will. 445 00:32:30,930 --> 00:32:36,090 So here we've bundled a ton of different trollware and we're just executing on a Windows machine. 446 00:32:36,090 --> 00:32:41,950 The idea here is you just see how much stuff can happen at once and what you can really do with it. 447 00:32:41,950 --> 00:32:47,090 It's a little overwhelming when it will execute and then it blue screens the box. 448 00:32:48,810 --> 00:32:50,310 But it's cool. 449 00:32:51,550 --> 00:32:54,150 So I'm just stepping into the directory where it is. 450 00:32:54,150 --> 00:32:57,770 I'm making the screen bigger so you can kind of see stuff as it happens. 451 00:32:57,910 --> 00:33:02,470 But once we execute this, the whole machine just goes to, you know, goes to hell. 452 00:33:09,280 --> 00:33:11,260 So this is going to run multiple payloads. 453 00:33:11,260 --> 00:33:16,540 This runs the mems which was made by Leoric, popularized by Dan cute. 454 00:33:18,000 --> 00:33:23,680 We had a good friend reverse a bunch of malware on the internet and we instrumented that. 455 00:33:24,200 --> 00:33:27,300 So that's just some of the trollware we like to throw around. 456 00:33:32,500 --> 00:33:33,500 All right. 457 00:33:33,500 --> 00:33:34,240 One demo down. 458 00:33:34,240 --> 00:33:35,200 One more to go. 459 00:33:37,080 --> 00:33:38,860 Yeah, the next one is actually live. 460 00:33:38,860 --> 00:33:39,660 That was just a video. 461 00:33:39,660 --> 00:33:41,200 But we're going to do this one live, too. 462 00:33:42,680 --> 00:33:44,920 We had another demo as well planned. 463 00:33:44,920 --> 00:33:46,580 RIP in the back there. 464 00:33:47,240 --> 00:33:51,480 But we'll save that for next year, right? 465 00:33:51,760 --> 00:33:59,340 So I'm going to boot up a virtual machine here called DEF CON 26 demo. 466 00:33:59,720 --> 00:34:02,500 This is just a standard OSX virtual machine. 467 00:34:02,800 --> 00:34:06,260 I'll make it full screen in a minute here. 468 00:34:06,560 --> 00:34:11,800 But first thing I want to do is I'm going to let's go through and make one of these together, right? 469 00:34:11,800 --> 00:34:13,780 So I've got my terminal up here. 470 00:34:13,780 --> 00:34:14,860 You guys can read that. 471 00:34:14,860 --> 00:34:19,460 I'll make it a little bit bigger for you guys. 472 00:34:20,520 --> 00:34:21,000 Cool. 473 00:34:21,000 --> 00:34:22,180 So I've got my terminal. 474 00:34:22,620 --> 00:34:24,280 I'm going to do an LS. 475 00:34:24,300 --> 00:34:29,200 I've got in here, we'll just go ahead and remove my test one so we can actually do it live. 476 00:34:29,400 --> 00:34:35,820 In it I've got a folder with a bunch of G scripts, right? 477 00:34:35,820 --> 00:34:44,060 This is all just Mac persistence technique, doing things like disabling the firewall and enabling guests and doing some SSH key persistence, right? 478 00:34:44,060 --> 00:34:49,060 And all of these, I'll show you one, like a service installer. 479 00:34:49,060 --> 00:34:54,200 It goes through and uses a library that we wrote called X service. 480 00:34:54,200 --> 00:34:58,400 So this is an experimental library, but it actually is a cross platform service installer. 481 00:34:58,400 --> 00:35:05,120 So it doesn't matter if there's a NITD or system D or it's a Windows box. 482 00:35:05,120 --> 00:35:10,420 You can very easily in one unified library install a system service, which is always fun. 483 00:35:10,420 --> 00:35:12,380 We love to do that when we're red teaming. 484 00:35:12,440 --> 00:35:14,080 So I've got all these scripts. 485 00:35:14,140 --> 00:35:16,860 I'm going to just go through and make one now live here with you. 486 00:35:16,860 --> 00:35:29,540 So I'm going to do G script, compile, dash, dash, output file, users, demo, OSX, live.bin. 487 00:35:30,000 --> 00:35:34,460 And then I'm going to say G scripts star.GS. 488 00:35:34,820 --> 00:35:36,780 And we're going to run this. 489 00:35:36,980 --> 00:35:42,800 It's going to take a minute , but relatively fast for considering what it's doing. 490 00:35:43,020 --> 00:35:52,360 Most of the time it's spending right now on this, it's spending actually embedding and encrypting all of the payloads that we're putting into this into the binary itself. 491 00:35:52,600 --> 00:35:56,760 So I think this takes about 20, 30 seconds right now. 492 00:35:56,760 --> 00:36:02,820 But as you see here, it does tell you all the scripts that it's essentially bundling into this executable. 493 00:36:02,820 --> 00:36:06,200 It lets you see some information that we're doing this for Darwin. 494 00:36:06,360 --> 00:36:08,040 Here's the output file. 495 00:36:08,120 --> 00:36:10,780 And some of those compiler flags, which I talked about before. 496 00:36:10,780 --> 00:36:15,740 So being able to keep the build directory, which will show you the source code that was used to make this. 497 00:36:15,740 --> 00:36:18,540 Enabling UPX compression disabled by default. 498 00:36:19,020 --> 00:36:21,120 A lot of different options we'll give you. 499 00:36:21,120 --> 00:36:23,640 And boom, scroll down, it's done. 500 00:36:23,680 --> 00:36:25,120 I'm going to look in there. 501 00:36:26,280 --> 00:36:28,920 It is a 26 megabyte binary. 502 00:36:28,920 --> 00:36:30,760 What payloads are you putting in here? 503 00:36:30,760 --> 00:36:31,780 Lord. 504 00:36:32,380 --> 00:36:34,480 Thank God that's local. 505 00:36:34,540 --> 00:36:35,900 And we have internet. 506 00:36:35,900 --> 00:36:36,780 Cool. 507 00:36:36,860 --> 00:36:43,040 I'm going to, while I'm here, SSH into our Merlin server. 508 00:36:45,500 --> 00:36:49,080 There we go. 509 00:36:49,160 --> 00:36:53,120 We've got some old dummy agents, but it's fine. 510 00:36:53,120 --> 00:36:55,260 They're not connected yet. 511 00:36:55,480 --> 00:37:03,460 Let's go into our VM now and take the executable that we just built, OSX live, copy it over. 512 00:37:08,810 --> 00:37:10,110 There we go. 513 00:37:10,110 --> 00:37:11,390 I don't have logging enabled. 514 00:37:11,390 --> 00:37:12,590 I didn't enable any of that. 515 00:37:12,590 --> 00:37:14,070 So it's going to be silent. 516 00:37:14,150 --> 00:37:20,030 So we're going to say sudo dot slash desktop OSX live, enter. 517 00:37:22,870 --> 00:37:25,030 And a bunch of stuff is happening. 518 00:37:25,130 --> 00:37:29,210 And then enter my password. 519 00:37:29,210 --> 00:37:31,250 That's not phishing at all. 520 00:37:32,910 --> 00:37:33,790 Boom. 521 00:37:33,890 --> 00:37:34,930 So something happened. 522 00:37:34,930 --> 00:37:36,350 I don't really know what. 523 00:37:36,450 --> 00:37:40,070 If I look back at my Merlin, I've now received a new agent check in. 524 00:37:40,890 --> 00:37:41,610 Live demo. 525 00:37:41,610 --> 00:37:42,390 Thank you. 526 00:37:47,820 --> 00:37:50,720 And we'll just come in here and look and see some things. 527 00:37:50,760 --> 00:37:54,680 So file sharing, remote log in, remote management, all this stuff was turned on. 528 00:37:54,680 --> 00:37:59,340 So all of the attack techniques that we just bundled into this were actually run on this machine. 529 00:37:59,420 --> 00:38:07,480 So if you're a red teamer, I think you can extrapolate why this is so valuable tool to use in your tool chain. 530 00:38:07,480 --> 00:38:19,360 If you're a blue teamer, if you work at a company that has a bunch of detection systems, man, how many of you guys have always wanted to know whether your vendor was actually telling the truth that they detect this thing or not? 531 00:38:19,660 --> 00:38:23,060 You can write the G script and I promise you they're not going to detect the binary. 532 00:38:23,160 --> 00:38:26,160 If they detect the actual activity, then you can validate that. 533 00:38:26,160 --> 00:38:36,340 And that's really the fundamental problem right now in the blue team space is how do I trust that when a vendor sells me something that says it does X that I actually know it can actually do that. 534 00:38:36,360 --> 00:38:52,100 What we're trying to do here is provide blue and red teams alike the ability to codify these techniques in a way where basic signature detection on a file is not going to just cheat the actual result of saying, yeah, I detect when something does shell code injection. 535 00:38:52,100 --> 00:38:58,800 Do you actually detect that or do you just detect that a file has a string in it that matches a certain thing? 536 00:38:59,140 --> 00:39:04,420 This is the type of evolution in security that we're trying to present to the world. 537 00:39:04,560 --> 00:39:13,900 So I will come back to our talk here and that's it. 538 00:39:13,980 --> 00:39:16,460 Version 1 is live right now on GitHub. 539 00:39:16,460 --> 00:39:18,580 I've written some documentations out. 540 00:39:18,580 --> 00:39:26,120 I've got some shoutouts for some awesome people who helped us with this on the side as well as somebody totally unnamed who didn't help at all with this project. 541 00:39:26,260 --> 00:39:27,540 He's not here. 542 00:39:27,540 --> 00:39:28,940 He didn't help us. 543 00:39:28,940 --> 00:39:32,240 His name is not at the bottom of that list of authors there. 544 00:39:33,020 --> 00:39:37,560 With that, I'd like to open it up to you guys for questions, comments, anything. 545 00:39:37,560 --> 00:39:38,360 Thank you. 546 00:39:48,270 --> 00:39:48,950 Anybody? 547 00:39:48,950 --> 00:39:49,730 Questions? 548 00:39:49,750 --> 00:39:50,730 You can just raise your hand. 549 00:39:50,730 --> 00:39:51,970 Yes, right there. 550 00:39:59,480 --> 00:40:01,480 Say that one more time. 551 00:40:09,130 --> 00:40:11,810 You probably could. 552 00:40:12,190 --> 00:40:17,510 I've not ‑‑ so the big problem with it has been the regular expression compatibility. 553 00:40:17,510 --> 00:40:23,090 So the question was, could you run a normal JavaScript application within G scripts? 554 00:40:23,290 --> 00:40:30,230 Yes, as long as it didn't break the regular expression or the asynchronous incompatibilities right now, it should be fine. 555 00:40:30,230 --> 00:40:33,290 So something like underscore, for example, does work within it. 556 00:40:33,290 --> 00:40:38,150 You can load an underscore library into that and it would work just fine. 557 00:40:38,210 --> 00:40:52,830 The ES6 compatibility is something where I think if we can get that actually implemented, it will give us a lot more flexibility in being able to allow more current JavaScript tools to be able to be run inside of it. 558 00:40:53,810 --> 00:40:55,290 Yes, right here. 559 00:41:01,300 --> 00:41:01,820 Okay. 560 00:41:02,720 --> 00:41:03,800 Yes. 561 00:41:07,550 --> 00:41:13,510 No, no, everything is ‑‑ so the question was, does the dropper fetch things from the GitHub URL? 562 00:41:13,510 --> 00:41:14,310 It doesn't. 563 00:41:14,310 --> 00:41:20,610 When you run G script compile, it contains everything you need right then and there into the binary. 564 00:41:20,650 --> 00:41:23,490 So everything happens at compile time, all the embedding does. 565 00:41:23,490 --> 00:41:33,570 It was one thing we were kind of on the fence about of saying, okay, should our droppers reach out and get stuff or should we just really try and pack them tightly and safely internally? 566 00:41:33,570 --> 00:41:38,930 One of the ideas there is when you're in a high security context solution, you may only have one or two ways out. 567 00:41:38,930 --> 00:41:44,110 You want to do things locally and use that existing C2 channel to shuttle stuff over. 568 00:41:44,350 --> 00:41:54,670 We have a request library and you can pull stuff down, but personally I like to kind of do stuff and go out of existing C2 channels and just operate through those channels. 569 00:41:56,070 --> 00:41:57,850 I think we had a question over here. 570 00:41:57,850 --> 00:41:58,510 Yes. 571 00:42:01,150 --> 00:42:07,610 Yeah, so the encryption of the assets is just AES 256. 572 00:42:08,090 --> 00:42:13,350 I'm not going to claim to be a crypto expert, but I try and just follow best practices on that. 573 00:42:13,470 --> 00:42:21,610 It is isolated per VM and it's unique every time you compile, so it's not generated in any sort of deterministic way. 574 00:42:21,610 --> 00:42:31,670 Now the obfuscation, I'm glad you asked, the obfuscation I would say is implemented in a way that assures zero reproducibility of builds. 575 00:42:31,710 --> 00:42:40,050 So if you're trying to reproduce an MD5 hash of two exact same inputs and outputs of a G script binary, I doubt that would actually ever happen. 576 00:42:40,270 --> 00:42:46,190 The obfuscator is meant to try and remove the ability to find static strings within it. 577 00:42:46,190 --> 00:42:51,710 It's meant to randomize things like function names and address space within the binary itself. 578 00:42:51,830 --> 00:42:58,390 And then we also have a post obfuscator that is not turned on by default, but you can play with it. 579 00:42:58,390 --> 00:43:00,570 It works really well on Windows and OSX. 580 00:43:00,570 --> 00:43:03,410 Windows, or excuse me, it works really well on Linux and OSX. 581 00:43:03,410 --> 00:43:08,670 Windows it kind of has some problems with sometimes. 582 00:43:09,270 --> 00:43:16,030 It basically after Go compiles your native binary, just goes through and starts patching stuff out of like the native executable. 583 00:43:16,050 --> 00:43:18,690 It's really dirty, but it does actually work. 584 00:43:18,690 --> 00:43:20,310 It does a great job sometimes. 585 00:43:21,750 --> 00:43:23,050 Yeah, sometimes. 586 00:43:23,210 --> 00:43:24,710 That's why we test, right? 587 00:43:24,770 --> 00:43:26,330 Anybody else have a question? 588 00:43:26,330 --> 00:43:28,070 We got about five minutes left. 589 00:43:28,330 --> 00:43:31,010 Maybe over here, I haven't... no? 590 00:43:31,530 --> 00:43:32,650 Come on. 591 00:43:33,490 --> 00:43:35,790 Everybody just wants to go to sleep, right? 592 00:43:35,790 --> 00:43:37,230 Yeah, we got a question in the back there. 593 00:43:39,470 --> 00:43:41,450 What if you want to write your own compiler? 594 00:43:41,450 --> 00:43:42,630 That's a great question. 595 00:43:43,550 --> 00:43:54,210 So we've implemented G script basically as in everything you've seen here, from the obfuscator to the compiler to the engine itself, it's all implemented itself as a library. 596 00:43:54,250 --> 00:44:09,290 So if you wanted to implement your own compiler, you could actually take the engine library, figure out how to translate whatever it is you wanted as your input into an engine itself, bundle that together in whatever way you want, and then boom, you've implemented your own essentially G script compiler. 597 00:44:09,790 --> 00:44:11,190 We've got some stuff on the works. 598 00:44:11,190 --> 00:44:29,190 If you're going to be at our workshop tomorrow, we'll touch on that a little bit of how we're actually looking at implementing a C2 in G script so that the C2 itself can supply the binary with G scripts at execution time so there's not actually something bundled into it or it can say, 599 00:44:29,190 --> 00:44:32,730 hey, switch up the C2 channel, talk to me now on this other channel. 600 00:44:33,190 --> 00:44:38,590 Interesting stuff like that is, I think, what you'd probably see from us next year in another follow-up talk. 601 00:44:38,770 --> 00:44:39,490 Yes, right here. 602 00:44:43,780 --> 00:44:45,840 Yeah, so we don't have a slack. 603 00:44:45,840 --> 00:44:47,360 We probably should have a slack. 604 00:44:47,360 --> 00:44:48,580 That's probably a good idea. 605 00:44:49,480 --> 00:44:51,480 At this point, it's just been on GitHub. 606 00:44:52,260 --> 00:44:55,280 If you send me a pull request, I would love it. 607 00:44:55,580 --> 00:44:57,220 We put a lot of effort into this. 608 00:44:57,220 --> 00:45:02,440 It's taken a lot of engineering hours and we're excited to kind of share it with the community. 609 00:45:03,720 --> 00:45:11,600 A lot of times we don't necessarily always release, so this has been something where we're excited to say, look, here, it can be good for the greater community at large. 610 00:45:11,600 --> 00:45:15,380 We have a few contributor guidelines, too, and then there's a lot of ways to get involved. 611 00:45:15,420 --> 00:45:25,700 You can write G scripts, you can help write different native libraries, you can help add to the compiler itself, and you can even just help with the documentation, right? 612 00:45:25,700 --> 00:45:29,340 Like anybody that wants to get involved, we're really receptive to people helping. 613 00:45:31,000 --> 00:45:33,620 I think we're... oh, one more? 614 00:45:33,620 --> 00:45:34,100 Where are we? 615 00:45:34,100 --> 00:45:34,760 Yes. 616 00:45:41,560 --> 00:45:42,140 Yes. 617 00:45:42,140 --> 00:45:53,340 So inside the documentation, if you go to this GitHub, there will be a link to Dan's repo where he is actually doing all of that miter mapping in a separate repo. 618 00:45:53,740 --> 00:45:55,660 I'm open to suggestions. 619 00:45:55,660 --> 00:46:05,080 So when you check it out, if you think there's a better folder structure, right now I was just doing it based on platforms and then I have each of the techniques linked in like the meta information in the top. 620 00:46:05,080 --> 00:46:08,200 But if there's a better way to organize it, I'm all ears. 621 00:46:09,500 --> 00:46:10,380 Cool. 622 00:46:10,900 --> 00:46:12,980 I think two minutes left. 623 00:46:12,980 --> 00:46:14,020 Anything else? 624 00:46:14,840 --> 00:46:17,760 Anybody raise your hand if you think you might use this at some point? 625 00:46:18,820 --> 00:46:19,700 Sweet. 626 00:46:19,980 --> 00:46:20,480 Awesome. 627 00:46:20,480 --> 00:46:22,760 Maybe we'll have a little G script con sometime. 628 00:46:23,900 --> 00:46:25,040 Thanks, guys.