start	end	text
0	5040	Hey, this is Alex. This is Dan. And I got something really cool to talk about.
8120	13840	How are you guys doing? Last talk of the day. Then you guys are going to go to bed right
13840	20400	after this, I imagine. Thanks for coming out, guys. This is pretty exciting for us. My name
20400	24660	is Alex Levenson. I've got Dan here. Today we're going to go through a tool that we wrote
24660	29020	the agenda today. We're going to talk about droppers and stagers, as some of you might
29020	33420	call them. Not really going to get pedantic about the terminology there. And how we kind
33420	37100	of got here today. After that, we're going to go into this technology that we built and how
37100	41180	it works. And we'll talk about some of the real world applications and then we'll give you a
41180	46840	demo which will inevitably fail. But, you know, we'll see how that goes. First off, just an
46840	53040	introduction for us. My name is Alex Levenson. I'm a senior security engineer at Uber. I've
53040	57980	been there for a couple of years. My specialty is really in tool development and red teaming. I
57980	64380	am a core red team member at the national CCDC and also the western regional CCDC as well.
64680	74480	Thank you. Hey guys. I'm Dan Borges. I'm a senior red team operator and dev. I also partake
74480	80580	in national CCDC on the red team. And Alex and I play a lot of cyber competitions together.
80800	87040	So we're just here to show you some of our cool tools. So we got to go back a little bit. We
87040	90460	are going to talk about what is a dropper, what is this classification thing we're talking
90460	96180	about. In our little hyper local kill chain right here, we have an exploit. This is your
96180	100280	initial vector. This is how you're getting on the server. This is usually like a memory
100280	104280	corruption attack, something like that. Next attackers usually move to some kind of stager.
104280	109020	This is moving from memory to their next tool. Often this can reach out and download more shell
109020	113280	code, do something like that. And then this is really where we're going to focus on. This is
113280	118120	your stage one. Some people call it the stage one, the stage two. This is the dropper. You're
118120	123180	moving from your exploit to bringing over your tools. This is what's going to bring over your
123180	128720	malware. It's going to put your persistence on the box, your deep slow stuff. And then finally
128720	133880	you have your own malware. These are your custom applications, maybe your specific TTPs that you
133880	138240	want to put on a box. And again, using a dropper here is important because you can protect your
138240	144860	TTPs, your tools and tactics and procedures by using the dropper. So where are droppers
144860	149960	used? We're trying to emulate what we see in the wild. What we see is a lot of third party
149960	154220	crime where people use these exploit kits and then between the exploit kit and their own
154220	158740	private malware, they'll usually lever some kind of dropper. They can do this as a form of
158740	164960	packing to either bundle it with other executables or just as a way to get their malware on to
164960	169760	the system. We can also use a dropper to be contextually aware and have contextually aware
169760	174940	implants. This is kind of like Stuxnet. Do you want to land on this system? Do I want to
174940	179760	deploy my payload? Sometimes you don't want to infect this host. That's a good thing for a
179760	185040	dropper to say and back off and not put the malware down. We use it a lot in our red team
185040	189660	operations for CCDC. We like to go fast and hard. This is the perfect tool for us to lay on
189660	196800	the pain fast. So a little bit of history about how we arrived here. Back in the day on the
196800	200280	CCDC red team, all these people would be bringing these super cool kits. We'd have really
200280	203760	advanced techniques. And they'd be going against a single team and they'd be using this
203760	209000	technique on this team. And what we wanted to do is we wanted to apply this pain to
209000	215640	everybody equally. So we started wrapping it in shell scripts, in PowerShell, bash and all
215640	220680	these great techniques to really just kind of drop six, seven implants, up to ten on a
220680	224980	single team. So now each team is not getting just one implant made specially for them. They're
224980	231120	getting all ten implants we made for everybody. So we can really share. And then around
231480	235280	2015, 2016, we moved to these, like I said, these scripts. But they started to have
235280	241240	drawbacks, right? They had like forensic drawbacks, right? People could find the scripts on
241240	245260	the systems, PowerShell script lock logging and they could tell exactly what we were doing.
245260	250920	They could get our source code, which was pretty dangerous for us as operators. So in late
250920	256460	2016, early 2017, we moved a lot of our tool chain to Golang. We did this for a number of
256460	261180	reasons, mostly because you get natively compiled executables. So you can get a binary that
261180	266700	runs specifically on an architecture. This means you have to disassemble it. It's hard to
266700	271540	decompile, which means you can't get that source code back. It's difficult to reverse. And
271540	276900	while we were doing this, we also started looking at what is a dropper? This had all of our
276900	282020	tactics built into it. And we really wanted to say, let's abstract our specific techniques
282020	289760	out and make a pure dropper that we can put any technique into. And at 2017 at a national
289760	294700	CCDC, we had a few friends, Virus, Lucas, and they put together this thing called Genesis,
294700	298480	where we had an SMB share, and you could just drop binaries in it. And we bundled them all
298480	302520	into one executable and ran it on the disk. It would run everything you put into the SMB
302520	307640	share. Just a native executable. This was really cool. This was really good. But it had a few
307640	312860	drawbacks. Instead of just running everything together, we wanted to specifically instrument
312860	321200	them in a certain way. So I think it was late 2017 into the 2018 CCDC season, Alex started
321200	326260	working on this prototype of G script, the Genesis scripting engine, which we'll get to. And
326260	330760	we used it. We used it all through this last CCDC season. It was really successful. We dropped
330760	335820	it on every single team at nationals. Everybody felt the pain. And then between then, which
335820	342180	was April 2018 and now, we've added a ton of cool new features. Like really sweet stuff. And
342180	349240	that's what we're going to get into today. Woo! Thank you, Dan. Yeah, as Dan said, today we
349240	355280	are going to show the world, you guys, the awesome information security community that we're
355280	360360	part of. Basically what we've done cumulatively over the last several years, but also some
360360	364760	really awesome features that even if you were at CCDC, you really didn't get a chance to play
364760	370060	with. But from now on, I'd like to introduce the Genesis scripting engine, or as we call it,
370060	375860	G script. What is G script? Dan covered sort of this thing. It's this dropper. It lets us take
375860	380760	malware and bundle it together and tape it up in a big ball and throw it at somebody. Great,
380760	384060	that's a good explanation. But how do you use it? What does it look like to you as the red
384060	390340	teamer? It's really easy. You have your payloads. You write a script for your payload. You use
390340	396100	the G script compiler on the command line. You get out a native binary. It couldn't be more
396100	401140	simple than that. I use this all over our documentation. G script is a framework that
401140	406940	allows you to rapidly implement custom droppers for all three major operating systems. So let's
406940	414920	talk about what makes up G script, right? So first off, there's the engine. The engine is the
414920	420920	thing that is inside of that native binary that you made that actually runs and executes the
420920	427060	logic that you've specified in your script. There's the compiler. The compiler takes your
427060	432340	script and turns it into that native binary. There's an obfuscator that's hooked into the
432340	435980	compiler that we wrote to try and make it a little bit harder for you blue team folks out
435980	442100	there. We really do like you, but, you know, we want to make you mad sometimes. We've got a
442100	446140	standard library. These are functions that you can use inside of your Genesis scripts. We've
446240	450200	got a command line tool. That's how you interact with the compiler and other things. And we
450200	455760	also have an interactive debugger to help you develop these scripts in a more reliable way,
455760	459960	let you test them out ahead of time so you're not doing stuff live. A high level walkthrough,
459960	466140	here's what happens. When you use the compiler and that three step process we just showed,
466140	470640	what ends up happening very first is the compiler goes and creates essentially
470640	476440	representations of engines within memory for each of the scripts that you pass into it. The
476440	480380	next thing it's going to do is every one of the payloads that you gave into it, we'll have
480380	484500	an interpreter payload, we'll have some shell code, we'll have some, you know, SSH keys that
484500	489380	we're going to drop somewhere, it encrypts and embeds them directly into that virtual
489380	494260	machine that it's got in memory. After that, it's going to take all in number of virtual
494260	498760	machines. Remember, it has a virtual machine isolated for each script. It's going to take all
498760	503300	in number of those and it's going to sew it all together. It's like with needle and thread
503840	509040	into an actual executable for whatever platform you're targeting. And then when that
509040	514780	executable is run, that main that it sewed up together is going to launch every one of those
514780	520400	run times in parallel. So let's do just a quick, quick walkthrough. You all know what, thank
520400	526340	you. So a quick walkthrough of this, just to kind of hopefully illuminate you guys on how
526340	533140	easy this is to use. So I've got a little example here. The example isn't, isn't crazy, it's
533140	537680	really simple. So we're going to write a script, it's eight lines. There's some important
537680	541940	things to note in this, though. It looks like JavaScript, for all intents and purposes it is
541940	546560	JavaScript, we've sprinkled some syntactic sugar in the form of comment macros, so
546560	550800	compiler macros that you see in the very first line there. That import statement is
550800	556540	telling the G script compiler, I want you to import this file off my disk when we go to bundle
556540	561320	this together. The next line, line three, is just a normal variable declaration like you
561320	565560	would call in JavaScript. And then lines five through eight there is a function called
565560	569960	deploy. Now when I talked before about when you run main, it launches all those virtual
569960	576960	machines, the JavaScript VMs essentially need an entry point to launch when that happens,
576960	581480	that's what it launches. It launches the deploy hook. So every one of your G scripts, no
581480	585440	matter what you're doing in it, will always have a function deploy with something defined
585440	591920	in it. What's defined in ours here? We get the payload dot text, the data that was in that
591920	597320	file, we get it as a string called payload data, and then we write that to the destination
597320	603240	file which we defined in line three. So very quick, very easy G script that anybody can
603240	608100	write. But hey, this is not just for one script, this can be for multiple things, right? So
608100	612680	let's write another one. What's this one doing? It's simply writing a file, second underscore
612680	620860	file dot text with the string rect. So what do we do now? Step three, just use the compiler,
620860	628440	one command, G script compile with an output file, star dot GS. GS is our file extension for
628440	636660	G script. That's it. And what did we get? At the top, we got dropper dot bin. What is dropper
636660	643160	dot bin? It's a 64 bit Mocko executable, I'm doing this on OSX. What else is in ‑‑ I run
643160	648620	it on the bottom of the first box there. And then what happens? All of a sudden you see
648620	653780	desk dot text and second file dot text in that directory. What's in those? Exactly the
653780	660720	contents that we had placed in them initially. All of you guys seem pretty quiet. Was that too
660720	666640	easy? Thank you. All right. So let's just talk about that. That seemed, you know, why
666640	671140	couldn't you do that with PowerShell or shell script or something like that? Well, first off,
671140	675480	you're getting a native binary. You're getting a native binary that I could have written the
675480	679580	first script, Dan could have written the next one. And if Dan messed his up or I messed mine
679580	683820	up, it's not going to take down the entire binary. It's going to keep executing. That's the
683820	688300	whole point of this is to be robust and resilient in the case of failure. When you do these
688300	692940	large scale red team ops and you have many people contributing code, you don't necessarily
692940	697880	have the luxury of constantly testing to make sure that somebody's payload isn't going to
697880	701700	mess up something in your process. So we really wanted to give the people writing the
701700	706580	payloads the ability to come up with their logic on how they wanted this to be bundled in to
707320	712260	the actual final binary. So you've got your native binary, you've got your isolated G script
712260	717340	engines, you've got the user defined logic in those scripts that is actually encrypted and
717340	722220	embedded just like the assets are into the binary. And then you've got the embedded assets
722220	727740	in their payloads. Those all get bundled together into one container inside of your native
727740	733160	binary. So let's talk about some of the features here, right? So first off, number one
733160	738080	feature we saw was that you get to do this in JavaScript. Now, I'm not a JavaScript
738080	744760	developer, but I think that we need to be making tools that are as easy for the broadest
744760	749100	selection of us to use, right? So I know a lot of people in here probably see programmers, a
749100	753360	lot of people in here do a lot of low level stuff. I wanted to make something common that
753360	756800	people were familiar with. There's a lot of people that do web pin testing. JavaScript
756800	760860	seems pretty familiar right now to a lot of people, so let's just go ahead and go with that.
760940	764620	So it's easy to write, it's easy to learn, there's good documentation on how to write
764620	769320	JavaScript well. Next thing is it's resilient to failure. As we talked about, if script 2
769320	775900	failed, script 1 would have kept on going. Third, it's highly customizable. So things like
775900	781400	order of operations of your script, timeouts, all of the stuff you can customize with those
781400	785300	compiler macros that we showed you, right? We showed you one, but there's many more you can
785300	791980	go with. So how is this cross-platform? It's written in Go. Essentially, this whole thing
791980	797440	is sort of leveraging the power of the Go compiler to make cross-platform malware for
797440	803860	anybody to be using here. Number 5, it's secure. We ran into this at CCDC where we had our
803860	807780	droppers essentially be reverse engineered very easily by just looking at the PowerShell
807780	813080	logs. I'm excited to release this today because I'm excited to see how hard it is for
813080	816620	somebody to actually reverse engineer one of these binaries. That is a challenge. Let me know
816620	822180	if you do. I'd love to see it. And the number one thing that is new to anybody who has seen
822180	827640	Genesys in the past is now you can actually call native Go from within your JavaScript. We'll
827640	833180	get into that. I know that sounds kind of wacky. So we talked about this initially, but
833180	838080	this diagram kind of gives you a little bit more context as to what happens. You've got your
838080	843540	main of your final binary. And when that gets run, you have all of these engines that are in
843540	848420	their own isolated namespace essentially get created. They initialize the JavaScript
848420	853380	virtual machine within them. They inject the scripts, all the assets and any libraries,
853380	857680	native Go libraries that you've called into it. And then it calls that deploy function, that
857680	863620	entry point, if you will, on each of those. And that happens pending any custom order of
863620	868920	operations with your macros. That happens all concurrently. So what does Gscript really let
868920	873740	you do? It lets you focus on what your stager is doing, not how am I going to implement this
873740	881540	for OSX even though I don't really know OSX or Windows or Linux. So this has been a process
881540	888020	for us, right? I'm not a computer science, you know, master's student who's studied the deep
888020	892800	internals of how software is made. I would like to say I was, but I definitely wasn't. I
892800	897420	started to take an operating systems class in college and I was way over my head. So this has
897420	901600	been a learning experience for me. And this is sort of some of the technology that I've
901600	906400	figured out and implemented here within Gscript. So when you go to do a compile, what
906400	910880	happens? Straightforward, the first thing that happens is it looks through all your scripts
910880	915520	and gets a essentially a mapping of all the macros that you've defined. The next thing it's
915520	921740	going to do is it's going to walk the abstract syntax tree of your JavaScript, notating
921740	926980	things like, oh, you imported a Go library with this macro and then you called it down here.
927120	930920	And registers, you know, things like how many arguments are you calling with it? What
931340	935440	might the type be? What can I infer the type might be of that argument? It then goes
935440	939880	through all the Go packages that you've included in that as well and does the same thing.
939880	944100	Walks all the AST there looking for places where functions are defined that you've called
944100	949160	from your JavaScript. Next, it's going to start marrying those together. It's going to
949160	954400	essentially create foreign function interface wrappers in Go on the fly for all of the
954400	958440	functions that you've called in JavaScript that are instrumented in native Go so that
958440	964780	you're, and then inject those into the VM that we're bundling itself together. That's
965340	969300	a probably another three talks worth of material to get into, but if you'd like to, it's
969300	974600	definitely on GitHub, you can go check it out. After that, we embed all the assets, we
974600	980360	encrypt them. Each VM has its own encryption key that all the assets get embedded with.
980540	985400	And the assets themselves don't actually get decrypted until you call them within your
985400	991600	script. So until you retrieve the asset, the asset isn't sitting in memory unencrypted. And
991600	996600	then the final step, optional, but we do enjoy it, is the obfuscation step. So we do the
996600	1002840	obfuscation both before and after native compilation. And we've got some interesting
1002840	1006980	stuff we'll kind of cover as to how that works there. So creating these standalone
1006980	1011520	executables, right? How do we go about doing that? Well, I said we leverage the Go compiler
1011520	1016620	to do that. Now, what's interesting about this is, if you can kind of see up here on
1016620	1022520	this, on the picture, we take your scripts and payload, and we actually write out an
1022520	1027460	entire Go program that contains the logic and everything needed that we just covered it
1028220	1032620	into this Go program. Now, there's flags in our compiler. You can go look at that code and
1032620	1037500	see what that looks like. It's incredibly unreadable. We needed to make it that way for
1038080	1044460	security, right? But it's been a really interesting thing to consider that, you know,
1044460	1048400	we're in a place in time where it's no longer enough to just write malware. You have to
1048400	1054220	write code that writes code that writes your malware, right? So we talked about this
1054220	1060220	before, too, and now I want to dive into this. Linking JavaScript and native Go. I was
1060220	1065360	called crazy a couple times in the process of this. This was definitely one of those. And I
1065360	1069340	still think it might be crazy. It's probably not the safest thing you can be doing in the
1069340	1077780	world, but it is crazy. Thank you. It's an interesting thing, right? You've got two
1077780	1082340	languages on completely opposite ends of the spectrum in terms of how they work. And
1082340	1087000	figuring out a way for a user to almost not know the difference between them is a
1087000	1091520	fascinating endeavor for me and Dan for us to kind of implement this and somebody in the
1091520	1097580	back who shall remain nameless. So here I've got a little example, right? So we use the
1097580	1102760	Go import macro, the compiler macro we talked about. We're going to import Redis. We're
1102760	1107280	going to import Redis because as far as I know, other than Node.js, there's really just
1107280	1111680	not an easy Redis library for JavaScript. There certainly isn't one for G script. You can't
1111680	1116720	import Node.js modules into this. So how are we going to interact with Redis and G
1116720	1123400	script? We're going to import the Go package for Redis. So we import that. And from there,
1123400	1129360	you import it, as you see there, as Redis. That as blank, blank is equal to the namespace
1129360	1133940	within the JavaScript program that you're defining here in your G script. So on the next
1133940	1139960	one, I call the functions directly. So Redis.parseURL is actually a exported function
1139960	1147260	within that Go package. And I can call it just like I would in Go. Now, one thing to
1147260	1155620	note, there's no multiple assignment in JavaScript. We're in ES5, not ES6. So in this
1155620	1162600	version, there's no multiple assignments. So if you look on line 5, you'll see R0. R0 is
1162600	1168120	because in our linker that we do, when we see that you're calling a Go function that's
1168120	1173240	returning multiple assignment, we actually make a dynamic array of that and give you back the
1173240	1179940	return of that inside a single object that is an array of various types. So R0 in that is
1179940	1186520	going to actually be the Redis client, the Redis connection URL. So line 5, we create a
1186520	1192680	Redis client. And line 6, we simply interact with it as we would any Go program, right? And
1192680	1198140	then down there, you look at the script, we compiled it normally and ran it and boom. Got
1198140	1205860	the, was able to interact with Redis right from G script using this native bridge. So I
1205860	1211880	wouldn't give you something incredibly, incredibly unsafe without some way to at least
1211880	1216000	play around with it and see how it worked and test your stuff, right? So we spent a lot of
1216000	1221360	time on an interactive debugger. It's pretty nice and easy to use. So at any time after you've
1221360	1226780	installed G script, you can simply do G script shell and it will drop you into a REPL right
1226780	1232120	there. The REPL has the entire standard library which we'll get into bundled into it. And you
1232120	1236700	can do kind of some various things. So for example, we talked about macros. How do you get a
1236700	1241400	macro into the shell when it's something the compiler knows? Well, in G script shell, you
1241400	1246260	can just pass the dash into it with macros. You can pass multiple as many as you'd like into
1246260	1250560	it. And then when it drops into that shell, it says if you've dropped into the deploy
1250560	1258260	function with that VM instrument. Other things you can do is you can step through your code. So
1258260	1262800	in this, you can see that I'm essentially doing the exact same thing that we were in the
1262800	1267060	previous demonstration of the native linking except now I've got some functions that as I'm
1267060	1271540	stepping through help me understand a little bit more about what's going on. So the function
1271540	1277520	type of, you can see is the third function I'm calling there. It's actually showing me that
1277520	1282600	under the hood in JavaScript, this is actually a pointer to a Redis client object in Go's
1282600	1290020	namespace. And that's a pretty nice thing to have to be able to use here as well. Also,
1290020	1295700	any time you're in a script, if you want to compile your binary for yourself but then be
1295700	1300440	able to drop into a debugger, we have a compiler flag enable debugging and you can just
1300440	1304560	use the function debug console just like you would debugger in Chrome or anything like
1304560	1308440	that. And when you run your binary, it will drop you into the same console right where you're
1308440	1314060	at in the context of your script. Outside of that, as I mentioned before, type of, we have a
1314060	1318580	bunch of specialty functions that are only available from within the debugger. That's been
1318580	1324300	something we've expanded on in the last several weeks to try and make the native linking a lot
1324300	1329900	more easy for people to do. Another one is symbol table. So you can call the symbol table
1329900	1333560	function in the interactive debugger and that's actually going to go through and show you all
1333560	1338320	the functions within Go's namespace that you've imported in there. Our standard library is
1338320	1342400	actually instrumented in Go. You don't have to import it as a Go module. The compiler is
1342400	1345900	smart enough to know, oh, you're calling a standard library function. I need to link against
1345900	1352080	that. So we talked about how cool it is. There are some limitations and we'll just get these
1352080	1358140	out of the way real quick. First thing, no free VSD support. I know that some of you neck
1358140	1365400	beards in the crowd, I'm looking front row here, are going to be real upset about that. But I
1365400	1369840	don't think it's impossible. It's just something where it was on a medium priority list for us
1369840	1375480	to go and get done. I think as Go becomes more free VSD compliant in things like its OS and
1375480	1380480	user lib, we'll be able to extend support to this as well. One of the other limitations that
1380480	1385220	kind of people I've seen have issues with is these are large binaries. If you've ever worked
1385220	1390400	with Go before, you know that Go binaries are never known to be the smallest, tiniest
1390400	1395500	payloads in the world. Another limitation is the regular expressions. If you're going to do
1395500	1401040	any regular expressions in JavaScript, they need to be essentially compliant with the RE2
1401040	1406600	library that Go uses. So things like look ahead and stuff like that, you're not going to
1406600	1410720	have compatibility in that. So you've got to be careful. You can't use crazy complex regular
1410720	1415840	expressions in it. Another thing that's been kind of difficult for us has been versioning.
1416340	1421880	Go's versioning story has not been the greatest part of the language as it's evolved over the
1421880	1426880	years. And that made it hard for us to do things like lock you into a specific version of it. So
1427620	1431660	as Dan and I have done this, Dan will go write a bunch of G scripts and I'll come around and
1431660	1435240	make a compiler change that will break all his scripts and he'll be like, oh, why can't I
1435240	1439880	still stick with the old version? Well, a lot of that has been tied to this Go versioning
1439880	1446940	problem. In the future, Go is releasing in 1.11 their new Go mod support. I think in the
1446940	1452520	next major version of G script will actually release with an ability to lock your engines to
1452660	1456960	a specific version of G script and be able to have backwards compatibility. As we said
1456960	1462820	before, ES5 is the only thing we support right now. Working on ES6 support, there's
1462820	1467260	complicated reasons why that's difficult for us. But something we'd like to do as we talk to
1467260	1470660	people that write a lot of JavaScript, they seem to think that would have been a really nice
1470660	1475160	feature for us. So we're working on that. Also something that we don't have is a lot of the
1475160	1480200	JavaScript concurrency primitives that you guys might be used to. Just like in ES6 you have
1480200	1484020	async. We don't have that stuff right now. Because our virtual machine is actually
1484020	1488980	instrumented in native Go, we have to do all of this concurrency actually outside of that
1488980	1494440	virtual machine's namespace. But as I mentioned before, we have the standard library. You
1494440	1499960	don't need to be a Go programmer to know how to use this on a basic level. We've got
1500680	1505140	libraries that cover almost every type of basic OS functionality you'll need. They're
1505140	1509720	entirely cross platform. They're supported by us. If there's ever a bug in one of these that
1509720	1514580	you find, please file it against us. We will fix it immediately. It is exactly the type of
1514580	1521640	stuff where as we sat down and used G script in our jobs and at CCDC, we were able to say,
1522360	1527840	there's some parts of Go that are just complicated and maybe not straightforward for the
1527840	1532620	normal person. So let's just go kind of wrap that basic functionality in our standard
1532620	1537560	library and present that to users for ease. So with that, I'm going to hand it back to Dan.
1537560	1541540	Dan's going to talk about some of the ways that we've used this in the real world and why it
1541540	1549770	just has really been powerful for us. So like Alex was saying, one of the number one
1549770	1555090	reasons we use it is because we encounter a wide array of systems. Windows, Linux and Mac.
1555090	1559430	And we didn't want to keep rewriting our techniques for these different operating systems.
1559430	1563510	It was really kind of a pain. So we really like the cross platform features of it. You can
1563510	1568550	actually write G scripts completely system, you can write them completely cross platform
1568550	1573550	where the binary itself will determine which operating system it's on using Go and then
1573550	1579570	execute according to that. Obviously you have to compile it to a specific architecture. So at
1579570	1582610	the compilation time, there's always that. And when you're embedding assets, you still need
1582610	1586670	to embed assets that can run on that specific architecture. But the platform itself is
1586670	1591730	cross platform. So I love that. It's also really easy to use. Originally we were
1591730	1596070	considering like having people write the Golang for that original Genesis dropper and then
1596070	1601930	use that to embed their stuff. And it was a really hard kind of ask for people to learn
1601930	1605890	Golang. So instead we decided to roll this out because now all they have to do is learn
1605890	1610530	JavaScript. And JavaScript is really forgiving. Unlike Golang where it's really opinionated
1610530	1614090	and you have to handle all your errors. So we think the barrier to entry with JavaScript
1614090	1620330	is a lot lower than Golang. Another neat feature of that is when we added the Golang native
1620330	1625130	linking, now it's also a good like gateway to learn Golang, right? You can start with
1625130	1628910	JavaScript, you can play around in the debugger and eventually you can just start writing
1628910	1633730	your own Golang native libs and then call them from G script, which is pretty cool.
1634610	1638870	Just like I was saying, where you can call any Golang native library like off of GitHub,
1638870	1643290	which is really freaking sweet. You can also wrap your existing tools. So you don't really
1643290	1647690	have to change any of your existing tactics or any of your existing methodology. You can
1647690	1652370	just instrument them now with G script. Which leads me to my next point, which is this is
1652370	1657410	now like persistence and techniques as code. It's very auditable. We can give somebody
1657410	1662130	this script that says this is exactly what it's going to do when it hits disk. Which
1662130	1668090	is really nice because as you'll see, we've been building a community around documenting
1668090	1672730	all of these different G scripts or I'm sorry, documenting miter attack techniques in G
1672730	1676390	script. So now if you're familiar with miter attack, we have these small little atomic
1676390	1681330	techniques. We've been writing G scripts such that you can compile native unsigned
1681330	1685750	binaries with these techniques. It's kind of neat because this way you can see can I
1685750	1690830	detect an unsigned binary doing this from a blue team perspective as opposed to like a
1690830	1696510	script doing this, which might be easier or harder depending on your instrumentation. So
1696510	1700430	like I was saying, we've been writing a ton of G scripts and we've been writing them to
1700430	1705390	the miter attack framework. I try to make them as atomic as possible. So I try to keep
1705390	1709830	the techniques as small as I can because you can compile N number of G scripts into a
1709830	1715250	single binary. So the idea is you have a bunch of little techniques that all play well
1715250	1720470	together. And again, we really want people to contribute stuff. We want to continue
1720470	1725950	to catalog that miter attack framework such that we can compile it to these native binaries.
1727290	1732330	So again, this tool was really built with a community in mind. This tool was built with
1732330	1736630	multiple red teamers contributing payloads to build a single binary. It's really
1736630	1744690	collaborative post exploitation is the idea. We want everybody to contribute a G script and
1745310	1752730	we're going to run them all on the victim because we're a team. So here's a quick little
1752730	1758790	example just showing some stuff. Up here we have a go import of a native package which is
1758790	1764690	OS. We're going to use this to create a temp directory later. But we also import a special
1764690	1769990	library we made called the X library. We had a lot of help with an unnamed person in the
1769990	1774910	back. And this is an amazing library because these are the functions that yes, they're
1774910	1779450	platform specific, but we would be remiss to leave them out. This is Windows registry
1779450	1783570	editing. This is process injection. This is kind of that fancy stuff that is platform
1783570	1787710	specific. And again, we move that into the X library because the core of G script is
1787710	1799970	supposed to be cross platform. And below that, we're embedding this croissant.xc. This is
1799970	1806670	so first thing we're doing is in this first block, this is just prepping the asset. This is
1806670	1811590	just saying we have an embedded asset from compile time and we're just going to create this
1811590	1816470	random temp directory string and that's where we're going to write this asset at execution.
1816690	1821890	Here we're actually using the standard library just to write that file to a path. We're
1821890	1829310	dropping a file. This is a great detection exercise. And then here is a run once key and
1829310	1834530	we're just adding this to show this persistence method. So the idea here is we're creating
1834530	1840210	persistence as code and we're abstracting the implant from it, right? So now you have this
1840210	1846430	arbitrary persistence technique and you can just persist any old implant. And it's great for
1846430	1852690	detection ops because do we detect persistence technique? It's also really cool for hunting
1852690	1858430	ops. One thing that I really like is this idea of compiling a G script with multiple techniques
1858430	1862950	in it like a technique A and a technique B and we can run this and then later a blue team can
1862950	1866310	find this, they can dissect this and they can understand the techniques in it. Then they can
1866310	1870930	hunt on those techniques. Let's say they had an alert for technique A, they reverse it and
1870930	1875230	they learn about technique B, then they can hunt their data for technique B. Then we can play
1875230	1879690	these games where we also compile a binary with technique B and technique C and do they find
1879690	1883910	that, right? Something they may not have the alert for. So it's kind of cool for these like
1883910	1890970	advanced hunt operations if you can get there in your organization. So kind of just like why do we
1890970	1896430	really love this? If I could give you one line, N number of techniques, we keep the techniques
1896430	1901490	really small and auditable. We wrap our existing tools so nothing really changes. We still use
1901490	1907890	our C2s, we still use all of our favorite tools on disk or in memory. But we can codify the
1907890	1912510	techniques of how we're instrumenting them and run them with a single click. So like what's not
1912510	1923370	to love? So this always works, right? One really cool part about CCDC, Dave Cohen is like the
1923370	1928350	grand master and he has this great strategic vision and at the end of day two at some point he
1928350	1932630	really like, he unleashes the hounds. He kind of like lets us go, right? And we get to burn things
1932630	1938930	down. So like taking down services is pretty straightforward, right? Like service, whatever,
1938930	1944290	stop. Pretty basic and boring. So you want to get creative with it and have some fun. So one
1944290	1951790	thing we like to do is make these troll payloads or trollware, if you will. So here we've
1951790	1956490	bundled a ton of different trollware and we're just executing on a Windows machine. The idea
1956490	1962270	here is you just see how much stuff can happen at once and what you can really do with it. It's a
1962270	1972010	little overwhelming when it will execute and then it blue screens the box. But it's cool. So I'm
1972010	1976090	just stepping into the directory where it is. I'm making the screen bigger so you can kind of
1976090	1981630	see stuff as it happens. But once we execute this, the whole machine just goes to, you know,
1981630	1993760	goes to hell. So this is going to run multiple payloads. This runs the mems which was made by
1993760	2000580	Leoric, popularized by Dan cute. We had a good friend reverse a bunch of malware on the
2000580	2006700	internet and we instrumented that. So that's just some of the trollware we like to throw
2006700	2019060	around. All right. One demo down. One more to go. Yeah, the next one is actually live. That was
2019060	2024920	just a video. But we're going to do this one live, too. We had another demo as well planned.
2024920	2033780	RIP in the back there. But we'll save that for next year, right? So I'm going to boot up a
2033780	2043360	virtual machine here called DEF CON 26 demo. This is just a standard OSX virtual machine. I'll
2043360	2050280	make it full screen in a minute here. But first thing I want to do is I'm going to let's go
2050280	2054160	through and make one of these together, right? So I've got my terminal up here. You guys can
2054160	2062860	read that. I'll make it a little bit bigger for you guys. Cool. So I've got my terminal. I'm
2062860	2067920	going to do an LS. I've got in here, we'll just go ahead and remove my test one so we can
2067920	2076200	actually do it live. In it I've got a folder with a bunch of G scripts, right? This is all
2076200	2080800	just Mac persistence technique, doing things like disabling the firewall and enabling guests
2080800	2088300	and doing some SSH key persistence, right? And all of these, I'll show you one, like a
2088300	2094540	service installer. It goes through and uses a library that we wrote called X service. So this
2094540	2099320	is an experimental library, but it actually is a cross platform service installer. So it doesn't
2099320	2107460	matter if there's a NITD or system D or it's a Windows box. You can very easily in one unified
2107460	2112380	library install a system service, which is always fun. We love to do that when we're red teaming.
2112440	2116860	So I've got all these scripts. I'm going to just go through and make one now live here with you.
2116860	2130320	So I'm going to do G script, compile, dash, dash, output file, users, demo, OSX, live.bin. And
2130320	2139020	then I'm going to say G scripts star.GS. And we're going to run this. It's going to take a
2139020	2145020	minute, but relatively fast for considering what it's doing. Most of the time it's spending right
2145020	2149560	now on this, it's spending actually embedding and encrypting all of the payloads that we're
2149560	2156760	putting into this into the binary itself. So I think this takes about 20, 30 seconds right now.
2156760	2161960	But as you see here, it does tell you all the scripts that it's essentially bundling into this
2161960	2167120	executable. It lets you see some information that we're doing this for Darwin. Here's the output
2167120	2171940	file. And some of those compiler flags, which I talked about before. So being able to keep the
2171940	2176540	build directory, which will show you the source code that was used to make this. Enabling UPX
2176540	2182600	compression disabled by default. A lot of different options we'll give you. And boom, scroll down,
2182600	2189780	it's done. I'm going to look in there. It is a 26 megabyte binary. What payloads are you
2189780	2199580	putting in here? Lord. Thank God that's local. And we have internet. Cool. I'm going to, while
2199580	2212580	I'm here, SSH into our Merlin server. There we go. We've got some old dummy agents, but it's
2212580	2220720	fine. They're not connected yet. Let's go into our VM now and take the executable that we just
2220720	2232090	built, OSX live, copy it over. There we go. I don't have logging enabled. I didn't enable any
2232090	2239330	of that. So it's going to be silent. So we're going to say sudo dot slash desktop OSX live,
2239330	2250550	enter. And a bunch of stuff is happening. And then enter my password. That's not phishing at
2250550	2258350	all. Boom. So something happened. I don't really know what. If I look back at my Merlin, I've now
2258350	2269740	received a new agent check in. Live demo. Thank you. And we'll just come in here and look and see
2269740	2274680	some things. So file sharing, remote log in, remote management, all this stuff was turned on.
2274680	2278520	So all of the attack techniques that we just bundled into this were actually run on this
2278520	2286320	machine. So if you're a red teamer, I think you can extrapolate why this is so valuable tool to
2286320	2290720	use in your tool chain. If you're a blue teamer, if you work at a company that has a bunch of
2290720	2296480	detection systems, man, how many of you guys have always wanted to know whether your vendor was
2296480	2300980	actually telling the truth that they detect this thing or not? You can write the G script and I
2300980	2304880	promise you they're not going to detect the binary. If they detect the actual activity, then
2304880	2309760	you can validate that. And that's really the fundamental problem right now in the blue team
2309760	2314440	space is how do I trust that when a vendor sells me something that says it does X that I
2314440	2319200	actually know it can actually do that. What we're trying to do here is provide blue and red
2319200	2325720	teams alike the ability to codify these techniques in a way where basic signature detection on a
2325720	2330580	file is not going to just cheat the actual result of saying, yeah, I detect when something
2330580	2337180	does shell code injection. Do you actually detect that or do you just detect that a file has a
2337180	2343020	string in it that matches a certain thing? This is the type of evolution in security that we're
2343020	2354960	trying to present to the world. So I will come back to our talk here and that's it. Version 1 is
2354960	2359620	live right now on GitHub. I've written some documentations out. I've got some shoutouts for
2359620	2363800	some awesome people who helped us with this on the side as well as somebody totally unnamed
2363800	2369760	who didn't help at all with this project. He's not here. He didn't help us. His name is not at
2369760	2375080	the bottom of that list of authors there. With that, I'd like to open it up to you guys for
2375080	2390730	questions, comments, anything. Thank you. Anybody? Questions? You can just raise your hand.
2390730	2414770	Yes, right there. Say that one more time. You probably could. I've not ‑‑ so the big
2414770	2418570	problem with it has been the regular expression compatibility. So the question was, could you run
2418690	2426290	a normal JavaScript application within G scripts? Yes, as long as it didn't break the regular
2426290	2430550	expression or the asynchronous incompatibilities right now, it should be fine. So something
2430550	2436330	like underscore, for example, does work within it. You can load an underscore library into that
2436330	2442510	and it would work just fine. The ES6 compatibility is something where I think if we can get
2442510	2449550	that actually implemented, it will give us a lot more flexibility in being able to allow more
2449550	2463800	current JavaScript tools to be able to be run inside of it. Yes, right here. Okay. Yes.
2467550	2472390	No, no, everything is ‑‑ so the question was, does the dropper fetch things from the
2472390	2478530	GitHub URL? It doesn't. When you run G script compile, it contains everything you need right
2478530	2483490	then and there into the binary. So everything happens at compile time, all the embedding does.
2483490	2488830	It was one thing we were kind of on the fence about of saying, okay, should our droppers reach
2488830	2493570	out and get stuff or should we just really try and pack them tightly and safely internally?
2493570	2497930	One of the ideas there is when you're in a high security context solution, you may only have one
2497930	2503310	or two ways out. You want to do things locally and use that existing C2 channel to shuttle
2503310	2509750	stuff over. We have a request library and you can pull stuff down, but personally I like to
2509750	2514670	kind of do stuff and go out of existing C2 channels and just operate through those channels.
2516070	2526730	I think we had a question over here. Yes. Yeah, so the encryption of the assets is just AES
2526730	2532650	256. I'm not going to claim to be a crypto expert, but I try and just follow best practices on
2532650	2540090	that. It is isolated per VM and it's unique every time you compile, so it's not generated in any
2540090	2545950	sort of deterministic way. Now the obfuscation, I'm glad you asked, the obfuscation I would
2545950	2553050	say is implemented in a way that assures zero reproducibility of builds. So if you're trying to
2553050	2558530	reproduce an MD5 hash of two exact same inputs and outputs of a G script binary, I doubt that
2558530	2564470	would actually ever happen. The obfuscator is meant to try and remove the ability to find
2564470	2570110	static strings within it. It's meant to randomize things like function names and address space
2570110	2575830	within the binary itself. And then we also have a post obfuscator that is not turned on by
2576370	2581430	default, but you can play with it. It works really well on Windows and OSX. Windows, or
2581430	2587150	excuse me, it works really well on Linux and OSX. Windows it kind of has some problems with
2587710	2592910	sometimes. It basically after Go compiles your native binary, just goes through and starts
2592910	2598390	patching stuff out of like the native executable. It's really dirty, but it does actually
2598390	2605470	work. It does a great job sometimes. Yeah, sometimes. That's why we test, right? Anybody else
2605470	2612650	have a question? We got about five minutes left. Maybe over here, I haven't... no? Come on.
2613490	2620010	Everybody just wants to go to sleep, right? Yeah, we got a question in the back there. What if
2620010	2625410	you want to write your own compiler? That's a great question. So we've implemented G script
2625410	2630390	basically as in everything you've seen here, from the obfuscator to the compiler to the
2630390	2635370	engine itself, it's all implemented itself as a library. So if you wanted to implement your
2635370	2639450	own compiler, you could actually take the engine library, figure out how to translate
2639450	2644370	whatever it is you wanted as your input into an engine itself, bundle that together in whatever
2644370	2650110	way you want, and then boom, you've implemented your own essentially G script compiler. We've
2650110	2655930	got some stuff on the works. If you're going to be at our workshop tomorrow, we'll touch on
2655930	2661750	that a little bit of how we're actually looking at implementing a C2 in G script so that the
2661750	2667550	C2 itself can supply the binary with G scripts at execution time so there's not actually
2667550	2671710	something bundled into it or it can say, hey, switch up the C2 channel, talk to me now on
2671710	2675870	this other channel. Interesting stuff like that is, I think, what you'd probably see from
2675870	2686100	us next year in another follow-up talk. Yes, right here. Yeah, so we don't have a slack. We
2686100	2690880	probably should have a slack. That's probably a good idea. At this point, it's just been on
2690880	2697360	GitHub. If you send me a pull request, I would love it. We put a lot of effort into this. It's
2697360	2704120	taken a lot of engineering hours and we're excited to kind of share it with the community. A
2704120	2707140	lot of times we don't necessarily always release, so this has been something where we're
2707140	2712380	excited to say, look, here, it can be good for the greater community at large. We have a few
2712380	2716280	contributor guidelines, too, and then there's a lot of ways to get involved. You can write G
2716280	2721240	scripts, you can help write different native libraries, you can help add to the compiler
2721240	2726680	itself, and you can even just help with the documentation, right? Like anybody that wants to
2726680	2733780	get involved, we're really receptive to people helping. I think we're... oh, one more? Where
2733780	2746760	are we? Yes. Yes. So inside the documentation, if you go to this GitHub, there will be a
2746760	2754140	link to Dan's repo where he is actually doing all of that miter mapping in a separate repo.
2754140	2757860	I'm open to suggestions. So when you check it out, if you think there's a better folder
2757860	2762940	structure, right now I was just doing it based on platforms and then I have each of the
2762940	2766660	techniques linked in like the meta information in the top. But if there's a better way to
2766660	2768200	organize it, I'm all ears.
2769500	2776240	Cool. I think two minutes left. Anything else? Anybody raise your hand if you think you
2776240	2782020	might use this at some point? Sweet. Awesome. Maybe we'll have a little G script con
2782020	2785040	sometime. Thanks, guys.
