1 00:00:00,000 --> 00:00:01,900 But yeah, let's get the show started. 2 00:00:01,940 --> 00:00:03,820 Build to hack, hack to build. 3 00:00:04,300 --> 00:00:04,980 Who am I? 4 00:00:04,980 --> 00:00:06,080 My name is Chris. 5 00:00:06,080 --> 00:00:07,940 I'm a security engineer at Heroku. 6 00:00:08,340 --> 00:00:11,080 We're pretty much remote code execution as a service. 7 00:00:11,080 --> 00:00:14,860 If you don't know what I'm talking about, go look at the platform and you'll see what I mean. 8 00:00:14,940 --> 00:00:16,720 Find me on Twitter, Brompony. 9 00:00:17,000 --> 00:00:18,780 But yeah, I like hacking stuff. 10 00:00:18,780 --> 00:00:19,680 I like building stuff. 11 00:00:19,680 --> 00:00:23,100 I am lazy, so I build stuff that helps me hack stuff quicker. 12 00:00:23,300 --> 00:00:26,760 Whether it's web, Windows, Android, and recently I've been looking at containers. 13 00:00:26,840 --> 00:00:28,080 They're a lot of fun. 14 00:00:28,100 --> 00:00:29,620 So this is what we're gonna look at. 15 00:00:29,680 --> 00:00:31,960 Problem, some existing research. 16 00:00:32,620 --> 00:00:33,920 I'll introduce to you Bob. 17 00:00:33,920 --> 00:00:35,680 So it's Bob with a silent T. 18 00:00:35,860 --> 00:00:38,720 And we'll look at some stuff that Bob can do. 19 00:00:38,760 --> 00:00:43,080 And yeah, this slide's more for me just to actually remind myself what it is that I actually share with you today. 20 00:00:43,080 --> 00:00:45,980 So we might deviate a bit, but I'll try to bring it back in. 21 00:00:46,180 --> 00:00:47,500 So what are the problems? 22 00:00:47,500 --> 00:00:59,160 So in a modern cloud, DevOps, SDLC, Agile environment, there was one big question that I had to ask myself quite often was, how do we identify and exploit container vulnerabilities? 23 00:00:59,400 --> 00:01:06,480 So if you're a pen test, or if you know, you got a shell in a box and you want to break out, you want to pwn some stuff, you know, how do you identify and exploit container vulnerabilities? 24 00:01:06,940 --> 00:01:11,440 But then in an engineering environment, how do we test, secure, and monitor our containers? 25 00:01:11,440 --> 00:01:16,100 So I come from a red teaming consulting background, and I do more engineering. 26 00:01:16,120 --> 00:01:18,120 So I'm constantly trying to break our platform. 27 00:01:18,380 --> 00:01:23,960 And when you've got thousands of containers, and you don't always want to pop shells and stuff, how do you do security at scale? 28 00:01:23,960 --> 00:01:32,660 So these two questions are very much aligned, but they're pretty much asking the same thing, which is how do we basically identify and pwn stuff, and break out of containers? 29 00:01:32,940 --> 00:01:37,000 So in terms of existing research, these are just categories of types of tools. 30 00:01:37,000 --> 00:01:44,460 This list is by no means complete, but if you're in a terminal, you got a shell, and you want to find out if you're in a container , am I contained? 31 00:01:44,700 --> 00:01:49,200 Identify as the SACCOM, CAPS, LXE, or Docker environment that you're in, and it will tell you, very important. 32 00:01:49,320 --> 00:01:51,360 Then there's a whole bunch of Google container tools . 33 00:01:51,360 --> 00:01:53,120 I highly recommend you look at their repo. 34 00:01:53,380 --> 00:01:59,980 Great stuff in terms of static analysis for container images, be it a Docker or an LXE image. 35 00:02:00,020 --> 00:02:04,400 Clay is really good, if you want to look for vulnerabilities in images, it's a really great tool. 36 00:02:04,400 --> 00:02:13,460 And when it comes to benchmarking, Aqua Security has done a lot of good work there, if you actually want to benchmark your images and your security controls that are in place. 37 00:02:13,460 --> 00:02:21,540 Now you'll see that from this list, there's not really much there in terms of actually breaking out and pwning containers. 38 00:02:22,080 --> 00:02:39,080 So, I came up, I had this problem that I experienced, that was the existing research that I had, so generally when I like to solve a problem, I like to just pwn everything if I can, so that's why I did Bob, you can find it on GitHub, it's written in Go, 39 00:02:39,080 --> 00:02:46,340 yeah the hipsters were doing it, so I figured let's see why the hipsters are doing everything in Go, I'm gonna, slightly ironic by my hat and beard, but you know I'm in denial. 40 00:02:48,120 --> 00:02:58,320 So basically like I said, I'm lazy and I just wanted something, you know when you're writing the same exploits over and over again and doing the same breakouts, you know, you kind of want to automate that stuff. 41 00:02:58,320 --> 00:03:05,700 So Bob will give you the ability to auto-pwn, so these kids are gonna love that, sorry I had to say it, but it's definitely a thing. 42 00:03:06,100 --> 00:03:15,380 Also helps you do not only breaking out of containers, but think Linux post exploitation, when there's a lot of things that you want to do when you get into it, you want to automate it, so Bob will help you do that. 43 00:03:15,580 --> 00:03:28,560 And of course you can do all these things in a pentastic kind of way, so if you want shells, you get shells, but if you also want to, you know, help your engineering environment, so set things up with turn codes and plug into your CR environment, Bob's also designed for that, 44 00:03:28,560 --> 00:03:30,180 and I'll show you what I mean by that. 45 00:03:30,300 --> 00:03:33,600 So that's Bob, like I said we're gonna be pwning stuff. 46 00:03:33,800 --> 00:03:46,480 When you're pwning containers, the hollow world of pwning containers is exploiting docker.sock, it's a Unix domain socket that docker uses to orchestrate basically containers, if that thing is ever exposed, you find it, it is game overs. 47 00:03:46,660 --> 00:03:57,940 So basically it comes from people wanting to use docker within docker, don't do that, use that, there's better ways to do it originally, but basically this allowed us to do a local privilege to root and basically break out of the container. 48 00:03:58,000 --> 00:04:01,180 It's a really fun, you know, way to get into container exploitation. 49 00:04:01,320 --> 00:04:02,080 So how do you do it? 50 00:04:02,080 --> 00:04:03,340 What are the manual steps? 51 00:04:03,340 --> 00:04:10,580 So first you gotta find docker.sock, so it's a Unix domain socket, it's speaking HTTP, it's basically a RESTful API on a domain socket. 52 00:04:10,620 --> 00:04:15,340 Then you want to interact with the socket with curl or a docker client or netcat. 53 00:04:15,860 --> 00:04:25,200 Once you find it and you can interact with it, you then want to create a new container and mount the hosts up, uh, file system in your container with the dash v command. 54 00:04:25,200 --> 00:04:32,940 Then run that new container and then use chroot or chroot or troot as I found this week, there are multiple pronunciations for that. 55 00:04:33,120 --> 00:04:34,540 Um, and there you go. 56 00:04:34,540 --> 00:04:38,700 You are then pretty much root on the host and you have access to the host file system. 57 00:04:38,700 --> 00:04:43,740 And now you know if it's Linux and you access the file system, everything's a file, it's game overs. 58 00:04:43,760 --> 00:04:45,420 So that's the manual step. 59 00:04:45,420 --> 00:04:47,340 Now you don't want to do that all the time. 60 00:04:48,140 --> 00:04:48,980 Excuse me. 61 00:04:48,980 --> 00:04:51,660 But now things get a little bit tricky in containers. 62 00:04:52,040 --> 00:04:58,880 Because when you're living off the land, especially in containers, the commands that you need, for example the found command, might not be in the container. 63 00:04:58,880 --> 00:05:05,720 So if you're using really minimal images like the docker image or the alpine image, that's the thing, you might not have the tools to actually do the stuff that you need to do. 64 00:05:05,720 --> 00:05:08,340 Like what if there's no ifconfig or ipadder. 65 00:05:08,340 --> 00:05:11,920 Sure you can read from procfs but this stuff can slow you down. 66 00:05:12,360 --> 00:05:14,980 Especially if you need to find docker, uh, the docker socket. 67 00:05:14,980 --> 00:05:19,120 It's not always at var on docker.sock, it could be at mu slash bob. 68 00:05:19,280 --> 00:05:23,220 If you don't have the found command, you don't have recursive searches, how are you actually going to find the socket? 69 00:05:23,680 --> 00:05:25,400 So this is where syscalls come in. 70 00:05:25,400 --> 00:05:28,780 So on the left there, those are the syscalls that the found command makes use of. 71 00:05:28,940 --> 00:05:33,280 And on the right there, that's what bob does in go code to do pretty much the found command. 72 00:05:33,280 --> 00:05:38,980 The nice thing about go is that when you start interacting uh, uh, with the operating system, go makes use of syscalls. 73 00:05:38,980 --> 00:05:41,280 It won't actually make use of actual shell commands. 74 00:05:41,280 --> 00:05:42,620 Some languages do that. 75 00:05:42,620 --> 00:05:49,520 So nice thing is, is that if the command isn't there, you can use the syscalls and the syscalls will be there to allow you to perform the actions that you want to do. 76 00:05:49,540 --> 00:05:51,860 So that, that's what we do with bob. 77 00:05:51,880 --> 00:05:53,660 And I'm going to show you a demo now. 78 00:05:54,260 --> 00:05:56,640 Um, these are pre-recorded. 79 00:05:56,880 --> 00:06:00,680 I'm done doing live demos because I just ran out of sacrifices all the time. 80 00:06:01,100 --> 00:06:08,240 Um, so what we're going to do here is, um, at the bottom terminal, so I know it's a little bit small, but basically that's our host. 81 00:06:08,240 --> 00:06:10,920 And we're just going to watch a directory on the host. 82 00:06:11,240 --> 00:06:13,820 Um, so you see there's one file called bob linux. 83 00:06:13,820 --> 00:06:16,500 In the top, we're going to run in, in a container. 84 00:06:16,580 --> 00:06:19,620 So we're just saying a docker run and then we're mounting a socket. 85 00:06:20,580 --> 00:06:21,940 Turn off the light. 86 00:06:23,360 --> 00:06:25,980 Yeah, unfortunately that's, can we turn the lights down? 87 00:06:25,980 --> 00:06:26,540 Can we? 88 00:06:26,540 --> 00:06:27,020 No. 89 00:06:27,020 --> 00:06:27,660 Yes. 90 00:06:28,660 --> 00:06:29,380 Yeah. 91 00:06:29,680 --> 00:06:33,040 Unfortunately I can't make it bigger because the resolution will go off the board. 92 00:06:34,060 --> 00:06:36,000 We can just break the lights. 93 00:06:37,440 --> 00:06:38,300 Ah. 94 00:06:39,520 --> 00:06:40,400 Ooh. 95 00:06:42,520 --> 00:06:46,240 A room full of hackers and you just turn the lights on and you get that reaction. 96 00:06:48,900 --> 00:06:49,900 It's magic. 97 00:06:52,200 --> 00:06:55,200 So we're in a container now and we're going to run bob. 98 00:06:55,860 --> 00:06:59,440 And you know, if you're inside a container, you want to find socket. 99 00:06:59,440 --> 00:07:01,280 So we're just saying dash socket equals true. 100 00:07:01,280 --> 00:07:05,200 And now what Bob's going to do is going to go and look for all the Unix domain sockets. 101 00:07:05,200 --> 00:07:07,040 Now you found a Unix domain socket. 102 00:07:07,040 --> 00:07:07,320 What now? 103 00:07:07,320 --> 00:07:08,140 What do you do? 104 00:07:08,160 --> 00:07:10,620 So of course you want to auto-pwn this stuff. 105 00:07:10,620 --> 00:07:14,220 So I'm now providing dash auto-pwn equals true. 106 00:07:14,360 --> 00:07:18,920 And what Bob's now going to do is it's going to look for the domain sockets that it can find. 107 00:07:18,920 --> 00:07:21,180 And it's going to try and pop it basically. 108 00:07:21,180 --> 00:07:23,980 And what you'll see now, Bob is now giving me a TTY. 109 00:07:24,260 --> 00:07:27,240 So this terminal that I'm in now is not actually a terminal on the host. 110 00:07:27,240 --> 00:07:29,600 You'll see that that's a OSX host there. 111 00:07:29,640 --> 00:07:37,060 And I'm now going to create a file inside a temp folder and that file is now going to appear at the bottom terminal which is on our host. 112 00:07:37,900 --> 00:07:40,220 And we'll see that appear in a bit. 113 00:07:40,220 --> 00:07:42,960 So now I'm in a TTY that Bob has provided me. 114 00:07:43,020 --> 00:07:45,980 And you'll see that file has now appeared on the underlying host. 115 00:07:45,980 --> 00:07:47,680 And within the container. 116 00:07:47,680 --> 00:07:51,920 Now once you're done with that, you can now exit Bob and now you're back into your container's terminal. 117 00:07:52,080 --> 00:08:01,800 So that's one way that, you know, instead of doing those steps that I mentioned earlier, you can just basically say auto-pwn and boom, your root on the host. 118 00:08:01,800 --> 00:08:06,480 Of course if the docker socket is not authenticated or protected, often it's not. 119 00:08:06,500 --> 00:08:09,920 So automatically just auto-pwn all that stuff. 120 00:08:10,020 --> 00:08:11,860 So it's quite nice to get a TTY on the host. 121 00:08:11,860 --> 00:08:14,560 If you want think pen test, you want to get a shell on the host. 122 00:08:14,760 --> 00:08:25,740 Also, if you want to test maybe in your CI environment, if there are exploitable sockets in your pre-production staging environment, you can tell Bob to do this and we'll make use of return codes. 123 00:08:26,180 --> 00:08:31,940 So what we'll do here is we have a CI environment and we're going to run the same thing. 124 00:08:31,940 --> 00:08:40,740 So what's happening over here in the top right, I've configured my CI environment to run Bob and I've provided the auto-pwn but you'll see that I've added the CRCD equals true flag. 125 00:08:40,740 --> 00:08:48,080 So what that means is, don't drop into a shell, but if you successfully exploit that vulnerability, set the return code greater than zero. 126 00:08:48,080 --> 00:08:54,540 Because if you're familiar with CI environments, fail tests are marked as any test that has a return code greater than zero. 127 00:08:54,540 --> 00:08:59,880 So if your CI environment runs a command, a test, and the return code is greater than zero, the test has failed. 128 00:08:59,880 --> 00:09:01,000 So Bob will do that. 129 00:09:01,000 --> 00:09:03,940 So this is very useful for engineers and for CI environments. 130 00:09:04,120 --> 00:09:17,620 And if you look on the left, the test is running and we'll see that Bob picks up a couple of Unix domain sockets, but because they're not exploitable, they're not docker sockets, you'll see Bob's found them, the test will actually pass. 131 00:09:17,800 --> 00:09:23,360 So this is quite a nice thing that you can do if, you know, it doesn't make sense to try to get a shell now. 132 00:09:23,500 --> 00:09:30,400 Like if you're doing thousands of, uh, push, uh, push requests, pull requests a day, you know, you're not going to want shells in this context. 133 00:09:30,500 --> 00:09:35,240 But from an engineering environment, you want to test, you know, are there exposed docker sockets? 134 00:09:35,240 --> 00:09:36,680 Is this thing pwnable? 135 00:09:36,760 --> 00:09:45,900 So you don't want your engineers focusing on understanding, okay, now I've got a, you know, exploit docker sockets, like, you know, just run it automagically and then you can find out if that's the case. 136 00:09:45,900 --> 00:09:48,040 So it's very useful in CI environments. 137 00:09:48,320 --> 00:09:52,260 But of course, there's more to pwn, there's more to will than docker sockets. 138 00:09:52,400 --> 00:09:54,000 It's called privileged containers. 139 00:09:54,000 --> 00:09:56,720 Anybody raise a hand, privileged container in here? 140 00:09:56,980 --> 00:09:57,620 Cool. 141 00:09:57,640 --> 00:10:04,500 So thank you for putting your hand up, but it's worse when you're at a talk and someone's like, can you please put your hand up if you have, you know, seen X or A or B or C. 142 00:10:04,620 --> 00:10:05,680 It's always the worst. 143 00:10:05,680 --> 00:10:10,660 But, um, privileged containers are pretty much the worst thing in the world of containers. 144 00:10:10,660 --> 00:10:11,060 Why? 145 00:10:12,860 --> 00:10:14,180 Cue awkward silence. 146 00:10:14,700 --> 00:10:19,660 The case for that is, I know, I just try to hide behind comedy and it's always an epic fail. 147 00:10:19,920 --> 00:10:25,880 So privileged containers are basically a, a, a, I was going to say another word there, but it's not a good thing. 148 00:10:26,040 --> 00:10:30,820 Um, and it's very dangerous when it comes to your syscalls that you have access to and the Linux capabilities. 149 00:10:31,040 --> 00:10:34,840 And this basically means very, very easy container escapes. 150 00:10:34,840 --> 00:10:38,180 But now you're in a privileged container, how do you break out? 151 00:10:38,180 --> 00:10:41,120 So, I'm going to show you a new feature that I released this week. 152 00:10:41,120 --> 00:10:48,220 Um, what this does is Bob makes use of C group controllers and we're inside a privileged container. 153 00:10:48,320 --> 00:10:53,300 And what we're going to do is we're going to abuse the C group Linux release agent, uh, capability. 154 00:10:53,740 --> 00:10:58,000 And what that means is that we're going to get command execution on the underlying host. 155 00:10:58,000 --> 00:11:07,180 This is how C groups work because we have access to the mount syscall and also because the Linux capability sysadmin has not been dropped, we can abuse that. 156 00:11:07,180 --> 00:11:13,200 So basically we mount the RDMA C group controller, we then kill off a process and then basically we get command execution. 157 00:11:13,320 --> 00:11:17,400 So you'll see now I'm using the pwn group, uh, host, uh, command. 158 00:11:17,400 --> 00:11:21,880 I'm saying hostname and I've got a hostname of, uh, docker desktop. 159 00:11:21,880 --> 00:11:24,180 So now I'm getting command execution, blah, blah, blah. 160 00:11:24,180 --> 00:11:24,700 Fun stuff. 161 00:11:24,700 --> 00:11:25,700 Let's get a shell. 162 00:11:25,700 --> 00:11:29,440 So at the bottom, I'm on my jump box, standard Netcat listener. 163 00:11:29,480 --> 00:11:38,820 The great thing, if you're using Dockon OS X, be aware that your VMs, uh, your containers are running in a Linux kit VM. 164 00:11:38,900 --> 00:11:45,540 That VM by default comes with Netcat enabled, of course, because it's got busy box, but of course it's got the dash E flag is enabled. 165 00:11:45,580 --> 00:11:46,300 The evil command. 166 00:11:46,300 --> 00:11:48,780 You do not want Netcat on your boxes with that. 167 00:11:48,800 --> 00:11:52,340 So it makes getting shells really easy. 168 00:11:52,360 --> 00:12:05,840 So we're gonna tell it, Bob, pwn the C group, so we're in the container, run this Netcat command, connect back to our jump box, and what's gonna happen is that we're gonna get a shell on the underlying host which happens to be the Linux kit VM. 169 00:12:06,100 --> 00:12:09,660 And in an OS X environment, that's basically game overs. 170 00:12:09,760 --> 00:12:12,600 So, cause we're running in a privileged container, this is really easy. 171 00:12:12,600 --> 00:12:14,740 Trail of bits did a great write up on this. 172 00:12:14,740 --> 00:12:17,920 Uh, C group , uh, pwnage, um, it's really interesting. 173 00:12:17,920 --> 00:12:22,020 And you'll see now we've got a shell at the bottom , and you'll see we're on a host called Docker desktops. 174 00:12:22,020 --> 00:12:26,440 If you see that host name, that is the VM that, uh, Docker for OS X uses. 175 00:12:26,480 --> 00:12:28,480 And now we're in the host file system. 176 00:12:28,500 --> 00:12:37,520 And if you ever want to find out where your container is living on the underlying host, look at the mount command, and if you look there, you'll see var lib docker overlay 2. 177 00:12:37,620 --> 00:12:39,260 That's where your container is living. 178 00:12:39,420 --> 00:12:50,240 And what I'm actually gonna do now is I'm gonna create a file in the Linux kit VM, and you'll see that it'll appear inside my container. 179 00:12:50,240 --> 00:13:00,040 So I'm in a container, and you'll see the OS does not like it, because there's some Docker weirdness, but you can see hello is over here, and we created it on our jump box. 180 00:13:00,040 --> 00:13:05,640 So basically, pwning C group, you break out of the container, and you basically root on underlying host. 181 00:13:05,640 --> 00:13:12,320 If you're running something on a Debian system, it's running bare metal, you'll end up actually being root on the host. 182 00:13:12,320 --> 00:13:19,800 So of course, if you added the CRCD flag to Bob with this, uh, it would exploit this, but then set the return code. 183 00:13:19,900 --> 00:13:22,980 So you wouldn't be getting shells, we can just execute a command that you want. 184 00:13:22,980 --> 00:13:26,380 So pretty useful, privileged containers, um, they are out there. 185 00:13:26,380 --> 00:13:35,560 But when it comes to containers, um, there's also environment variables, very, very good place to look when you wanna pwn containers, you'd be surprised what's in environment variables. 186 00:13:35,560 --> 00:13:39,000 So there's good old env, if you type that in the terminal, that's what you'll get. 187 00:13:39,000 --> 00:13:41,020 But there's also the procfs in Linux. 188 00:13:41,140 --> 00:13:45,420 Procfs, it, it, it, it's given me a lot of this hair loss that you see over here today. 189 00:13:45,600 --> 00:13:52,920 Um, but basically if you read proc and then the PID of the process environment, you'll get access to the environment variables that have been set for that process. 190 00:13:52,920 --> 00:13:59,760 Now this gets interesting, because env is not always cleared, and things might be living in proc PID. 191 00:13:59,760 --> 00:14:02,380 And this is when, uh, ephemerality becomes a problem. 192 00:14:02,380 --> 00:14:12,880 So you might do like a PS orcs and see, okay, there's a process with PID 99, you go read proc 99 in Viron, there'll be, there might be nothing there because the process is dead. 193 00:14:12,880 --> 00:14:14,900 So you gotta be really quick when you're doing this. 194 00:14:15,020 --> 00:14:24,780 Bob does this really quickly via OS and Viron, and Bob will go ahead and check the env, OS.env, so like typing env in your terminal, and go in the procfs and analyze it. 195 00:14:24,780 --> 00:14:32,000 Because sometimes there's the case where the env in your terminal's been cleared, but the proc in Viron, uh, mapping has not been cleared. 196 00:14:32,020 --> 00:14:39,260 So sometimes you can find a whole bunch of stuff, because of course, you know, environment variables, it's, you know, the next gen, uh, secret storage, uh, mechanism. 197 00:14:39,880 --> 00:14:44,780 So that's pretty much what the Go code looks like if you want to process procfs. 198 00:14:44,840 --> 00:14:46,480 It's really nice and minimal. 199 00:14:46,560 --> 00:14:50,400 Um, I'm a big fan of Go, um, as you can probably hear or see. 200 00:14:50,400 --> 00:14:51,940 But how do we actually go about doing this? 201 00:14:51,940 --> 00:14:57,660 So we're gonna run a container, and I should probably press play, that's a good place to start. 202 00:14:57,760 --> 00:15:00,700 And we're gonna add in an environment variable. 203 00:15:00,700 --> 00:15:03,680 So it's called touch of approval and super secret password. 204 00:15:04,020 --> 00:15:13,600 So what Bob will do by default, if you do the recon flag, if you don't pass a word list, Bob will look for password and secret. 205 00:15:14,000 --> 00:15:25,700 And you can see now Bob has said, okay, we've now found these PIDs that have this, uh, key term in proc in Viron, and Bob will then look for the process that it exists in. 206 00:15:26,020 --> 00:15:27,360 And that's by default. 207 00:15:27,360 --> 00:15:31,060 But what you can also do with Bob is you can also supply a word list. 208 00:15:31,060 --> 00:15:40,780 So you can tell Bob, you know what, analyze all the processes that you have access to and use the, use for, uh, look for these words in this word list. 209 00:15:40,920 --> 00:15:51,280 So we're gonna provide a word list now, and inside that word list were the terms password, YOLO, secret, find me, and Bob went ahead and looked at ENV and in all the processes inside there. 210 00:15:51,280 --> 00:15:54,760 Now, this is where, uh, return codes also happen. 211 00:15:54,760 --> 00:16:01,020 So if Bob has found a keyword in a process environment that you're looking for, the return code will be greater than zero. 212 00:16:01,060 --> 00:16:02,780 That's what I'm gonna show you now. 213 00:16:02,780 --> 00:16:05,620 So now you're gonna use a word list where there's nothing inside. 214 00:16:05,620 --> 00:16:10,420 And you can see Bob didn't find any of the entries inside the word list, inside any of the processes. 215 00:16:10,420 --> 00:16:16,220 And then you'll see the return code now will be zero because Bob didn't find any of those key terms. 216 00:16:16,460 --> 00:16:19,560 So that's all fine and dandy. 217 00:16:20,220 --> 00:16:22,520 How do we also do this in a CI environment? 218 00:16:22,540 --> 00:16:29,900 So you definitely want to scan your environment variables in your pre-production or production environments because you never know what's gonna be lingering there. 219 00:16:30,000 --> 00:16:35,500 So in this case, and these configs are all the same on the, uh, CI environments that you're using. 220 00:16:35,500 --> 00:16:38,360 So we're using a shell script here and we're gonna be running two Bob commands. 221 00:16:38,360 --> 00:16:40,520 So we're gonna be doing the socket auto-po. 222 00:16:40,520 --> 00:16:45,180 So we're gonna try to see if we have any vulnerable sockets and we're gonna be scanning our environment variables. 223 00:16:45,360 --> 00:16:51,560 And Bob will go ahead and do that on every git push and every pull request or however you've configured your CI environments. 224 00:16:52,120 --> 00:16:56,520 So let me just fast forward this. 225 00:16:56,640 --> 00:17:02,140 This is, in true Chris fashion, I made too much content for what I have. 226 00:17:02,140 --> 00:17:04,900 So I'm like, let's get to the really cool fun stuff. 227 00:17:05,340 --> 00:17:08,560 And of course you can't double up speed with the videos that I make. 228 00:17:08,560 --> 00:17:10,380 I'm just challenged in that way. 229 00:17:10,660 --> 00:17:14,100 So in every CI environment, Bob is gonna look for these key terms. 230 00:17:14,100 --> 00:17:15,280 It is regex as well. 231 00:17:15,280 --> 00:17:19,020 So you can say, okay, look for S3 tokens or whatever. 232 00:17:19,020 --> 00:17:20,180 It's, it's regex. 233 00:17:20,300 --> 00:17:22,260 Um, the world will definitely burn at some point. 234 00:17:22,420 --> 00:17:25,000 So we can see Bob has gone ahead and run those two commands. 235 00:17:25,200 --> 00:17:31,660 And the test will pass because from the previous tests, we know that there are no exploitable docker sockets. 236 00:17:32,080 --> 00:17:37,880 And in the container that we are running, now remember in our, in this CI environment, all our tests are running in containers. 237 00:17:37,880 --> 00:17:38,820 That's how we configured it. 238 00:17:38,820 --> 00:17:43,420 And now we know great stuff that test passed our containers in pre-production. 239 00:17:43,420 --> 00:17:45,680 Do not have exploitable docker sockets. 240 00:17:45,780 --> 00:17:50,280 And the environment variables that are there do not have any of the key terms that we specified. 241 00:17:50,940 --> 00:17:54,280 But of course, clouds, uh, clouds, yeah. 242 00:17:54,400 --> 00:17:56,520 Clouds love to host containers. 243 00:17:56,640 --> 00:17:59,400 Um, and of course we've got metadata services. 244 00:17:59,480 --> 00:18:05,120 So the 169254 address, it exists in GCP or AWS, Azure. 245 00:18:05,260 --> 00:18:07,900 And basically if you can get access to this, you can do a whole bunch of stuff. 246 00:18:07,900 --> 00:18:09,480 It depends on the platform. 247 00:18:09,480 --> 00:18:15,720 So for example, that call request in AWS, if there's an IAM role associated to the instance, you get the credentials for that. 248 00:18:15,800 --> 00:18:16,720 It'll, it changes. 249 00:18:16,720 --> 00:18:18,120 It varies on GCP. 250 00:18:18,320 --> 00:18:23,520 Um, there's a whole, yeah, that is a whole world and talk right there on what you can do with metadata services. 251 00:18:23,900 --> 00:18:24,660 Excuse me. 252 00:18:24,660 --> 00:18:26,940 So you really want to find these things. 253 00:18:26,940 --> 00:18:30,800 But also, if you think Kubernetes, there's also APIs out there. 254 00:18:30,800 --> 00:18:32,840 Metadata service is basically an API. 255 00:18:33,060 --> 00:18:34,620 And you want to look for these things. 256 00:18:34,620 --> 00:18:37,780 Also you want to find out what is on your network ranges for your containers. 257 00:18:37,860 --> 00:18:40,780 For example, EC2 classic, still around. 258 00:18:40,780 --> 00:18:48,840 If you use EC2 classic, um, and this is from the documentation, your, all the hosts, every client that uses EC2 classic is all on one big flat network. 259 00:18:49,000 --> 00:18:49,660 Yes, I know. 260 00:18:49,660 --> 00:18:50,840 What year is this? 261 00:18:50,900 --> 00:18:56,480 Um, so if you are running anything on EC2 classic, your host is exposed on that 10 range. 262 00:18:56,480 --> 00:19:02,400 So, you know, if you're in container environments or any post exploitation environment, you want to find what APIs or what stuff's available. 263 00:19:02,500 --> 00:19:07,760 But if we go back to the container quirks now, you might not have nmap in the container. 264 00:19:07,760 --> 00:19:09,300 You might not have wget or cull. 265 00:19:09,300 --> 00:19:14,100 You might not have the tools that you need to do the um, foot printing that you want to do. 266 00:19:14,100 --> 00:19:18,780 So of course, uh, Bob has a useful feature. 267 00:19:18,780 --> 00:19:28,340 So you can tell Bob, go ahead and uh, look for uh, metadata services if you don't have wget or cull, um, and all the interesting stuff. 268 00:19:28,340 --> 00:19:38,620 So you just add the um, metadata flag and Bob by default will look for two endpoints, uh, kubernetes control plane endpoints and the 169254. 269 00:19:38,640 --> 00:19:43,540 So you can see now in this point, in this container, those two endpoints weren't there. 270 00:19:43,540 --> 00:19:49,040 But now we're going to tell Bob, use the word list and see if the container can hit heroku.com. 271 00:19:49,060 --> 00:19:58,720 Um, and we're going to specify the endpoint list and then Bob's just going to process that list and see, okay, can I issue a successful HTTP request to that host? 272 00:19:58,720 --> 00:19:59,460 And there we go. 273 00:19:59,460 --> 00:20:04,680 We see Bob says, we got a response from heroku.com and if we look at the return code, it's one. 274 00:20:04,700 --> 00:20:07,000 So you can use this in your CI environments as well. 275 00:20:07,000 --> 00:20:13,640 If you want to check what the egress is, you want to see, okay, I know that my, my kubernetes or my control planes are sitting on these IPs. 276 00:20:14,340 --> 00:20:22,200 Tell Bob to scan those IPs in your prepod or in your production and Bob will tell you, oh, by the way, I can, I can, I can interact with this endpoint, which I shouldn't. 277 00:20:22,420 --> 00:20:30,620 And of course, when you're on a host and you want to break out or just pwn more stuff, it's pretty useful when you don't have wget or curl. 278 00:20:30,840 --> 00:20:32,980 So there's also binary hijacking. 279 00:20:32,980 --> 00:20:38,600 This is awesome because a lot of orchestration environments explicitly trust the commands that they provide with. 280 00:20:38,600 --> 00:20:46,440 So if you run docker exec on a running container, docker exec doesn't go and check, am I going to run the legit ls command on the container? 281 00:20:46,440 --> 00:20:47,620 It just runs ls. 282 00:20:47,620 --> 00:20:51,540 So if you're in control of that container, you can overwrite the ls command to write your command. 283 00:20:51,540 --> 00:20:53,520 And we can do some pretty cool stuff with that. 284 00:20:54,200 --> 00:20:58,380 An example is kubectl or kubectl, there's another pronunciation. 285 00:20:58,560 --> 00:21:00,560 You learn something new in Vegas every year. 286 00:21:00,560 --> 00:21:07,060 So with kubectl, it executes the containers or the, the pods, um, tar command. 287 00:21:07,060 --> 00:21:13,080 That was recently exploited and used in an interesting chain by Twistlock, I highly recommend. 288 00:21:13,080 --> 00:21:19,940 But because as an attacker, you had access to the tar command on the host, you could mess with kubernetes and basically break out. 289 00:21:19,940 --> 00:21:22,080 So, pretty interesting. 290 00:21:22,440 --> 00:21:27,540 Important to remember that at some point in a container's lifetime, a binary might be executed. 291 00:21:27,540 --> 00:21:28,600 By binary I mean command. 292 00:21:28,600 --> 00:21:33,600 So maybe the power off command or the IP adder command might be executed in your container. 293 00:21:33,600 --> 00:21:34,620 So what do we do? 294 00:21:34,660 --> 00:21:36,380 We hijack all the binaries. 295 00:21:36,920 --> 00:21:42,280 So be careful, you can really break stuff here, uh, you're overwriting binaries. 296 00:21:42,460 --> 00:21:46,060 Um, so it's not too friendly for production environments, um, so I've been told. 297 00:21:46,400 --> 00:21:48,180 So, if you want to do this, what do you do? 298 00:21:48,180 --> 00:21:49,240 So these are the manual steps. 299 00:21:49,240 --> 00:21:54,160 So you've got to find out if you have read or write permissions to burn or sbin or use sbin in the container. 300 00:21:54,280 --> 00:21:56,800 You want to create a malicious executable that does something. 301 00:21:56,800 --> 00:22:02,460 So either a webhook to verify execution or you want to fuzz something, you can go ahead and do that. 302 00:22:02,460 --> 00:22:12,460 You then want to replace every binary that's in sbin or bin with your malicious executable and then basically you just, you wait and uh, you can loot some hosts. 303 00:22:12,980 --> 00:22:16,300 So, in terms of payloads, Bob will do this by default. 304 00:22:16,360 --> 00:22:17,680 We use webhooks, why? 305 00:22:17,680 --> 00:22:26,840 Because sometimes, you know, if you execute, if you put it in a shell payload and then you set up your handler and then it could be one minute, it could be 24 hours until you get a callback. 306 00:22:27,040 --> 00:22:30,580 Webhooks are useful because it will, it will confirm exploits ability. 307 00:22:30,740 --> 00:22:35,560 In this case, we're going to say, okay, tell me which command was called and what parameters were sent to it. 308 00:22:36,680 --> 00:22:37,980 That's how you would do it in bash. 309 00:22:37,980 --> 00:22:43,040 If you want a Linux host on a container, you, if you were to write a bash script, that's what it would look like. 310 00:22:43,380 --> 00:22:46,640 Um, so how do we actually do this and what do we get from this? 311 00:22:46,640 --> 00:22:51,780 So you could get a callback in one minute or five minute or next week, it really depends. 312 00:22:52,060 --> 00:22:58,520 Um, I've, what I've successfully achieved with this kind of attack is getting, uh, tokens provided to call commands. 313 00:22:58,520 --> 00:23:06,640 So some cloud platforms will say, okay, this client's running a container, it's been 24 hours, let's back up the content of the container and let's push it to an S3 bucket. 314 00:23:06,640 --> 00:23:10,340 And of course, you know, it's not an open S3 bucket, they authenticate it as they should. 315 00:23:10,340 --> 00:23:23,660 But because they're running the call command inside my container, I've overwritten the call command and actually calling my command and then because they're using a token, they have to give the token to the call command that they're running in my container to back up the contents. 316 00:23:23,660 --> 00:23:26,300 So you can find some interesting stuff over there. 317 00:23:26,380 --> 00:23:37,520 You can also prevent logic, so often client environments when you hijack binaries, hijack the power off command, a lot of orchestrators say, okay, this person has had two hours of compute, turn off that instance. 318 00:23:37,800 --> 00:23:47,140 Okay, cool, but now you've just hijacked the power off command and that orchestrator thinks that they've executed the actual legit power off command, but you've hijacked it, so you might get more compute time. 319 00:23:47,520 --> 00:23:50,440 And general blockage, you can really break stuff with this kind of stuff. 320 00:23:50,440 --> 00:23:52,460 So hijacking binaries, it's fun. 321 00:23:52,800 --> 00:23:56,300 So enough of me talking, let's actually see this in action. 322 00:23:58,580 --> 00:24:10,460 So on the right, we're in a container and basically I'm telling Bob, go ahead and use the hijack command and I know that text is really small, I apologize, you can throw stuff at me later about that. 323 00:24:10,980 --> 00:24:18,580 But we're telling Bob, hijack all the binaries in the host, in the container, and execute this command. 324 00:24:18,580 --> 00:24:28,700 So Bob is going to configure the host such that any command that's been hijacked, it's going to execute a call command and that's going to hit a web end point, which is the logs that you see over here. 325 00:24:28,700 --> 00:24:33,420 So I executed the ID command and you'll see that I got a call back over here. 326 00:24:33,420 --> 00:24:42,760 I was told, so I'm going to say ID hello, and then my logs on my web server say, okay, someone executed the ID command on the container and they sent the parameters, hello, y'all. 327 00:24:43,260 --> 00:24:47,880 So what does it look like if we were to run maybe docker exec on this running container? 328 00:24:48,360 --> 00:24:50,220 So that's what we're going to do now. 329 00:24:50,560 --> 00:25:03,020 So this could be kubectl copy, execute the talk command, so we're going to run the ID command via docker exec and then you'll see on the left we just got a call back because we've overwritten, we've hijacked the ID command. 330 00:25:03,220 --> 00:25:06,720 So that gets a lot of fun, that gets pretty interesting. 331 00:25:06,720 --> 00:25:10,460 I enjoy doing that, you'd be surprised as to what you can get. 332 00:25:10,520 --> 00:25:13,080 So Bob automates that whole task and it's a lot of fun. 333 00:25:13,180 --> 00:25:14,800 But of course, there's more. 334 00:25:15,440 --> 00:25:19,280 What about all the CVs and all the lovely stuff that we have in docker? 335 00:25:19,280 --> 00:25:24,960 Yes, you did just see shell shock and bash bug and you probably like what year is it? 336 00:25:24,980 --> 00:25:34,400 That's actually quite a useful thing to actually look on containers because you'd be surprised how old some infrastructure is and if you, yeah, in infosec you know people don't patch things. 337 00:25:34,400 --> 00:25:38,680 So that's a good payload to know, especially in container environments, especially for LXC containers. 338 00:25:38,680 --> 00:25:48,180 There's a whole bunch of stuff, that's some really useful CVs, but one of my recent favorite ones is the run C pwnage that came out really cool. 339 00:25:48,500 --> 00:25:54,940 Basically similar to hijacking binaries but here you are hijacking the run C binary on the underlying host. 340 00:25:54,940 --> 00:25:56,740 That's what the vulnerability allows you to do. 341 00:25:56,740 --> 00:26:06,380 So basically from your container you overwrite the run C binary on the underlying host and then you run in the context of that and because it's owned by root you run as root. 342 00:26:06,460 --> 00:26:15,220 Now this is slightly destructive, so yeah, I always call this a last resort exploit because you can actually break the underlying run time because you're breaking the run C binary. 343 00:26:16,160 --> 00:26:20,320 For docker and LXC it gets a bit tricky, sometimes you need to be a privileged container, sometimes you need root. 344 00:26:20,320 --> 00:26:23,640 This is because LXC and docker treat privileged containers very differently. 345 00:26:23,640 --> 00:26:25,860 I won't get into that but it's really interesting. 346 00:26:26,200 --> 00:26:36,620 And yeah, what you're going to do in this case, and Bob is pretty useful, if you want to verify if a host is exploitable to this because you can't actually trigger your payload being executed. 347 00:26:36,620 --> 00:26:41,260 The payload is only executed in this vulnerability when someone runs a command inside your container. 348 00:26:41,260 --> 00:26:47,520 So if someone's running a kubectl copy or someone's running a docker exec. 349 00:26:47,540 --> 00:26:48,760 So you could wait. 350 00:26:48,780 --> 00:26:53,480 So in this case we're going to give a very nice webhook. 351 00:26:54,780 --> 00:26:59,960 So we're going to tell Bob, oh I hate cotton mouth, sorry excuse me. 352 00:27:00,520 --> 00:27:03,400 And I should probably play, auto play. 353 00:27:03,400 --> 00:27:05,420 If only someone invented that by now. 354 00:27:07,600 --> 00:27:15,080 So we're in a container in the top and we're going to tell Bob try and exploit CVE blah blah blah blah blah blah blah blah. 355 00:27:15,540 --> 00:27:25,140 And the payload that we're going to give is a curl command so we're going to tell if this successfully is exploited we should get a call back on our host. 356 00:27:25,140 --> 00:27:26,540 So that will be the terminal on the left. 357 00:27:26,640 --> 00:27:30,100 So that's our curl command we're saying execute this. 358 00:27:30,100 --> 00:27:31,380 So now we've run the payload. 359 00:27:31,940 --> 00:27:33,460 Now you got to wait with this payload. 360 00:27:33,460 --> 00:27:38,000 So now to trigger it I'm going to run a docker exec and that's at the bottom terminal on that container. 361 00:27:38,180 --> 00:27:41,060 So you can't trigger this. 362 00:27:41,340 --> 00:27:44,460 And basically I'm going to run an exec and I'm just going to get a shell. 363 00:27:44,460 --> 00:27:48,340 Because you know I want to administer this container that I'm working from. 364 00:27:48,500 --> 00:27:52,140 So I'm going to run bin sh and you'll see Bob will exit at the top. 365 00:27:52,140 --> 00:27:55,620 So it says finished and now we've got a call back in the bottom left. 366 00:27:55,620 --> 00:28:01,840 So now that tells us okay this particular container was vulnerable to that CVE and we now got a call back. 367 00:28:01,840 --> 00:28:07,640 So now you could go ahead and get another container on that platform and then you know give your shell payload. 368 00:28:07,800 --> 00:28:09,580 So pretty useful. 369 00:28:09,580 --> 00:28:13,520 If you want to do that exploit manually there is a bit of work to it. 370 00:28:13,520 --> 00:28:15,520 But Bob will take care of that for you. 371 00:28:16,340 --> 00:28:17,100 Awesome. 372 00:28:17,140 --> 00:28:18,020 Conclusion. 373 00:28:18,080 --> 00:28:21,140 Yes and I haven't had my time cut yet because that always happens. 374 00:28:21,300 --> 00:28:25,140 So Bob can be used by both pen testers and engineers as you can see. 375 00:28:25,140 --> 00:28:28,860 I can use it to get shells um or to verify exploits ability. 376 00:28:28,920 --> 00:28:34,260 Uh you can also use it within your SDLC environment so security at scale is really really hard. 377 00:28:34,460 --> 00:28:40,820 And quite an important point here is that we are testing for two kinds of vulnerabilities. 378 00:28:41,080 --> 00:28:46,280 Immediate, so like getting a shell immediately or we are also getting delayed. 379 00:28:46,280 --> 00:28:49,940 So remember the hijacking binaries or the rancy that is delayed. 380 00:28:49,940 --> 00:28:51,120 I have ten minutes. 381 00:28:51,120 --> 00:28:52,720 Was that ten minutes Jeff? 382 00:28:52,740 --> 00:28:53,360 Awesome. 383 00:28:53,360 --> 00:28:54,960 This is like, this never happens. 384 00:28:54,960 --> 00:28:55,620 I apologize. 385 00:28:55,620 --> 00:28:57,860 Your ears must be, I'm going really fast as well. 386 00:28:57,980 --> 00:29:00,560 Caffeine, I blame that. 387 00:29:00,560 --> 00:29:02,480 And of course it being ten o'clock in the morning. 388 00:29:02,480 --> 00:29:05,580 It's like ah get everything out before everyone falls asleep. 389 00:29:05,780 --> 00:29:07,180 So you see I digress. 390 00:29:07,180 --> 00:29:08,120 Now I need to come back. 391 00:29:08,120 --> 00:29:09,280 Yes Chris what were you saying? 392 00:29:09,280 --> 00:29:10,740 Feedback, yes that thing. 393 00:29:10,740 --> 00:29:14,240 So you gonna be able to get feedback on two kinds of vulnerabilities. 394 00:29:14,520 --> 00:29:20,980 So if you hijack all the binaries, you have a web end point, you can get it at some time and also with the rancy stuff. 395 00:29:21,400 --> 00:29:24,920 There are a couple other features that I have not touched on today. 396 00:29:24,920 --> 00:29:30,060 So there is some stuff that like if you are on a host and you want to push stuff to S3 buckets for data exfil, it's pretty useful. 397 00:29:30,400 --> 00:29:32,260 I added that recently to Bob. 398 00:29:32,340 --> 00:29:35,180 Um there's also quite a cool way that you can scrape metadata stuff. 399 00:29:35,180 --> 00:29:40,720 So if you know if you've ever gotten access to a metadata services that's a real pain to get the actual content. 400 00:29:40,720 --> 00:29:45,280 There's a nice trick that you can do on GCP uh legacy metadata services. 401 00:29:45,280 --> 00:29:47,960 You just basically connect on port 80 with net cat. 402 00:29:47,960 --> 00:29:49,500 Don't send the host header. 403 00:29:49,620 --> 00:29:51,620 Enter, enter and blah. 404 00:29:51,620 --> 00:29:53,280 All the metadata stuff is yours. 405 00:29:53,280 --> 00:29:55,760 So I built that into Bob to do it automatically. 406 00:29:55,900 --> 00:29:57,160 So yeah there's a couple other things. 407 00:29:57,160 --> 00:29:59,920 It's all on the GitHub repo. 408 00:29:59,920 --> 00:30:01,980 So all the documentation is there. 409 00:30:02,160 --> 00:30:04,740 Um I haven't gone through all the functionality. 410 00:30:04,800 --> 00:30:05,860 But yeah it's all there. 411 00:30:05,860 --> 00:30:06,660 You can find it. 412 00:30:06,660 --> 00:30:09,000 Uh all the binary releases are there. 413 00:30:09,000 --> 00:30:11,780 And yes I thank you for your time. 414 00:30:11,780 --> 00:30:13,200 It's early Saturday morning. 415 00:30:13,420 --> 00:30:14,680 And yeah I'm going to end it there. 416 00:30:14,680 --> 00:30:15,540 Thank you so much. 417 00:30:15,960 --> 00:30:16,260 Audience Applause