[00:00.000 --> 00:04.160] All right, let's get moving. Hope you guys have had an awesome DEF CON so far. [00:04.180 --> 00:07.320] Let's dive right in. So this is Bad Salt Adversarial DevOps. [00:07.760 --> 00:12.020] I'm going to start with a quick introduction, some background about myself. My name is Casey [00:12.020 --> 00:17.140] Erdman. You may know me by my handle Ngame on Twitter or other aspects of the interwebs. [00:17.280 --> 00:20.820] I'm a giant offensive security nerd, that's why I'm here in the Red Team Village. [00:21.280 --> 00:25.680] I am the co-founder of DC706, which is a Columbus, Georgia DEF CON group, [00:25.680 --> 00:27.820] so if you're ever in the area, feel free to roll through. [00:28.400 --> 00:31.560] These are some of my professional certifications, if you care about that type of thing. [00:31.560 --> 00:35.120] In my day-to-day, though, I am a manager of an information security department. [00:35.200 --> 00:39.400] We are a very small team, so I touch pretty much everything. We're in the kind of financial space, [00:39.400 --> 00:44.340] so lots of offensive security stuff, pin testing, that type of thing, incident response, [00:44.340 --> 00:48.420] good old PCI compliance, stuff like that. But I think the most interesting thing you should [00:48.420 --> 00:52.080] all know about me is that I'm a programmer gone rogue. Most of my background is in software [00:52.080 --> 00:57.900] development, and I just kind of got into CTFs and started hacking, and I decided, [00:57.900 --> 01:01.620] no more software development, let's do the offensive security stuff. That's a lot more fun. [01:01.620 --> 01:04.400] So that's where a lot of my passion is, and that's just a little bit about me. [01:05.020 --> 01:09.320] This is probably the most important slide today. If you don't take a picture of anything else, [01:09.320 --> 01:12.540] I'm going to give everybody a second to take a picture of this. All of the code, [01:12.540 --> 01:17.100] the slides for this talk, any of the PCAPs or stuff like that are at this GitHub repo, [01:17.100 --> 01:29.880] and we'll be there. So I'll give you guys a minute. All right. Perfect. So let's move along. [01:30.120 --> 01:34.940] Here's our agenda for today. First, we're going to hit some of the high points, introduce anybody [01:34.940 --> 01:40.440] to the concepts of configuration management, how we landed on SaltStack, why this technology is [01:40.440 --> 01:44.880] even the focal point of this talk today. Then we're going to talk about some attacks against [01:44.880 --> 01:49.400] that platform. And then the meat of the talk is actually going to be hacking with that platform. [01:49.400 --> 01:53.900] When we're talking about adversarial DevOps, we're talking about using these new fancy tools [01:53.900 --> 01:58.520] that are in our industry as an offensive person. How can I take advantage of these? And that's [01:58.520 --> 02:01.920] really where we're going to dive in and look at a couple of those things. And then, of course, [02:01.920 --> 02:06.460] we're going to also give our blue teamers the chance to stop anything that they see like this, [02:06.460 --> 02:13.180] and we'll cover those investigation techniques at the end. All right. So what is SaltStack? [02:13.840 --> 02:17.500] So to talk about SaltStack, first we need to talk about configuration management. [02:17.500 --> 02:22.500] So configuration management isn't really new. We've got configurations we've been managing for [02:22.620 --> 02:27.780] a long time in the industry. But there's kind of new technologies that help us facilitate this idea. [02:27.780 --> 02:32.360] And the goal here is to establish some baseline and some integrity across our systems to make [02:32.360 --> 02:38.680] sure they look and act how they should and don't have any variants here. Some common new tools for [02:38.680 --> 02:44.100] configuration management you may have heard of are things like Puppet, Chef, Ansible, and SaltStack. [02:44.100 --> 02:48.260] So we're going to take a high-level look at some of these tools. All of these tools can [02:48.260 --> 02:52.180] essentially accomplish the same goal. So I'm not saying any one tool is better than the other. I'm [02:52.180 --> 02:56.100] not sponsored by any of these companies. I just want to kind of give a narrative of how I landed [02:56.100 --> 03:01.760] on what I landed on. So starting with Puppet, Puppet's kind of one of the industry-leading [03:01.760 --> 03:06.660] tools in this space here. They've been around for a while. It integrates really well with [03:06.660 --> 03:11.820] other products because its baseline purpose is the concept of configuration management. So [03:12.760 --> 03:17.700] when these tools first started coming out, you may have heard things like maybe Puppet and Chef. [03:17.700 --> 03:21.860] And it's this bundle of tools where Puppet would be the foundation and help you do the [03:21.860 --> 03:26.420] configuration management where something like Chef or Ansible would go then execute on those [03:26.420 --> 03:31.000] configurations. So that's kind of where things kind of got started. It's got a little bit of [03:31.000 --> 03:37.080] maturity, good foundation, but there's also other tools out there that have matured a lot more. And [03:37.080 --> 03:41.800] so Puppet and Chef can kind of just be replaced by Chef nowadays. Chef has come a long way. [03:41.800 --> 03:46.000] But at first, it was more focused on infrastructure as code and not really [03:46.000 --> 03:50.280] configuration management. However, inherently, when you're talking about infrastructure as code, [03:50.280 --> 03:56.540] you're defining how your machines look in some kind of code syntax or configuration. So naturally, [03:56.540 --> 04:03.200] Chef kind of became its own configuration management utility. And the focus here is, [04:03.200 --> 04:06.700] of course, that continuous automation. You can continue upgrading, changing your configurations [04:06.700 --> 04:12.680] in your systems, and also manage those configurations. Chef also provides a couple [04:12.680 --> 04:16.720] neat other tools like Inspect or Habitat. I don't know a whole lot about these tools. I know [04:16.720 --> 04:20.780] Inspect is supposed to be some kind of cool code audit tool of some sort. But the point is, [04:20.780 --> 04:24.300] it's matured a lot more now and there's a lot of feature sets. It could be a good option when [04:24.300 --> 04:28.160] you're looking to explore the concept of configuration management for your infrastructure. [04:29.360 --> 04:33.880] Now, Ansible is a little bit different from these other tools. So Ansible is more about [04:33.880 --> 04:38.340] the infrastructure automation, not so much the configuration management. While, again, [04:38.340 --> 04:42.700] you can do pretty much everything with all of these tools, Ansible I like to think of as like [04:42.700 --> 04:47.060] mass SSHing or something like that. You're able to go and execute on hundreds and hundreds of [04:47.060 --> 04:52.040] systems at one time to apply whatever state or configuration that you're trying to apply. [04:52.760 --> 04:57.320] And so I like to equate maybe Puppet and Ansible as something a little bit closer to what Salt [04:57.320 --> 05:03.340] Stack is. But again, it's less about configuration management and just more about the execution of [05:03.340 --> 05:10.360] the automation of whatever your configurations are. All right, so we got all these great tools. [05:10.360 --> 05:16.300] Why did it land on Salt Stack? So from a professional standpoint, when myself and the [05:16.300 --> 05:22.280] other members of the DevOps team are coordinating and looking at different ways to do configuration [05:22.280 --> 05:25.860] management on our infrastructure, we found that Salt Stack scales a little bit easier. And the [05:25.860 --> 05:31.260] reason is because it's agent-based. So a lot of these other tools may require you to have access [05:31.260 --> 05:37.180] or credentials or go open up some firewall rules or network communications. There seems to be a lot [05:37.180 --> 05:43.360] more setup. Things are changing very rapidly with a lot of these tools. So what's true today, of [05:43.360 --> 05:48.660] course, may not be true later. But at the time of selection for a tool, Salt Stack really scaled well. [05:49.660 --> 05:54.200] And of course, it does everything all the other tools do. And it just does it all in one. You [05:54.200 --> 05:59.580] don't need an Ansible and a Puppet. You could just use Salt Stack and get all the same capabilities [05:59.580 --> 06:04.280] out. Doesn't make it better, doesn't make it worse. You just have those options available to you. [06:05.240 --> 06:09.800] And Salt Stack's primary purpose is for configuration management. That's kind of what [06:09.800 --> 06:15.460] it's built around. It's built around the concept of desired state. So desired state is this idea that [06:15.460 --> 06:20.720] your machine is going to match your configuration all the time, no matter what. And if at any point [06:20.720 --> 06:25.460] it's not matching that desired state, it's going to correct itself and make sure it maintains that [06:25.460 --> 06:30.240] integrity. And that's kind of what Salt Stack's built around. And because of kind of the agent-based [06:30.240 --> 06:35.600] nature, it integrates with kind of some older or more standardized systems a little bit easier. [06:35.700 --> 06:41.760] We're able to deploy this in anywhere from like cloud environments like AWS or Google Cloud or [06:41.760 --> 06:46.220] traditional data centers or co-locations. It's really easy. You just kind of set up a master and [06:46.220 --> 06:50.500] look at the architecture in a couple slides. You set up the salt master, you deploy minions, you [06:50.500 --> 06:54.620] set the egress out where you want, and you're good to go start configuring hundreds and hundreds of [06:54.620 --> 07:01.640] systems in Salt Stack. So that's kind of how we landed on this from the standpoint, and I kind of [07:01.640 --> 07:06.460] took it and ran with it for the majority of the talk. But just how we got there. This is Salt Stack [07:06.460 --> 07:09.740] architecture. I'm not going to dive into this. I don't expect anybody to actually read it. It's [07:09.740 --> 07:16.640] really complex though. That's kind of why I wanted to show this slide. So the kind of key points [07:16.640 --> 07:20.960] here that we're going to look at is this idea of the master and then these little beacons or [07:20.960 --> 07:25.400] minions as they're actually called. So there's a lot of functionality in Salt Stack. Please read [07:25.400 --> 07:29.740] more of the documentation. It's really cool. But this is the simplified version that's a lot easier [07:29.740 --> 07:35.820] to understand. So salt minions and salt masters. That's kind of what we're primarily focused on [07:35.820 --> 07:42.760] here. So the salt master is going to be listening on two ports, 45.05 and 45.06. 45.05 is the [07:42.760 --> 07:46.720] publisher port. This is where the master is going to issue a command, say, hey go run who am I or [07:46.720 --> 07:52.540] whatever. And then 45.06 is where the minion is going to pull up and publish its results. So the [07:52.540 --> 07:58.120] minion is going to go up to port 45.05, grab that command, execute it, and then return up to 45.06 [07:58.120 --> 08:03.920] with whatever its output is. Now this request server also handles file management. So one of [08:03.920 --> 08:08.080] the cool things we'll do that we'll kind of look at a little bit later is manage files. So if you [08:08.080 --> 08:12.780] want to copy other configurations for other components or install applications from a custom [08:12.780 --> 08:18.720] repo, whatever have you, you can copy those. And that port is where the salt minion will go [08:18.720 --> 08:24.760] fetch or send commands, either one, to that request server. Now of course we have this execution of [08:24.760 --> 08:29.260] commands and the sending of response. Sounds kind of like a C2 server. So keep that in the back of [08:29.260 --> 08:35.900] your brain as we go forward. All right, kind of wrap up this section. Configuration management. Why is [08:35.900 --> 08:41.120] it cool? What are we using this for? Well, you can enforce hardening standards with it. You can [08:41.120 --> 08:46.400] enforce those nasty compliance standards with it. Create uniformity across all your environments. [08:46.480 --> 08:51.040] And then ultimately the coolest thing that works both on the offensive side and the defensive side [08:51.040 --> 08:55.480] is making sure stuff is installed that should be and making sure that stuff that isn't installed [08:55.480 --> 09:00.340] shouldn't be. So you're really able to enforce that and help lock that down with this concept [09:00.340 --> 09:05.060] of desired state where the system will go and see what it should look like. If it doesn't match, [09:05.060 --> 09:10.320] it'll go try to correct itself. All right, so hopefully everybody's got a good overview of the [09:10.320 --> 09:15.540] concepts of configuration management, desired state, what all these tools are for. Let's hack [09:15.540 --> 09:22.080] SaltStack. All right, so quick history lesson. SaltStack was released back in March 2011. This [09:22.080 --> 09:27.660] was a very stable or very not stable, very early version. The first stable release came out a [09:27.660 --> 09:33.980] couple months later in November 2011. And we're now on version 2019.2, which was like in February. [09:33.980 --> 09:37.580] And this is true as of the time of typing of the slide. There may have been a new release like this [09:37.580 --> 09:42.720] week. I don't know. But the point here that I'm trying to illustrate is this is back in 2011. [09:42.720 --> 09:48.000] We're in, what, 2019 now. About eight years. That doesn't sound like long ago because it's 2011, [09:48.000 --> 09:52.860] but it was eight years ago. Old things have bugs. SaltStack is now kind of an old thing. It's kind [09:52.860 --> 09:58.220] of weird to think about. But to illustrate that old things have bugs, here's a list of kind of [09:58.220 --> 10:04.640] recent CVEs for SaltStack. Just to kind of go over and glance real quick, this list is longer than [10:04.640 --> 10:11.800] here. This is just a snap of part of the MVD. But we got some code execution. We got some directory [10:11.800 --> 10:18.680] traversal. Some information type of issues. The goal of this research wasn't any kind of [10:18.680 --> 10:22.680] vulnerability research specifically. So I encourage you to go dive down these your own. Just to show [10:22.680 --> 10:27.120] that SaltStack has had some problems. And what I did from there is kind of see if there's any [10:27.120 --> 10:33.160] proof of concepts out there. See if based on what is known, what type of attack vector should I be [10:33.160 --> 10:38.100] challenging myself to go look for in a current version of SaltStack. And the first thing I kind [10:38.100 --> 10:43.440] of stumbled upon was this evil minions project. Now, this isn't really a proof of concept to [10:43.440 --> 10:48.420] exploit any kind of vulnerability. It's actually just a load generator. It was made for purposes [10:48.420 --> 10:54.480] of going and testing how many minions or processes a particular minion service could handle. So it [10:54.480 --> 10:59.120] just spawned a whole bunch of minions and test the load. So nothing really crazy in terms of [10:59.120 --> 11:04.120] exploiting vulnerabilities, but might be cool for some denial of service attack or whatever have you. [11:04.120 --> 11:08.720] That was just the first thing I stumbled on with some simple Googling and looking at search terms. [11:09.520 --> 11:14.380] I dug a little bit deeper, though, and I found Chicken Salt. So Chicken Salt is this neat little [11:14.380 --> 11:22.640] POC for abusing the communication between minions and masters when they do this handshake for [11:23.220 --> 11:28.640] key public key authentication. So this allows for man in the middle attack, which ultimately allows [11:28.640 --> 11:33.360] you to take over minions. Now, this is important because while you may think, oh, well, if I can [11:33.360 --> 11:37.620] get access to the master, well, then I can control everything on the network, right? Well, what if [11:37.620 --> 11:42.560] you could just stand up your own master? You don't need access to that master. And then you get [11:42.560 --> 11:46.400] everybody to talk to you, and now you can control all of the minions it controls. That's what this [11:46.400 --> 11:52.400] kind of attack allows you to do. And what happens here is you'll sniff the handshake upon initial [11:52.400 --> 11:57.240] communication between a minion and a master. You would be able to grab the public key and the [11:57.240 --> 12:02.100] verification token for that particular communication. Then you can man in the middle, [12:02.100 --> 12:06.720] serve up that public key and token you acquired, and bam, you can pwn all the minions. Couldn't [12:06.720 --> 12:10.660] really find a CVE for this one, though. It didn't match any of the things that I had already found [12:10.660 --> 12:17.920] when doing initial research. It looks like it was probably patched in version 0.17.1. It might be [12:17.920 --> 12:22.520] related to that CVE that's on the slide there. That has to do with Salt not validating SHHOS [12:22.520 --> 12:26.620] key request, which also resulted in a man in the middle attack vector. It's just really hard to [12:26.620 --> 12:32.860] tell. All I know is it doesn't work now because I tried. However, when I tried, I found a new [12:32.860 --> 12:38.400] attack vector. So I kind of want to talk about modern man-in-the-middle attacks against Salt [12:38.400 --> 12:43.260] Stack. Now, this isn't any kind of crazy OODA. We're not doing anything super sophisticated. [12:43.260 --> 12:47.700] This is a really easy attack, and it's really not a high risk. It's actually just by design, [12:47.700 --> 12:53.140] how Salt works. And what I'm trying to communicate here is just awareness for good configuration [12:53.140 --> 12:58.780] standards of your Salt environment, because it's really easy to mitigate this type of issue, [12:58.780 --> 13:03.020] but by default, it is not mitigated. And that's just by design. It's not a vulnerability. It's [13:03.020 --> 13:08.060] not any kind of issue, but it is a potential risk that you need to be aware of, especially if you [13:08.060 --> 13:14.160] have Salt in your environments. So the issue is caused by the need to distribute keys. Once you [13:14.160 --> 13:18.520] install an agent on a box, it's got to go talk to the master, and it's got to do this kind of [13:18.520 --> 13:24.900] exception thing. So we'll look at that on the next slide. So here's how the key exchange works. [13:24.900 --> 13:29.940] So you have a Salt minion and your Salt master, like we've seen. The Salt minion is going to [13:29.940 --> 13:34.080] communicate initially with the Salt master and say, hey, here's my public key. Do you want to [13:34.080 --> 13:39.280] accept it? If you choose to accept it on the Salt master side, it'll add that minion into [13:39.820 --> 13:43.640] your queue, and now you can execute commands and facilitate communications with the minion. [13:44.940 --> 13:49.720] So the problem here is that the Salt minions will trust a master on initial communication no [13:49.720 --> 13:54.300] matter what. This is any master at any point in time. The solution to this problem, which is [13:54.300 --> 14:00.420] built into Salt already, is to give Salt minions a fingerprint for the good known master. So [14:00.420 --> 14:04.680] everything's good, right? We give them the fingerprint, and we're good to go. Well, how do [14:04.680 --> 14:10.200] you give the minion the fingerprint? Fingerprints have to be issued on initial deployment. If you [14:10.200 --> 14:14.440] don't issue them on initial deployment, they won't be set, therefore making you potentially [14:14.440 --> 14:18.800] vulnerable to this type of attack factor. Now, it's really easy to fix this issue, as we'll see, [14:18.800 --> 14:24.540] but here's the kind of capabilities and control that you have. So let's hop into this demo real [14:24.540 --> 14:30.400] quick. So here we've set up BetterCap with a man in the middle listening on our two Salt ports [14:30.400 --> 14:39.020] for our fake master. And then here is our Salt minion. So the Salt minion is going to just show [14:39.020 --> 14:44.800] you what our configurations are. That's pointing to this 128.13 master. There's no master [14:44.800 --> 14:49.680] fingerprint set by default. This is fresh install. And it's started the service. So now it should [14:49.680 --> 14:54.180] call home. This is going to show this is the legitimate master. It's going to be dot 13. [14:55.460 --> 15:00.660] And we'll list our keys here. And there's no unaccepted keys, even though there should be. [15:00.660 --> 15:04.980] We should be getting a callback from that minion, right? Well, if you go back over to our evil [15:04.980 --> 15:09.460] master and see we've got some communications from our interception from man in the middle. [15:09.980 --> 15:12.720] And run this. We're going to show that we're not the same IP. [15:15.520 --> 15:18.560] And now we're going to see what unaccepted keys are in our bad master's queue. [15:18.960 --> 15:22.580] Oh, it looks like we've got one. So we're going to accept that key. [15:24.040 --> 15:26.900] And now we've successfully manned in the middle of that minion and we're ready to [15:28.540 --> 15:32.000] execute commands on this host. So that's kind of how the attack plays out. [15:32.000 --> 15:38.400] Real simple. Not anything complex to it. But it is very much an attack vector and it is [15:39.220 --> 15:44.980] caused by this default configuration. The good news here is this only works on initial [15:44.980 --> 15:51.040] communication. Like I said, it's fairly low risk. What happens is on that initial communication, [15:51.040 --> 16:01.960] once a master accepts the minion communication, it's going to cache that fingerprint that we [16:01.960 --> 16:07.580] there. But it is not in the configuration. Which means if at any point that cache gets cleared out [16:07.580 --> 16:12.620] for any reason by whether it's manual deletion or some debugging or reinstallation of a minion, [16:12.620 --> 16:17.600] whatever have you, it could potentially go away. However, if you have minions already in your [16:17.600 --> 16:21.360] environment, they've already communicated with your legitimate master, what will actually happen [16:21.360 --> 16:25.180] if I try to do that man in the middle attack is there's a conditional set. So the people who make [16:25.180 --> 16:31.720] salt stack are already aware of this particular issue. And this nice helpful log message that [16:31.720 --> 16:37.360] you might be getting man in the middle attack will dump into the salt minion logs. So it kind [16:37.360 --> 16:41.200] of fixes itself if you've already had that initial communication. But if you haven't, [16:41.200 --> 16:46.140] then you're open to this potential vulnerability. Now, detecting this type of attack is fairly [16:46.140 --> 16:50.700] simple. In the first image we have here, a successful attack basically looks like nothing. [16:50.700 --> 16:55.400] It's completely normal. You don't see anything going wrong. A failed attack, however, has that [16:55.400 --> 16:59.860] log message that we looked at on the previous slide. Now, there are two ways to prevent this [16:59.860 --> 17:05.180] type of attack. Of course, the best way is to deploy your salt minions with the fingerprint. [17:05.400 --> 17:08.680] And that's part of the configuration. Real simple. There's no reason not to do it. Doesn't [17:08.680 --> 17:13.400] break anything. Doesn't cost you anything extra. You literally just spit out on your legit master [17:13.400 --> 17:17.080] whatever the fingerprint is, go pop it in your minion configure whenever you're setting up [17:17.080 --> 17:21.740] minions, and you will never be vulnerable to this type of attack. Real easy. Option two is you could [17:21.740 --> 17:27.160] automatically set all of your minions to always be accepted on master. This will work and kind [17:27.160 --> 17:31.720] of mitigate after that initial communication. But, of course, if an attacker is already on your [17:31.720 --> 17:34.580] network man-in-the-middle and all the things, option two doesn't really work because we're just [17:34.580 --> 17:39.860] going to keep intercepting stuff. With that said, this is a pretty tight attack vector. It's lower [17:39.860 --> 17:45.320] risk. The conditions to kind of pull this off, you would first need access to the target [17:45.320 --> 17:49.780] environment. That's easy. We can get into any environment, right? Next up would be that we need [17:49.780 --> 17:53.540] to be able to pull off man-in-the-middle attacks in the environment. This could be a little bit [17:53.540 --> 17:59.220] harder if you have fancier network segmentation or other kind of rules to catch you going on, but [17:59.220 --> 18:05.660] still easier than most other types of attacks. The catch is that you would definitely need to [18:05.660 --> 18:09.720] catch your target in the middle of some kind of minion deployment. So hopefully you hacked a [18:10.200 --> 18:13.060] DevOps engineer's calendar and you know when they're doing the next salt deployment or something [18:13.060 --> 18:17.440] like that. That's really niche. Good luck. You could try to pull it off. I don't recommend doing [18:17.440 --> 18:22.080] this if you're on some kind of red team or pentest engagement. It's probably not going to be your [18:22.080 --> 18:27.060] best way in, but if all the cards align, you could potentially get in with this method. And [18:27.060 --> 18:31.060] there's no really notion of them patching this because, like I said, it's not really a [18:31.060 --> 18:35.080] vulnerability. It's about us managing our configurations properly. If you go out and you [18:35.080 --> 18:39.000] establish your fingerprint, you're never going to have a problem with this. So I just kind of [18:39.000 --> 18:42.840] wanted to raise awareness there because this is not the default. There's no fingerprint set. It [18:42.840 --> 18:47.200] can't be because it's not going to know what your custom master is once you've spun it up. Be sure [18:47.200 --> 18:51.980] you go set that fingerprint so you avoid this type of issue. All right, now that we've looked [18:51.980 --> 18:55.660] at attacking SALT a few different ways, let's get into the meat of what I want to bring to the [18:55.660 --> 19:01.680] table today. And that is hacking with SALTstack. So to start off, I want to talk about some C2s. [19:01.680 --> 19:05.340] So hopefully most of us are familiar with a couple of command and control frameworks, [19:05.340 --> 19:11.340] such as Merlin or PowerShell Empire or the Metasploit framework and SALTstack. Yeah, [19:11.340 --> 19:16.240] so if you remember that little architecture slide from the SALT master and minions, we had that [19:16.240 --> 19:20.380] little C2 type communication. We can execute commands from the master and the minions will [19:20.380 --> 19:26.480] post their responses. So I kind of wanted to just pick out two C2s that I felt related to [19:26.480 --> 19:30.200] SALTstack. And I felt Empire and Merlin were probably the best candidates, but I'm a fanboy [19:30.200 --> 19:35.620] of Merlin, so I picked Merlin instead. And the reason being is because the communications work [19:35.620 --> 19:41.680] very similar. Now while Merlin and Empire both operate on like a single port communication, [19:42.260 --> 19:48.520] the idea of the master service posting commands, your agent coming in and connecting, [19:48.520 --> 19:53.020] establishing that command, and then pulling back up to send the response is kind of the same [19:53.020 --> 19:58.340] type of thing. So it's just this pulling agent idea that makes them similar. So let's compare [19:58.340 --> 20:02.820] these two. First looking at Merlin, is it a C2? Yeah, that's what it's built for. It does command [20:02.820 --> 20:09.200] and control, does it pretty well. The traffic for Merlin is disguised to look like HTTPS traffic, [20:09.200 --> 20:13.120] so looks like normal web calls coming out of your environment, helpful for getting around some [20:13.120 --> 20:17.140] firewall rules or maybe just doing some light evasion so you're not instantly being detected [20:17.140 --> 20:21.140] on a network. It's got some really cool post exploitation modules built in now so you can run [20:21.140 --> 20:26.560] things like Mimikatz or whatever have you. And it's got some AV evasion. This isn't because it's [20:26.560 --> 20:31.500] built to evade AV, this is just because Golang's kind of new and it's really hard for most modern [20:31.500 --> 20:35.320] AV to detect Golang. That will definitely change as we progress forward in the future and Golang [20:35.320 --> 20:39.000] becomes even more popular than it is now. But for the time being I've found that on most of [20:39.000 --> 20:43.700] my engagements I can drop a Merlin agent, don't have any problems with any AV. So just throwing [20:43.700 --> 20:48.440] that out there if you haven't used it on engagement. Pretty neat tool. Alright, let's compare [20:48.440 --> 20:54.800] that to SaltStack. Is it a C2? Yeah. Execute commands, get control, do your thing. Kind of [20:54.800 --> 20:59.420] covered that a little bit. What about the communications? Well, everything is encrypted, [20:59.420 --> 21:06.680] you have a complete encrypted channel, but it's not quite HTTPS. It's pretty much clear, or not [21:06.680 --> 21:12.600] clear, but it's straightforward TCP communications to the master. You can do some things to kind of [21:12.600 --> 21:16.140] change up ports that you're listening on and change your configuration to your master to kind [21:16.140 --> 21:21.620] of be more stealthy, and we'll see that a little bit later. But overall it's going to be pretty [21:21.620 --> 21:26.020] clear that the communication is abnormal. It's not looking like any kind of standard thing in [21:26.020 --> 21:32.580] your environment. It's going to be pretty exposed in that regard. But it is encrypted and it is a [21:32.580 --> 21:38.000] secure channel. Post-exploitation modules? Well, I mean they're not baked in, but we call this [21:38.000 --> 21:41.380] desired state. And this is kind of where the cool stuff gets in that we'll look at in a couple [21:41.380 --> 21:50.180] slides. So post-exploitation modules for SaltStack is going to be this idea that we are going to [21:50.180 --> 21:56.340] take the concept of configuration management and build our own configurations that are bad. They [21:56.340 --> 22:00.940] do things that an attacker wants to do rather than what maybe an infrastructure engineer wants to do. [22:01.000 --> 22:05.560] AV evasion? Yeah, these are trusted agents from professional software. Yeah, they're not going to [22:05.560 --> 22:12.260] be picked up by anything. Real easy, guaranteed to go through. So we get some leverage there from [22:12.260 --> 22:20.800] being able to cash in on this trusted software. Alright, so in terms of using this platform as an [22:20.800 --> 22:26.940] adversary, like I mentioned, this desired state configuration concept is going to be kind of the [22:26.940 --> 22:30.120] key here. This is what makes it really cool because, I mean, we've got command and control [22:30.120 --> 22:35.540] for days. What makes this any different? Why is this a neat option to explore? Well, I call this [22:35.540 --> 22:40.800] like post-exploitation modules in advanced mode. It's kind of cheesy, but it's really easy to [22:40.800 --> 22:46.340] automate your persistence. And basically what this means is you can pre-build these states [22:46.340 --> 22:52.340] to say on all these types of systems, Windows, Linux, Mac, whatever have you, do this. So if you [22:52.340 --> 22:57.800] have compromised, you know, I don't know, 10, 20, 100 systems and they're all different operating systems [22:57.800 --> 23:02.340] types, you can have conditionals set in your state and say, okay, I want to do the same type of [23:02.340 --> 23:08.120] persistence across all of these different platforms, have them categorized out beforehand, hit [23:08.120 --> 23:11.920] state apply, it's just going to run through and do all your persistence for you and you're good to go. [23:12.760 --> 23:16.600] And so that's really, just really freaking powerful and I think it's really cool. [23:17.720 --> 23:21.100] You're able to enforce that persistence, so of course desired state, you don't want your system [23:21.100 --> 23:27.040] to deviate from how it looks. So this is your server now. Think of how you as an adversary want [23:27.040 --> 23:30.800] your server to look at all times now that you've compromised it. You want to make sure you're [23:30.800 --> 23:34.380] maintaining the access and being on the box and as long as your agent doesn't get removed, well you [23:34.380 --> 23:38.080] can keep enforcing that additional persistence. As long as that additional persistence is getting [23:38.080 --> 23:42.120] enforced, even if your agent does get removed, you can play your cat and mouse game, get back in with [23:42.120 --> 23:48.300] your other methods. So that's kind of the real power here, is that being able to correct the [23:48.300 --> 23:52.560] server from how it looks to how you want it to be. And you're able to do that from the attacker's [23:52.560 --> 23:57.460] perspective. So it's really just a super cool post-exploitation. It works a little different [23:57.460 --> 24:01.340] than things that are built for post-exploitation because it wasn't made for that, but we can make [24:01.340 --> 24:07.000] it for that. So I kind of want to introduce BadSalt. So that's kind of where this comes into play. [24:07.500 --> 24:11.540] SaltStack is really hard to learn. It can take some time to set up. You actually get pretty [24:11.540 --> 24:16.060] snappy at it once you've done it a couple times. But when I was doing all this research, I got tired [24:16.060 --> 24:21.400] of setting up new boxes and, you know, reinstalling agents and going through the whole rigmarole. So [24:21.400 --> 24:26.280] I automated everything. So that's the BadSalt project. It's not really anything fancy right now. [24:26.280 --> 24:30.300] Don't expect much. It's literally just a couple automation scripts to help you get started and get [24:30.300 --> 24:34.560] things set up. But if this is all brand new to you, this is a good way to get started. Especially [24:34.560 --> 24:40.440] if you're interested in this from an offensive perspective. So the goal here eventually would [24:40.440 --> 24:45.880] be to pre-build out some of these post-exploitation states. And also kind of make some sexier stagers [24:45.880 --> 24:50.540] to easily deploy onto potential targets because right now it's just a bunch of like batch and [24:50.540 --> 24:55.600] batch scripts. Really, truly nothing fancy, but it did help automate a lot of things. [24:56.280 --> 25:01.520] So let's look at using Salt as like a C2 from an adversarial's perspective. So let's see this in [25:01.520 --> 25:06.080] action. So I want to demonstrate a couple things. The first one is going to be, of course, AV evasion [25:06.080 --> 25:10.680] with the trusted minion. So we've got a fresh malware byte. It's all live protection installed, [25:10.680 --> 25:16.000] set up, ready to go. We're going to go... see it's not even detecting anything wrong with the [25:16.000 --> 25:20.820] recode. There's nothing malicious going on here. Obviously you'll see some pretty janky stuff going [25:20.820 --> 25:25.520] on. Pretty clear things that you could see as IOCs. And we'll cover that later once we talk about [25:25.520 --> 25:29.940] detecting this type of stuff. So purely just for automation and proof of concept purposes, [25:30.300 --> 25:34.800] this will take a minute to set up. But what's going on here is it's pulling down from the main [25:34.800 --> 25:41.920] repo.salt.com the installer binary for a Salt agent. And then it's running an install command. [25:41.920 --> 25:45.940] And then the last thing it'll do is pull down my custom bad configuration. And all I've done [25:45.940 --> 25:53.080] really at this point is change 4505 and 4506 to ADM443 to look a little bit more stealthy and [25:53.080 --> 25:59.020] get past some egress filters. So this is going to take a minute to set up. Once it does, though, [25:59.020 --> 26:05.380] we'll switch over to our Salt master and apply one of those bad states that we've set up as an [26:05.380 --> 26:18.720] attacker. Any day now. This is why Windows is my least favorite. Throw that jab out there. [26:22.480 --> 26:26.680] All right. Cool. So we've copied our config over. And now we're going to [26:26.680 --> 26:33.020] go over to our master. We're going to accept the key. And then we're going to see that there [26:33.020 --> 26:37.300] is no backdoored user installed. So we're going to run on that user command. This is like an IE [26:37.300 --> 26:41.980] test box. So these are some of the default users on that IE test box for Vagrant. And now we're [26:41.980 --> 26:45.720] going to run our persistent state. And this is going to be very simple. We'll look at the code [26:45.720 --> 26:49.280] for this on the next slide. But it's going to install this backdoored user. Did it pretty [26:49.280 --> 26:54.200] quickly. And now we have a backdoored user installed on the box called backdoor. Has [26:54.200 --> 26:59.260] administrative privileges and RDP purpose. Pretty quick, pretty effective. What does that actually [26:59.260 --> 27:03.780] look like? We'll start actually with a Linux state. So this is going to look similar. We're [27:03.780 --> 27:06.580] actually going to look at the Windows state as well. But these are what states look like. They're [27:06.580 --> 27:12.380] just YAML configurations. They're real simple, real easy to adapt. And basically just think of [27:12.380 --> 27:16.820] how systems are configured and what you want to do on those systems. And you do it in YAML. And [27:16.820 --> 27:20.980] it's pretty straightforward and easy to read. So here I've named this configuration add backdoor [27:20.980 --> 27:25.760] Nix user. So when I call it later, I'll say, hey, for Linux machines or Unix machines, go do this [27:25.760 --> 27:32.380] thing. And then what it's going to do is it's going to check if a user is present. So user.present, [27:32.380 --> 27:37.740] it's very declarative. You think, is the state of this machine's way? If it's not, go do it. [27:37.740 --> 27:42.660] Rather than saying, go do this to this machine. It's going to check first and validate. So if [27:42.660 --> 27:46.600] it's not present, it's going to add a user with name backdoor. Password's going to be doorback. [27:46.600 --> 27:51.460] It'll hash it. Give us a home directory of slash home slash thread. And then add us to like wheel, [27:51.460 --> 27:57.940] sudoers, root, et cetera. So now we have a root account ready to go. In a much more powerful vein, [27:57.940 --> 28:04.760] you can also do these file managed states. So here we got a sample one for how you might go [28:04.760 --> 28:10.080] deploy an interpreter payload on a particular target. So here we just have our salt repo set [28:10.080 --> 28:15.840] up as salt colon slash slash is actually a local directory on your master system. It'll be in like [28:15.840 --> 28:20.780] slash serve slash salt. And you'll kind of set a directory structure here. I've got one called [28:20.780 --> 28:25.140] payloads, nix, and then I put any of my Linux payloads that I might want to do managed file [28:25.140 --> 28:29.740] stuff with there. In this case, it's an interpreter payload. I'm going to tell it to go, hey, [28:29.740 --> 28:37.380] install this into slash temp. Give it executable, read, write permissions, et cetera. And then go [28:37.380 --> 28:41.240] run it. And then this BG is go run it in the background. So it'll go execute it, run it in [28:41.240 --> 28:45.480] the background, and then I should get an interpreter session that pops over once that happens. [28:45.480 --> 28:52.520] Now, with just these two ideas, you can go crazy. So from just the managed file, being able to run [28:52.520 --> 28:56.240] all your custom binaries from one place, you could get salt stack in there and say, all right, I want [28:56.240 --> 29:00.680] to do some crazy stuff with my custom tool sets that I already have. You can apply it like that [29:00.680 --> 29:06.740] and saw it across as many systems as you have into your salt stack instance and go from there. So [29:06.740 --> 29:11.260] whether it's an interpreter, Merlin, or some crazy custom toolkit you have, that's about how you do [29:11.260 --> 29:17.300] it. Now, for Windows, it's about the same. This is just to show kind of the difference between [29:18.140 --> 29:22.100] the language that you're going to be using in the YAML file, but this is the exact state we just ran [29:22.100 --> 29:27.900] in that demo. So we're checking for user present. If it's not, we add a user back door, pass through [29:27.980 --> 29:33.940] a door back, and add it to the administrators and RDP groups. Really simple, really effective. [29:33.940 --> 29:40.140] That's all it was. That's all we did. The managed file payload or configuration state is the exact [29:40.140 --> 29:44.660] same as Linux one, only we don't have to set any executable permissions because Windows is going to [29:44.660 --> 29:49.460] know it's an exe. And we just copy it to wherever we want, in this case Windows temp, and run it in [29:49.460 --> 29:53.660] the background as well. So these are really, really, really simple and really, really, really [29:53.660 --> 29:57.540] effective. And I hope it kind of gets your brain turning and new ideas of things you could build [29:57.540 --> 30:02.920] really easily with these types of desired state configurations. And what's really great about [30:02.920 --> 30:08.120] these is, like I said, that concept of desired state. You are missing this from the system you [30:08.120 --> 30:12.020] just installed. Your user is not there anymore. Any of the persistence you just set up is gone. [30:12.060 --> 30:16.520] As long as it's still calling home to your salt master, you can even set it up as Java. It'll go [30:16.520 --> 30:20.100] correct itself on its own, but if you're there monitoring it or babysitting it, it's as simple [30:20.100 --> 30:25.540] as a state.apply and it'll go fix itself. So you can do it with automation, you can do it manually, [30:25.540 --> 30:29.300] whatever have you, but you can always correct to fix things as they should be. [30:30.720 --> 30:35.960] Alright, so let's talk about detecting hackers that are abusing salt stack. No red team or [30:35.960 --> 30:40.340] security team is worth their salt without helping our blue teams. We're not doing any good, [30:40.340 --> 30:43.500] we're not helping anyone. This is probably the most important piece. [30:44.960 --> 30:50.520] First and foremost, simple log analysis. Go back to basics. Check the salt minion and master logs, [30:50.520 --> 30:54.580] especially in the context of like a man-in-the-middle attack. Kind of harkening back to [30:54.580 --> 30:59.560] that screenshot from last where we pull out, hey, this might be a man-in-the-middle attack of some [30:59.560 --> 31:03.440] sort. Those logs will just tell on themselves. It's kind of your golden ticket for seeing all [31:03.440 --> 31:08.060] the minion and master communications. It will tell you who, what, when, where, what time, etc. [31:08.220 --> 31:14.160] that minions are talking to a given master, even if it is the wrong master. And so you can kind of [31:14.160 --> 31:19.440] use that in your investigation to see what's going on. Alright, so that's kind of basics. [31:19.440 --> 31:24.180] Another thing we can do is observe the network traffic patterns. While everything is encrypted, [31:24.180 --> 31:28.340] it's actually kind of easy to spot. And of course, pcapture didn't happen. In that repo, [31:28.340 --> 31:31.360] there's all the actual pcaps from the researcher did. You can go look at them yourself if you don't [31:31.360 --> 31:34.620] feel like taking your own packet captures. I'm not going to dive into this. I don't expect [31:34.620 --> 31:39.980] anybody to read it. But one thing I want to point out here is that we've remapped port 4505 to 80 [31:39.980 --> 31:46.200] and port 4506 to 443, kind of like I mentioned a couple slides ago. This is actually what's going [31:46.200 --> 31:51.860] on, though, in that pcap. So the first thing we're doing is accepting a key from a potential [31:51.860 --> 31:56.200] minion that we've actually man-in-the-middle in this case. So we've successfully pulled off a [31:56.200 --> 32:00.100] middle attack. We've got our key accepted. We're going to run a test.ping, which just [32:00.100 --> 32:05.160] says that we can talk to that minion. Then we're going to run a couple commands like whoami, id, [32:05.160 --> 32:09.900] ls, et cetera. And that's just to kind of show what's going on here. But what's actually [32:09.900 --> 32:14.440] happening in terms of communication patterns is what's important from a Blue Teamers perspective [32:14.440 --> 32:20.160] to detect. So when a minion calls home, in this case on port 80, it's going to check in on port [32:20.160 --> 32:24.600] 81st. And the master's not going to publish anything because they're not associated yet. [32:24.880 --> 32:28.880] And then it's going to go up and say, hey, on port 443, do you want to trust me? [32:28.880 --> 32:33.740] If you accept, the master's in. Now it'll send you its public key and you're good to go to keep [32:33.740 --> 32:40.780] your communications running. Here, we can execute commands. So maybe on the salt master, we'll run [32:40.780 --> 32:47.580] whoami. And then the master will publish that on port 80 in this case to say, hey, go run whoami. [32:47.580 --> 32:52.500] When the minion checks in on port 80, it'll go fetch that, run it, and then come back up to 443 [32:52.500 --> 32:56.700] and say, hey, I was rude. And kind of the pattern here that I want everybody to notice is that [32:56.700 --> 33:03.020] you'll have a connection to port 80 or port 4505 followed by one or more connections to port 443 [33:03.020 --> 33:07.640] to the exact same host. That's a pretty clear pattern that we can see carved out there. And [33:07.640 --> 33:12.600] it's even easier if they are using the default ports for 4505 and 4506 because it might give [33:12.600 --> 33:16.920] away that it's salt stack right away. But that's a pattern that you could use. So tandem with those [33:16.920 --> 33:23.060] log analysis and kind of your packet captures, you can kind of correlate these two events and [33:23.060 --> 33:27.060] say, hey, maybe this is some kind of attacker abusing salt stack as a command and control [33:27.060 --> 33:34.480] service. Another way to kind of detect this type of activity is the fact that salt master and minion [33:34.480 --> 33:40.140] installations are very, very noisy. Now, obviously, an attacker could change all of the configurations [33:40.140 --> 33:44.840] and move things to different directories or whatever. It's an open source project. So [33:44.840 --> 33:50.140] there's a lot of power they have. But by default, it is extremely noisy. So if any of these [33:50.140 --> 33:55.800] directories exist on your system, whether it's bar log salt, at C salt, serve salt, if you [33:55.800 --> 34:00.500] have a master on your system for whatever reason possible, or C colon back slash salt for [34:00.500 --> 34:04.560] Windows, if any of those things exist, it's a pretty clear sign that somebody might have [34:04.560 --> 34:10.140] installed salt stack in some shape or form on that box. Another thing to do is check your [34:10.140 --> 34:14.600] repo files or your network communications to repo.saltstack.com. Because if they're pulling [34:14.600 --> 34:19.680] from the default not compiling their own binaries, it's going to be a clear communication just [34:19.680 --> 34:23.040] like with that batch file. So if somebody just wants to go be a script kitty and pull [34:23.040 --> 34:26.880] down that GitHub project and go use it on a potential target, it's going to be real [34:26.880 --> 34:31.600] easy to pinpoint that that's happening. Like I said, it is an open source project. There's [34:31.600 --> 34:35.000] always ways to modify and change this. Those are things that I'm going to be looking into [34:35.000 --> 34:38.880] more in the future. But for the most part, it's pretty clear when somebody installs a [34:39.320 --> 34:43.520] minion, these logs and these existence of these directories is a clear indication that [34:43.520 --> 34:48.600] that's happened. A crucial thing, though, to take a look at is if you are legitimately [34:48.600 --> 34:53.300] using SaltStack in your environment, an attacker could still install a duplicate minion on [34:53.420 --> 34:57.920] a particular target they've compromised. So you'll be able to identify multiple minions [34:57.920 --> 35:02.540] in that case, because you should only really ever have one minion running on a box. It's [35:02.540 --> 35:06.100] supported to have more than one, which is why this is possible. But in a legitimate [35:06.100 --> 35:10.080] configuration, that's not recommended. So hopefully you're not doing that. If you are, [35:10.080 --> 35:17.840] here's how you might be able to detect a bad one. So when an attacker goes to install a [35:17.840 --> 35:23.380] second minion on a box, they're going to either A, bring their own minion binary, or B, use [35:23.380 --> 35:27.680] the one that you already have installed and then just point it at their bad configurations. [35:28.260 --> 35:34.880] So what you're going to want to look for in these cases are the potential usage of the [35:34.880 --> 35:39.940] same log file. So if two minions are installed and they haven't reconfigured their minion [35:39.940 --> 35:44.180] to point to a different log file, you're going to see really weird activity going on in that [35:44.180 --> 35:48.380] log from two different minions going on in the box. So you can check that out. [35:48.580 --> 35:52.580] Another thing would be your system dlogs. You can look for activity that's going on [35:52.580 --> 35:56.560] on one minion that might be similar to activity going on on the other minion, [35:56.560 --> 36:00.520] but one's not named like a minion. It's just a behavior type thing. So you notice [36:00.520 --> 36:06.360] that two services are behaving the same. One is a legitimate minion. One's like weird XYZ [36:06.360 --> 36:10.800] daemon or something. So that's stuff you may want to look for. And then of course, [36:10.800 --> 36:14.040] kind of dead giveaway that I think is going to be your network traffic. It's got to [36:14.040 --> 36:18.940] communicate back home. So if it's not talking to your master, it's probably not your minion. [36:18.940 --> 36:22.640] And so you can go trace that back to whatever your process is. So that's pretty important if [36:22.640 --> 36:25.300] you are using SaltStack in your environment because all the other ways are a little bit [36:25.300 --> 36:28.200] easier to detect. These are the things you're going to want to look for if you already have [36:28.200 --> 36:34.440] minions installed. So that's kind of all the things I wanted to cover today. To wrap this up, [36:34.440 --> 36:39.040] I wanted to say, hey, go check out Salt if you're looking for a potential tool for your [36:39.040 --> 36:43.140] configuration management or any of the tools really. I'd just favor this. It's great for [36:43.140 --> 36:47.920] operations, great for blue teams, and seems pretty fun to use as a red team tool potentially [36:47.920 --> 36:52.740] as well. A couple of appreciation shout outs. First and foremost, Seth. The only reason I even [36:52.740 --> 36:58.440] chased down this research, he was one of our DevOps on the team at the time. Really educated [36:58.440 --> 37:03.140] me a lot on the platform and I kind of took this home and ran with it from there. Chris and Robert, [37:03.140 --> 37:07.980] always being real supportive. Daniel Robertson, Dan Borges, both of these two have been great [37:08.500 --> 37:12.900] influencers, mentors, whether they realize it or not. And then Camilla, also a great supporter [37:12.900 --> 37:17.740] of my life. A couple of references. Like I said, these slides will be available on that GitHub [37:17.740 --> 37:23.320] repo. I want to point out Seth's brain again. That guy's really smart. And with that, we have [37:23.320 --> 37:58.500] questions. Can you repeat that? I'm sorry, I didn't hear you. Yeah, so the question was, [37:58.500 --> 38:04.540] is it better to, or not is it better, was the second option for mitigating the issue to [38:04.540 --> 38:08.620] automatically accept minions to the master. And yes, that was the second recommendation. [38:14.050 --> 38:18.810] Yeah, and that's absolutely true, which is why is okay, but definitely not the best idea. The [38:18.810 --> 38:22.070] best solution is just to install the fingerprint where it should be in your configuration. That's [38:22.070 --> 38:33.790] absolutely true. What's up? You spoke briefly of desired state. I know that after like a [38:33.790 --> 38:38.670] pentesting engagement, we want to get everything back to normal. Can we use desired states to get [38:38.670 --> 38:45.470] back to that normal? Yeah, so you'd have to know and coordinate with your red teams or your pentest [38:45.470 --> 38:49.130] teams to know exactly what they installed and anything like that as well. But if you potentially [38:49.130 --> 38:55.510] wanted to use that as a way to clean up after known good engagements, rather than having to [38:55.510 --> 38:58.790] go back and maintain up, that is absolutely an option. So you can build your states around what [38:58.790 --> 39:02.550] you know that you've done and work with those offensive security people to execute on those [39:02.550 --> 39:24.940] states. So that's definitely an option to help make cleanup quicker. Yeah, so I don't know exactly [39:24.940 --> 39:29.960] where I'll dive down in terms of that, but I do definitely want to explore other new tools or [39:29.960 --> 39:33.880] existing tools to see if there's anything better than doing things with SaltStack as we've done it, [39:33.880 --> 39:37.760] because it's definitely possible. Like I said, any of these do all do about the same thing. So [39:37.760 --> 39:41.220] you can accomplish anything that we've shown in SaltStack today with another one of those tools [39:41.220 --> 39:45.820] like Puppet Chef or Ansible. It's the idea of just using these tools from the perspective of [39:45.820 --> 39:59.440] the adversary. All right, cool. Well, I'll be around if you want to ask me any other questions, [39:59.440 --> 40:00.560] but thank you all for coming.