[00:00.000 --> 00:06.080] But yeah, let's get the show started. Build to hack, hack to build. Who am I? My name is Chris. [00:06.080 --> 00:11.200] I'm a security engineer at Heroku. We're pretty much remote code execution as a service. If you [00:11.200 --> 00:14.860] don't know what I'm talking about, go look at the platform and you'll see what I mean. [00:14.940 --> 00:20.400] Find me on Twitter, Brompony. But yeah, I like hacking stuff. I like building stuff. I am lazy, [00:20.400 --> 00:24.880] so I build stuff that helps me hack stuff quicker. Whether it's web, Windows, Android, [00:24.880 --> 00:28.920] and recently I've been looking at containers. They're a lot of fun. So this is what we're [00:28.920 --> 00:34.940] gonna look at. Problem, some existing research. I'll introduce to you Bob. So it's Bob with a [00:34.940 --> 00:40.360] silent T. And we'll look at some stuff that Bob can do. And yeah, this slide's more for me just [00:40.360 --> 00:44.020] to actually remind myself what it is that I actually share with you today. So we might [00:44.200 --> 00:50.380] deviate a bit, but I'll try to bring it back in. So what are the problems? So in a modern cloud, [00:50.380 --> 00:55.480] DevOps, SDLC, Agile environment, there was one big question that I had to ask myself [00:55.480 --> 00:59.940] quite often was, how do we identify and exploit container vulnerabilities? So if you're a pen [00:59.940 --> 01:02.920] test, or if you know, you got a shell in a box and you want to break out, you want to [01:02.920 --> 01:07.300] pwn some stuff, you know, how do you identify and exploit container vulnerabilities? But then [01:07.300 --> 01:11.820] in an engineering environment, how do we test, secure, and monitor our containers? So I come [01:11.820 --> 01:16.800] from a red teaming consulting background, and I do more engineering. So I'm constantly trying [01:16.800 --> 01:21.160] to break our platform. And when you've got thousands of containers, and you don't always [01:21.160 --> 01:24.920] want to pop shells and stuff, how do you do security at scale? So these two questions are [01:24.920 --> 01:29.820] very much aligned, but they're pretty much asking the same thing, which is how do we [01:29.820 --> 01:34.040] basically identify and pwn stuff, and break out of containers? So in terms of existing [01:34.040 --> 01:39.660] research, these are just categories of types of tools. This list is by no means complete, [01:39.660 --> 01:43.240] but if you're in a terminal, you got a shell, and you want to find out if you're in a [01:43.240 --> 01:47.580] container, am I contained? Identify as the SACCOM, CAPS, LXE, or Docker environment that [01:47.580 --> 01:51.220] you're in, and it will tell you, very important. Then there's a whole bunch of Google [01:51.220 --> 01:54.580] container tools. I highly recommend you look at their repo. Great stuff in terms of static [01:54.580 --> 02:01.600] analysis for container images, be it a Docker or an LXE image. Clay is really good, if you [02:01.600 --> 02:04.960] want to look for vulnerabilities in images, it's a really great tool. And when it comes [02:04.960 --> 02:08.560] to benchmarking, Aqua Security has done a lot of good work there, if you actually want [02:08.560 --> 02:14.040] to benchmark your images and your security controls that are in place. Now you'll see [02:14.040 --> 02:20.260] that from this list, there's not really much there in terms of actually breaking out and [02:20.260 --> 02:27.060] pwning containers. So, I came up, I had this problem that I experienced, that was the [02:27.060 --> 02:32.240] existing research that I had, so generally when I like to solve a problem, I like to just [02:32.240 --> 02:38.260] pwn everything if I can, so that's why I did Bob, you can find it on GitHub, it's written in [02:38.260 --> 02:41.780] Go, yeah the hipsters were doing it, so I figured let's see why the hipsters are doing [02:41.780 --> 02:45.720] everything in Go, I'm gonna, slightly ironic by my hat and beard, but you know I'm in [02:45.720 --> 02:52.500] denial. So basically like I said, I'm lazy and I just wanted something, you know when you're [02:52.500 --> 02:56.820] writing the same exploits over and over again and doing the same breakouts, you know, you [02:56.820 --> 03:01.040] kind of want to automate that stuff. So Bob will give you the ability to auto-pwn, so [03:01.040 --> 03:06.460] these kids are gonna love that, sorry I had to say it, but it's definitely a thing. Also [03:06.460 --> 03:11.180] helps you do not only breaking out of containers, but think Linux post exploitation, when [03:11.180 --> 03:14.140] there's a lot of things that you want to do when you get into it, you want to automate it, so [03:14.140 --> 03:18.320] Bob will help you do that. And of course you can do all these things in a pentastic kind of [03:18.320 --> 03:22.900] way, so if you want shells, you get shells, but if you also want to, you know, help your [03:22.900 --> 03:26.520] engineering environment, so set things up with turn codes and plug into your CR [03:26.520 --> 03:30.700] environment, Bob's also designed for that, and I'll show you what I mean by that. So that's [03:30.700 --> 03:35.220] Bob, like I said we're gonna be pwning stuff. When you're pwning containers, the [03:35.220 --> 03:40.320] hollow world of pwning containers is exploiting docker.sock, it's a Unix domain socket [03:40.320 --> 03:44.780] that docker uses to orchestrate basically containers, if that thing is ever exposed, you find [03:44.780 --> 03:49.920] it, it is game overs. So basically it comes from people wanting to use docker within [03:49.920 --> 03:54.160] docker, don't do that, use that, there's better ways to do it originally, but basically this [03:54.160 --> 03:58.380] allowed us to do a local privilege to root and basically break out of the container. It's a [03:58.380 --> 04:02.440] really fun, you know, way to get into container exploitation. So how do you do it? What are [04:02.440 --> 04:06.620] the manual steps? So first you gotta find docker.sock, so it's a Unix domain socket, it's [04:06.620 --> 04:11.740] speaking HTTP, it's basically a RESTful API on a domain socket. Then you want to interact [04:11.740 --> 04:17.040] with the socket with curl or a docker client or netcat. Once you find it and you can [04:17.040 --> 04:22.580] interact with it, you then want to create a new container and mount the hosts up, uh, file [04:22.580 --> 04:27.900] system in your container with the dash v command. Then run that new container and then [04:27.900 --> 04:32.340] use chroot or chroot or troot as I found this week, there are multiple pronunciations for [04:32.340 --> 04:37.760] that. Um, and there you go. You are then pretty much root on the host and you have access to [04:37.760 --> 04:41.580] the host file system. And now you know if it's Linux and you access the file system, [04:41.580 --> 04:46.100] everything's a file, it's game overs. So that's the manual step. Now you don't want to do [04:46.100 --> 04:51.660] that all the time. Excuse me. But now things get a little bit tricky in containers. [04:52.040 --> 04:55.700] Because when you're living off the land, especially in containers, the commands that you [04:55.700 --> 04:59.280] need, for example the found command, might not be in the container. So if you're using [04:59.280 --> 05:02.980] really minimal images like the docker image or the alpine image, that's the thing, you might [05:02.980 --> 05:06.560] not have the tools to actually do the stuff that you need to do. Like what if there's no [05:07.140 --> 05:11.920] ifconfig or ipadder. Sure you can read from procfs but this stuff can slow you down. [05:12.360 --> 05:15.600] Especially if you need to find docker, uh, the docker socket. It's not always at [05:15.600 --> 05:20.300] var on docker.sock, it could be at mu slash bob. If you don't have the found command, you [05:20.300 --> 05:24.280] don't have recursive searches, how are you actually going to find the socket? So this is [05:24.280 --> 05:27.520] where syscalls come in. So on the left there, those are the syscalls that the found [05:27.520 --> 05:32.040] command makes use of. And on the right there, that's what bob does in go code to do pretty [05:32.040 --> 05:36.800] much the found command. The nice thing about go is that when you start interacting uh, uh, [05:36.800 --> 05:40.400] with the operating system, go makes use of syscalls. It won't actually make use of actual [05:40.400 --> 05:44.440] shell commands. Some languages do that. So nice thing is, is that if the command isn't [05:44.440 --> 05:48.400] there, you can use the syscalls and the syscalls will be there to allow you to perform the [05:48.400 --> 05:52.820] actions that you want to do. So that, that's what we do with bob. And I'm going to show you a [05:52.820 --> 05:59.280] demo now. Um, these are pre-recorded. I'm done doing live demos because I just ran out of [05:59.280 --> 06:05.840] sacrifices all the time. Um, so what we're going to do here is, um, at the bottom terminal, [06:05.840 --> 06:08.940] so I know it's a little bit small, but basically that's our host. And we're just going to [06:08.940 --> 06:14.680] watch a directory on the host. Um, so you see there's one file called bob linux. In the top, [06:14.680 --> 06:18.320] we're going to run in, in a container. So we're just saying a docker run and then we're [06:18.320 --> 06:25.480] mounting a socket. Turn off the light. Yeah, unfortunately that's, can we turn the lights [06:25.480 --> 06:31.680] down? Can we? No. Yes. Yeah. Unfortunately I can't make it bigger because the resolution [06:31.680 --> 06:44.100] will go off the board. We can just break the lights. Ah. Ooh. A room full of hackers and you [06:44.100 --> 06:54.060] just turn the lights on and you get that reaction. It's magic. So we're in a container now and [06:54.060 --> 06:58.980] we're going to run bob. And you know, if you're inside a container, you want to find [06:58.980 --> 07:02.680] socket. So we're just saying dash socket equals true. And now what Bob's going to do is [07:02.680 --> 07:07.040] going to go and look for all the Unix domain sockets. Now you found a Unix domain socket. [07:07.040 --> 07:11.220] What now? What do you do? So of course you want to auto-pwn this stuff. So I'm now [07:11.220 --> 07:16.600] providing dash auto-pwn equals true. And what Bob's now going to do is it's going to look [07:16.600 --> 07:21.280] for the domain sockets that it can find. And it's going to try and pop it basically. And [07:21.280 --> 07:26.100] what you'll see now, Bob is now giving me a TTY. So this terminal that I'm in now is not [07:26.100 --> 07:30.360] actually a terminal on the host. You'll see that that's a OSX host there. And I'm now going [07:30.360 --> 07:34.460] to create a file inside a temp folder and that file is now going to appear at the bottom [07:34.460 --> 07:41.520] terminal which is on our host. And we'll see that appear in a bit. So now I'm in a TTY that [07:41.520 --> 07:45.980] Bob has provided me. And you'll see that file has now appeared on the underlying host. [07:45.980 --> 07:50.100] And within the container. Now once you're done with that, you can now exit Bob and now [07:50.100 --> 07:54.760] you're back into your container's terminal. So that's one way that, you know, instead of [07:54.760 --> 08:00.440] doing those steps that I mentioned earlier, you can just basically say auto-pwn and boom, [08:00.440 --> 08:05.340] your root on the host. Of course if the docker socket is not authenticated or protected, [08:05.340 --> 08:11.180] often it's not. So automatically just auto-pwn all that stuff. So it's quite nice to get a [08:11.180 --> 08:16.080] TTY on the host. If you want think pen test, you want to get a shell on the host. Also, if [08:16.080 --> 08:20.760] you want to test maybe in your CI environment, if there are exploitable sockets in your [08:20.760 --> 08:24.720] pre-production staging environment, you can tell Bob to do this and we'll make use of [08:24.720 --> 08:31.300] return codes. So what we'll do here is we have a CI environment and we're going to run the [08:31.300 --> 08:34.480] same thing. So what's happening over here in the top right, I've configured my CI [08:34.480 --> 08:39.160] environment to run Bob and I've provided the auto-pwn but you'll see that I've added the [08:39.160 --> 08:43.760] CRCD equals true flag. So what that means is, don't drop into a shell, but if you [08:43.760 --> 08:48.380] successfully exploit that vulnerability, set the return code greater than zero. Because if [08:48.380 --> 08:53.300] you're familiar with CI environments, fail tests are marked as any test that has a return [08:53.300 --> 08:57.600] code greater than zero. So if your CI environment runs a command, a test, and the return [08:57.600 --> 09:01.940] code is greater than zero, the test has failed. So Bob will do that. So this is very useful [09:01.940 --> 09:06.720] for engineers and for CI environments. And if you look on the left, the test is running and [09:06.720 --> 09:11.200] we'll see that Bob picks up a couple of Unix domain sockets, but because they're not [09:11.200 --> 09:16.660] exploitable, they're not docker sockets, you'll see Bob's found them, the test will actually [09:16.660 --> 09:22.200] pass. So this is quite a nice thing that you can do if, you know, it doesn't make sense to try [09:22.200 --> 09:26.760] to get a shell now. Like if you're doing thousands of, uh, push, uh, push requests, pull [09:26.760 --> 09:31.140] requests a day, you know, you're not going to want shells in this context. But from an [09:31.140 --> 09:35.480] engineering environment, you want to test, you know, are there exposed docker sockets? Is [09:35.480 --> 09:39.380] this thing pwnable? So you don't want your engineers focusing on understanding, okay, now [09:39.380 --> 09:44.120] I've got a, you know, exploit docker sockets, like, you know, just run it automagically and [09:44.120 --> 09:48.640] then you can find out if that's the case. So it's very useful in CI environments. But of [09:48.640 --> 09:52.620] course, there's more to pwn, there's more to will than docker sockets. It's called [09:52.620 --> 09:58.560] privileged containers. Anybody raise a hand, privileged container in here? Cool. So thank you [09:58.560 --> 10:01.200] for putting your hand up, but it's worse when you're at a talk and someone's like, can you [10:01.200 --> 10:05.680] please put your hand up if you have, you know, seen X or A or B or C. It's always the worst. [10:05.680 --> 10:11.060] But, um, privileged containers are pretty much the worst thing in the world of containers. Why? [10:12.860 --> 10:17.840] Cue awkward silence. The case for that is, I know, I just try to hide behind comedy and [10:17.840 --> 10:23.820] it's always an epic fail. So privileged containers are basically a, a, a, I was going to say [10:23.820 --> 10:28.100] another word there, but it's not a good thing. Um, and it's very dangerous when it comes to [10:28.100 --> 10:32.780] your syscalls that you have access to and the Linux capabilities. And this basically means [10:32.780 --> 10:37.260] very, very easy container escapes. But now you're in a privileged container, how do you [10:37.260 --> 10:42.120] break out? So, I'm going to show you a new feature that I released this week. Um, what this [10:42.120 --> 10:48.800] does is Bob makes use of C group controllers and we're inside a privileged container. And [10:48.800 --> 10:52.480] what we're going to do is we're going to abuse the C group Linux release agent, uh, [10:52.480 --> 10:57.100] capability. And what that means is that we're going to get command execution on the [10:57.100 --> 11:02.440] underlying host. This is how C groups work because we have access to the mount syscall and [11:02.440 --> 11:07.280] also because the Linux capability sysadmin has not been dropped, we can abuse that. So [11:07.280 --> 11:11.720] basically we mount the RDMA C group controller, we then kill off a process and then basically [11:11.720 --> 11:17.400] we get command execution. So you'll see now I'm using the pwn group, uh, host, uh, command. [11:17.400 --> 11:22.600] I'm saying hostname and I've got a hostname of, uh, docker desktop. So now I'm getting [11:22.600 --> 11:26.820] command execution, blah, blah, blah. Fun stuff. Let's get a shell. So at the bottom, I'm on [11:26.820 --> 11:34.060] my jump box, standard Netcat listener. The great thing, if you're using Dockon OS X, be aware [11:34.060 --> 11:40.360] that your VMs, uh, your containers are running in a Linux kit VM. That VM by default comes [11:40.360 --> 11:44.160] with Netcat enabled, of course, because it's got busy box, but of course it's got the dash E [11:44.160 --> 11:50.020] flag is enabled. The evil command. You do not want Netcat on your boxes with that. So it [11:50.020 --> 11:54.980] makes getting shells really easy. So we're gonna tell it, Bob, pwn the C group, so we're in [11:54.980 --> 11:59.740] the container, run this Netcat command, connect back to our jump box, and what's gonna [11:59.740 --> 12:04.800] happen is that we're gonna get a shell on the underlying host which happens to be the Linux [12:04.800 --> 12:11.140] kit VM. And in an OS X environment, that's basically game overs. So, cause we're running in a [12:11.140 --> 12:15.440] privileged container, this is really easy. Trail of bits did a great write up on this. Uh, C [12:15.440 --> 12:19.560] group, uh, pwnage, um, it's really interesting. And you'll see now we've got a shell at the [12:19.560 --> 12:23.480] bottom, and you'll see we're on a host called Docker desktops. If you see that host name, [12:23.480 --> 12:29.200] that is the VM that, uh, Docker for OS X uses. And now we're in the host file system. And if [12:29.200 --> 12:33.560] you ever want to find out where your container is living on the underlying host, look at the [12:33.560 --> 12:37.900] mount command, and if you look there, you'll see var lib docker overlay 2. That's where your [12:37.900 --> 12:43.980] container is living. And what I'm actually gonna do now is I'm gonna create a file in the [12:43.980 --> 12:52.040] Linux kit VM, and you'll see that it'll appear inside my container. So I'm in a container, and [12:52.040 --> 12:56.060] you'll see the OS does not like it, because there's some Docker weirdness, but you can see [12:56.060 --> 13:01.740] hello is over here, and we created it on our jump box. So basically, pwning C group, you [13:01.740 --> 13:06.280] break out of the container, and you basically root on underlying host. If you're running [13:06.280 --> 13:11.740] something on a Debian system, it's running bare metal, you'll end up actually being root on [13:11.740 --> 13:18.360] the host. So of course, if you added the CRCD flag to Bob with this, uh, it would exploit this, [13:18.360 --> 13:22.120] but then set the return code. So you wouldn't be getting shells, we can just execute a [13:22.120 --> 13:26.720] command that you want. So pretty useful, privileged containers, um, they are out there. But [13:26.720 --> 13:31.480] when it comes to containers, um, there's also environment variables, very, very good place to [13:31.480 --> 13:35.880] look when you wanna pwn containers, you'd be surprised what's in environment variables. So [13:35.880 --> 13:39.260] there's good old env, if you type that in the terminal, that's what you'll get. But there's [13:39.260 --> 13:44.180] also the procfs in Linux. Procfs, it, it, it, it's given me a lot of this hair loss that you [13:44.180 --> 13:49.080] see over here today. Um, but basically if you read proc and then the PID of the process [13:49.080 --> 13:52.140] environment, you'll get access to the environment variables that have been set for that [13:52.140 --> 13:58.340] process. Now this gets interesting, because env is not always cleared, and things might be [13:58.340 --> 14:03.700] living in proc PID. And this is when, uh, ephemerality becomes a problem. So you might do [14:03.700 --> 14:10.100] like a PS orcs and see, okay, there's a process with PID 99, you go read proc 99 in [14:10.100 --> 14:13.240] Viron, there'll be, there might be nothing there because the process is dead. So you gotta be [14:13.240 --> 14:17.820] really quick when you're doing this. Bob does this really quickly via OS and Viron, and Bob [14:17.820 --> 14:23.300] will go ahead and check the env, OS.env, so like typing env in your terminal, and go in the [14:23.300 --> 14:27.520] procfs and analyze it. Because sometimes there's the case where the env in your terminal's [14:27.520 --> 14:32.680] been cleared, but the proc in Viron, uh, mapping has not been cleared. So sometimes you can [14:32.680 --> 14:36.300] find a whole bunch of stuff, because of course, you know, environment variables, it's, you [14:36.300 --> 14:42.320] know, the next gen, uh, secret storage, uh, mechanism. So that's pretty much what the Go code [14:42.320 --> 14:47.600] looks like if you want to process procfs. It's really nice and minimal. Um, I'm a big fan of [14:47.600 --> 14:53.040] Go, um, as you can probably hear or see. But how do we actually go about doing this? So we're [14:53.040 --> 14:58.240] gonna run a container, and I should probably press play, that's a good place to start. And we're [14:58.240 --> 15:02.840] gonna add in an environment variable. So it's called touch of approval and super secret [15:02.840 --> 15:11.000] password. So what Bob will do by default, if you do the recon flag, if you don't pass a word [15:11.000 --> 15:15.980] list, Bob will look for password and secret. And you can see now Bob has said, okay, we've [15:15.980 --> 15:23.020] now found these PIDs that have this, uh, key term in proc in Viron, and Bob will then look for [15:23.040 --> 15:29.120] the process that it exists in. And that's by default. But what you can also do with Bob is you [15:29.120 --> 15:34.820] can also supply a word list. So you can tell Bob, you know what, analyze all the processes that [15:34.820 --> 15:41.320] you have access to and use the, use for, uh, look for these words in this word list. So we're [15:41.320 --> 15:45.920] gonna provide a word list now, and inside that word list were the terms password, YOLO, [15:45.920 --> 15:51.280] secret, find me, and Bob went ahead and looked at ENV and in all the processes inside there. [15:51.280 --> 15:57.580] Now, this is where, uh, return codes also happen. So if Bob has found a keyword in a process [15:57.580 --> 16:01.700] environment that you're looking for, the return code will be greater than zero. That's what I'm [16:01.700 --> 16:05.760] gonna show you now. So now you're gonna use a word list where there's nothing inside. And you [16:05.760 --> 16:10.420] can see Bob didn't find any of the entries inside the word list, inside any of the processes. [16:10.420 --> 16:15.540] And then you'll see the return code now will be zero because Bob didn't find any of those key [16:15.540 --> 16:22.900] terms. So that's all fine and dandy. How do we also do this in a CI environment? So you [16:22.900 --> 16:27.020] definitely want to scan your environment variables in your pre-production or production [16:27.020 --> 16:31.800] environments because you never know what's gonna be lingering there. So in this case, and [16:31.800 --> 16:36.200] these configs are all the same on the, uh, CI environments that you're using. So we're using a [16:36.200 --> 16:39.660] shell script here and we're gonna be running two Bob commands. So we're gonna be doing the [16:39.660 --> 16:43.400] socket auto-po. So we're gonna try to see if we have any vulnerable sockets and we're gonna be [16:43.400 --> 16:48.060] scanning our environment variables. And Bob will go ahead and do that on every git push and [16:48.060 --> 16:55.140] every pull request or however you've configured your CI environments. So let me just fast [16:55.140 --> 17:02.340] forward this. This is, in true Chris fashion, I made too much content for what I have. So I'm [17:02.340 --> 17:07.860] like, let's get to the really cool fun stuff. And of course you can't double up speed with the [17:07.860 --> 17:12.860] videos that I make. I'm just challenged in that way. So in every CI environment, Bob is gonna [17:12.860 --> 17:18.380] look for these key terms. It is regex as well. So you can say, okay, look for S3 tokens or [17:18.380 --> 17:22.920] whatever. It's, it's regex. Um, the world will definitely burn at some point. So we can see [17:22.920 --> 17:28.020] Bob has gone ahead and run those two commands. And the test will pass because from the [17:28.020 --> 17:33.180] previous tests, we know that there are no exploitable docker sockets. And in the container [17:33.180 --> 17:37.180] that we are running, now remember in our, in this CI environment, all our tests are running [17:37.180 --> 17:41.600] in containers. That's how we configured it. And now we know great stuff that test passed our [17:41.600 --> 17:46.280] containers in pre-production. Do not have exploitable docker sockets. And the environment [17:46.280 --> 17:52.220] variables that are there do not have any of the key terms that we specified. But of course, [17:52.220 --> 17:58.080] clouds, uh, clouds, yeah. Clouds love to host containers. Um, and of course we've got [17:58.080 --> 18:05.900] metadata services. So the 169254 address, it exists in GCP or AWS, Azure. And basically if you [18:05.900 --> 18:09.760] can get access to this, you can do a whole bunch of stuff. It depends on the platform. So for [18:09.760 --> 18:14.300] example, that call request in AWS, if there's an IAM role associated to the instance, you get [18:14.300 --> 18:19.840] the credentials for that. It'll, it changes. It varies on GCP. Um, there's a whole, yeah, that [18:19.840 --> 18:24.660] is a whole world and talk right there on what you can do with metadata services. Excuse me. [18:24.660 --> 18:29.820] So you really want to find these things. But also, if you think Kubernetes, there's also [18:29.820 --> 18:34.620] APIs out there. Metadata service is basically an API. And you want to look for these things. [18:34.620 --> 18:38.700] Also you want to find out what is on your network ranges for your containers. For example, [18:38.700 --> 18:44.320] EC2 classic, still around. If you use EC2 classic, um, and this is from the documentation, [18:44.320 --> 18:49.320] your, all the hosts, every client that uses EC2 classic is all on one big flat network. Yes, I [18:49.320 --> 18:54.360] know. What year is this? Um, so if you are running anything on EC2 classic, your host is [18:54.360 --> 18:59.000] exposed on that 10 range. So, you know, if you're in container environments or any post [18:59.000 --> 19:03.280] exploitation environment, you want to find what APIs or what stuff's available. But if we go [19:03.280 --> 19:08.240] back to the container quirks now, you might not have nmap in the container. You might not [19:08.240 --> 19:13.240] have wget or cull. You might not have the tools that you need to do the um, foot printing [19:13.240 --> 19:20.320] that you want to do. So of course, uh, Bob has a useful feature. So you can tell Bob, go [19:20.320 --> 19:27.080] ahead and uh, look for uh, metadata services if you don't have wget or cull, um, and all [19:27.080 --> 19:33.400] the interesting stuff. So you just add the um, metadata flag and Bob by default will look [19:33.400 --> 19:39.220] for two endpoints, uh, kubernetes control plane endpoints and the 169254. So you can see [19:39.220 --> 19:44.040] now in this point, in this container, those two endpoints weren't there. But now we're [19:44.040 --> 19:49.920] going to tell Bob, use the word list and see if the container can hit heroku.com. Um, and [19:49.920 --> 19:54.040] we're going to specify the endpoint list and then Bob's just going to process that list and [19:54.040 --> 20:00.540] see, okay, can I issue a successful HTTP request to that host? And there we go. We see Bob [20:00.540 --> 20:04.960] says, we got a response from heroku.com and if we look at the return code, it's one. So you [20:04.960 --> 20:08.800] can use this in your CI environments as well. If you want to check what the egress is, you [20:08.800 --> 20:12.760] want to see, okay, I know that my, my kubernetes or my control planes are sitting on these [20:12.760 --> 20:18.300] IPs. Tell Bob to scan those IPs in your prepod or in your production and Bob will tell you, oh, [20:18.300 --> 20:22.800] by the way, I can, I can, I can interact with this endpoint, which I shouldn't. And of [20:22.800 --> 20:28.020] course, when you're on a host and you want to break out or just pwn more stuff, it's pretty [20:28.020 --> 20:33.660] useful when you don't have wget or curl. So there's also binary hijacking. This is awesome [20:33.660 --> 20:37.740] because a lot of orchestration environments explicitly trust the commands that they [20:37.740 --> 20:42.780] provide with. So if you run docker exec on a running container, docker exec doesn't go and [20:42.780 --> 20:48.080] check, am I going to run the legit ls command on the container? It just runs ls. So if you're [20:48.080 --> 20:51.760] in control of that container, you can overwrite the ls command to write your command. And we [20:51.760 --> 20:57.420] can do some pretty cool stuff with that. An example is kubectl or kubectl, there's another [20:57.420 --> 21:03.640] pronunciation. You learn something new in Vegas every year. So with kubectl, it executes the [21:03.640 --> 21:10.320] containers or the, the pods, um, tar command. That was recently exploited and used in an [21:10.320 --> 21:15.400] interesting chain by Twistlock, I highly recommend. But because as an attacker, you had [21:15.400 --> 21:19.500] access to the tar command on the host, you could mess with kubernetes and basically break [21:19.500 --> 21:25.220] out. So, pretty interesting. Important to remember that at some point in a container's [21:25.220 --> 21:29.560] lifetime, a binary might be executed. By binary I mean command. So maybe the power off [21:29.560 --> 21:34.860] command or the IP adder command might be executed in your container. So what do we do? We [21:34.860 --> 21:40.240] hijack all the binaries. So be careful, you can really break stuff here, uh, you're [21:40.240 --> 21:45.320] overwriting binaries. Um, so it's not too friendly for production environments, um, so [21:45.320 --> 21:49.240] I've been told. So, if you want to do this, what do you do? So these are the manual steps. [21:49.240 --> 21:52.620] So you've got to find out if you have read or write permissions to burn or sbin or use [21:52.620 --> 21:56.920] sbin in the container. You want to create a malicious executable that does something. So [21:56.920 --> 22:01.980] either a webhook to verify execution or you want to fuzz something, you can go ahead and do [22:01.980 --> 22:06.640] that. You then want to replace every binary that's in sbin or bin with your malicious [22:06.640 --> 22:14.000] executable and then basically you just, you wait and uh, you can loot some hosts. So, in [22:14.000 --> 22:18.600] terms of payloads, Bob will do this by default. We use webhooks, why? Because sometimes, [22:18.600 --> 22:21.820] you know, if you execute, if you put it in a shell payload and then you set up your [22:21.820 --> 22:26.840] handler and then it could be one minute, it could be 24 hours until you get a callback. [22:27.040 --> 22:31.540] Webhooks are useful because it will, it will confirm exploits ability. In this case, we're [22:31.540 --> 22:35.560] going to say, okay, tell me which command was called and what parameters were sent to it. [22:36.680 --> 22:40.800] That's how you would do it in bash. If you want a Linux host on a container, you, if you [22:40.800 --> 22:45.480] were to write a bash script, that's what it would look like. Um, so how do we actually do [22:45.480 --> 22:49.840] this and what do we get from this? So you could get a callback in one minute or five minute or [22:49.840 --> 22:55.140] next week, it really depends. Um, I've, what I've successfully achieved with this kind of [22:55.140 --> 23:00.020] attack is getting, uh, tokens provided to call commands. So some cloud platforms will say, [23:00.020 --> 23:04.580] okay, this client's running a container, it's been 24 hours, let's back up the content of the [23:04.580 --> 23:08.400] container and let's push it to an S3 bucket. And of course, you know, it's not an open S3 [23:08.400 --> 23:12.000] bucket, they authenticate it as they should. But because they're running the call command [23:12.000 --> 23:17.100] inside my container, I've overwritten the call command and actually calling my command and [23:17.100 --> 23:21.320] then because they're using a token, they have to give the token to the call command that they're [23:21.320 --> 23:25.660] running in my container to back up the contents. So you can find some interesting stuff over [23:25.660 --> 23:30.080] there. You can also prevent logic, so often client environments when you hijack binaries, hijack [23:30.080 --> 23:34.860] the power off command, a lot of orchestrators say, okay, this person has had two hours of [23:34.860 --> 23:39.600] compute, turn off that instance. Okay, cool, but now you've just hijacked the power off [23:39.600 --> 23:43.260] command and that orchestrator thinks that they've executed the actual legit power off [23:43.260 --> 23:48.440] command, but you've hijacked it, so you might get more compute time. And general blockage, you [23:48.440 --> 23:53.860] can really break stuff with this kind of stuff. So hijacking binaries, it's fun. So enough of [23:53.860 --> 24:01.920] me talking, let's actually see this in action. So on the right, we're in a container and [24:01.920 --> 24:07.380] basically I'm telling Bob, go ahead and use the hijack command and I know that text is really [24:07.380 --> 24:12.900] small, I apologize, you can throw stuff at me later about that. But we're telling Bob, [24:12.900 --> 24:19.560] hijack all the binaries in the host, in the container, and execute this command. So Bob is [24:19.560 --> 24:23.660] going to configure the host such that any command that's been hijacked, it's going to [24:23.660 --> 24:27.600] execute a call command and that's going to hit a web end point, which is the logs that you [24:27.600 --> 24:33.420] see over here. So I executed the ID command and you'll see that I got a call back over here. [24:33.420 --> 24:38.540] I was told, so I'm going to say ID hello, and then my logs on my web server say, okay, [24:38.540 --> 24:42.160] someone executed the ID command on the container and they sent the parameters, hello, [24:42.160 --> 24:46.980] y'all. So what does it look like if we were to run maybe docker exec on this running [24:46.980 --> 24:52.760] container? So that's what we're going to do now. So this could be kubectl copy, [24:54.060 --> 24:58.040] execute the talk command, so we're going to run the ID command via docker exec and then [24:58.040 --> 25:02.000] you'll see on the left we just got a call back because we've overwritten, we've hijacked the [25:02.000 --> 25:07.700] ID command. So that gets a lot of fun, that gets pretty interesting. I enjoy doing that, [25:07.700 --> 25:12.420] you'd be surprised as to what you can get. So Bob automates that whole task and it's a lot of [25:12.420 --> 25:18.580] fun. But of course, there's more. What about all the CVs and all the lovely stuff that we [25:18.580 --> 25:24.000] have in docker? Yes, you did just see shell shock and bash bug and you probably like what [25:24.000 --> 25:27.560] year is it? That's actually quite a useful thing to actually look on containers because you'd [25:27.560 --> 25:33.260] be surprised how old some infrastructure is and if you, yeah, in infosec you know people [25:33.260 --> 25:36.540] don't patch things. So that's a good payload to know, especially in container [25:36.540 --> 25:40.160] environments, especially for LXC containers. There's a whole bunch of stuff, that's some [25:40.160 --> 25:47.080] really useful CVs, but one of my recent favorite ones is the run C pwnage that came out [25:47.080 --> 25:53.360] really cool. Basically similar to hijacking binaries but here you are hijacking the run C [25:53.360 --> 25:56.840] binary on the underlying host. That's what the vulnerability allows you to do. So [25:56.840 --> 26:02.200] basically from your container you overwrite the run C binary on the underlying host and [26:02.200 --> 26:06.740] then you run in the context of that and because it's owned by root you run as root. Now this [26:06.740 --> 26:11.700] is slightly destructive, so yeah, I always call this a last resort exploit because you can [26:11.700 --> 26:16.320] actually break the underlying run time because you're breaking the run C binary. For [26:16.320 --> 26:19.340] docker and LXC it gets a bit tricky, sometimes you need to be a privileged container, [26:19.340 --> 26:23.040] sometimes you need root. This is because LXC and docker treat privileged containers very [26:23.040 --> 26:29.080] differently. I won't get into that but it's really interesting. And yeah, what you're [26:29.080 --> 26:32.400] going to do in this case, and Bob is pretty useful, if you want to verify if a host is [26:32.400 --> 26:36.700] exploitable to this because you can't actually trigger your payload being executed. The [26:36.700 --> 26:40.540] payload is only executed in this vulnerability when someone runs a command inside your [26:40.540 --> 26:47.820] container. So if someone's running a kubectl copy or someone's running a docker exec. So you [26:47.820 --> 26:55.700] could wait. So in this case we're going to give a very nice webhook. So we're going to tell [26:55.700 --> 27:03.620] Bob, oh I hate cotton mouth, sorry excuse me. And I should probably play, auto play. If only [27:03.620 --> 27:11.340] someone invented that by now. So we're in a container in the top and we're going to tell Bob [27:11.340 --> 27:16.840] try and exploit CVE blah blah blah blah blah blah blah blah. And the payload that we're [27:16.840 --> 27:23.700] going to give is a curl command so we're going to tell if this successfully is exploited we [27:23.700 --> 27:27.040] should get a call back on our host. So that will be the terminal on the left. So that's our [27:27.040 --> 27:32.880] curl command we're saying execute this. So now we've run the payload. Now you got to wait [27:32.880 --> 27:36.360] with this payload. So now to trigger it I'm going to run a docker exec and that's at the [27:36.360 --> 27:42.940] bottom terminal on that container. So you can't trigger this. And basically I'm going to run [27:42.940 --> 27:46.920] an exec and I'm just going to get a shell. Because you know I want to administer this [27:46.920 --> 27:51.540] container that I'm working from. So I'm going to run bin sh and you'll see Bob will exit at the [27:51.540 --> 27:56.680] top. So it says finished and now we've got a call back in the bottom left. So now that tells [27:56.680 --> 28:01.880] us okay this particular container was vulnerable to that CVE and we now got a call back. So [28:01.880 --> 28:05.940] now you could go ahead and get another container on that platform and then you know give [28:05.940 --> 28:11.740] your shell payload. So pretty useful. If you want to do that exploit manually there is a bit [28:11.740 --> 28:18.720] of work to it. But Bob will take care of that for you. Awesome. Conclusion. Yes and I haven't [28:18.720 --> 28:23.680] had my time cut yet because that always happens. So Bob can be used by both pen testers and [28:23.680 --> 28:29.520] engineers as you can see. I can use it to get shells um or to verify exploits ability. Uh you [28:29.520 --> 28:34.940] can also use it within your SDLC environment so security at scale is really really hard. And [28:35.560 --> 28:40.820] quite an important point here is that we are testing for two kinds of vulnerabilities. [28:41.080 --> 28:46.600] Immediate, so like getting a shell immediately or we are also getting delayed. So remember [28:46.600 --> 28:51.580] the hijacking binaries or the rancy that is delayed. I have ten minutes. Was that ten [28:51.580 --> 28:56.560] minutes Jeff? Awesome. This is like, this never happens. I apologize. Your ears must be, I'm [28:56.560 --> 29:02.100] going really fast as well. Caffeine, I blame that. And of course it being ten o'clock in the [29:02.100 --> 29:07.180] morning. It's like ah get everything out before everyone falls asleep. So you see I digress. [29:07.180 --> 29:11.200] Now I need to come back. Yes Chris what were you saying? Feedback, yes that thing. So you [29:11.200 --> 29:15.380] gonna be able to get feedback on two kinds of vulnerabilities. So if you hijack all the [29:15.380 --> 29:20.980] binaries, you have a web end point, you can get it at some time and also with the rancy stuff. [29:21.400 --> 29:25.800] There are a couple other features that I have not touched on today. So there is some stuff [29:25.800 --> 29:29.100] that like if you are on a host and you want to push stuff to S3 buckets for data exfil, it's [29:29.100 --> 29:34.000] pretty useful. I added that recently to Bob. Um there's also quite a cool way that you can [29:34.000 --> 29:37.860] scrape metadata stuff. So if you know if you've ever gotten access to a metadata services [29:37.860 --> 29:43.060] that's a real pain to get the actual content. There's a nice trick that you can do on GCP [29:43.060 --> 29:48.560] uh legacy metadata services. You just basically connect on port 80 with net cat. Don't send [29:48.560 --> 29:54.160] the host header. Enter, enter and blah. All the metadata stuff is yours. So I built that into [29:54.160 --> 29:59.060] Bob to do it automatically. So yeah there's a couple other things. It's all on the GitHub [29:59.060 --> 30:04.740] repo. So all the documentation is there. Um I haven't gone through all the functionality. [30:04.800 --> 30:10.400] But yeah it's all there. You can find it. Uh all the binary releases are there. And yes I [30:10.400 --> 30:14.680] thank you for your time. It's early Saturday morning. And yeah I'm going to end it there. [30:14.680 --> 30:15.540] Thank you so much. [30:15.960 --> 30:16.260] Audience Applause