start	end	text
0	4160	All right, let's get moving. Hope you guys have had an awesome DEF CON so far.
4180	7320	Let's dive right in. So this is Bad Salt Adversarial DevOps.
7760	12020	I'm going to start with a quick introduction, some background about myself. My name is Casey
12020	17140	Erdman. You may know me by my handle Ngame on Twitter or other aspects of the interwebs.
17280	20820	I'm a giant offensive security nerd, that's why I'm here in the Red Team Village.
21280	25680	I am the co-founder of DC706, which is a Columbus, Georgia DEF CON group,
25680	27820	so if you're ever in the area, feel free to roll through.
28400	31560	These are some of my professional certifications, if you care about that type of thing.
31560	35120	In my day-to-day, though, I am a manager of an information security department.
35200	39400	We are a very small team, so I touch pretty much everything. We're in the kind of financial space,
39400	44340	so lots of offensive security stuff, pin testing, that type of thing, incident response,
44340	48420	good old PCI compliance, stuff like that. But I think the most interesting thing you should
48420	52080	all know about me is that I'm a programmer gone rogue. Most of my background is in software
52080	57900	development, and I just kind of got into CTFs and started hacking, and I decided,
57900	61620	no more software development, let's do the offensive security stuff. That's a lot more fun.
61620	64400	So that's where a lot of my passion is, and that's just a little bit about me.
65020	69320	This is probably the most important slide today. If you don't take a picture of anything else,
69320	72540	I'm going to give everybody a second to take a picture of this. All of the code,
72540	77100	the slides for this talk, any of the PCAPs or stuff like that are at this GitHub repo,
77100	89880	and we'll be there. So I'll give you guys a minute. All right. Perfect. So let's move along.
90120	94940	Here's our agenda for today. First, we're going to hit some of the high points, introduce anybody
94940	100440	to the concepts of configuration management, how we landed on SaltStack, why this technology is
100440	104880	even the focal point of this talk today. Then we're going to talk about some attacks against
104880	109400	that platform. And then the meat of the talk is actually going to be hacking with that platform.
109400	113900	When we're talking about adversarial DevOps, we're talking about using these new fancy tools
113900	118520	that are in our industry as an offensive person. How can I take advantage of these? And that's
118520	121920	really where we're going to dive in and look at a couple of those things. And then, of course,
121920	126460	we're going to also give our blue teamers the chance to stop anything that they see like this,
126460	133180	and we'll cover those investigation techniques at the end. All right. So what is SaltStack?
133840	137500	So to talk about SaltStack, first we need to talk about configuration management.
137500	142500	So configuration management isn't really new. We've got configurations we've been managing for
142620	147780	a long time in the industry. But there's kind of new technologies that help us facilitate this idea.
147780	152360	And the goal here is to establish some baseline and some integrity across our systems to make
152360	158680	sure they look and act how they should and don't have any variants here. Some common new tools for
158680	164100	configuration management you may have heard of are things like Puppet, Chef, Ansible, and SaltStack.
164100	168260	So we're going to take a high-level look at some of these tools. All of these tools can
168260	172180	essentially accomplish the same goal. So I'm not saying any one tool is better than the other. I'm
172180	176100	not sponsored by any of these companies. I just want to kind of give a narrative of how I landed
176100	181760	on what I landed on. So starting with Puppet, Puppet's kind of one of the industry-leading
181760	186660	tools in this space here. They've been around for a while. It integrates really well with
186660	191820	other products because its baseline purpose is the concept of configuration management. So
192760	197700	when these tools first started coming out, you may have heard things like maybe Puppet and Chef.
197700	201860	And it's this bundle of tools where Puppet would be the foundation and help you do the
201860	206420	configuration management where something like Chef or Ansible would go then execute on those
206420	211000	configurations. So that's kind of where things kind of got started. It's got a little bit of
211000	217080	maturity, good foundation, but there's also other tools out there that have matured a lot more. And
217080	221800	so Puppet and Chef can kind of just be replaced by Chef nowadays. Chef has come a long way.
221800	226000	But at first, it was more focused on infrastructure as code and not really
226000	230280	configuration management. However, inherently, when you're talking about infrastructure as code,
230280	236540	you're defining how your machines look in some kind of code syntax or configuration. So naturally,
236540	243200	Chef kind of became its own configuration management utility. And the focus here is,
243200	246700	of course, that continuous automation. You can continue upgrading, changing your configurations
246700	252680	in your systems, and also manage those configurations. Chef also provides a couple
252680	256720	neat other tools like Inspect or Habitat. I don't know a whole lot about these tools. I know
256720	260780	Inspect is supposed to be some kind of cool code audit tool of some sort. But the point is,
260780	264300	it's matured a lot more now and there's a lot of feature sets. It could be a good option when
264300	268160	you're looking to explore the concept of configuration management for your infrastructure.
269360	273880	Now, Ansible is a little bit different from these other tools. So Ansible is more about
273880	278340	the infrastructure automation, not so much the configuration management. While, again,
278340	282700	you can do pretty much everything with all of these tools, Ansible I like to think of as like
282700	287060	mass SSHing or something like that. You're able to go and execute on hundreds and hundreds of
287060	292040	systems at one time to apply whatever state or configuration that you're trying to apply.
292760	297320	And so I like to equate maybe Puppet and Ansible as something a little bit closer to what Salt
297320	303340	Stack is. But again, it's less about configuration management and just more about the execution of
303340	310360	the automation of whatever your configurations are. All right, so we got all these great tools.
310360	316300	Why did it land on Salt Stack? So from a professional standpoint, when myself and the
316300	322280	other members of the DevOps team are coordinating and looking at different ways to do configuration
322280	325860	management on our infrastructure, we found that Salt Stack scales a little bit easier. And the
325860	331260	reason is because it's agent-based. So a lot of these other tools may require you to have access
331260	337180	or credentials or go open up some firewall rules or network communications. There seems to be a lot
337180	343360	more setup. Things are changing very rapidly with a lot of these tools. So what's true today, of
343360	348660	course, may not be true later. But at the time of selection for a tool, Salt Stack really scaled well.
349660	354200	And of course, it does everything all the other tools do. And it just does it all in one. You
354200	359580	don't need an Ansible and a Puppet. You could just use Salt Stack and get all the same capabilities
359580	364280	out. Doesn't make it better, doesn't make it worse. You just have those options available to you.
365240	369800	And Salt Stack's primary purpose is for configuration management. That's kind of what
369800	375460	it's built around. It's built around the concept of desired state. So desired state is this idea that
375460	380720	your machine is going to match your configuration all the time, no matter what. And if at any point
380720	385460	it's not matching that desired state, it's going to correct itself and make sure it maintains that
385460	390240	integrity. And that's kind of what Salt Stack's built around. And because of kind of the agent-based
390240	395600	nature, it integrates with kind of some older or more standardized systems a little bit easier.
395700	401760	We're able to deploy this in anywhere from like cloud environments like AWS or Google Cloud or
401760	406220	traditional data centers or co-locations. It's really easy. You just kind of set up a master and
406220	410500	look at the architecture in a couple slides. You set up the salt master, you deploy minions, you
410500	414620	set the egress out where you want, and you're good to go start configuring hundreds and hundreds of
414620	421640	systems in Salt Stack. So that's kind of how we landed on this from the standpoint, and I kind of
421640	426460	took it and ran with it for the majority of the talk. But just how we got there. This is Salt Stack
426460	429740	architecture. I'm not going to dive into this. I don't expect anybody to actually read it. It's
429740	436640	really complex though. That's kind of why I wanted to show this slide. So the kind of key points
436640	440960	here that we're going to look at is this idea of the master and then these little beacons or
440960	445400	minions as they're actually called. So there's a lot of functionality in Salt Stack. Please read
445400	449740	more of the documentation. It's really cool. But this is the simplified version that's a lot easier
449740	455820	to understand. So salt minions and salt masters. That's kind of what we're primarily focused on
455820	462760	here. So the salt master is going to be listening on two ports, 45.05 and 45.06. 45.05 is the
462760	466720	publisher port. This is where the master is going to issue a command, say, hey go run who am I or
466720	472540	whatever. And then 45.06 is where the minion is going to pull up and publish its results. So the
472540	478120	minion is going to go up to port 45.05, grab that command, execute it, and then return up to 45.06
478120	483920	with whatever its output is. Now this request server also handles file management. So one of
483920	488080	the cool things we'll do that we'll kind of look at a little bit later is manage files. So if you
488080	492780	want to copy other configurations for other components or install applications from a custom
492780	498720	repo, whatever have you, you can copy those. And that port is where the salt minion will go
498720	504760	fetch or send commands, either one, to that request server. Now of course we have this execution of
504760	509260	commands and the sending of response. Sounds kind of like a C2 server. So keep that in the back of
509260	515900	your brain as we go forward. All right, kind of wrap up this section. Configuration management. Why is
515900	521120	it cool? What are we using this for? Well, you can enforce hardening standards with it. You can
521120	526400	enforce those nasty compliance standards with it. Create uniformity across all your environments.
526480	531040	And then ultimately the coolest thing that works both on the offensive side and the defensive side
531040	535480	is making sure stuff is installed that should be and making sure that stuff that isn't installed
535480	540340	shouldn't be. So you're really able to enforce that and help lock that down with this concept
540340	545060	of desired state where the system will go and see what it should look like. If it doesn't match,
545060	550320	it'll go try to correct itself. All right, so hopefully everybody's got a good overview of the
550320	555540	concepts of configuration management, desired state, what all these tools are for. Let's hack
555540	562080	SaltStack. All right, so quick history lesson. SaltStack was released back in March 2011. This
562080	567660	was a very stable or very not stable, very early version. The first stable release came out a
567660	573980	couple months later in November 2011. And we're now on version 2019.2, which was like in February.
573980	577580	And this is true as of the time of typing of the slide. There may have been a new release like this
577580	582720	week. I don't know. But the point here that I'm trying to illustrate is this is back in 2011.
582720	588000	We're in, what, 2019 now. About eight years. That doesn't sound like long ago because it's 2011,
588000	592860	but it was eight years ago. Old things have bugs. SaltStack is now kind of an old thing. It's kind
592860	598220	of weird to think about. But to illustrate that old things have bugs, here's a list of kind of
598220	604640	recent CVEs for SaltStack. Just to kind of go over and glance real quick, this list is longer than
604640	611800	here. This is just a snap of part of the MVD. But we got some code execution. We got some directory
611800	618680	traversal. Some information type of issues. The goal of this research wasn't any kind of
618680	622680	vulnerability research specifically. So I encourage you to go dive down these your own. Just to show
622680	627120	that SaltStack has had some problems. And what I did from there is kind of see if there's any
627120	633160	proof of concepts out there. See if based on what is known, what type of attack vector should I be
633160	638100	challenging myself to go look for in a current version of SaltStack. And the first thing I kind
638100	643440	of stumbled upon was this evil minions project. Now, this isn't really a proof of concept to
643440	648420	exploit any kind of vulnerability. It's actually just a load generator. It was made for purposes
648420	654480	of going and testing how many minions or processes a particular minion service could handle. So it
654480	659120	just spawned a whole bunch of minions and test the load. So nothing really crazy in terms of
659120	664120	exploiting vulnerabilities, but might be cool for some denial of service attack or whatever have you.
664120	668720	That was just the first thing I stumbled on with some simple Googling and looking at search terms.
669520	674380	I dug a little bit deeper, though, and I found Chicken Salt. So Chicken Salt is this neat little
674380	682640	POC for abusing the communication between minions and masters when they do this handshake for
683220	688640	key public key authentication. So this allows for man in the middle attack, which ultimately allows
688640	693360	you to take over minions. Now, this is important because while you may think, oh, well, if I can
693360	697620	get access to the master, well, then I can control everything on the network, right? Well, what if
697620	702560	you could just stand up your own master? You don't need access to that master. And then you get
702560	706400	everybody to talk to you, and now you can control all of the minions it controls. That's what this
706400	712400	kind of attack allows you to do. And what happens here is you'll sniff the handshake upon initial
712400	717240	communication between a minion and a master. You would be able to grab the public key and the
717240	722100	verification token for that particular communication. Then you can man in the middle,
722100	726720	serve up that public key and token you acquired, and bam, you can pwn all the minions. Couldn't
726720	730660	really find a CVE for this one, though. It didn't match any of the things that I had already found
730660	737920	when doing initial research. It looks like it was probably patched in version 0.17.1. It might be
737920	742520	related to that CVE that's on the slide there. That has to do with Salt not validating SHHOS
742520	746620	key request, which also resulted in a man in the middle attack vector. It's just really hard to
746620	752860	tell. All I know is it doesn't work now because I tried. However, when I tried, I found a new
752860	758400	attack vector. So I kind of want to talk about modern man-in-the-middle attacks against Salt
758400	763260	Stack. Now, this isn't any kind of crazy OODA. We're not doing anything super sophisticated.
763260	767700	This is a really easy attack, and it's really not a high risk. It's actually just by design,
767700	773140	how Salt works. And what I'm trying to communicate here is just awareness for good configuration
773140	778780	standards of your Salt environment, because it's really easy to mitigate this type of issue,
778780	783020	but by default, it is not mitigated. And that's just by design. It's not a vulnerability. It's
783020	788060	not any kind of issue, but it is a potential risk that you need to be aware of, especially if you
788060	794160	have Salt in your environments. So the issue is caused by the need to distribute keys. Once you
794160	798520	install an agent on a box, it's got to go talk to the master, and it's got to do this kind of
798520	804900	exception thing. So we'll look at that on the next slide. So here's how the key exchange works.
804900	809940	So you have a Salt minion and your Salt master, like we've seen. The Salt minion is going to
809940	814080	communicate initially with the Salt master and say, hey, here's my public key. Do you want to
814080	819280	accept it? If you choose to accept it on the Salt master side, it'll add that minion into
819820	823640	your queue, and now you can execute commands and facilitate communications with the minion.
824940	829720	So the problem here is that the Salt minions will trust a master on initial communication no
829720	834300	matter what. This is any master at any point in time. The solution to this problem, which is
834300	840420	built into Salt already, is to give Salt minions a fingerprint for the good known master. So
840420	844680	everything's good, right? We give them the fingerprint, and we're good to go. Well, how do
844680	850200	you give the minion the fingerprint? Fingerprints have to be issued on initial deployment. If you
850200	854440	don't issue them on initial deployment, they won't be set, therefore making you potentially
854440	858800	vulnerable to this type of attack factor. Now, it's really easy to fix this issue, as we'll see,
858800	864540	but here's the kind of capabilities and control that you have. So let's hop into this demo real
864540	870400	quick. So here we've set up BetterCap with a man in the middle listening on our two Salt ports
870400	879020	for our fake master. And then here is our Salt minion. So the Salt minion is going to just show
879020	884800	you what our configurations are. That's pointing to this 128.13 master. There's no master
884800	889680	fingerprint set by default. This is fresh install. And it's started the service. So now it should
889680	894180	call home. This is going to show this is the legitimate master. It's going to be dot 13.
895460	900660	And we'll list our keys here. And there's no unaccepted keys, even though there should be.
900660	904980	We should be getting a callback from that minion, right? Well, if you go back over to our evil
904980	909460	master and see we've got some communications from our interception from man in the middle.
909980	912720	And run this. We're going to show that we're not the same IP.
915520	918560	And now we're going to see what unaccepted keys are in our bad master's queue.
918960	922580	Oh, it looks like we've got one. So we're going to accept that key.
924040	926900	And now we've successfully manned in the middle of that minion and we're ready to
928540	932000	execute commands on this host. So that's kind of how the attack plays out.
932000	938400	Real simple. Not anything complex to it. But it is very much an attack vector and it is
939220	944980	caused by this default configuration. The good news here is this only works on initial
944980	951040	communication. Like I said, it's fairly low risk. What happens is on that initial communication,
951040	961960	once a master accepts the minion communication, it's going to cache that fingerprint that we
961960	967580	there. But it is not in the configuration. Which means if at any point that cache gets cleared out
967580	972620	for any reason by whether it's manual deletion or some debugging or reinstallation of a minion,
972620	977600	whatever have you, it could potentially go away. However, if you have minions already in your
977600	981360	environment, they've already communicated with your legitimate master, what will actually happen
981360	985180	if I try to do that man in the middle attack is there's a conditional set. So the people who make
985180	991720	salt stack are already aware of this particular issue. And this nice helpful log message that
991720	997360	you might be getting man in the middle attack will dump into the salt minion logs. So it kind
997360	1001200	of fixes itself if you've already had that initial communication. But if you haven't,
1001200	1006140	then you're open to this potential vulnerability. Now, detecting this type of attack is fairly
1006140	1010700	simple. In the first image we have here, a successful attack basically looks like nothing.
1010700	1015400	It's completely normal. You don't see anything going wrong. A failed attack, however, has that
1015400	1019860	log message that we looked at on the previous slide. Now, there are two ways to prevent this
1019860	1025180	type of attack. Of course, the best way is to deploy your salt minions with the fingerprint.
1025400	1028680	And that's part of the configuration. Real simple. There's no reason not to do it. Doesn't
1028680	1033400	break anything. Doesn't cost you anything extra. You literally just spit out on your legit master
1033400	1037080	whatever the fingerprint is, go pop it in your minion configure whenever you're setting up
1037080	1041740	minions, and you will never be vulnerable to this type of attack. Real easy. Option two is you could
1041740	1047160	automatically set all of your minions to always be accepted on master. This will work and kind
1047160	1051720	of mitigate after that initial communication. But, of course, if an attacker is already on your
1051720	1054580	network man-in-the-middle and all the things, option two doesn't really work because we're just
1054580	1059860	going to keep intercepting stuff. With that said, this is a pretty tight attack vector. It's lower
1059860	1065320	risk. The conditions to kind of pull this off, you would first need access to the target
1065320	1069780	environment. That's easy. We can get into any environment, right? Next up would be that we need
1069780	1073540	to be able to pull off man-in-the-middle attacks in the environment. This could be a little bit
1073540	1079220	harder if you have fancier network segmentation or other kind of rules to catch you going on, but
1079220	1085660	still easier than most other types of attacks. The catch is that you would definitely need to
1085660	1089720	catch your target in the middle of some kind of minion deployment. So hopefully you hacked a
1090200	1093060	DevOps engineer's calendar and you know when they're doing the next salt deployment or something
1093060	1097440	like that. That's really niche. Good luck. You could try to pull it off. I don't recommend doing
1097440	1102080	this if you're on some kind of red team or pentest engagement. It's probably not going to be your
1102080	1107060	best way in, but if all the cards align, you could potentially get in with this method. And
1107060	1111060	there's no really notion of them patching this because, like I said, it's not really a
1111060	1115080	vulnerability. It's about us managing our configurations properly. If you go out and you
1115080	1119000	establish your fingerprint, you're never going to have a problem with this. So I just kind of
1119000	1122840	wanted to raise awareness there because this is not the default. There's no fingerprint set. It
1122840	1127200	can't be because it's not going to know what your custom master is once you've spun it up. Be sure
1127200	1131980	you go set that fingerprint so you avoid this type of issue. All right, now that we've looked
1131980	1135660	at attacking SALT a few different ways, let's get into the meat of what I want to bring to the
1135660	1141680	table today. And that is hacking with SALTstack. So to start off, I want to talk about some C2s.
1141680	1145340	So hopefully most of us are familiar with a couple of command and control frameworks,
1145340	1151340	such as Merlin or PowerShell Empire or the Metasploit framework and SALTstack. Yeah,
1151340	1156240	so if you remember that little architecture slide from the SALT master and minions, we had that
1156240	1160380	little C2 type communication. We can execute commands from the master and the minions will
1160380	1166480	post their responses. So I kind of wanted to just pick out two C2s that I felt related to
1166480	1170200	SALTstack. And I felt Empire and Merlin were probably the best candidates, but I'm a fanboy
1170200	1175620	of Merlin, so I picked Merlin instead. And the reason being is because the communications work
1175620	1181680	very similar. Now while Merlin and Empire both operate on like a single port communication,
1182260	1188520	the idea of the master service posting commands, your agent coming in and connecting,
1188520	1193020	establishing that command, and then pulling back up to send the response is kind of the same
1193020	1198340	type of thing. So it's just this pulling agent idea that makes them similar. So let's compare
1198340	1202820	these two. First looking at Merlin, is it a C2? Yeah, that's what it's built for. It does command
1202820	1209200	and control, does it pretty well. The traffic for Merlin is disguised to look like HTTPS traffic,
1209200	1213120	so looks like normal web calls coming out of your environment, helpful for getting around some
1213120	1217140	firewall rules or maybe just doing some light evasion so you're not instantly being detected
1217140	1221140	on a network. It's got some really cool post exploitation modules built in now so you can run
1221140	1226560	things like Mimikatz or whatever have you. And it's got some AV evasion. This isn't because it's
1226560	1231500	built to evade AV, this is just because Golang's kind of new and it's really hard for most modern
1231500	1235320	AV to detect Golang. That will definitely change as we progress forward in the future and Golang
1235320	1239000	becomes even more popular than it is now. But for the time being I've found that on most of
1239000	1243700	my engagements I can drop a Merlin agent, don't have any problems with any AV. So just throwing
1243700	1248440	that out there if you haven't used it on engagement. Pretty neat tool. Alright, let's compare
1248440	1254800	that to SaltStack. Is it a C2? Yeah. Execute commands, get control, do your thing. Kind of
1254800	1259420	covered that a little bit. What about the communications? Well, everything is encrypted,
1259420	1266680	you have a complete encrypted channel, but it's not quite HTTPS. It's pretty much clear, or not
1266680	1272600	clear, but it's straightforward TCP communications to the master. You can do some things to kind of
1272600	1276140	change up ports that you're listening on and change your configuration to your master to kind
1276140	1281620	of be more stealthy, and we'll see that a little bit later. But overall it's going to be pretty
1281620	1286020	clear that the communication is abnormal. It's not looking like any kind of standard thing in
1286020	1292580	your environment. It's going to be pretty exposed in that regard. But it is encrypted and it is a
1292580	1298000	secure channel. Post-exploitation modules? Well, I mean they're not baked in, but we call this
1298000	1301380	desired state. And this is kind of where the cool stuff gets in that we'll look at in a couple
1301380	1310180	slides. So post-exploitation modules for SaltStack is going to be this idea that we are going to
1310180	1316340	take the concept of configuration management and build our own configurations that are bad. They
1316340	1320940	do things that an attacker wants to do rather than what maybe an infrastructure engineer wants to do.
1321000	1325560	AV evasion? Yeah, these are trusted agents from professional software. Yeah, they're not going to
1325560	1332260	be picked up by anything. Real easy, guaranteed to go through. So we get some leverage there from
1332260	1340800	being able to cash in on this trusted software. Alright, so in terms of using this platform as an
1340800	1346940	adversary, like I mentioned, this desired state configuration concept is going to be kind of the
1346940	1350120	key here. This is what makes it really cool because, I mean, we've got command and control
1350120	1355540	for days. What makes this any different? Why is this a neat option to explore? Well, I call this
1355540	1360800	like post-exploitation modules in advanced mode. It's kind of cheesy, but it's really easy to
1360800	1366340	automate your persistence. And basically what this means is you can pre-build these states
1366340	1372340	to say on all these types of systems, Windows, Linux, Mac, whatever have you, do this. So if you
1372340	1377800	have compromised, you know, I don't know, 10, 20, 100 systems and they're all different operating systems
1377800	1382340	types, you can have conditionals set in your state and say, okay, I want to do the same type of
1382340	1388120	persistence across all of these different platforms, have them categorized out beforehand, hit
1388120	1391920	state apply, it's just going to run through and do all your persistence for you and you're good to go.
1392760	1396600	And so that's really, just really freaking powerful and I think it's really cool.
1397720	1401100	You're able to enforce that persistence, so of course desired state, you don't want your system
1401100	1407040	to deviate from how it looks. So this is your server now. Think of how you as an adversary want
1407040	1410800	your server to look at all times now that you've compromised it. You want to make sure you're
1410800	1414380	maintaining the access and being on the box and as long as your agent doesn't get removed, well you
1414380	1418080	can keep enforcing that additional persistence. As long as that additional persistence is getting
1418080	1422120	enforced, even if your agent does get removed, you can play your cat and mouse game, get back in with
1422120	1428300	your other methods. So that's kind of the real power here, is that being able to correct the
1428300	1432560	server from how it looks to how you want it to be. And you're able to do that from the attacker's
1432560	1437460	perspective. So it's really just a super cool post-exploitation. It works a little different
1437460	1441340	than things that are built for post-exploitation because it wasn't made for that, but we can make
1441340	1447000	it for that. So I kind of want to introduce BadSalt. So that's kind of where this comes into play.
1447500	1451540	SaltStack is really hard to learn. It can take some time to set up. You actually get pretty
1451540	1456060	snappy at it once you've done it a couple times. But when I was doing all this research, I got tired
1456060	1461400	of setting up new boxes and, you know, reinstalling agents and going through the whole rigmarole. So
1461400	1466280	I automated everything. So that's the BadSalt project. It's not really anything fancy right now.
1466280	1470300	Don't expect much. It's literally just a couple automation scripts to help you get started and get
1470300	1474560	things set up. But if this is all brand new to you, this is a good way to get started. Especially
1474560	1480440	if you're interested in this from an offensive perspective. So the goal here eventually would
1480440	1485880	be to pre-build out some of these post-exploitation states. And also kind of make some sexier stagers
1485880	1490540	to easily deploy onto potential targets because right now it's just a bunch of like batch and
1490540	1495600	batch scripts. Really, truly nothing fancy, but it did help automate a lot of things.
1496280	1501520	So let's look at using Salt as like a C2 from an adversarial's perspective. So let's see this in
1501520	1506080	action. So I want to demonstrate a couple things. The first one is going to be, of course, AV evasion
1506080	1510680	with the trusted minion. So we've got a fresh malware byte. It's all live protection installed,
1510680	1516000	set up, ready to go. We're going to go... see it's not even detecting anything wrong with the
1516000	1520820	recode. There's nothing malicious going on here. Obviously you'll see some pretty janky stuff going
1520820	1525520	on. Pretty clear things that you could see as IOCs. And we'll cover that later once we talk about
1525520	1529940	detecting this type of stuff. So purely just for automation and proof of concept purposes,
1530300	1534800	this will take a minute to set up. But what's going on here is it's pulling down from the main
1534800	1541920	repo.salt.com the installer binary for a Salt agent. And then it's running an install command.
1541920	1545940	And then the last thing it'll do is pull down my custom bad configuration. And all I've done
1545940	1553080	really at this point is change 4505 and 4506 to ADM443 to look a little bit more stealthy and
1553080	1559020	get past some egress filters. So this is going to take a minute to set up. Once it does, though,
1559020	1565380	we'll switch over to our Salt master and apply one of those bad states that we've set up as an
1565380	1578720	attacker. Any day now. This is why Windows is my least favorite. Throw that jab out there.
1582480	1586680	All right. Cool. So we've copied our config over. And now we're going to
1586680	1593020	go over to our master. We're going to accept the key. And then we're going to see that there
1593020	1597300	is no backdoored user installed. So we're going to run on that user command. This is like an IE
1597300	1601980	test box. So these are some of the default users on that IE test box for Vagrant. And now we're
1601980	1605720	going to run our persistent state. And this is going to be very simple. We'll look at the code
1605720	1609280	for this on the next slide. But it's going to install this backdoored user. Did it pretty
1609280	1614200	quickly. And now we have a backdoored user installed on the box called backdoor. Has
1614200	1619260	administrative privileges and RDP purpose. Pretty quick, pretty effective. What does that actually
1619260	1623780	look like? We'll start actually with a Linux state. So this is going to look similar. We're
1623780	1626580	actually going to look at the Windows state as well. But these are what states look like. They're
1626580	1632380	just YAML configurations. They're real simple, real easy to adapt. And basically just think of
1632380	1636820	how systems are configured and what you want to do on those systems. And you do it in YAML. And
1636820	1640980	it's pretty straightforward and easy to read. So here I've named this configuration add backdoor
1640980	1645760	Nix user. So when I call it later, I'll say, hey, for Linux machines or Unix machines, go do this
1645760	1652380	thing. And then what it's going to do is it's going to check if a user is present. So user.present,
1652380	1657740	it's very declarative. You think, is the state of this machine's way? If it's not, go do it.
1657740	1662660	Rather than saying, go do this to this machine. It's going to check first and validate. So if
1662660	1666600	it's not present, it's going to add a user with name backdoor. Password's going to be doorback.
1666600	1671460	It'll hash it. Give us a home directory of slash home slash thread. And then add us to like wheel,
1671460	1677940	sudoers, root, et cetera. So now we have a root account ready to go. In a much more powerful vein,
1677940	1684760	you can also do these file managed states. So here we got a sample one for how you might go
1684760	1690080	deploy an interpreter payload on a particular target. So here we just have our salt repo set
1690080	1695840	up as salt colon slash slash is actually a local directory on your master system. It'll be in like
1695840	1700780	slash serve slash salt. And you'll kind of set a directory structure here. I've got one called
1700780	1705140	payloads, nix, and then I put any of my Linux payloads that I might want to do managed file
1705140	1709740	stuff with there. In this case, it's an interpreter payload. I'm going to tell it to go, hey,
1709740	1717380	install this into slash temp. Give it executable, read, write permissions, et cetera. And then go
1717380	1721240	run it. And then this BG is go run it in the background. So it'll go execute it, run it in
1721240	1725480	the background, and then I should get an interpreter session that pops over once that happens.
1725480	1732520	Now, with just these two ideas, you can go crazy. So from just the managed file, being able to run
1732520	1736240	all your custom binaries from one place, you could get salt stack in there and say, all right, I want
1736240	1740680	to do some crazy stuff with my custom tool sets that I already have. You can apply it like that
1740680	1746740	and saw it across as many systems as you have into your salt stack instance and go from there. So
1746740	1751260	whether it's an interpreter, Merlin, or some crazy custom toolkit you have, that's about how you do
1751260	1757300	it. Now, for Windows, it's about the same. This is just to show kind of the difference between
1758140	1762100	the language that you're going to be using in the YAML file, but this is the exact state we just ran
1762100	1767900	in that demo. So we're checking for user present. If it's not, we add a user back door, pass through
1767980	1773940	a door back, and add it to the administrators and RDP groups. Really simple, really effective.
1773940	1780140	That's all it was. That's all we did. The managed file payload or configuration state is the exact
1780140	1784660	same as Linux one, only we don't have to set any executable permissions because Windows is going to
1784660	1789460	know it's an exe. And we just copy it to wherever we want, in this case Windows temp, and run it in
1789460	1793660	the background as well. So these are really, really, really simple and really, really, really
1793660	1797540	effective. And I hope it kind of gets your brain turning and new ideas of things you could build
1797540	1802920	really easily with these types of desired state configurations. And what's really great about
1802920	1808120	these is, like I said, that concept of desired state. You are missing this from the system you
1808120	1812020	just installed. Your user is not there anymore. Any of the persistence you just set up is gone.
1812060	1816520	As long as it's still calling home to your salt master, you can even set it up as Java. It'll go
1816520	1820100	correct itself on its own, but if you're there monitoring it or babysitting it, it's as simple
1820100	1825540	as a state.apply and it'll go fix itself. So you can do it with automation, you can do it manually,
1825540	1829300	whatever have you, but you can always correct to fix things as they should be.
1830720	1835960	Alright, so let's talk about detecting hackers that are abusing salt stack. No red team or
1835960	1840340	security team is worth their salt without helping our blue teams. We're not doing any good,
1840340	1843500	we're not helping anyone. This is probably the most important piece.
1844960	1850520	First and foremost, simple log analysis. Go back to basics. Check the salt minion and master logs,
1850520	1854580	especially in the context of like a man-in-the-middle attack. Kind of harkening back to
1854580	1859560	that screenshot from last where we pull out, hey, this might be a man-in-the-middle attack of some
1859560	1863440	sort. Those logs will just tell on themselves. It's kind of your golden ticket for seeing all
1863440	1868060	the minion and master communications. It will tell you who, what, when, where, what time, etc.
1868220	1874160	that minions are talking to a given master, even if it is the wrong master. And so you can kind of
1874160	1879440	use that in your investigation to see what's going on. Alright, so that's kind of basics.
1879440	1884180	Another thing we can do is observe the network traffic patterns. While everything is encrypted,
1884180	1888340	it's actually kind of easy to spot. And of course, pcapture didn't happen. In that repo,
1888340	1891360	there's all the actual pcaps from the researcher did. You can go look at them yourself if you don't
1891360	1894620	feel like taking your own packet captures. I'm not going to dive into this. I don't expect
1894620	1899980	anybody to read it. But one thing I want to point out here is that we've remapped port 4505 to 80
1899980	1906200	and port 4506 to 443, kind of like I mentioned a couple slides ago. This is actually what's going
1906200	1911860	on, though, in that pcap. So the first thing we're doing is accepting a key from a potential
1911860	1916200	minion that we've actually man-in-the-middle in this case. So we've successfully pulled off a
1916200	1920100	middle attack. We've got our key accepted. We're going to run a test.ping, which just
1920100	1925160	says that we can talk to that minion. Then we're going to run a couple commands like whoami, id,
1925160	1929900	ls, et cetera. And that's just to kind of show what's going on here. But what's actually
1929900	1934440	happening in terms of communication patterns is what's important from a Blue Teamers perspective
1934440	1940160	to detect. So when a minion calls home, in this case on port 80, it's going to check in on port
1940160	1944600	81st. And the master's not going to publish anything because they're not associated yet.
1944880	1948880	And then it's going to go up and say, hey, on port 443, do you want to trust me?
1948880	1953740	If you accept, the master's in. Now it'll send you its public key and you're good to go to keep
1953740	1960780	your communications running. Here, we can execute commands. So maybe on the salt master, we'll run
1960780	1967580	whoami. And then the master will publish that on port 80 in this case to say, hey, go run whoami.
1967580	1972500	When the minion checks in on port 80, it'll go fetch that, run it, and then come back up to 443
1972500	1976700	and say, hey, I was rude. And kind of the pattern here that I want everybody to notice is that
1976700	1983020	you'll have a connection to port 80 or port 4505 followed by one or more connections to port 443
1983020	1987640	to the exact same host. That's a pretty clear pattern that we can see carved out there. And
1987640	1992600	it's even easier if they are using the default ports for 4505 and 4506 because it might give
1992600	1996920	away that it's salt stack right away. But that's a pattern that you could use. So tandem with those
1996920	2003060	log analysis and kind of your packet captures, you can kind of correlate these two events and
2003060	2007060	say, hey, maybe this is some kind of attacker abusing salt stack as a command and control
2007060	2014480	service. Another way to kind of detect this type of activity is the fact that salt master and minion
2014480	2020140	installations are very, very noisy. Now, obviously, an attacker could change all of the configurations
2020140	2024840	and move things to different directories or whatever. It's an open source project. So
2024840	2030140	there's a lot of power they have. But by default, it is extremely noisy. So if any of these
2030140	2035800	directories exist on your system, whether it's bar log salt, at C salt, serve salt, if you
2035800	2040500	have a master on your system for whatever reason possible, or C colon back slash salt for
2040500	2044560	Windows, if any of those things exist, it's a pretty clear sign that somebody might have
2044560	2050140	installed salt stack in some shape or form on that box. Another thing to do is check your
2050140	2054600	repo files or your network communications to repo.saltstack.com. Because if they're pulling
2054600	2059680	from the default not compiling their own binaries, it's going to be a clear communication just
2059680	2063040	like with that batch file. So if somebody just wants to go be a script kitty and pull
2063040	2066880	down that GitHub project and go use it on a potential target, it's going to be real
2066880	2071600	easy to pinpoint that that's happening. Like I said, it is an open source project. There's
2071600	2075000	always ways to modify and change this. Those are things that I'm going to be looking into
2075000	2078880	more in the future. But for the most part, it's pretty clear when somebody installs a
2079320	2083520	minion, these logs and these existence of these directories is a clear indication that
2083520	2088600	that's happened. A crucial thing, though, to take a look at is if you are legitimately
2088600	2093300	using SaltStack in your environment, an attacker could still install a duplicate minion on
2093420	2097920	a particular target they've compromised. So you'll be able to identify multiple minions
2097920	2102540	in that case, because you should only really ever have one minion running on a box. It's
2102540	2106100	supported to have more than one, which is why this is possible. But in a legitimate
2106100	2110080	configuration, that's not recommended. So hopefully you're not doing that. If you are,
2110080	2117840	here's how you might be able to detect a bad one. So when an attacker goes to install a
2117840	2123380	second minion on a box, they're going to either A, bring their own minion binary, or B, use
2123380	2127680	the one that you already have installed and then just point it at their bad configurations.
2128260	2134880	So what you're going to want to look for in these cases are the potential usage of the
2134880	2139940	same log file. So if two minions are installed and they haven't reconfigured their minion
2139940	2144180	to point to a different log file, you're going to see really weird activity going on in that
2144180	2148380	log from two different minions going on in the box. So you can check that out.
2148580	2152580	Another thing would be your system dlogs. You can look for activity that's going on
2152580	2156560	on one minion that might be similar to activity going on on the other minion,
2156560	2160520	but one's not named like a minion. It's just a behavior type thing. So you notice
2160520	2166360	that two services are behaving the same. One is a legitimate minion. One's like weird XYZ
2166360	2170800	daemon or something. So that's stuff you may want to look for. And then of course,
2170800	2174040	kind of dead giveaway that I think is going to be your network traffic. It's got to
2174040	2178940	communicate back home. So if it's not talking to your master, it's probably not your minion.
2178940	2182640	And so you can go trace that back to whatever your process is. So that's pretty important if
2182640	2185300	you are using SaltStack in your environment because all the other ways are a little bit
2185300	2188200	easier to detect. These are the things you're going to want to look for if you already have
2188200	2194440	minions installed. So that's kind of all the things I wanted to cover today. To wrap this up,
2194440	2199040	I wanted to say, hey, go check out Salt if you're looking for a potential tool for your
2199040	2203140	configuration management or any of the tools really. I'd just favor this. It's great for
2203140	2207920	operations, great for blue teams, and seems pretty fun to use as a red team tool potentially
2207920	2212740	as well. A couple of appreciation shout outs. First and foremost, Seth. The only reason I even
2212740	2218440	chased down this research, he was one of our DevOps on the team at the time. Really educated
2218440	2223140	me a lot on the platform and I kind of took this home and ran with it from there. Chris and Robert,
2223140	2227980	always being real supportive. Daniel Robertson, Dan Borges, both of these two have been great
2228500	2232900	influencers, mentors, whether they realize it or not. And then Camilla, also a great supporter
2232900	2237740	of my life. A couple of references. Like I said, these slides will be available on that GitHub
2237740	2243320	repo. I want to point out Seth's brain again. That guy's really smart. And with that, we have
2243320	2278500	questions. Can you repeat that? I'm sorry, I didn't hear you. Yeah, so the question was,
2278500	2284540	is it better to, or not is it better, was the second option for mitigating the issue to
2284540	2288620	automatically accept minions to the master. And yes, that was the second recommendation.
2294050	2298810	Yeah, and that's absolutely true, which is why is okay, but definitely not the best idea. The
2298810	2302070	best solution is just to install the fingerprint where it should be in your configuration. That's
2302070	2313790	absolutely true. What's up? You spoke briefly of desired state. I know that after like a
2313790	2318670	pentesting engagement, we want to get everything back to normal. Can we use desired states to get
2318670	2325470	back to that normal? Yeah, so you'd have to know and coordinate with your red teams or your pentest
2325470	2329130	teams to know exactly what they installed and anything like that as well. But if you potentially
2329130	2335510	wanted to use that as a way to clean up after known good engagements, rather than having to
2335510	2338790	go back and maintain up, that is absolutely an option. So you can build your states around what
2338790	2342550	you know that you've done and work with those offensive security people to execute on those
2342550	2364940	states. So that's definitely an option to help make cleanup quicker. Yeah, so I don't know exactly
2364940	2369960	where I'll dive down in terms of that, but I do definitely want to explore other new tools or
2369960	2373880	existing tools to see if there's anything better than doing things with SaltStack as we've done it,
2373880	2377760	because it's definitely possible. Like I said, any of these do all do about the same thing. So
2377760	2381220	you can accomplish anything that we've shown in SaltStack today with another one of those tools
2381220	2385820	like Puppet Chef or Ansible. It's the idea of just using these tools from the perspective of
2385820	2399440	the adversary. All right, cool. Well, I'll be around if you want to ask me any other questions,
2399440	2400560	but thank you all for coming.
