1 00:00:04,000 --> 00:00:05,600 All right. 2 00:00:05,600 --> 00:00:08,180 Thank you so much for coming to my talk, everyone. 3 00:00:08,340 --> 00:00:13,580 Not only am I a first-time speaker, but it's also my first time attending DEF CON. 4 00:00:13,580 --> 00:00:16,560 So I'm really excited to be... yeah, that's right. 5 00:00:17,680 --> 00:00:19,080 Thank you. 6 00:00:19,400 --> 00:00:20,020 Yeah. 7 00:00:20,020 --> 00:00:24,240 So I'm excited to be here and give you my talk, C4. 8 00:00:26,180 --> 00:00:33,240 As a quick disclaimer, this is given on my personal behalf and does not reflect my current employer, Sony Corporation. 9 00:00:34,720 --> 00:00:35,320 All right. 10 00:00:35,320 --> 00:00:40,840 So like I said, I'm Scott Taylor, and I'm part of Sony's internal red team. 11 00:00:41,260 --> 00:00:44,540 Prior to Sony, I've done red team work with T. 12 00:00:44,540 --> 00:00:46,940 Rowe Price and the MITRE Corporation. 13 00:00:47,060 --> 00:00:56,120 But before all of the offensive security work, I started as a Linux system administrator, because you have to learn how to build before you break things. 14 00:00:57,020 --> 00:00:59,540 Additionally, I have a couple of certs and degrees. 15 00:01:00,280 --> 00:01:07,060 So for today, I'm going to be talking about a tool that I wrote called C4, the cross-compatible command and control. 16 00:01:07,520 --> 00:01:15,200 And this tool heavily relies on the commonly known technique in the red team world called external C2 or external command and control . 17 00:01:15,700 --> 00:01:26,920 So in your typical red team operation, as usual, you're going to drop malware onto the blue team's monitor computers, and that malware is going to reach out to your red team command and control server. 18 00:01:27,220 --> 00:01:40,020 Now, some of the more advanced teams, instead of directly communicating from your malware to the team server, you're going to instead use a trusted third party website to perform your message communication. 19 00:01:40,240 --> 00:01:49,960 So there's been instances of using like GitHub and AWS, various trusted websites that typical users in your enterprise are going to browse to. 20 00:01:49,960 --> 00:01:57,500 But instead, as offensive security folks, we are going to send our malicious messages through these same trusted websites. 21 00:01:58,560 --> 00:02:05,340 So earlier this year, there was a really cool project that was released called the LOLC2 or living off the land C2. 22 00:02:05,340 --> 00:02:11,160 And this documented numerous websites that were compatible with external C2. 23 00:02:11,160 --> 00:02:24,480 So security researchers managed to figure out how to do this communication over very popular websites like Microsoft OneDrive, Google Calendar, and even some fun ones like over a counter strike server. 24 00:02:25,500 --> 00:02:37,720 So security researchers are certainly using this in the wild and doing a lot of creative research in this space, but also threat actors or the bad guys are also getting in on this. 25 00:02:38,080 --> 00:02:45,770 So as you can see, I have a screen shot of the MITRE attack framework, because of course, as a former MITRE employee, I have to rep the attack framework. 26 00:02:46,290 --> 00:02:54,230 And you see there's a couple of examples like Google Drive, Dropbox, and all these trusted websites being used in the wild. 27 00:02:54,550 --> 00:03:00,830 Now one thing to note is in this attack framework, this technique was actually added all the way back in 2017. 28 00:03:01,250 --> 00:03:05,110 So it's certainly not a new development in the red team space. 29 00:03:05,110 --> 00:03:08,710 So you might be wondering, well, why are you coming to DEF CON and talking about it? 30 00:03:09,970 --> 00:03:24,670 Well, I started thinking about external C2, and I was like, well, there's all these C2 frameworks out there, but when you actually start using them, there's only a handful of external C2 options available for each one. 31 00:03:24,930 --> 00:03:29,630 So in Cobblestrike, you see a couple of the interesting C2 profiles. 32 00:03:29,630 --> 00:03:38,190 Personally, I'm a mythic C2 person, and there's a handful there, but in the previous screen shot, you saw loads of examples. 33 00:03:38,650 --> 00:03:49,890 So, you know, I started looking at it, and I'm like, well, yeah, it's challenging to take some of these really custom C2 profiles that are specific to a framework and port it to other frameworks. 34 00:03:50,050 --> 00:03:57,950 So today I'm going to talk about my tool C4, and how I aim to tackle this issue of portability of external C2. 35 00:03:59,930 --> 00:04:10,090 So, like I mentioned, I'm a mythic C2 fan, and with this framework, it's quite simple to develop your C2 profiles. 36 00:04:10,090 --> 00:04:19,590 Mythic deploys in multiple docker containers, and the actual C2 portion of the framework runs in its own docker container. 37 00:04:19,590 --> 00:04:33,290 So what I did was I developed the server side in Python, and this is published on GitHub, and not, you know, granted I'm exploiting GitHub, but in this case, it's actually published on GitHub. 38 00:04:33,490 --> 00:04:37,810 And on the client side, this is where mythic is a little bit more unique. 39 00:04:38,170 --> 00:04:45,290 Commonly in C2 frameworks, you have one agent for one C2 framework, so you might have, for example, beacon for Cobalt Strike. 40 00:04:45,290 --> 00:04:48,570 In mythic, there's multiple agents that exist. 41 00:04:48,570 --> 00:04:59,030 So for myself, I decided to develop this for the Athena agent, which is an agent run by check commander, and this agent is written in the dot net framework. 42 00:04:59,410 --> 00:05:12,890 So with dot net, I was able to find a dot net library out there to very easily interact with GitHub, and this is quite specific developed for this agent. 43 00:05:15,090 --> 00:05:18,250 Now, the cool thing is, yeah, this worked great. 44 00:05:18,250 --> 00:05:35,230 I was able to do my, you know, GitHub C2 using the Athena agent in the mythic C2 framework, but some of the other agent developers for this framework were like, well, I want to get in on the fun, but it's a little more challenging to take what I developed in dot net and port it to all these other languages . 45 00:05:35,730 --> 00:05:40,790 You know, all you malware developers out there, I'm sure you all have your preferred languages that you like to write in. 46 00:05:41,250 --> 00:05:45,170 You know, even in this case, I have a table of all the different agents, just some of them. 47 00:05:45,170 --> 00:05:46,210 There are more than this. 48 00:05:46,410 --> 00:05:49,970 And, you know, it ranges from all over the place. 49 00:05:50,230 --> 00:05:54,730 There's even like a JavaScript agent that acts as a malicious Visual Studio code extension. 50 00:05:54,810 --> 00:06:08,150 So, really cool stuff, but again, I wanted to find a way to take these external C2 profiles that I'm developing and make it more accessible for malware developers regardless of language of choice. 51 00:06:08,810 --> 00:06:17,510 So, this started my security research endeavor and I ended up stumbling upon WebAssembly. 52 00:06:19,070 --> 00:06:25,550 So, for WebAssembly, I went into this thinking, well, this is more of like a browser technology thing. 53 00:06:25,550 --> 00:06:27,730 And, you know, this is partly true. 54 00:06:27,790 --> 00:06:34,810 For WebAssembly, this is a compiled format, so you end up with a bunch of dot WASM files. 55 00:06:35,170 --> 00:06:41,250 And these WASM files, or WASM modules, I should say, they run at near native speed. 56 00:06:41,250 --> 00:06:43,350 So, for web developers, they love it. 57 00:06:43,350 --> 00:06:53,950 For example, the folks that develop Photoshop took that really intensive program, compiled it down to a WebAssembly module, loaded it in the browser, and now you can do Photoshop in the browser. 58 00:06:53,970 --> 00:06:55,990 So, really cool advancements. 59 00:06:56,030 --> 00:07:03,370 But the problem is, for WebAssembly, you know, this instance, this is all in the browser. 60 00:07:03,370 --> 00:07:06,730 But us red team operators, we're on the operating system. 61 00:07:06,790 --> 00:07:16,770 So, I needed to figure out how I could take all this really cool WebAssembly stuff and end up using it on the real host that we're trying to hack into. 62 00:07:16,990 --> 00:07:27,990 Now, for WebAssembly, again, popular in the web browser, however, there are WASM, or WebAssembly run times, outside of the browser. 63 00:07:28,550 --> 00:07:36,030 And further down the rabbit hole, this led me to discovering WASI, the WebAssembly system interface. 64 00:07:36,330 --> 00:07:44,910 Now, this is exactly what I was looking for, because this allows your WebAssembly modules to actually interact directly with the operating system. 65 00:07:44,910 --> 00:07:49,010 This is the bridge for the WebAssembly modules to your computer. 66 00:07:49,370 --> 00:07:59,850 So, with WASI enabled, you're able to interact with the file system, so you can read, write, delete files, you can read the system time, and you can interact with sockets. 67 00:07:59,870 --> 00:08:02,050 So, you can start making network requests. 68 00:08:02,470 --> 00:08:05,990 So, for what I was trying to do, this is looking very promising. 69 00:08:06,410 --> 00:08:10,030 And WASI also advertises that it works in all kinds of places. 70 00:08:10,030 --> 00:08:21,790 So, you can run WebAssembly modules in the cloud, server side apps, embedded system developers really like this stuff, but what I was really interested in is the fact that it was advertised as a plug-in system. 71 00:08:22,370 --> 00:08:28,290 So, for myself, because I wanted to develop external C2 plug-ins, this was looking really promising. 72 00:08:29,370 --> 00:08:38,650 So, this all sounds great in theory, but I needed to find an actual project that I could take and really make this happen, take the theory to the practical. 73 00:08:39,170 --> 00:08:43,990 So, this led me to discovering a project called Xtism, which is developed by Delipso. 74 00:08:44,650 --> 00:08:53,950 And aside from this wicked cool logo, it advertised exactly what I was looking for, a universal WebAssembly plug-in system. 75 00:08:54,350 --> 00:09:01,770 It supports multiple languages, so that's exactly what I was shooting for, and there's the idea of a plug-in kit and a host kit. 76 00:09:01,910 --> 00:09:11,890 For plug-ins, you can write your plug-ins in multiple different languages, compile it down to WebAssembly, and then take that WebAssembly module and run it in multiple languages. 77 00:09:11,890 --> 00:09:13,650 So, very, very ideal. 78 00:09:13,830 --> 00:09:32,370 Additionally, the WebAssembly runtime that Xtism produces has a couple of nice features, such as persistent memory, host-based control, so you can specify what HTTP endpoints your WebModules can reach out to, and a couple of execution guard rails , which helps keep the WebAssembly module secure. 79 00:09:33,770 --> 00:09:38,030 Here's a high-level overview of what this development pipeline looks like. 80 00:09:38,330 --> 00:09:49,390 So, for myself, I developed my plug-ins in Rust, and Rust can sometimes scare folks, so no need to fear, you can develop your plug-ins in multiple different languages. 81 00:09:49,610 --> 00:10:04,490 Regardless of the language you choose, compile it down to a WASM file, and then you take that and run it and load it inside of multiple languages, and this is where the malware developers get really excited, because you can take whatever language you're writing in, 82 00:10:04,490 --> 00:10:09,570 and start loading this WebAssembly module, and start running this shared code very seamlessly. 83 00:10:11,530 --> 00:10:20,830 So, this all sounds great in theory, but it was time to actually put it to the test, and that's when I started developing my tool, C4, the cross-compatible command and control. 84 00:10:22,410 --> 00:10:28,570 So, in a typical crawl, walk, run fashion, we had to start with a basic hello world. 85 00:10:28,630 --> 00:10:38,070 Now, this is a very basic six-line Rust program to just return hello world, and then I went language by language and just tested this out. 86 00:10:38,470 --> 00:10:45,230 Sure enough, one by one, each of the programming languages returned my basic hello world message, so we're off to a good start. 87 00:10:47,050 --> 00:11:04,090 Next, we had to step it up a little bit, we had to really make sure that this thing could do reliable HTTP requests, so now my Rust program got a little bit more complex, but no need to worry, each programming language returned a status 200, indicating that your website is up and active. 88 00:11:04,310 --> 00:11:12,930 So, we're able to make, we're able to compile WebAssembly modules and make HTTP requests and interact with APIs and all that fun stuff. 89 00:11:13,250 --> 00:11:20,850 Which then leads me to my first example of the AWS S3 plugin that I developed. 90 00:11:21,010 --> 00:11:28,810 Now, for those that aren't familiar, AWS S3 is a cloud-based service that's very popular for file sharing and file hosting. 91 00:11:29,730 --> 00:11:35,910 So, in this case, I developed two actions, and this is true across all of the plugins that I developed. 92 00:11:35,910 --> 00:11:38,690 There is a basic send and receive function. 93 00:11:38,950 --> 00:11:47,070 In the context of AWS S3, you're going to send a message by uploading a file to an AWS S3 bucket. 94 00:11:47,390 --> 00:11:55,530 Receiving a message, you're downloading a message from AWS S3, and then I also go ahead and delete the file after retrieving the message. 95 00:11:55,550 --> 00:11:57,230 You know, cleaning up after ourselves. 96 00:11:58,130 --> 00:12:06,030 Now, in a red team operation, there's a couple of things that you need to consider when developing an operationally ready external C2 channel. 97 00:12:06,330 --> 00:12:11,310 First thing, you need to be able to support multiple agents simultaneously calling back. 98 00:12:11,430 --> 00:12:14,430 In the red team world, two is one, one is none. 99 00:12:14,430 --> 00:12:19,230 You have to make sure you have a backup agent in case one of your other agents gets burned. 100 00:12:19,630 --> 00:12:26,950 So, in this case, I organized my messages into multiple folders, depending on which agent is sending and receiving messages. 101 00:12:27,250 --> 00:12:31,970 So, this ensures that multiple agents can simultaneously communicate with the C2. 102 00:12:33,190 --> 00:12:37,010 Additionally, we have to make sure the files that we're uploading don't overwrite each other. 103 00:12:37,010 --> 00:12:38,350 They can't have the same name. 104 00:12:38,350 --> 00:12:45,410 So, with WASI, I read the system time, and each of the files that are being uploaded are named after the time that it is. 105 00:12:46,050 --> 00:12:51,650 And additionally, you have to make sure that large messages are compatible. 106 00:12:52,230 --> 00:13:03,190 In this case, AWS S3 supports very large files, but this is really important when you go to exfiltrate or steal really large files off of a victim computer. 107 00:13:03,810 --> 00:13:10,390 So, with this, AWS S3 is a very good and viable option for external C2. 108 00:13:11,810 --> 00:13:18,310 In the plug-in, just as we talked about earlier, these are the two actions that are existing. 109 00:13:18,310 --> 00:13:22,390 It's your send and receive commands, and I handle all of this with JSON. 110 00:13:22,390 --> 00:13:27,970 So, when you call your functions out of plug-ins, you're just sending a little JSON blob. 111 00:13:28,030 --> 00:13:42,690 So, in this case, because we're dealing with AWS S3, the parameters are going to include AWS specific details, like your access and secret key, the bucket name that you're creating and writing files to, and the region that that bucket is located in. 112 00:13:45,190 --> 00:13:50,610 So, here's an example of actually taking a plug-in and using it in Python. 113 00:13:51,090 --> 00:13:59,630 So, for Python, to actually get this WASM or WebAssembly run time, it's just as simple as pip install XSIM. 114 00:13:59,630 --> 00:14:02,450 You know, I'm sure the Python developers are familiar with that. 115 00:14:02,450 --> 00:14:18,350 You import your XSIM package, and then inside of a manifest configuration, you have to specify that this WebAssembly module is allowed to make network connections, and in this case, I just allow it to make connections anywhere, but if you want it to be more OPSEC safe, 116 00:14:18,350 --> 00:14:20,970 you could limit it to just AWS S3. 117 00:14:21,630 --> 00:14:29,710 Then you have to enable WASI, because we're making network connections, we're reading the system time, all that fun stuff. 118 00:14:29,710 --> 00:14:37,750 So, we enable WASI, and then we have a loaded plug-in, and we can start actually calling it and making actions. 119 00:14:39,330 --> 00:14:45,230 So, here's an example of actually calling this loaded plug-in that we have in Python. 120 00:14:45,890 --> 00:14:54,850 So, we take our loaded plug-in, we build out our JSON message, and in this example, we're sending a message, just very basic test message. 121 00:14:54,850 --> 00:15:02,130 As you can see, we have some redacted access and secret keys, and some details about the S3 bucket that we're communicating with. 122 00:15:02,930 --> 00:15:12,170 And with that, we're very, it's very simple to continue to call these actions, and likewise with sending, you can receive just as easily. 123 00:15:12,350 --> 00:15:18,530 So, in the context of external C2, you know, this is all you really need, right? 124 00:15:18,530 --> 00:15:30,730 I look at a lot of agents on the open source side of things, and you just set up your infinite for loop, and you continue to call and receive, or send and receive messages to and from your C2 server. 125 00:15:32,750 --> 00:15:40,910 So, with that, hopefully you're walking away from this saying, well, external C2, it doesn't have to be that hard. 126 00:15:41,090 --> 00:15:50,770 With this, I have multiple plug-ins, I support AWS S3, Confluence, everyone's favorite documentation site, and GitHub Gist. 127 00:15:50,770 --> 00:15:55,590 So, with that, I have tons of plans for developing more external C2 channels. 128 00:15:56,390 --> 00:16:01,790 Additionally, WASM is a relatively new technology, I'd highly suggest checking it out. 129 00:16:02,190 --> 00:16:06,350 It's constantly being developed, and it's just a really cool tech to keep up with. 130 00:16:06,810 --> 00:16:13,110 So, with that, start downloading some C4 plug-ins and loading them up in your malware today. 131 00:16:13,110 --> 00:16:17,010 If you have any questions, reach out to me at scottctaylor12 across all the socials. 132 00:16:17,010 --> 00:16:18,490 Thank you so much for your time, everyone.