1 00:00:00,000 --> 00:00:01,520 All right, let's get moving. 2 00:00:01,520 --> 00:00:04,160 Hope you guys have had an awesome DEF CON so far. 3 00:00:04,180 --> 00:00:05,020 Let's dive right in. 4 00:00:05,020 --> 00:00:07,320 So this is Bad Salt Adversarial DevOps. 5 00:00:07,760 --> 00:00:11,360 I'm going to start with a quick introduction, some background about myself. 6 00:00:11,360 --> 00:00:12,740 My name is Casey Erdman. 7 00:00:12,880 --> 00:00:17,140 You may know me by my handle Ngame on Twitter or other aspects of the interwebs. 8 00:00:17,280 --> 00:00:20,820 I'm a giant offensive security nerd, that's why I'm here in the Red Team Village. 9 00:00:21,280 --> 00:00:27,820 I am the co-founder of DC706, which is a Columbus, Georgia DEF CON group, so if you're ever in the area, feel free to roll through. 10 00:00:28,400 --> 00:00:31,560 These are some of my professional certifications, if you care about that type of thing. 11 00:00:31,560 --> 00:00:35,120 In my day-to-day, though, I am a manager of an information security department. 12 00:00:35,200 --> 00:00:37,600 We are a very small team, so I touch pretty much everything. 13 00:00:37,600 --> 00:00:46,660 We're in the kind of financial space, so lots of offensive security stuff, pin testing, that type of thing, incident response, good old PCI compliance, stuff like that. 14 00:00:46,800 --> 00:00:50,580 But I think the most interesting thing you should all know about me is that I'm a programmer gone rogue. 15 00:00:50,580 --> 00:01:00,500 Most of my background is in software development, and I just kind of got into CTFs and started hacking, and I decided, no more software development, let's do the offensive security stuff. 16 00:01:00,500 --> 00:01:01,620 That's a lot more fun. 17 00:01:01,620 --> 00:01:04,400 So that's where a lot of my passion is, and that's just a little bit about me. 18 00:01:05,020 --> 00:01:07,380 This is probably the most important slide today. 19 00:01:07,400 --> 00:01:11,460 If you don't take a picture of anything else, I'm going to give everybody a second to take a picture of this. 20 00:01:11,460 --> 00:01:18,080 All of the code, the slides for this talk, any of the PCAPs or stuff like that are at this GitHub repo, and we'll be there. 21 00:01:18,900 --> 00:01:20,120 So I'll give you guys a minute. 22 00:01:24,280 --> 00:01:25,260 All right. 23 00:01:28,140 --> 00:01:28,760 Perfect. 24 00:01:28,760 --> 00:01:29,880 So let's move along. 25 00:01:30,120 --> 00:01:31,560 Here's our agenda for today. 26 00:01:31,860 --> 00:01:42,560 First, we're going to hit some of the high points, introduce anybody to the concepts of configuration management, how we landed on SaltStack, why this technology is even the focal point of this talk today. 27 00:01:42,600 --> 00:01:46,040 Then we're going to talk about some attacks against that platform. 28 00:01:46,300 --> 00:01:49,400 And then the meat of the talk is actually going to be hacking with that platform. 29 00:01:49,400 --> 00:01:56,400 When we're talking about adversarial DevOps, we're talking about using these new fancy tools that are in our industry as an offensive person. 30 00:01:56,400 --> 00:01:58,180 How can I take advantage of these? 31 00:01:58,180 --> 00:02:01,180 And that's really where we're going to dive in and look at a couple of those things. 32 00:02:01,240 --> 00:02:09,920 And then, of course, we're going to also give our blue teamers the chance to stop anything that they see like this, and we'll cover those investigation techniques at the end. 33 00:02:10,680 --> 00:02:11,220 All right. 34 00:02:11,220 --> 00:02:13,180 So what is SaltStack? 35 00:02:13,840 --> 00:02:17,500 So to talk about SaltStack, first we need to talk about configuration management. 36 00:02:17,500 --> 00:02:20,400 So configuration management isn't really new. 37 00:02:20,400 --> 00:02:23,940 We've got configurations we've been managing for a long time in the industry. 38 00:02:23,940 --> 00:02:27,780 But there's kind of new technologies that help us facilitate this idea. 39 00:02:27,780 --> 00:02:36,620 And the goal here is to establish some baseline and some integrity across our systems to make sure they look and act how they should and don't have any variants here. 40 00:02:36,680 --> 00:02:44,100 Some common new tools for configuration management you may have heard of are things like Puppet, Chef, Ansible, and SaltStack. 41 00:02:44,100 --> 00:02:47,080 So we're going to take a high-level look at some of these tools. 42 00:02:47,160 --> 00:02:50,140 All of these tools can essentially accomplish the same goal. 43 00:02:50,140 --> 00:02:52,100 So I'm not saying any one tool is better than the other. 44 00:02:52,100 --> 00:02:53,860 I'm not sponsored by any of these companies. 45 00:02:53,860 --> 00:02:57,460 I just want to kind of give a narrative of how I landed on what I landed on. 46 00:02:58,180 --> 00:03:03,440 So starting with Puppet, Puppet's kind of one of the industry-leading tools in this space here. 47 00:03:03,440 --> 00:03:04,860 They've been around for a while. 48 00:03:05,420 --> 00:03:11,720 It integrates really well with other products because its baseline purpose is the concept of configuration management. 49 00:03:11,720 --> 00:03:17,700 So when these tools first started coming out, you may have heard things like maybe Puppet and Chef. 50 00:03:17,700 --> 00:03:27,340 And it's this bundle of tools where Puppet would be the foundation and help you do the configuration management where something like Chef or Ansible would go then execute on those configurations. 51 00:03:27,640 --> 00:03:30,360 So that's kind of where things kind of got started. 52 00:03:30,360 --> 00:03:37,080 It's got a little bit of maturity, good foundation, but there's also other tools out there that have matured a lot more. 53 00:03:37,080 --> 00:03:40,860 And so Puppet and Chef can kind of just be replaced by Chef nowadays. 54 00:03:40,860 --> 00:03:41,800 Chef has come a long way. 55 00:03:41,800 --> 00:03:47,500 But at first, it was more focused on infrastructure as code and not really configuration management. 56 00:03:47,500 --> 00:03:55,240 However, inherently, when you're talking about infrastructure as code, you're defining how your machines look in some kind of code syntax or configuration. 57 00:03:55,240 --> 00:04:01,500 So naturally, Chef kind of became its own configuration management utility. 58 00:04:01,840 --> 00:04:04,460 And the focus here is, of course, that continuous automation. 59 00:04:04,460 --> 00:04:10,840 You can continue upgrading, changing your configurations in your systems, and also manage those configurations. 60 00:04:11,120 --> 00:04:15,440 Chef also provides a couple neat other tools like Inspect or Habitat. 61 00:04:15,440 --> 00:04:16,600 I don't know a whole lot about these tools. 62 00:04:16,600 --> 00:04:19,940 I know Inspect is supposed to be some kind of cool code audit tool of some sort. 63 00:04:19,980 --> 00:04:23,260 But the point is, it's matured a lot more now and there's a lot of feature sets. 64 00:04:23,260 --> 00:04:28,160 It could be a good option when you're looking to explore the concept of configuration management for your infrastructure. 65 00:04:29,360 --> 00:04:32,580 Now, Ansible is a little bit different from these other tools. 66 00:04:32,580 --> 00:04:37,660 So Ansible is more about the infrastructure automation, not so much the configuration management. 67 00:04:37,660 --> 00:04:44,560 While, again, you can do pretty much everything with all of these tools, Ansible I like to think of as like mass SSHing or something like that. 68 00:04:44,560 --> 00:04:52,040 You're able to go and execute on hundreds and hundreds of systems at one time to apply whatever state or configuration that you're trying to apply. 69 00:04:52,760 --> 00:04:58,280 And so I like to equate maybe Puppet and Ansible as something a little bit closer to what Salt Stack is. 70 00:04:58,740 --> 00:05:06,120 But again, it's less about configuration management and just more about the execution of the automation of whatever your configurations are. 71 00:05:07,100 --> 00:05:10,360 All right, so we got all these great tools. 72 00:05:10,360 --> 00:05:12,060 Why did it land on Salt Stack? 73 00:05:12,060 --> 00:05:25,700 So from a professional standpoint, when myself and the other members of the DevOps team are coordinating and looking at different ways to do configuration management on our infrastructure, we found that Salt Stack scales a little bit easier. 74 00:05:25,700 --> 00:05:27,560 And the reason is because it's agent-based. 75 00:05:27,560 --> 00:05:36,100 So a lot of these other tools may require you to have access or credentials or go open up some firewall rules or network communications. 76 00:05:36,100 --> 00:05:38,080 There seems to be a lot more setup. 77 00:05:38,680 --> 00:05:41,240 Things are changing very rapidly with a lot of these tools. 78 00:05:41,240 --> 00:05:44,380 So what's true today, of course, may not be true later. 79 00:05:44,380 --> 00:05:48,660 But at the time of selection for a tool, Salt Stack really scaled well. 80 00:05:49,660 --> 00:05:52,640 And of course, it does everything all the other tools do. 81 00:05:52,640 --> 00:05:54,120 And it just does it all in one. 82 00:05:54,120 --> 00:05:56,720 You don't need an Ansible and a Puppet. 83 00:05:56,720 --> 00:05:59,980 You could just use Salt Stack and get all the same capabilities out. 84 00:05:59,980 --> 00:06:01,960 Doesn't make it better, doesn't make it worse. 85 00:06:02,040 --> 00:06:04,280 You just have those options available to you. 86 00:06:05,240 --> 00:06:09,220 And Salt Stack's primary purpose is for configuration management. 87 00:06:09,220 --> 00:06:10,360 That's kind of what it's built around. 88 00:06:10,360 --> 00:06:13,380 It's built around the concept of desired state. 89 00:06:13,680 --> 00:06:19,880 So desired state is this idea that your machine is going to match your configuration all the time, no matter what. 90 00:06:19,880 --> 00:06:26,180 And if at any point it's not matching that desired state, it's going to correct itself and make sure it maintains that integrity. 91 00:06:26,180 --> 00:06:28,060 And that's kind of what Salt Stack's built around. 92 00:06:28,520 --> 00:06:35,600 And because of kind of the agent-based nature, it integrates with kind of some older or more standardized systems a little bit easier. 93 00:06:35,700 --> 00:06:43,740 We're able to deploy this in anywhere from like cloud environments like AWS or Google Cloud or traditional data centers or co-locations. 94 00:06:43,740 --> 00:06:44,600 It's really easy. 95 00:06:44,600 --> 00:06:48,280 You just kind of set up a master and look at the architecture in a couple slides. 96 00:06:48,280 --> 00:06:55,760 You set up the salt master, you deploy minions, you set the egress out where you want, and you're good to go start configuring hundreds and hundreds of systems in Salt Stack. 97 00:06:56,120 --> 00:07:03,520 So that's kind of how we landed on this from the standpoint, and I kind of took it and ran with it for the majority of the talk. 98 00:07:03,520 --> 00:07:04,820 But just how we got there. 99 00:07:05,580 --> 00:07:07,180 This is Salt Stack architecture. 100 00:07:07,180 --> 00:07:08,180 I'm not going to dive into this. 101 00:07:08,180 --> 00:07:09,560 I don't expect anybody to actually read it. 102 00:07:09,560 --> 00:07:11,020 It's really complex though. 103 00:07:11,020 --> 00:07:13,960 That's kind of why I wanted to show this slide. 104 00:07:14,340 --> 00:07:22,780 So the kind of key points here that we're going to look at is this idea of the master and then these little beacons or minions as they're actually called. 105 00:07:22,780 --> 00:07:24,700 So there's a lot of functionality in Salt Stack. 106 00:07:24,760 --> 00:07:26,420 Please read more of the documentation. 107 00:07:26,420 --> 00:07:27,360 It's really cool. 108 00:07:27,420 --> 00:07:30,640 But this is the simplified version that's a lot easier to understand. 109 00:07:31,380 --> 00:07:33,940 So salt minions and salt masters. 110 00:07:33,940 --> 00:07:36,280 That's kind of what we're primarily focused on here. 111 00:07:36,280 --> 00:07:41,240 So the salt master is going to be listening on two ports, 45.05 and 45.06. 112 00:07:41,600 --> 00:07:43,480 45.05 is the publisher port. 113 00:07:43,480 --> 00:07:47,360 This is where the master is going to issue a command, say, hey go run who am I or whatever. 114 00:07:47,800 --> 00:07:52,160 And then 45.06 is where the minion is going to pull up and publish its results. 115 00:07:52,160 --> 00:07:59,900 So the minion is going to go up to port 45.05, grab that command, execute it, and then return up to 45.06 with whatever its output is. 116 00:08:00,040 --> 00:08:03,200 Now this request server also handles file management. 117 00:08:03,200 --> 00:08:07,640 So one of the cool things we'll do that we'll kind of look at a little bit later is manage files. 118 00:08:07,640 --> 00:08:15,540 So if you want to copy other configurations for other components or install applications from a custom repo, whatever have you, you can copy those. 119 00:08:15,540 --> 00:08:23,140 And that port is where the salt minion will go fetch or send commands, either one, to that request server. 120 00:08:23,160 --> 00:08:26,640 Now of course we have this execution of commands and the sending of response. 121 00:08:26,640 --> 00:08:28,320 Sounds kind of like a C2 server. 122 00:08:28,320 --> 00:08:30,520 So keep that in the back of your brain as we go forward. 123 00:08:31,900 --> 00:08:33,940 All right, kind of wrap up this section. 124 00:08:34,560 --> 00:08:35,540 Configuration management. 125 00:08:35,540 --> 00:08:36,520 Why is it cool? 126 00:08:36,520 --> 00:08:38,000 What are we using this for? 127 00:08:38,200 --> 00:08:40,860 Well, you can enforce hardening standards with it. 128 00:08:40,860 --> 00:08:43,900 You can enforce those nasty compliance standards with it. 129 00:08:43,940 --> 00:08:46,400 Create uniformity across all your environments. 130 00:08:46,480 --> 00:08:56,260 And then ultimately the coolest thing that works both on the offensive side and the defensive side is making sure stuff is installed that should be and making sure that stuff that isn't installed shouldn't be. 131 00:08:56,260 --> 00:09:04,040 So you're really able to enforce that and help lock that down with this concept of desired state where the system will go and see what it should look like. 132 00:09:04,040 --> 00:09:06,740 If it doesn't match, it'll go try to correct itself. 133 00:09:07,520 --> 00:09:14,740 All right, so hopefully everybody's got a good overview of the concepts of configuration management, desired state, what all these tools are for. 134 00:09:15,120 --> 00:09:16,400 Let's hack SaltStack. 135 00:09:16,840 --> 00:09:18,820 All right, so quick history lesson. 136 00:09:19,320 --> 00:09:21,980 SaltStack was released back in March 2011. 137 00:09:21,980 --> 00:09:25,280 This was a very stable or very not stable, very early version. 138 00:09:25,640 --> 00:09:29,520 The first stable release came out a couple months later in November 2011. 139 00:09:29,520 --> 00:09:33,920 And we're now on version 2019.2, which was like in February. 140 00:09:33,920 --> 00:09:36,260 And this is true as of the time of typing of the slide. 141 00:09:36,260 --> 00:09:37,900 There may have been a new release like this week. 142 00:09:37,900 --> 00:09:38,660 I don't know. 143 00:09:38,900 --> 00:09:42,720 But the point here that I'm trying to illustrate is this is back in 2011. 144 00:09:42,720 --> 00:09:44,140 We're in, what, 2019 now. 145 00:09:44,140 --> 00:09:45,240 About eight years. 146 00:09:45,540 --> 00:09:49,400 That doesn't sound like long ago because it's 2011, but it was eight years ago. 147 00:09:49,400 --> 00:09:50,500 Old things have bugs. 148 00:09:50,500 --> 00:09:52,600 SaltStack is now kind of an old thing. 149 00:09:52,600 --> 00:09:53,940 It's kind of weird to think about. 150 00:09:54,220 --> 00:10:00,180 But to illustrate that old things have bugs, here's a list of kind of recent CVEs for SaltStack. 151 00:10:00,380 --> 00:10:05,020 Just to kind of go over and glance real quick, this list is longer than here. 152 00:10:05,020 --> 00:10:08,640 This is just a snap of part of the MVD. 153 00:10:09,140 --> 00:10:10,640 But we got some code execution. 154 00:10:10,640 --> 00:10:12,720 We got some directory traversal. 155 00:10:12,720 --> 00:10:15,900 Some information type of issues. 156 00:10:16,680 --> 00:10:20,180 The goal of this research wasn't any kind of vulnerability research specifically. 157 00:10:20,180 --> 00:10:22,140 So I encourage you to go dive down these your own. 158 00:10:22,140 --> 00:10:24,640 Just to show that SaltStack has had some problems. 159 00:10:25,160 --> 00:10:28,240 And what I did from there is kind of see if there's any proof of concepts out there. 160 00:10:28,240 --> 00:10:37,200 See if based on what is known, what type of attack vector should I be challenging myself to go look for in a current version of SaltStack. 161 00:10:37,260 --> 00:10:40,840 And the first thing I kind of stumbled upon was this evil minions project. 162 00:10:40,840 --> 00:10:44,840 Now, this isn't really a proof of concept to exploit any kind of vulnerability. 163 00:10:45,000 --> 00:10:46,500 It's actually just a load generator. 164 00:10:46,500 --> 00:10:54,160 It was made for purposes of going and testing how many minions or processes a particular minion service could handle. 165 00:10:54,160 --> 00:10:57,160 So it just spawned a whole bunch of minions and test the load. 166 00:10:57,320 --> 00:11:04,120 So nothing really crazy in terms of exploiting vulnerabilities, but might be cool for some denial of service attack or whatever have you. 167 00:11:04,120 --> 00:11:08,720 That was just the first thing I stumbled on with some simple Googling and looking at search terms. 168 00:11:09,520 --> 00:11:12,000 I dug a little bit deeper, though, and I found Chicken Salt. 169 00:11:12,200 --> 00:11:24,900 So Chicken Salt is this neat little POC for abusing the communication between minions and masters when they do this handshake for key public key authentication. 170 00:11:24,900 --> 00:11:30,000 So this allows for man in the middle attack, which ultimately allows you to take over minions. 171 00:11:30,000 --> 00:11:37,120 Now, this is important because while you may think, oh, well, if I can get access to the master, well, then I can control everything on the network, right? 172 00:11:37,220 --> 00:11:39,040 Well, what if you could just stand up your own master? 173 00:11:39,040 --> 00:11:40,640 You don't need access to that master. 174 00:11:40,800 --> 00:11:45,840 And then you get everybody to talk to you, and now you can control all of the minions it controls. 175 00:11:45,840 --> 00:11:47,840 That's what this kind of attack allows you to do. 176 00:11:48,320 --> 00:11:54,860 And what happens here is you'll sniff the handshake upon initial communication between a minion and a master. 177 00:11:55,040 --> 00:12:00,740 You would be able to grab the public key and the verification token for that particular communication. 178 00:12:00,780 --> 00:12:06,160 Then you can man in the middle, serve up that public key and token you acquired, and bam, you can pwn all the minions. 179 00:12:06,480 --> 00:12:08,360 Couldn't really find a CVE for this one, though. 180 00:12:08,360 --> 00:12:12,140 It didn't match any of the things that I had already found when doing initial research. 181 00:12:12,520 --> 00:12:16,640 It looks like it was probably patched in version 0.17.1. 182 00:12:17,100 --> 00:12:20,180 It might be related to that CVE that's on the slide there. 183 00:12:20,180 --> 00:12:25,380 That has to do with Salt not validating SHHOS key request, which also resulted in a man in the middle attack vector. 184 00:12:25,640 --> 00:12:27,240 It's just really hard to tell. 185 00:12:27,300 --> 00:12:29,700 All I know is it doesn't work now because I tried. 186 00:12:29,920 --> 00:12:33,820 However, when I tried, I found a new attack vector. 187 00:12:34,500 --> 00:12:38,960 So I kind of want to talk about modern man-in-the-middle attacks against Salt Stack. 188 00:12:38,960 --> 00:12:41,140 Now, this isn't any kind of crazy OODA. 189 00:12:41,140 --> 00:12:43,260 We're not doing anything super sophisticated. 190 00:12:43,260 --> 00:12:45,920 This is a really easy attack, and it's really not a high risk. 191 00:12:45,920 --> 00:12:49,100 It's actually just by design, how Salt works. 192 00:12:49,300 --> 00:13:00,920 And what I'm trying to communicate here is just awareness for good configuration standards of your Salt environment, because it's really easy to mitigate this type of issue, but by default, it is not mitigated. 193 00:13:00,920 --> 00:13:01,920 And that's just by design. 194 00:13:01,920 --> 00:13:02,920 It's not a vulnerability. 195 00:13:02,920 --> 00:13:09,360 It's not any kind of issue, but it is a potential risk that you need to be aware of, especially if you have Salt in your environments. 196 00:13:09,380 --> 00:13:13,600 So the issue is caused by the need to distribute keys. 197 00:13:13,740 --> 00:13:19,380 Once you install an agent on a box, it's got to go talk to the master, and it's got to do this kind of exception thing. 198 00:13:19,380 --> 00:13:21,360 So we'll look at that on the next slide. 199 00:13:22,280 --> 00:13:24,900 So here's how the key exchange works. 200 00:13:24,900 --> 00:13:28,280 So you have a Salt minion and your Salt master, like we've seen. 201 00:13:28,360 --> 00:13:33,660 The Salt minion is going to communicate initially with the Salt master and say, hey, here's my public key. 202 00:13:33,660 --> 00:13:34,900 Do you want to accept it? 203 00:13:34,980 --> 00:13:43,640 If you choose to accept it on the Salt master side, it'll add that minion into your queue, and now you can execute commands and facilitate communications with the minion. 204 00:13:44,940 --> 00:13:50,180 So the problem here is that the Salt minions will trust a master on initial communication no matter what. 205 00:13:50,180 --> 00:13:52,280 This is any master at any point in time. 206 00:13:52,400 --> 00:13:59,840 The solution to this problem, which is built into Salt already, is to give Salt minions a fingerprint for the good known master. 207 00:14:00,240 --> 00:14:01,160 So everything's good, right? 208 00:14:01,160 --> 00:14:03,300 We give them the fingerprint, and we're good to go. 209 00:14:03,360 --> 00:14:06,260 Well, how do you give the minion the fingerprint? 210 00:14:07,320 --> 00:14:09,940 Fingerprints have to be issued on initial deployment. 211 00:14:09,940 --> 00:14:16,480 If you don't issue them on initial deployment, they won't be set, therefore making you potentially vulnerable to this type of attack factor. 212 00:14:16,840 --> 00:14:23,440 Now, it's really easy to fix this issue, as we'll see, but here's the kind of capabilities and control that you have. 213 00:14:23,440 --> 00:14:25,200 So let's hop into this demo real quick. 214 00:14:25,800 --> 00:14:32,620 So here we've set up BetterCap with a man in the middle listening on our two Salt ports for our fake master. 215 00:14:34,160 --> 00:14:36,400 And then here is our Salt minion. 216 00:14:36,780 --> 00:14:40,620 So the Salt minion is going to just show you what our configurations are. 217 00:14:40,760 --> 00:14:43,700 That's pointing to this 128.13 master. 218 00:14:44,100 --> 00:14:46,060 There's no master fingerprint set by default. 219 00:14:46,060 --> 00:14:47,380 This is fresh install. 220 00:14:48,120 --> 00:14:49,380 And it's started the service. 221 00:14:49,380 --> 00:14:50,460 So now it should call home. 222 00:14:51,080 --> 00:14:52,960 This is going to show this is the legitimate master. 223 00:14:52,960 --> 00:14:54,180 It's going to be dot 13. 224 00:14:55,460 --> 00:14:57,340 And we'll list our keys here. 225 00:14:58,260 --> 00:15:00,660 And there's no unaccepted keys, even though there should be. 226 00:15:00,660 --> 00:15:02,760 We should be getting a callback from that minion, right? 227 00:15:03,500 --> 00:15:09,460 Well, if you go back over to our evil master and see we've got some communications from our interception from man in the middle. 228 00:15:09,980 --> 00:15:10,920 And run this. 229 00:15:10,920 --> 00:15:12,720 We're going to show that we're not the same IP. 230 00:15:15,520 --> 00:15:18,560 And now we're going to see what unaccepted keys are in our bad master's queue. 231 00:15:18,960 --> 00:15:20,200 Oh, it looks like we've got one. 232 00:15:21,140 --> 00:15:22,580 So we're going to accept that key. 233 00:15:24,040 --> 00:15:29,920 And now we've successfully manned in the middle of that minion and we're ready to execute commands on this host. 234 00:15:29,920 --> 00:15:32,000 So that's kind of how the attack plays out. 235 00:15:32,000 --> 00:15:33,200 Real simple. 236 00:15:33,360 --> 00:15:35,800 Not anything complex to it. 237 00:15:35,800 --> 00:15:41,560 But it is very much an attack vector and it is caused by this default configuration. 238 00:15:42,220 --> 00:15:45,620 The good news here is this only works on initial communication. 239 00:15:45,620 --> 00:15:47,360 Like I said, it's fairly low risk. 240 00:15:48,240 --> 00:16:02,900 What happens is on that initial communication, once a master accepts the minion communication, it's going to cache that fingerprint that we there. 241 00:16:03,280 --> 00:16:05,280 But it is not in the configuration. 242 00:16:05,280 --> 00:16:15,080 Which means if at any point that cache gets cleared out for any reason by whether it's manual deletion or some debugging or reinstallation of a minion, whatever have you, it could potentially go away. 243 00:16:15,080 --> 00:16:24,520 However, if you have minions already in your environment, they've already communicated with your legitimate master, what will actually happen if I try to do that man in the middle attack is there's a conditional set. 244 00:16:24,520 --> 00:16:29,720 So the people who make salt stack are already aware of this particular issue. 245 00:16:29,740 --> 00:16:35,820 And this nice helpful log message that you might be getting man in the middle attack will dump into the salt minion logs. 246 00:16:36,020 --> 00:16:40,140 So it kind of fixes itself if you've already had that initial communication. 247 00:16:40,140 --> 00:16:43,200 But if you haven't, then you're open to this potential vulnerability. 248 00:16:44,060 --> 00:16:46,840 Now, detecting this type of attack is fairly simple. 249 00:16:47,220 --> 00:16:50,700 In the first image we have here, a successful attack basically looks like nothing. 250 00:16:50,700 --> 00:16:51,860 It's completely normal. 251 00:16:51,860 --> 00:16:53,320 You don't see anything going wrong. 252 00:16:53,500 --> 00:16:57,620 A failed attack, however, has that log message that we looked at on the previous slide. 253 00:16:58,360 --> 00:17:00,560 Now, there are two ways to prevent this type of attack. 254 00:17:00,560 --> 00:17:05,180 Of course, the best way is to deploy your salt minions with the fingerprint. 255 00:17:05,400 --> 00:17:06,680 And that's part of the configuration. 256 00:17:06,680 --> 00:17:07,220 Real simple. 257 00:17:07,220 --> 00:17:08,520 There's no reason not to do it. 258 00:17:08,520 --> 00:17:09,400 Doesn't break anything. 259 00:17:09,400 --> 00:17:10,920 Doesn't cost you anything extra. 260 00:17:10,940 --> 00:17:19,640 You literally just spit out on your legit master whatever the fingerprint is, go pop it in your minion configure whenever you're setting up minions, and you will never be vulnerable to this type of attack. 261 00:17:19,640 --> 00:17:20,520 Real easy. 262 00:17:20,620 --> 00:17:26,180 Option two is you could automatically set all of your minions to always be accepted on master. 263 00:17:26,180 --> 00:17:29,440 This will work and kind of mitigate after that initial communication. 264 00:17:29,940 --> 00:17:36,020 But, of course, if an attacker is already on your network man-in-the-middle and all the things, option two doesn't really work because we're just going to keep intercepting stuff. 265 00:17:37,120 --> 00:17:39,440 With that said, this is a pretty tight attack vector. 266 00:17:39,440 --> 00:17:40,700 It's lower risk. 267 00:17:41,160 --> 00:17:45,820 The conditions to kind of pull this off, you would first need access to the target environment. 268 00:17:45,820 --> 00:17:46,280 That's easy. 269 00:17:46,280 --> 00:17:47,740 We can get into any environment, right? 270 00:17:48,340 --> 00:17:52,680 Next up would be that we need to be able to pull off man-in-the-middle attacks in the environment. 271 00:17:52,680 --> 00:18:02,220 This could be a little bit harder if you have fancier network segmentation or other kind of rules to catch you going on, but still easier than most other types of attacks. 272 00:18:02,980 --> 00:18:08,500 The catch is that you would definitely need to catch your target in the middle of some kind of minion deployment. 273 00:18:08,500 --> 00:18:13,540 So hopefully you hacked a DevOps engineer's calendar and you know when they're doing the next salt deployment or something like that. 274 00:18:13,540 --> 00:18:14,960 That's really niche. 275 00:18:14,960 --> 00:18:15,500 Good luck. 276 00:18:15,500 --> 00:18:16,500 You could try to pull it off. 277 00:18:16,500 --> 00:18:20,980 I don't recommend doing this if you're on some kind of red team or pentest engagement. 278 00:18:20,980 --> 00:18:26,740 It's probably not going to be your best way in, but if all the cards align, you could potentially get in with this method. 279 00:18:26,900 --> 00:18:31,280 And there's no really notion of them patching this because, like I said, it's not really a vulnerability . 280 00:18:31,280 --> 00:18:33,820 It's about us managing our configurations properly. 281 00:18:33,820 --> 00:18:37,840 If you go out and you establish your fingerprint, you're never going to have a problem with this. 282 00:18:38,060 --> 00:18:41,280 So I just kind of wanted to raise awareness there because this is not the default. 283 00:18:41,280 --> 00:18:42,360 There's no fingerprint set. 284 00:18:42,360 --> 00:18:46,560 It can't be because it's not going to know what your custom master is once you've spun it up. 285 00:18:46,560 --> 00:18:49,640 Be sure you go set that fingerprint so you avoid this type of issue. 286 00:18:50,920 --> 00:18:56,240 All right, now that we've looked at attacking SALT a few different ways, let's get into the meat of what I want to bring to the table today. 287 00:18:56,240 --> 00:18:58,140 And that is hacking with SALTstack. 288 00:18:58,140 --> 00:19:01,680 So to start off, I want to talk about some C2s. 289 00:19:01,680 --> 00:19:10,760 So hopefully most of us are familiar with a couple of command and control frameworks, such as Merlin or PowerShell Empire or the Metasploit framework and SALTstack. 290 00:19:10,920 --> 00:19:17,720 Yeah, so if you remember that little architecture slide from the SALT master and minions, we had that little C2 type communication. 291 00:19:17,720 --> 00:19:21,640 We can execute commands from the master and the minions will post their responses. 292 00:19:22,680 --> 00:19:27,060 So I kind of wanted to just pick out two C2s that I felt related to SALTstack. 293 00:19:27,060 --> 00:19:32,360 And I felt Empire and Merlin were probably the best candidates, but I'm a fanboy of Merlin, so I picked Merlin instead. 294 00:19:32,460 --> 00:19:36,240 And the reason being is because the communications work very similar. 295 00:19:36,240 --> 00:19:54,040 Now while Merlin and Empire both operate on like a single port communication, the idea of the master service posting commands, your agent coming in and connecting, establishing that command, and then pulling back up to send the response is kind of the same type of thing. 296 00:19:54,060 --> 00:19:57,400 So it's just this pulling agent idea that makes them similar. 297 00:19:57,600 --> 00:19:59,140 So let's compare these two. 298 00:19:59,600 --> 00:20:01,420 First looking at Merlin, is it a C2? 299 00:20:01,420 --> 00:20:02,460 Yeah, that's what it's built for. 300 00:20:02,460 --> 00:20:04,740 It does command and control, does it pretty well. 301 00:20:05,680 --> 00:20:18,020 The traffic for Merlin is disguised to look like HTTPS traffic, so looks like normal web calls coming out of your environment, helpful for getting around some firewall rules or maybe just doing some light evasion so you're not instantly being detected on a network. 302 00:20:18,160 --> 00:20:23,540 It's got some really cool post exploitation modules built in now so you can run things like Mimikatz or whatever have you. 303 00:20:23,940 --> 00:20:25,640 And it's got some AV evasion. 304 00:20:25,640 --> 00:20:32,580 This isn't because it's built to evade AV, this is just because Golang's kind of new and it's really hard for most modern AV to detect Golang. 305 00:20:32,580 --> 00:20:37,200 That will definitely change as we progress forward in the future and Golang becomes even more popular than it is now. 306 00:20:37,260 --> 00:20:42,700 But for the time being I've found that on most of my engagements I can drop a Merlin agent, don't have any problems with any AV. 307 00:20:42,780 --> 00:20:45,540 So just throwing that out there if you haven't used it on engagement. 308 00:20:45,540 --> 00:20:46,600 Pretty neat tool. 309 00:20:47,500 --> 00:20:49,660 Alright, let's compare that to SaltStack. 310 00:20:49,660 --> 00:20:50,800 Is it a C2? 311 00:20:50,840 --> 00:20:51,560 Yeah. 312 00:20:51,840 --> 00:20:54,580 Execute commands, get control, do your thing. 313 00:20:54,580 --> 00:20:55,920 Kind of covered that a little bit. 314 00:20:55,920 --> 00:20:57,360 What about the communications? 315 00:20:57,380 --> 00:21:03,740 Well, everything is encrypted, you have a complete encrypted channel, but it's not quite HTTPS. 316 00:21:04,340 --> 00:21:11,040 It's pretty much clear, or not clear, but it's straightforward TCP communications to the master. 317 00:21:11,080 --> 00:21:18,480 You can do some things to kind of change up ports that you're listening on and change your configuration to your master to kind of be more stealthy, and we'll see that a little bit later. 318 00:21:18,720 --> 00:21:23,700 But overall it's going to be pretty clear that the communication is abnormal. 319 00:21:23,700 --> 00:21:26,740 It's not looking like any kind of standard thing in your environment. 320 00:21:26,740 --> 00:21:30,200 It's going to be pretty exposed in that regard. 321 00:21:30,200 --> 00:21:33,280 But it is encrypted and it is a secure channel. 322 00:21:33,600 --> 00:21:34,980 Post-exploitation modules? 323 00:21:34,980 --> 00:21:38,440 Well, I mean they're not baked in, but we call this desired state. 324 00:21:38,440 --> 00:21:42,300 And this is kind of where the cool stuff gets in that we'll look at in a couple slides. 325 00:21:42,600 --> 00:21:56,220 So post-exploitation modules for SaltStack is going to be this idea that we are going to take the concept of configuration management and build our own configurations that are bad. 326 00:21:56,220 --> 00:22:00,940 They do things that an attacker wants to do rather than what maybe an infrastructure engineer wants to do. 327 00:22:01,000 --> 00:22:02,040 AV evasion? 328 00:22:02,040 --> 00:22:04,820 Yeah, these are trusted agents from professional software. 329 00:22:04,820 --> 00:22:06,720 Yeah, they're not going to be picked up by anything. 330 00:22:06,720 --> 00:22:09,120 Real easy, guaranteed to go through. 331 00:22:09,600 --> 00:22:16,260 So we get some leverage there from being able to cash in on this trusted software. 332 00:22:17,360 --> 00:22:27,400 Alright, so in terms of using this platform as an adversary, like I mentioned, this desired state configuration concept is going to be kind of the key here. 333 00:22:27,400 --> 00:22:30,640 This is what makes it really cool because, I mean, we've got command and control for days. 334 00:22:30,640 --> 00:22:31,960 What makes this any different? 335 00:22:31,960 --> 00:22:34,200 Why is this a neat option to explore? 336 00:22:34,200 --> 00:22:37,900 Well, I call this like post-exploitation modules in advanced mode. 337 00:22:37,900 --> 00:22:42,560 It's kind of cheesy, but it's really easy to automate your persistence. 338 00:22:42,680 --> 00:22:52,000 And basically what this means is you can pre-build these states to say on all these types of systems, Windows, Linux, Mac, whatever have you, do this. 339 00:22:52,000 --> 00:23:04,920 So if you have compromised, you know, I don't know, 10, 20, 100 systems and they're all different operating systems types, you can have conditionals set in your state and say, okay, I want to do the same type of persistence across all of these different platforms, 340 00:23:04,920 --> 00:23:11,920 have them categorized out beforehand, hit state apply, it's just going to run through and do all your persistence for you and you're good to go. 341 00:23:12,760 --> 00:23:16,600 And so that's really, just really freaking powerful and I think it's really cool. 342 00:23:17,720 --> 00:23:23,200 You're able to enforce that persistence, so of course desired state, you don't want your system to deviate from how it looks. 343 00:23:23,300 --> 00:23:24,640 So this is your server now. 344 00:23:24,640 --> 00:23:30,200 Think of how you as an adversary want your server to look at all times now that you've compromised it. 345 00:23:30,200 --> 00:23:36,280 You want to make sure you're maintaining the access and being on the box and as long as your agent doesn't get removed, well you can keep enforcing that additional persistence. 346 00:23:36,280 --> 00:23:43,080 As long as that additional persistence is getting enforced, even if your agent does get removed, you can play your cat and mouse game, get back in with your other methods. 347 00:23:43,540 --> 00:23:50,820 So that's kind of the real power here, is that being able to correct the server from how it looks to how you want it to be. 348 00:23:50,820 --> 00:23:53,260 And you're able to do that from the attacker's perspective. 349 00:23:53,740 --> 00:23:56,200 So it's really just a super cool post-exploitation. 350 00:23:56,220 --> 00:24:02,100 It works a little different than things that are built for post-exploitation because it wasn't made for that, but we can make it for that. 351 00:24:02,100 --> 00:24:05,060 So I kind of want to introduce BadSalt. 352 00:24:05,060 --> 00:24:07,000 So that's kind of where this comes into play. 353 00:24:07,500 --> 00:24:09,040 SaltStack is really hard to learn. 354 00:24:09,220 --> 00:24:10,760 It can take some time to set up. 355 00:24:10,760 --> 00:24:13,660 You actually get pretty snappy at it once you've done it a couple times. 356 00:24:13,660 --> 00:24:21,220 But when I was doing all this research, I got tired of setting up new boxes and, you know, reinstalling agents and going through the whole rigmarole. 357 00:24:21,220 --> 00:24:22,680 So I automated everything. 358 00:24:23,100 --> 00:24:24,400 So that's the BadSalt project. 359 00:24:24,400 --> 00:24:26,280 It's not really anything fancy right now. 360 00:24:26,280 --> 00:24:27,460 Don't expect much. 361 00:24:27,460 --> 00:24:31,300 It's literally just a couple automation scripts to help you get started and get things set up. 362 00:24:31,300 --> 00:24:34,260 But if this is all brand new to you, this is a good way to get started. 363 00:24:34,260 --> 00:24:36,920 Especially if you're interested in this from an offensive perspective. 364 00:24:37,540 --> 00:24:43,800 So the goal here eventually would be to pre-build out some of these post-exploitation states. 365 00:24:43,800 --> 00:24:51,300 And also kind of make some sexier stagers to easily deploy onto potential targets because right now it's just a bunch of like batch and batch scripts. 366 00:24:51,300 --> 00:24:55,600 Really, truly nothing fancy, but it did help automate a lot of things. 367 00:24:56,280 --> 00:25:00,860 So let's look at using Salt as like a C2 from an adversarial's perspective. 368 00:25:00,860 --> 00:25:02,160 So let's see this in action. 369 00:25:02,320 --> 00:25:04,240 So I want to demonstrate a couple things. 370 00:25:04,240 --> 00:25:07,580 The first one is going to be, of course, AV evasion with the trusted minion. 371 00:25:07,580 --> 00:25:08,840 So we've got a fresh malware byte. 372 00:25:08,840 --> 00:25:11,880 It's all live protection installed, set up, ready to go. 373 00:25:12,820 --> 00:25:16,260 We're going to go... see it's not even detecting anything wrong with the recode. 374 00:25:16,260 --> 00:25:17,960 There's nothing malicious going on here. 375 00:25:18,720 --> 00:25:21,120 Obviously you'll see some pretty janky stuff going on. 376 00:25:21,120 --> 00:25:23,900 Pretty clear things that you could see as IOCs. 377 00:25:23,900 --> 00:25:27,020 And we'll cover that later once we talk about detecting this type of stuff. 378 00:25:27,020 --> 00:25:31,460 So purely just for automation and proof of concept purposes, this will take a minute to set up. 379 00:25:31,460 --> 00:25:40,280 But what's going on here is it's pulling down from the main repo.salt.com the installer binary for a Salt agent. 380 00:25:40,280 --> 00:25:41,920 And then it's running an install command. 381 00:25:41,920 --> 00:25:45,300 And then the last thing it'll do is pull down my custom bad configuration. 382 00:25:45,400 --> 00:25:55,400 And all I've done really at this point is change 4505 and 4506 to ADM443 to look a little bit more stealthy and get past some egress filters. 383 00:25:56,060 --> 00:25:58,120 So this is going to take a minute to set up. 384 00:25:58,200 --> 00:26:06,080 Once it does, though, we'll switch over to our Salt master and apply one of those bad states that we've set up as an attacker. 385 00:26:08,080 --> 00:26:09,480 Any day now. 386 00:26:15,240 --> 00:26:17,460 This is why Windows is my least favorite. 387 00:26:17,620 --> 00:26:18,720 Throw that jab out there. 388 00:26:22,480 --> 00:26:23,100 All right. 389 00:26:23,100 --> 00:26:23,540 Cool. 390 00:26:23,540 --> 00:26:25,120 So we've copied our config over. 391 00:26:25,320 --> 00:26:28,080 And now we're going to go over to our master. 392 00:26:28,080 --> 00:26:29,380 We're going to accept the key. 393 00:26:30,640 --> 00:26:34,860 And then we're going to see that there is no backdoored user installed. 394 00:26:34,860 --> 00:26:36,440 So we're going to run on that user command. 395 00:26:36,540 --> 00:26:38,220 This is like an IE test box. 396 00:26:38,220 --> 00:26:41,220 So these are some of the default users on that IE test box for Vagrant. 397 00:26:41,460 --> 00:26:43,820 And now we're going to run our persistent state. 398 00:26:43,900 --> 00:26:45,180 And this is going to be very simple. 399 00:26:45,180 --> 00:26:46,860 We'll look at the code for this on the next slide. 400 00:26:46,860 --> 00:26:48,720 But it's going to install this backdoored user. 401 00:26:48,720 --> 00:26:49,900 Did it pretty quickly. 402 00:26:50,700 --> 00:26:53,880 And now we have a backdoored user installed on the box called backdoor. 403 00:26:53,880 --> 00:26:56,340 Has administrative privileges and RDP purpose. 404 00:26:56,340 --> 00:26:57,880 Pretty quick, pretty effective. 405 00:26:58,120 --> 00:27:00,120 What does that actually look like? 406 00:27:00,260 --> 00:27:02,300 We'll start actually with a Linux state. 407 00:27:02,400 --> 00:27:03,680 So this is going to look similar. 408 00:27:03,680 --> 00:27:05,060 We're actually going to look at the Windows state as well. 409 00:27:05,060 --> 00:27:06,440 But these are what states look like. 410 00:27:06,440 --> 00:27:07,860 They're just YAML configurations. 411 00:27:07,860 --> 00:27:10,520 They're real simple, real easy to adapt. 412 00:27:11,000 --> 00:27:15,680 And basically just think of how systems are configured and what you want to do on those systems. 413 00:27:15,680 --> 00:27:16,720 And you do it in YAML. 414 00:27:16,720 --> 00:27:18,280 And it's pretty straightforward and easy to read. 415 00:27:18,280 --> 00:27:21,920 So here I've named this configuration add backdoor Nix user. 416 00:27:21,920 --> 00:27:26,360 So when I call it later, I'll say, hey, for Linux machines or Unix machines, go do this thing. 417 00:27:26,920 --> 00:27:31,220 And then what it's going to do is it's going to check if a user is present. 418 00:27:31,220 --> 00:27:33,560 So user.present, it's very declarative. 419 00:27:33,560 --> 00:27:36,600 You think, is the state of this machine's way? 420 00:27:36,600 --> 00:27:37,740 If it's not, go do it. 421 00:27:37,740 --> 00:27:40,160 Rather than saying, go do this to this machine. 422 00:27:40,160 --> 00:27:41,840 It's going to check first and validate. 423 00:27:42,240 --> 00:27:45,460 So if it's not present, it's going to add a user with name backdoor. 424 00:27:45,500 --> 00:27:46,600 Password's going to be doorback. 425 00:27:46,600 --> 00:27:47,600 It'll hash it. 426 00:27:47,600 --> 00:27:49,780 Give us a home directory of slash home slash thread. 427 00:27:49,780 --> 00:27:52,940 And then add us to like wheel, sudoers, root, et cetera. 428 00:27:53,260 --> 00:27:55,080 So now we have a root account ready to go. 429 00:27:56,080 --> 00:28:01,960 In a much more powerful vein, you can also do these file managed states. 430 00:28:01,960 --> 00:28:07,600 So here we got a sample one for how you might go deploy an interpreter payload on a particular target. 431 00:28:07,760 --> 00:28:15,240 So here we just have our salt repo set up as salt colon slash slash is actually a local directory on your master system. 432 00:28:15,240 --> 00:28:17,300 It'll be in like slash serve slash salt. 433 00:28:17,700 --> 00:28:20,100 And you'll kind of set a directory structure here. 434 00:28:20,100 --> 00:28:26,240 I've got one called payloads, nix, and then I put any of my Linux payloads that I might want to do managed file stuff with there. 435 00:28:26,240 --> 00:28:27,840 In this case, it's an interpreter payload. 436 00:28:28,140 --> 00:28:32,640 I'm going to tell it to go, hey, install this into slash temp. 437 00:28:32,900 --> 00:28:36,320 Give it executable, read, write permissions, et cetera. 438 00:28:36,680 --> 00:28:37,700 And then go run it. 439 00:28:37,700 --> 00:28:40,000 And then this BG is go run it in the background. 440 00:28:40,000 --> 00:28:45,480 So it'll go execute it, run it in the background, and then I should get an interpreter session that pops over once that happens. 441 00:28:45,480 --> 00:28:50,380 Now, with just these two ideas, you can go crazy. 442 00:28:50,380 --> 00:28:59,600 So from just the managed file, being able to run all your custom binaries from one place, you could get salt stack in there and say, all right, I want to do some crazy stuff with my custom tool sets that I already have. 443 00:28:59,600 --> 00:29:06,640 You can apply it like that and saw it across as many systems as you have into your salt stack instance and go from there. 444 00:29:06,640 --> 00:29:11,780 So whether it's an interpreter, Merlin, or some crazy custom toolkit you have, that's about how you do it. 445 00:29:12,540 --> 00:29:14,780 Now, for Windows, it's about the same. 446 00:29:15,140 --> 00:29:23,060 This is just to show kind of the difference between the language that you're going to be using in the YAML file, but this is the exact state we just ran in that demo. 447 00:29:23,280 --> 00:29:25,500 So we're checking for user present. 448 00:29:25,540 --> 00:29:32,080 If it's not, we add a user back door, pass through a door back, and add it to the administrators and RDP groups. 449 00:29:32,540 --> 00:29:33,940 Really simple, really effective. 450 00:29:33,940 --> 00:29:34,860 That's all it was. 451 00:29:34,860 --> 00:29:35,820 That's all we did. 452 00:29:36,560 --> 00:29:45,700 The managed file payload or configuration state is the exact same as Linux one, only we don't have to set any executable permissions because Windows is going to know it's an exe. 453 00:29:45,800 --> 00:29:50,380 And we just copy it to wherever we want, in this case Windows temp, and run it in the background as well. 454 00:29:50,380 --> 00:29:54,280 So these are really, really, really simple and really, really, really effective. 455 00:29:54,280 --> 00:30:01,460 And I hope it kind of gets your brain turning and new ideas of things you could build really easily with these types of desired state configurations. 456 00:30:01,820 --> 00:30:05,840 And what's really great about these is, like I said, that concept of desired state. 457 00:30:05,840 --> 00:30:08,700 You are missing this from the system you just installed. 458 00:30:08,700 --> 00:30:10,080 Your user is not there anymore. 459 00:30:10,080 --> 00:30:12,020 Any of the persistence you just set up is gone. 460 00:30:12,060 --> 00:30:16,280 As long as it's still calling home to your salt master, you can even set it up as Java. 461 00:30:16,280 --> 00:30:22,780 It'll go correct itself on its own, but if you're there monitoring it or babysitting it, it's as simple as a state.apply and it'll go fix itself. 462 00:30:23,020 --> 00:30:29,300 So you can do it with automation, you can do it manually, whatever have you, but you can always correct to fix things as they should be. 463 00:30:30,720 --> 00:30:34,980 Alright, so let's talk about detecting hackers that are abusing salt stack. 464 00:30:34,980 --> 00:30:39,240 No red team or security team is worth their salt without helping our blue teams. 465 00:30:39,240 --> 00:30:41,580 We're not doing any good, we're not helping anyone. 466 00:30:41,580 --> 00:30:43,500 This is probably the most important piece. 467 00:30:44,960 --> 00:30:47,160 First and foremost, simple log analysis. 468 00:30:47,160 --> 00:30:48,300 Go back to basics. 469 00:30:48,600 --> 00:30:52,940 Check the salt minion and master logs, especially in the context of like a man-in-the-middle attack. 470 00:30:53,240 --> 00:31:00,180 Kind of harkening back to that screenshot from last where we pull out, hey, this might be a man-in-the-middle attack of some sort. 471 00:31:00,240 --> 00:31:01,920 Those logs will just tell on themselves. 472 00:31:01,920 --> 00:31:05,180 It's kind of your golden ticket for seeing all the minion and master communications. 473 00:31:05,180 --> 00:31:08,060 It will tell you who, what, when, where, what time, etc. 474 00:31:08,220 --> 00:31:13,240 that minions are talking to a given master, even if it is the wrong master. 475 00:31:13,460 --> 00:31:16,520 And so you can kind of use that in your investigation to see what's going on. 476 00:31:16,920 --> 00:31:19,440 Alright, so that's kind of basics. 477 00:31:19,440 --> 00:31:22,540 Another thing we can do is observe the network traffic patterns. 478 00:31:22,540 --> 00:31:25,620 While everything is encrypted, it's actually kind of easy to spot. 479 00:31:25,620 --> 00:31:27,200 And of course, pcapture didn't happen. 480 00:31:27,600 --> 00:31:30,180 In that repo, there's all the actual pcaps from the researcher did. 481 00:31:30,180 --> 00:31:33,100 You can go look at them yourself if you don't feel like taking your own packet captures. 482 00:31:33,240 --> 00:31:34,300 I'm not going to dive into this. 483 00:31:34,300 --> 00:31:35,360 I don't expect anybody to read it. 484 00:31:35,360 --> 00:31:44,000 But one thing I want to point out here is that we've remapped port 4505 to 80 and port 4506 to 443, kind of like I mentioned a couple slides ago. 485 00:31:45,140 --> 00:31:47,360 This is actually what's going on, though, in that pcap. 486 00:31:47,640 --> 00:31:54,000 So the first thing we're doing is accepting a key from a potential minion that we've actually man-in-the-middle in this case. 487 00:31:54,000 --> 00:31:56,580 So we've successfully pulled off a middle attack. 488 00:31:56,580 --> 00:31:57,880 We've got our key accepted. 489 00:31:57,880 --> 00:32:02,220 We're going to run a test.ping, which just says that we can talk to that minion. 490 00:32:02,360 --> 00:32:06,400 Then we're going to run a couple commands like whoami, id, ls, et cetera. 491 00:32:06,800 --> 00:32:08,920 And that's just to kind of show what's going on here. 492 00:32:08,920 --> 00:32:15,600 But what's actually happening in terms of communication patterns is what's important from a Blue Teamers perspective to detect. 493 00:32:15,820 --> 00:32:21,160 So when a minion calls home, in this case on port 80, it's going to check in on port 81st. 494 00:32:21,320 --> 00:32:24,600 And the master's not going to publish anything because they're not associated yet. 495 00:32:24,880 --> 00:32:28,880 And then it's going to go up and say, hey, on port 443, do you want to trust me? 496 00:32:28,880 --> 00:32:30,780 If you accept, the master's in. 497 00:32:30,780 --> 00:32:35,180 Now it'll send you its public key and you're good to go to keep your communications running. 498 00:32:35,880 --> 00:32:37,660 Here, we can execute commands. 499 00:32:37,800 --> 00:32:41,640 So maybe on the salt master, we'll run whoami. 500 00:32:41,740 --> 00:32:47,580 And then the master will publish that on port 80 in this case to say, hey, go run whoami. 501 00:32:47,580 --> 00:32:53,960 When the minion checks in on port 80, it'll go fetch that, run it, and then come back up to 443 and say, hey, I was rude. 502 00:32:54,200 --> 00:33:04,900 And kind of the pattern here that I want everybody to notice is that you'll have a connection to port 80 or port 4505 followed by one or more connections to port 443 to the exact same host. 503 00:33:04,900 --> 00:33:07,520 That's a pretty clear pattern that we can see carved out there. 504 00:33:07,520 --> 00:33:14,440 And it's even easier if they are using the default ports for 4505 and 4506 because it might give away that it's salt stack right away. 505 00:33:14,440 --> 00:33:16,000 But that's a pattern that you could use. 506 00:33:16,000 --> 00:33:27,920 So tandem with those log analysis and kind of your packet captures, you can kind of correlate these two events and say, hey, maybe this is some kind of attacker abusing salt stack as a command and control service. 507 00:33:29,200 --> 00:33:36,500 Another way to kind of detect this type of activity is the fact that salt master and minion installations are very, very noisy. 508 00:33:36,500 --> 00:33:43,620 Now, obviously, an attacker could change all of the configurations and move things to different directories or whatever. 509 00:33:43,620 --> 00:33:44,660 It's an open source project. 510 00:33:44,660 --> 00:33:46,340 So there's a lot of power they have. 511 00:33:46,340 --> 00:33:48,880 But by default, it is extremely noisy. 512 00:33:49,100 --> 00:34:08,560 So if any of these directories exist on your system, whether it's bar log salt, at C salt, serve salt, if you have a master on your system for whatever reason possible, or C colon back slash salt for Windows, if any of those things exist, it's a pretty clear sign that somebody might have installed salt stack in some shape or form on that box. 513 00:34:08,720 --> 00:34:13,920 Another thing to do is check your repo files or your network communications to repo.saltstack.com. 514 00:34:13,920 --> 00:34:20,740 Because if they're pulling from the default not compiling their own binaries, it's going to be a clear communication just like with that batch file. 515 00:34:20,740 --> 00:34:29,080 So if somebody just wants to go be a script kitty and pull down that GitHub project and go use it on a potential target, it's going to be real easy to pinpoint that that's happening. 516 00:34:29,380 --> 00:34:31,420 Like I said, it is an open source project. 517 00:34:31,420 --> 00:34:33,540 There's always ways to modify and change this. 518 00:34:33,700 --> 00:34:35,760 Those are things that I'm going to be looking into more in the future. 519 00:34:35,760 --> 00:34:44,140 But for the most part, it's pretty clear when somebody installs a minion , these logs and these existence of these directories is a clear indication that that's happened. 520 00:34:45,720 --> 00:34:55,140 A crucial thing, though, to take a look at is if you are legitimately using SaltStack in your environment, an attacker could still install a duplicate minion on a particular target they've compromised. 521 00:34:55,240 --> 00:35:01,680 So you'll be able to identify multiple minions in that case, because you should only really ever have one minion running on a box. 522 00:35:02,060 --> 00:35:04,860 It's supported to have more than one, which is why this is possible. 523 00:35:04,860 --> 00:35:07,680 But in a legitimate configuration, that's not recommended. 524 00:35:07,680 --> 00:35:09,200 So hopefully you're not doing that. 525 00:35:09,200 --> 00:35:13,860 If you are, here's how you might be able to detect a bad one. 526 00:35:13,860 --> 00:35:27,680 So when an attacker goes to install a second minion on a box, they're going to either A, bring their own minion binary, or B, use the one that you already have installed and then just point it at their bad configurations. 527 00:35:28,260 --> 00:35:35,720 So what you're going to want to look for in these cases are the potential usage of the same log file. 528 00:35:35,720 --> 00:35:47,180 So if two minions are installed and they haven't reconfigured their minion to point to a different log file, you're going to see really weird activity going on in that log from two different minions going on in the box. 529 00:35:47,180 --> 00:35:48,380 So you can check that out. 530 00:35:48,580 --> 00:35:50,620 Another thing would be your system dlogs. 531 00:35:50,620 --> 00:35:58,640 You can look for activity that's going on on one minion that might be similar to activity going on on the other minion, but one's not named like a minion. 532 00:35:58,640 --> 00:36:00,000 It's just a behavior type thing. 533 00:36:00,000 --> 00:36:03,220 So you notice that two services are behaving the same. 534 00:36:03,220 --> 00:36:04,640 One is a legitimate minion. 535 00:36:04,640 --> 00:36:07,540 One's like weird XYZ daemon or something. 536 00:36:07,940 --> 00:36:09,900 So that's stuff you may want to look for. 537 00:36:09,900 --> 00:36:13,560 And then of course, kind of dead giveaway that I think is going to be your network traffic. 538 00:36:13,560 --> 00:36:15,320 It's got to communicate back home. 539 00:36:15,660 --> 00:36:18,940 So if it's not talking to your master, it's probably not your minion. 540 00:36:18,940 --> 00:36:21,580 And so you can go trace that back to whatever your process is. 541 00:36:21,580 --> 00:36:26,220 So that's pretty important if you are using SaltStack in your environment because all the other ways are a little bit easier to detect. 542 00:36:26,220 --> 00:36:29,240 These are the things you're going to want to look for if you already have minions installed. 543 00:36:31,000 --> 00:36:33,200 So that's kind of all the things I wanted to cover today. 544 00:36:33,320 --> 00:36:41,080 To wrap this up, I wanted to say, hey, go check out Salt if you're looking for a potential tool for your configuration management or any of the tools really. 545 00:36:41,080 --> 00:36:42,340 I'd just favor this. 546 00:36:42,520 --> 00:36:48,700 It's great for operations, great for blue teams, and seems pretty fun to use as a red team tool potentially as well. 547 00:36:49,120 --> 00:36:50,640 A couple of appreciation shout outs. 548 00:36:50,640 --> 00:36:52,080 First and foremost, Seth. 549 00:36:52,080 --> 00:36:57,400 The only reason I even chased down this research, he was one of our DevOps on the team at the time. 550 00:36:57,700 --> 00:37:01,980 Really educated me a lot on the platform and I kind of took this home and ran with it from there. 551 00:37:02,360 --> 00:37:04,900 Chris and Robert, always being real supportive. 552 00:37:05,240 --> 00:37:10,800 Daniel Robertson, Dan Borges, both of these two have been great influencers, mentors, whether they realize it or not. 553 00:37:10,860 --> 00:37:13,760 And then Camilla, also a great supporter of my life. 554 00:37:14,520 --> 00:37:15,620 A couple of references. 555 00:37:15,620 --> 00:37:18,420 Like I said, these slides will be available on that GitHub repo. 556 00:37:18,760 --> 00:37:20,420 I want to point out Seth's brain again. 557 00:37:20,560 --> 00:37:21,740 That guy's really smart. 558 00:37:22,480 --> 00:37:24,100 And with that, we have questions. 559 00:37:44,410 --> 00:37:46,510 Can you repeat that? 560 00:37:46,510 --> 00:37:47,250 I'm sorry, I didn't hear you. 561 00:37:48,610 --> 00:37:48,970 Yeah 562 00:37:54,660 --> 00:38:06,720 , so the question was, is it better to, or not is it better, was the second option for mitigating the issue to automatically accept minions to the master. 563 00:38:06,720 --> 00:38:08,620 And yes, that was the second recommendation. 564 00:38:14,050 --> 00:38:18,710 Yeah, and that's absolutely true, which is why is okay, but definitely not the best idea. 565 00:38:18,710 --> 00:38:21,930 The best solution is just to install the fingerprint where it should be in your configuration. 566 00:38:21,930 --> 00:38:23,010 That's absolutely true. 567 00:38:28,830 --> 00:38:29,790 What's up? 568 00:38:30,310 --> 00:38:32,610 You spoke briefly of desired state. 569 00:38:32,610 --> 00:38:36,650 I know that after like a pentesting engagement, we want to get everything back to normal. 570 00:38:36,650 --> 00:38:40,070 Can we use desired states to get back to that normal? 571 00:38:40,270 --> 00:38:48,530 Yeah, so you'd have to know and coordinate with your red teams or your pentest teams to know exactly what they installed and anything like that as well. 572 00:38:48,530 --> 00:38:57,410 But if you potentially wanted to use that as a way to clean up after known good engagements, rather than having to go back and maintain up, that is absolutely an option. 573 00:38:57,410 --> 00:39:03,050 So you can build your states around what you know that you've done and work with those offensive security people to execute on those states. 574 00:39:03,050 --> 00:39:05,230 So that's definitely an option to help make cleanup quicker. 575 00:39:23,300 --> 00:39:35,020 Yeah, so I don't know exactly where I'll dive down in terms of that, but I do definitely want to explore other new tools or existing tools to see if there's anything better than doing things with SaltStack as we've done it, because it's definitely possible. 576 00:39:35,020 --> 00:39:37,420 Like I said, any of these do all do about the same thing. 577 00:39:37,420 --> 00:39:42,640 So you can accomplish anything that we've shown in SaltStack today with another one of those tools like Puppet Chef or Ansible. 578 00:39:42,640 --> 00:39:46,820 It's the idea of just using these tools from the perspective of the adversary. 579 00:39:56,260 --> 00:39:57,040 All right, cool. 580 00:39:57,060 --> 00:40:00,560 Well, I'll be around if you want to ask me any other questions, but thank you all for coming.