00:00:00.033,00:00:05.339 >>Hey, how’s everyone doing? [applause] Awesome. Hey I know this is a great big conference 00:00:05.339,00:00:11.245 with a lot of really awesome things to do so thank you so much for opting to spend the 00:00:11.245,00:00:17.451 next 45 minutes or so with me. Today I’m going to talk about MOSE, which will allow you to 00:00:17.451,00:00:22.456 easily take advantage of configuration management tools in order to do evil things. And 00:00:26.393,00:00:31.398 ok, good. You can see my laptop right? No. >>There we go [applause/cheering] >>Anyway as 00:00:46.480,00:00:51.785 I was saying, uh, this is the slide that the powers that be put on here, uh essentially I’m 00:00:51.785,00:00:55.422 not speaking on behalf of my employer or any of my previous employers nor am I here 00:00:55.422,00:00:58.859 representing my current employer or any previous employers and finally my opinions do not 00:00:58.859,00:01:05.666 reflect those of my current employer or any previous ones. Alright, now that we’re past 00:01:05.666,00:01:09.836 that. This is me in my more natural state presenting in front of a group of people. The 00:01:09.836,00:01:16.343 content and delivery is a bit different, but I’ll figure it out. I’m a Death Metal Vocalist 00:01:16.343,00:01:19.746 in a band called Carrying Kind with that guy right there. And uh I’ve been playing metal for 00:01:19.746,00:01:21.748 around 19 years now. I used to tour around the U.S. with another band with that guy right 00:01:21.748,00:01:26.453 there. Uh a lot of great metal dudes in the audience today. But I’ve since settled for playing 00:01:26.453,00:01:31.458 local shows every so often. Once upon a time I was a Sysadmin and a DevOps Engineer. And currently 00:01:40.834,00:01:47.441 I’m a penetration tester on the product security team at Splunk. My role consists of reviewing 00:01:47.441,00:01:52.446 the various products we have for potential issues. Uh plug, we’re hiring. And before that I built 00:01:54.881,00:01:59.886 and ran the corporate red team at Sandia National Labs. And I also really enjoy automating 00:02:02.089,00:02:07.094 things that break stuff. Which help to motivate this talk. Ok, on the agenda for today, we’re 00:02:10.397,00:02:14.968 gonna begin by talking about what are configuration management tools. After that we 00:02:14.968,00:02:20.607 will discuss how we can use them for less than savory purposes. Following that I’ll talk about 00:02:20.607,00:02:25.612 what MOSE is. And why it exists. After addressing those I will show you how to use it. I will 00:02:27.814,00:02:34.154 also be discussing existing tools in the space. And there will be some pre-recorded demos 00:02:34.154,00:02:39.826 because the demo Gods are cruel. And finally uh I’m gonna talk about my plans for MOSE’ s 00:02:39.826,00:02:44.831 future when it goes off to one day. Quick poll before we go any further. Who here enjoys post 00:02:51.204,00:02:56.209 exploitation? Raise your hand please. Awesome. Keep them up for a second. Who here that 00:02:58.345,00:03:05.085 enjoys post exploitation, feels like you have enough time to do it on a regular basis? I’m 00:03:05.085,00:03:10.090 seeing a lot less hands. That is what I expected. So for me, post exploitation is my favorite part 00:03:13.460,00:03:18.398 of a pen test and no matter where I work, I’ve never felt like I’ve had enough time to do 00:03:18.398,00:03:23.403 it properly. So my goal has been to automate as much of it as I can. And that’s motivation for a 00:03:26.073,00:03:31.078 lot of the tools that I end up writing. And I found it to be a really effective way to maximize 00:03:33.313,00:03:39.119 what I can do in the most efficient way possible. I’ve got a couple of stories around post 00:03:39.119,00:03:43.824 exploitation, specifically with configuration management tools to kind of highlight some of the 00:03:43.824,00:03:49.463 tools that we could start thinking about doing. On the first one I was just beginning 00:03:49.463,00:03:54.601 recon on engagement, doing some port scanning and service discovery when I came across a 00:03:54.601,00:04:01.308 system with port 23 75 exposed. This is the socket for the docker daemon as some of you may 00:04:01.308,00:04:07.581 know. And essentially this meant that I could docker exec into any of the containers running on 00:04:07.581,00:04:14.054 that system. One of them happened to be a puppet master for a dev enclave. Subsequently 00:04:14.054,00:04:20.560 I was able to compromise around 50 or so machines. Uh, but this in turn led to a ton of lateral 00:04:20.560,00:04:25.565 movement both inside and outside of that Enclave, so that was pretty fun. On another one I 00:04:28.335,00:04:34.808 compromised a Jenkins box and once I had the Jenkins SSH key, I was able to get into around 15 00:04:34.808,00:04:40.981 or so systems. But one of them was a puppet master. From this system I was able to compromise 00:04:40.981,00:04:47.320 hundreds of servers, countless databases. I got into the devs hip chat which is always really 00:04:47.320,00:04:49.790 entertaining. And I got admin on their gitlab. It was awesome.So MOSE is a tool to help you enjoy 00:04:49.790,00:04:51.792 these sorts of successes in your own engagements. Alright let’s talk about what cm tools are 00:04:51.792,00:04:53.793 exactly. They are first and foremost used for provisioning systems. So if you have a brand 00:04:53.793,00:04:55.795 new system that needs part of a cluster or it needs to run certain software you provision 00:04:55.795,00:05:00.734 it to do so. Uh they can also be used to manage the state of the systems in your environment, so 00:05:28.695,00:05:33.833 uh if you want to make sure that a service is always running or you want to make sure that 00:05:33.833,00:05:39.206 machines in that environment are being updated automatically on a regular basis. These are some 00:05:39.206,00:05:44.211 good use cases for configuration management tools. These tools have a lot of things in common. 00:05:48.415,00:05:54.354 To start, they have this concept of Idempotency. Which essentially means that you run 00:05:54.354,00:05:59.359 the code as many times as you want and can expect to produce the same result. You can also 00:06:01.561,00:06:07.000 scale infrastructure while guaranteeing consistency and you have the availability to 00:06:07.000,00:06:13.273 provision uh a bunch of machines that are running on a variety of operating systems. For example, 00:06:13.273,00:06:19.913 you could have a puppet module that works for Debian, Suse, RedHat, Ubuntu, Windows, et 00:06:19.913,00:06:26.019 cetera. And they all have a form of secrets management which we’ll discuss a little bit 00:06:26.019,00:06:31.725 later. Uh it is worth noting that puppet doesn’t truly have a native secret management 00:06:31.725,00:06:36.730 solution per say, but Hiera-eyaml has more taken And and lastly it’s worth noting 00:06:39.065,00:06:45.372 that you can run these tools and client client server format. Um for this talk we’re going to 00:06:45.372,00:06:49.976 focus primarily on client server format, since that’s what you can expect to see in most 00:06:49.976,00:06:54.981 enterprise environments. As you can see, these tools are used in a lot of different 00:07:01.688,00:07:06.693 organizations. This is by no means exhaustive, pardon me. Um, and some of these organizations 00:07:08.928,00:07:15.769 use multiple uh of these tools so so you can have an organization that’s using and 00:07:15.769,00:07:21.675 example. Um, but the point here is if you haven’t come across these at some point, you’re 00:07:21.675,00:07:26.680 going to, because they are quite prevalent. These are some of the more popular options. So 00:07:30.750,00:07:35.755 essentially we have puppet, chef, salt and ansible. There are some differences that exist 00:07:43.263,00:07:48.535 amongst these tools. For this talk, I’m going to be focusing on puppet and chef since these 00:07:48.535,00:07:53.540 are the two that MOSE currently supports, but go ahead and take a look at that. And if uh I’m 00:08:01.047,00:08:05.385 gonna show you an example of how to provision the system with one of these tools in a moment. But 00:08:05.385,00:08:11.257 if you’re still processing why you’d use this technology. Consider this example of an 11 00:08:11.257,00:08:16.262 hundred line batch script, which has zero functions and is completely void of hope. So it’s 00:08:20.066,00:08:25.071 nice to have code that runs your infrastructure, but not when it’s a giant script that gets 00:08:27.774,00:08:32.779 passed down from generation to generation and becomes a right of passage to maintain. Alright 00:08:37.384,00:08:42.622 so for this example I’m going to show you how to provision a couple of puppet agents with a 00:08:42.622,00:08:47.627 puppet master. Real quick we’re going to take a look at the master manifest for the 00:08:49.729,00:08:55.902 production environment. And I want you to focus specifically on the webprod dot demo dot com 00:08:55.902,00:08:59.906 node here. Essentially we’re going to install a couple of packages and then essentially we 00:08:59.906,00:09:04.844 are going to set up a web server which will run a web page on top of it. As you can see there’s 00:09:08.782,00:09:14.054 nothing currently running for that system. We’re gonna go ahead and pop into that 00:09:14.054,00:09:19.059 particular puppet agent. And as you can see hdvd is not running. But when we run the puppet 00:09:25.131,00:09:30.336 agent, the agent goes to the puppet master and says hey, I’m lost in this world, what am I 00:09:30.336,00:09:35.875 supposed to be doing with my life? Puppet master says, fear not, you are supposed to be a 00:09:35.875,00:09:40.880 web server running a web page. Do that. And obviously that was not 18 seconds, but magically we 00:09:44.350,00:09:50.623 now have a web page that is running on top of a web server. For the next example, we’re 00:09:50.623,00:09:55.628 gonna take a look at the dev main manifest. And here I want you to focus on node default, um 00:09:58.298,00:10:02.469 we’re gonna install a couple of packages, but it’s important to note for puppet that node 00:10:02.469,00:10:07.574 default means that that case will match any puppet agents that are not explicit and with 00:10:07.574,00:10:12.812 the node definition. So the only definition that was defined was the web dev dot demo dot come in 00:10:12.812,00:10:16.983 the case as you can see the packages are not installed. Puppet agent for the development 00:10:16.983,00:10:23.756 environment. Same thing. Goes to the pupper . Says hey, what am I supposed to be doing. Hub master 00:10:23.756,00:10:28.761 says, install these packages. And subsequently, we now have GCC make and no js installed. So 00:10:37.237,00:10:41.841 hopefully this is a nice uh little basic example to get you into the mindset of what we’re 00:10:41.841,00:10:46.846 looking at here. Ok. Some of you are thinking, you can do that with containers. H**l you even 00:10:53.653,00:11:00.093 just use them for your example. Why would an organization still be using this technology and to 00:11:00.093,00:11:06.399 that I would say a couple of things. First, not everything can be a cloud native ephemeral 00:11:06.399,00:11:11.404 workload that runs in a container. Secondly, it’s typically not a trivial effort 00:11:14.007,00:11:19.012 to migrate older monoliths to container based deployments. And further more you still have to 00:11:21.214,00:11:26.219 install, configure and manage your Kubernetes . So I do not believe that this technology is 00:11:29.923,00:11:36.930 going to be going anywhere, anytime soon. Now that we’ve talked a bit about these CM 00:11:36.930,00:11:41.000 tools, I would imagine some of the more offensive minded folks in the audience are starting to 00:11:41.000,00:11:46.005 get some ideas about what we could do with this technology. If not, let me give you a couple 00:11:50.376,00:11:55.381 of ideas. It’s important to keep in mind that successfully compromising a CM server, giving 00:11:58.651,00:12:03.590 the attacker the ability to run any command on every connected system. This can lead to 00:12:07.493,00:12:13.700 introducing backdoors, adding or deleting files, modifying database data, getting a whole 00:12:13.700,00:12:18.705 bunch of shells. Really the sky’s the limit. And pardon me. So long as your implanted code 00:12:23.176,00:12:28.181 isn’t modified, you have a guarantee that it will run on a regular basis. So persistence is 00:12:31.050,00:12:37.757 effectively built in for you. Which is pretty nice, right? And because these tools all provide 00:12:37.757,00:12:42.762 secret management solutions, we can look at stealing the secrets. Now obviously secrets 00:12:45.898,00:12:49.535 are something we should keep an eye out for, regardless of whether or not we’re on a CM 00:12:49.535,00:12:54.040 server, but it can be especially interesting if we land on a CM server and start looking for 00:12:54.040,00:12:58.645 secrets, because some of these secrets were created to run on a whole bunch of different 00:12:58.645,00:13:03.583 systems. And as such, they can provide us with ample lateral and vertical escalation paths 00:13:06.986,00:13:09.088 and opportunities. So for virtually all these solutions, it comes down to getting on the 00:13:09.088,00:13:11.090 right system and running the decrypt command. Alright, let’s talk a bit about MOSE. MOSE is a 00:13:11.090,00:13:13.092 translator between the user and a variety of CM tools. So what we want to do and what commands 00:13:13.092,00:13:18.097 we want to run, but we don’t necessarily know how to do them for a particular CM tool. MOSE 00:13:28.675,00:13:33.680 take the command we want to execute and translates them into a format that a given CM tool 00:13:46.993,00:13:53.533 can understand. This is a project that I started working on back in December of last year 00:13:53.533,00:13:59.739 and since then, a lot of uh nights and weekends have gone into it. When I was coming up 00:13:59.739,00:14:05.445 with the original idea. I decided that I wanted to be in GoLang because well, I drink 00:14:05.445,00:14:10.450 black coffee and IPAs and I have this beard, so. I figured I would complete the ensemble. Uh. 00:14:14.954,00:14:20.193 I decided to make it in Golang so that we can trivially target a variety of operating systems 00:14:20.193,00:14:25.198 and architectures, leverage, native concurrency and generate a binary that we can run on a 00:14:27.233,00:14:34.207 target system without having to worry about dependencies. I decided to source it through my 00:14:34.207,00:14:40.480 previous employer. Sandia National Labs for PR and hiring purposes. Sandia is an awesome 00:14:40.480,00:14:45.384 place to work and they’re super down with open source security tools and contributing to the 00:14:45.384,00:14:50.389 security community. So I wanted to recognize them for that. Before continuing on I wanted to 00:14:59.465,00:15:06.172 address another potential question that may be on some of your minds. Why do I need a tool 00:15:06.172,00:15:11.177 to go in between myself and these CM tools? Can’t I just use the tools myself? And the real 00:15:14.413,00:15:19.418 answer is, you can. If you have the time to spare. For anyone that’s used these tools, let’s 00:15:21.687,00:15:27.426 face it, there’s a learning curve. And since you will likely encounter several different CM 00:15:27.426,00:15:32.431 tools while on engagements, you have to deal with that learning curve multiple times over. You 00:15:35.635,00:15:41.774 can’t choose which tools your target uses. So you want to be able to weaponize them all and 00:15:41.774,00:15:47.313 not have to worry about the syntactic differences. It’s also a really important to keep in 00:15:47.313,00:15:53.419 mind that you can seriously muck thing up if you’re not careful. Imagine running one command and 00:15:53.419,00:15:59.125 taking down 500 production servers all at once. If that’s not in scope for you, you are in 00:15:59.125,00:16:04.063 trouble. That being said, if you tell MOSE you want to run rmrf slash on all puppet agents, bad 00:16:07.400,00:16:13.706 things are gonna happen. Don’t do that. To give you some perspective, these are some of 00:16:13.706,00:16:19.912 the links that comprise the documentation for puppet. This is what I’m talking about with 00:16:19.912,00:16:25.685 respect to the learning curve. The documentation for most of this technology is extensive and 00:16:25.685,00:16:30.690 it takes time to ingest and understand. Two things typically come to mind for me when I hear 00:16:35.494,00:16:42.201 about a new tool. The first being surely someone has released something already that 00:16:42.201,00:16:45.004 enables you to do this.And the second being, there’s so many tools in this space, do we 00:16:45.004,00:16:50.009 really need another one? And when I looked at the existing solutions for this particular 00:16:55.348,00:17:02.054 problem, there weren’t really too many out there. Right now we’ve got Pwnpet and Pwnsible. 00:17:02.054,00:17:07.059 Both are created by a security researcher that goes by the handle naughtly pwnsible is a 00:17:09.695,00:17:15.301 bash script that creates an msfvenom generated payload and tells you how to run it with 00:17:15.301,00:17:20.306 Ansible. Pwnpet is a bash script that creates a new manifest and module to run an msfvenom 00:17:23.910,00:17:28.915 generated payload. On a somewhat unrelated note, there’s also a great article from Ryan Wendel 00:17:32.218,00:17:37.290 uh which talks about compromising Chef via the Chef server web UI called cooking up 00:17:37.290,00:17:42.828 shells with a compromised chef server. I’ve included in the read me for MOSE when I get that 00:17:42.828,00:17:47.833 up shortly. Uh so that’s worth your time to check out. Ok, back to pwnpet and pwnsible. They’re 00:17:51.437,00:17:53.439 a great place to start and, but there’s a couple of issues with them. They’re decent little bash 00:17:53.439,00:17:55.441 scripts that work well to demonstrate the problem that’s associated with having your CM 00:17:55.441,00:17:57.443 servers compromised. But they weren’t both to scale or give you the ability to translate 00:17:57.443,00:18:02.381 your thoughts and ideas into code. They only support generating payloads with 00:18:07.820,00:18:12.825 msfvenom. So if we didn’t want to use msfvenom, we had to make modifications. Additionally, 00:18:21.167,00:18:26.172 both require manual work. For Pwnsible, hello. For Pwnsible. Outside of creating the payload, 00:18:29.642,00:18:36.182 basically everything is manual and for Pwnpet, the user needs to physically modify the main 00:18:36.182,00:18:42.521 manifest on the server by copy pasting from the generated payload. And you also have to 00:18:42.521,00:18:48.961 get the associated module and file into place. Plus they don’t attempt to get us the juicy 00:18:48.961,00:18:53.966 secrets that we all really want. So rather than having to manually place files, run 00:18:57.603,00:19:02.541 commands, modify files on the remote server. MOSE automates all that for you. And there are 00:19:05.978,00:19:11.717 a lot of really great post ex tools out there that it would be really ideal to be able to 00:19:11.717,00:19:18.090 leverage in new kind of work spaces, so MOSE gives you the ability to upload scripts or 00:19:18.090,00:19:23.095 binaries and execute them on a ton of systems all at once. You can also pick and choose the 00:19:25.231,00:19:30.369 nodes that you want to target for specific tasks strategically. So this could be 00:19:30.369,00:19:36.108 something like uploading a web shell for all the web servers. Or you could pop reverse shells 00:19:36.108,00:19:42.314 on all the managed laptops when they come online. Or you could have a specific power shell 00:19:42.314,00:19:48.687 payload that specifically for the Windows servers. And because MOSE allows the user to clearly 00:19:48.687,00:19:55.061 go from thought to command without having to go deep in the weeds of tool specific details. 00:19:55.061,00:19:59.899 It helps prevent someone less experienced with these technologies from accidentally 00:19:59.899,00:20:04.904 running the wrong command and decimating a whole bunch of servers all at once. So the user 00:20:08.707,00:20:13.079 doesn’t need to use tool specific implementation details to run MOSE. Essentially you 00:20:13.079,00:20:17.783 input your command that you want to run the same way, whether you’re looking at Chef or 00:20:17.783,00:20:22.721 puppet. Although you do need to specify the name of the tool that you want to target. It’s 00:20:22.721,00:20:28.828 really simple, you just do dash t puppet or dash t chef. However, for users that do have 00:20:28.828,00:20:34.700 CM experience, you can use MOSE as well to customize your attacks further. A lot of the 00:20:34.700,00:20:40.506 functionality that exists in most is template based and so more advanced users can modify 00:20:40.506,00:20:45.511 these templates to extend other functionality that MOSE provides out of the box. Also for you 00:20:47.880,00:20:54.019 more advanced users and uh potential future collaborators, this is the code that MOSE uses 00:20:54.019,00:20:59.592 for payload generation. You’ll notice that for both puppet and Chef, these have the same core 00:20:59.592,00:21:04.530 pieces. And this makes it clear and straightforward to develop and modify as is needed. Alright 00:21:09.668,00:21:16.375 let’s talk about the workflow for using MOSE. To start, MOSE does come with a make file, so 00:21:16.375,00:21:20.012 to begin you would run make build, which would get all the co-dependencies in place for you 00:21:20.012,00:21:25.017 and compile your binary. After you’ve done that, you’ll be at this point. So you specify the 00:21:27.119,00:21:30.756 command that you want to run. In this case we’re gonna run LS. It’s not every exciting, but 00:21:30.756,00:21:34.960 it’s just demonstrate the point of what we’re doing and then you specify the target as whatever 00:21:34.960,00:21:40.366 CM tool you want to, you want to specifically target. So in this case, puppet. There’s also a 00:21:40.366,00:21:47.006 JSON config file to specify more advanced options that you’re not gonna need as regularly so um, 00:21:47.006,00:21:53.546 this includes things like pass to SSL certs, um, where you want to store X filled uh Chef files 00:21:53.546,00:21:59.185 and a number of other things. So, once you’ve got everything in place for how you want it 00:21:59.185,00:22:04.990 with the JSON and you have the command that you want to run, you just you run MOSE. It 00:22:04.990,00:22:07.059 generates a payload as a binary. And from th- by default it will standup a web server for you and 00:22:07.059,00:22:09.061 host the payload. If you don’t want to go that route you can just specify a different 00:22:09.061,00:22:11.063 parameter and it will spit out the payload for you and you can transfer it up via FCP or 00:22:11.063,00:22:15.134 whoever you want to get it up there. Once it’s up, you run the payload on the target CM server, 00:22:15.134,00:22:20.139 you answer a question or two and that’s it. You’ll notice that this is one slide of 00:22:23.409,00:22:28.414 documentation and we can go from nothing to fully compromising a bunch of systems. So alright, 00:22:43.162,00:22:48.167 let’s take a look at MOSE and puppet. And just for uh just to give you a kind of visual 00:22:51.537,00:22:54.740 representation of what we’re looking at here. Puppet environments can get a lot more 00:22:54.740,00:23:00.379 complex than this, but this is a good abstraction of what you can expect to see. So essentially 00:23:00.379,00:23:05.985 you have a puppet master that has some modules that are probably in a doe repo and this 00:23:05.985,00:23:10.990 puppet master is connected to a bunch of puppet agents. So, we go ahead and specify the command 00:23:14.894,00:23:18.697 we want to run. In this case, we’re gonna create a Hello dot text file in the temp directory 00:23:18.697,00:23:25.271 and throw this string in there. Uh, the target is puppet and uh we had this SSL option which 00:23:25.271,00:23:30.376 allows us to use TLS for the web server that we’re gonna use to host the payload and we’re 00:23:30.376,00:23:35.381 opting to use port 80 90 for the web server. Alright so we ran it in the previous slide, now at 00:23:37.850,00:23:44.056 this point we’re on the target. We go ahead and grab it. As you can see here, Uh, we provide a 00:23:44.056,00:23:49.061 self signed cert with MOSE which I highly encourage none of you to use. But if you do use it, 00:23:52.364,00:23:57.369 this is what it looks like and as you can see it’s very conspicuous. Alright, so. At 00:24:00.372,00:24:04.777 this point we run the payload, it asks us if we want to make a backup of the existing 00:24:04.777,00:24:10.849 manifests, I encourage you to do this, unless you don’t really want to worry about cleaning up 00:24:10.849,00:24:16.722 later. So if you do make a back up, you can run the puppet Linux binary again with a dash C param 00:24:16.722,00:24:21.493 and it will undo all the stuff that you did with with the MOSE. But if you’re trying to be a 00:24:21.493,00:24:25.898 little stealthier, um, ok I I get why you wouldn’t want to have a dot bak dot MOSE file on 00:24:25.898,00:24:31.603 the system, but I’ll leave that up to you. It will then identify all puppet agents that are known 00:24:31.603,00:24:38.043 to the puppet master. It will also identify modules that are known to the puppet master. From 00:24:38.043,00:24:43.482 there, it generates a rogue module based on the command that we specified and then puts it 00:24:43.482,00:24:47.986 into place. You’ll also notice at the bottom here it found a secret for us. So we’ll hold 00:24:47.986,00:24:52.991 onto that for later. At this point, puppet agents by default check in with the puppet master 00:24:56.829,00:25:00.799 every 30 minutes, but we wanted to get a nice visual representation of what’s going 00:25:00.799,00:25:05.904 on here, so I’ve gone ahead and kicked it off manually as you can see, the agent checks in 00:25:05.904,00:25:09.575 with the master, the master tells it that it needs to run the rogue payload that we 00:25:09.575,00:25:14.580 specified and subsequently, we have this string and the hello dot text file. Alright. Next 00:25:18.817,00:25:23.822 let’s take a look at MOSE and Chef. Again, this is uh this is kind of what you can expect to 00:25:30.829,00:25:34.733 see here as far as a Chef environment goes basically, you have a Chef workstation, which 00:25:34.733,00:25:39.271 allows you to upload recipes and cookbooks to the Chef server. The Chef server interfaces with 00:25:39.271,00:25:44.576 Chef nodes, so there’s an added level of complexity with Chef. Um Chef workstation is usually 00:25:44.576,00:25:49.581 run from a developers. Um, a dev group server, Jenkins, et cetera. And then Chef server is 00:25:51.784,00:25:56.789 just there. Eh as far as Chef nomenclature goes, um, basically Chef nodes run a client which is 00:25:59.191,00:26:05.197 known as the agent. So I’ll probably be using agent and client interchangeably. Uh try 00:26:05.197,00:26:12.037 not to get too hung up on it. Alright so we’re gonna start with compromising a Chef 00:26:12.037,00:26:17.042 workstation since this is a lot more straight forward. As you can see we’re basically running 00:26:19.077,00:26:23.449 the exact command that we ran for the puppet master, with the exception of changing the string 00:26:23.449,00:26:30.355 from puppet to Chef and we are also specifying the target as Chef as opposed to Puppet. We go 00:26:30.355,00:26:35.360 ahead and run the command, it generates the binary for us. We download the payload onto the 00:26:37.696,00:26:42.701 target Chef workstation. And then we run it and when we do run it, it will identify all 00:26:45.904,00:26:51.143 nodes that are known to this Chef server. It also identifies cookbooks that are known to the 00:26:51.143,00:26:56.748 Chef server. Um, it then allows us to target specific Chef agents. This is functionality 00:26:56.748,00:27:01.053 I’m hoping to add to puppet, but I just didn’t get time this uh for this particular release. 00:27:01.053,00:27:07.459 Sorry about that. Um, so. You can input the systems that you want to target specifically or 00:27:07.459,00:27:12.164 you can just opt to target all of them. Once you’ve done that, it will generate the rogue 00:27:12.164,00:27:17.202 cookbook for you. It will upload it to the Chef server and then it will add it to the run list 00:27:17.202,00:27:22.207 for the target systems that you specified. In this case, Chef agent 1. Uh if you’re using the 00:27:27.012,00:27:32.251 Chef client cookbook which co- is considered an industry best practice, the Chef clients will 00:27:32.251,00:27:37.689 check in with the Chef server every 30 minutes. In this case again, I’m just uh running it 00:27:37.689,00:27:43.028 manually so you can get a visual understanding of what’s going on here basically it checks in with 00:27:43.028,00:27:48.300 the Chef server. Sees that there’s the new cookbook to run. Runs it. Generates a file with 00:27:48.300,00:27:53.305 the string in it and all is well in the world. That wasn’t too bad right? I mean it’s basically 00:27:55.707,00:28:00.646 the same thing that we did for the puppet master. Chef server is a little more complicated. So 00:28:07.352,00:28:12.357 again just uh for your uh visual perspective uh we are on the Chef server, which communicates 00:28:14.593,00:28:19.598 with the Chef nodes. Ok. So we can spawn a cookbook with MOSE. But the Chef server has no way 00:28:22.868,00:28:27.606 to provision Chef clients with it, because as an industry best practice and typically in most 00:28:27.606,00:28:33.178 environments, it’s not going to have the knife utility. So we need a Chef workstation for 00:28:33.178,00:28:39.651 that. What we can get are the certificates that are associated with organizations in the Chef 00:28:39.651,00:28:45.791 environment, which we can use in conjunction with a Chef workstation to achieve our 00:28:45.791,00:28:51.830 desired results of running the rogue cookbooks on the Chef server. Now we don’t necessarily 00:28:51.830,00:28:55.033 want to install workstation on the Chef server, because we could clobber some 00:28:55.033,00:28:58.904 dependendencies or break something and or get made if we’re trying to be more 00:28:58.904,00:29:03.842 stealthy. It’s not idea. And we don’t really want to install it on our own systems either 00:29:03.842,00:29:09.247 because same issues and it just you know might be painful and time consuming whatever else. 00:29:09.247,00:29:14.252 And in the spirit of MOSE, we want it to be automated for us. So the solution I ended up 00:29:17.856,00:29:22.861 coming up with uh revolved around docker and some templating. The idea is we exfil 00:29:26.431,00:29:33.372 all the data that we need and we use it to automatically build our own Chef workstation. So 00:29:33.372,00:29:38.276 just to visually sum up what the plan of attack is here. Essentially we land on the Chef 00:29:38.276,00:29:43.281 server. We exfil the keys and the org names to our own system and then we use those to standup 00:29:45.484,00:29:52.057 our own Chef workstation. Once we do that, we can run MOSE on the containerized workstation 00:29:52.057,00:29:57.062 and go to town on the agents. Alright so let’s uh walk through the first couple of steps here. 00:30:01.199,00:30:06.571 Again, to begin we run MOSE pretty much just like we did for the previous two targets. The 00:30:06.571,00:30:11.209 two differences you’ll hea- you’ll see here are the dash L parameter which specifies our 00:30:11.209,00:30:17.749 local IP address for exfil purposes and we specify the dash EP param which allows us to 00:30:17.749,00:30:22.988 specify the exfil port that we’re going to use. After that, we run it. MOSE generates the 00:30:22.988,00:30:27.993 payload for us. We get it onto the target system. And when we run it, it will detect that we 00:30:32.197,00:30:37.202 are on a Chef server. So back on the attacker system, as soon as we download that payload, it 00:30:39.404,00:30:41.406 will immediately ask us theses questions. Are you on a workstation? No I am not. I am 00:30:41.406,00:30:43.408 on a Chef server. Once you say that you are on a Chef server, it will start the listener up 00:30:43.408,00:30:48.413 for you so now you can exfil the data that you need to. Ok, so at this point we’re on step 5 here. 00:30:59.858,00:31:05.063 It’s pretty simple really. MOSE finds everything that we need and steals it. Um it posts it 00:31:05.063,00:31:10.068 posts it to the endpoint that we stood up and it’s really all we need to do. Alright, so at this 00:31:13.138,00:31:18.877 point we have the information that we need and so now we can stand up a workstation of our 00:31:18.877,00:31:24.583 own and use it to run whatever command binary or script that we wanted to run initially. On some 00:31:24.583,00:31:29.588 or all the nodes. MOSE automatically stands up a container for us. With all the 00:31:32.257,00:31:38.029 dependencies that we need. It then drops us into it. So at this point we are running within 00:31:38.029,00:31:44.035 the context of the workstation container that we created. From there, you follow the exact same 00:31:44.035,00:31:49.040 steps as you did. Uh eh as you would as if you were on Chef workstation and that’s it. 00:31:52.878,00:31:58.383 Alright so for this demo, we’re gonna return to the environment that we were working in 00:31:58.383,00:32:04.422 initially where we provisioned a web server to run a webpage for us and we had the the dev 00:32:04.422,00:32:09.427 laptop. This is the payload we’re going to use, um, we’re just gonna get an html file from 00:32:12.798,00:32:18.403 a google drive and just put it into place. This endpoint is no longer up for any of you out 00:32:18.403,00:32:23.408 there. Um, so we run MOSE with the payload. We get onto the target system. Download the 00:32:25.777,00:32:31.149 payload that we generated, we run it, create a backup, um, as you can see, uh, it detected all 00:32:31.149,00:32:36.154 the modules, puppet agents, it found a secret for us so we’ll hold onto that for later. Let’s 00:32:36.154,00:32:40.826 go ahead and take a look at the master manifest. There is the payload that we introduced and 00:32:40.826,00:32:45.831 we’ll go ahead and take a look at the payload logic as well. Pretty simple. It put a file 00:32:48.834,00:32:53.839 into place that runs a- that has our script that we specified and then it runs it as root. So if 00:32:59.377,00:33:01.313 we go ahead and look at the web uh site from earlier. Nothing is really changed, which is you 00:33:01.313,00:33:03.315 know expected. But within a whatever 30 minute window or if we run puppet agent dash t 00:33:03.315,00:33:08.320 ourselves like we’re going to do right now, agent checks in with the master, the master tells it 00:33:21.967,00:33:26.972 something has changed in your logic, please do it. The agent complies. And now when we reload 00:33:29.841,00:33:34.646 the page, some shenanigans occurred. And beyond that we have that secret that we found 00:33:34.646,00:33:36.815 earlier. The my SQL root password. So, there is a my SQL system that is known to this 00:33:36.815,00:33:41.820 particular box. Let’s go ahead and pop into it with that secret and see if it works. Specify the 00:33:47.158,00:33:52.163 host, specify the user as root. And Hazzah! Looks like it worked great. So this is a prime 00:34:01.106,00:34:07.946 example of us being able to target a specific uh agent or set of agents and be able to 00:34:07.946,00:34:12.951 then live off of the land. Use some of the secrets that we have to get into additional systems. 00:34:16.288,00:34:21.493 This next demo is pretty simple, but I think it highlights some of the things that some of us or 00:34:21.493,00:34:27.165 maybe all of us want to do with this sort of thing. This is a different uh puppet environment. 00:34:27.165,00:34:32.170 So I’m just gonna show you what’s going on here, pretty simple, um, so basically we’ve 00:34:34.706,00:34:39.210 got the production environment and we’re gonna take a look at the existing modules. There is 00:34:39.210,00:34:43.615 this hello module, I can assure you it’s not very exciting so I didn’t bother showing you what’s 00:34:43.615,00:34:47.519 up and notice there’s a node default and that’s the only node. So basically that means 00:34:47.519,00:34:51.856 that puppet agents in this environment are going to be using whatever is in that node 00:34:51.856,00:34:58.330 definition. Here we’re gonna start a tool up. It’s called Platypus. It’s a neat little 00:34:58.330,00:35:03.268 Golang tool that essentially allows us to just get a bunch of reverse shells in. It’s uh kind 00:35:05.937,00:35:12.143 of like a light weight alternative to an interpreter if you will. Ok, from here, we’re 00:35:12.143,00:35:16.181 just gonna run a, you know pretty classic uh reverse shell payload. Don’t worry I’ll show 00:35:16.181,00:35:22.854 it to you again shortly. We go ahead and get the payload onto the target puppet master and it 00:35:22.854,00:35:27.792 goes ahead and does- does it’s thing. There aren’t any secrets, but that’s alright. It dropped 00:35:27.792,00:35:33.598 our rogue module into place as you can see here, we found around 19 puppet ah- agents, 00:35:33.598,00:35:35.734 exactly 19 puppet agents. Um. And uh there’s that Hello World module that was there 00:35:35.734,00:35:37.736 previously. So. If we go ahead and take a look at the main manifest, we now have the rogue 00:35:37.736,00:35:39.738 payload which was introduced which was replaced. We can go ahead and take a look at the 00:35:39.738,00:35:44.743 module that we generated as well. And again, pretty classic as far as reverse shells go. We 00:35:56.821,00:36:01.760 can run as root. And so, at this point, we could wait for 30 minutes, but I don’t have that 00:36:06.665,00:36:11.469 much time, so uh, I’m gonna speed things up by running this bash script here, which will run 00:36:11.469,00:36:16.474 puppet agent for all of the targets. So we’ll just pretend that we’ve been hanging out for 00:36:19.477,00:36:25.417 a little bit, hoping that something good happens after we injected our rogue payload. All 00:36:25.417,00:36:29.854 of a sudden a connection comes in, we say, oh! Cool, hopefully this is what we expect it to be. 00:36:29.854,00:36:34.859 Let’s take a look. So we’ll grab it, jump to that session, and lo we are running at agent 2. Looks 00:36:44.169,00:36:47.972 like there’s a couple more connections coming in. So why don’t we check those out as 00:36:47.972,00:36:52.811 well. We’ll just pick one. So we will interact with this and check it out, looks like we’re 00:36:52.811,00:36:58.416 running as root on agent 6. And at this point it’s basically just raining shells down on us, 00:36:58.416,00:37:03.354 so uh, looks like things are working properly. And we’ll just pick one more just to be sure. 00:37:08.126,00:37:13.131 Go ahead and jump into it. And as you can see, we are running as root on agent 13. So at this 00:37:15.834,00:37:20.839 point I would say that our Cool. So if you are a responsible penetration tester or red teamer 00:37:28.947,00:37:33.585 which I hope some or all of you are. And you want to try some of this on your own without 00:37:33.585,00:37:38.156 unleashing it on one of your clients. And you want to have a test environment, but you don’t 00:37:38.156,00:37:43.161 necessarily need- want to find out how to do it yourself, fear not. I’ve created some for you. 00:37:43.161,00:37:49.100 Uh, you’ll be able to find them here in a bit. They use docker and vagrant, so um, that- that’s 00:37:49.100,00:37:55.573 really in terms of dependencies don’t worry these links will show up again shortly. On a side 00:37:55.573,00:38:00.111 note, I think that the test labs and MOSE for that matter, could be really interesting for blue 00:38:00.111,00:38:05.950 teams to use as well. Uh for fire drilling or building uh, detection mechanisms, uh 00:38:05.950,00:38:10.488 automated sig gen. If there’s anyone here that’s doing blue teaming and having sort of uh 00:38:10.488,00:38:14.425 automated pipeline to do that sort of stuff, I’d love to talk to you about what you’re doing. 00:38:14.425,00:38:19.430 So come say what’s up. Looking to the future. Uh, I would like to of course be able to support 00:38:22.700,00:38:27.705 Ansible and Chef. Um, Jenkins obviously isn’t a CM tool persay, but I think of MOSE as 00:38:29.808,00:38:35.613 first and foremost. And Jenkins has a lot of interesting thing you can do. I mean, 00:38:35.613,00:38:40.385 realistically it’s uh, it’s basically the world’s worst enterprise grade password 00:38:40.385,00:38:45.023 manager. And um, I don’t know maybe do something like, spawn rogue jobs or something. I 00:38:45.023,00:38:50.061 haven’t looked into it too much, so if anyone’s done any research there, hit me up. I’d love to 00:38:50.061,00:38:55.099 hear from you. Um, I think it’s be nice to be able to interface with tools like metasploit uh 00:38:55.099,00:39:00.138 via containers so you know generate listeners, um. So you don’t necessarily have to run 00:39:00.138,00:39:06.144 this in Kali or deal with Metasploit. I think it would be interesting to be able to 00:39:06.144,00:39:11.983 backdoor existing recipes, modules, playbooks, states, et cetera. Um, as as you can 00:39:11.983,00:39:18.089 recall, their generating a module and modifying the main manifest. It would be nice if we 00:39:18.089,00:39:21.859 could just piggyback off of something that is already there. Um, so you specify the command 00:39:21.859,00:39:25.496 you want to run, whatever. Systems you want to run it on. And then it backdoors the 00:39:25.496,00:39:31.069 existing code. And it would be nice to turn some of this functionality into some 00:39:31.069,00:39:36.174 Metasploit modules potentially. Um I could see something like the higher EML secrets gathering 00:39:36.174,00:39:39.811 like a post module for example. Uh maybe you guys have some ideas about what we could do 00:39:39.811,00:39:45.850 there. Hit me up. Uh and then lastly this is an open source project and uh I there’s a lot 00:39:45.850,00:39:50.855 of very smart people in this room. And I would love to hear what great ideas you have. Um, 00:39:50.855,00:39:56.160 so, please consider contributing. Real quick. I wanted to thank a couple of 00:39:56.160,00:40:02.333 people in the room. You’ve got my wonderful wife Amanda. Who uh, put up with me being super 00:40:02.333,00:40:07.205 grouchy and working nights and weekends for the past month and a half. So thank you very much. 00:40:07.205,00:40:12.043 Wouldn’t have been able to do it without you. Um also want to thank my buddy Al, who’s 00:40:12.043,00:40:17.582 somewhere. Hey, there he is. Uh he’s the first contributor to MOSE and uh without him, I 00:40:17.582,00:40:22.020 wouldn’t be able to get in nearly as many awesome features as MOSE has today. So thank you 00:40:22.020,00:40:27.458 very much. Uh couple of people helped me to go through this talk and make sure it didn’t 00:40:27.458,00:40:33.564 sound like dog s**t and also gave me some tips on my code. So thank you to those people. And 00:40:33.564,00:40:39.504 finally, uh, this is like a pretty crazy event and uh, uh I’ve gotten a a a little bit of 00:40:39.504,00:40:43.474 a better sense how the sausage is made so to speak. So could we please give it up for the DefCon 00:40:43.474,00:40:48.479 staff for doing such an awesome job year after year? [applause] And so if you’re interested uh 00:40:56.454,00:41:02.760 we myself and this wonderful man, Al here, are going to be talking about a great recon tool 00:41:02.760,00:41:08.266 tomorrow. Uh from 12 to 150 in Planet Hollywood. Um, if you’re interested uh come on by, say 00:41:08.266,00:41:12.370 what’s up. If you want to talk about MOSE that’s totally cool too. Uh if you want to drink 00:41:12.370,00:41:19.077 beers we can definitely do that as well. So again, this is an open source project. I would 00:41:19.077,00:41:24.649 love to see what ideas you guys have. Um, send me some poll requests, send me some issues. 00:41:24.649,00:41:29.253 Um, let’s make this a really awesome tool that we can enjoy and see some successes with in 00:41:29.253,00:41:34.826 our various engagements. Um, this is where you’ll be able to find MOSE uh in a bit after the 00:41:34.826,00:41:41.699 talk and then test labs as well. Um, this is my contact info and uh at this point uh we have some 00:41:41.699,00:41:48.406 amount of time that exists like, 5 minutes for questions, if anyone has any questions. Now’s 00:41:48.406,00:41:52.677 the time. Thank you. [applause]