WEBVTT

00:00.000 --> 00:01.900
But yeah, let's get the show started.

00:01.940 --> 00:03.820
Build to hack, hack to build.

00:04.300 --> 00:04.980
Who am I?

00:04.980 --> 00:06.080
My name is Chris.

00:06.080 --> 00:07.940
I'm a security engineer at Heroku.

00:08.340 --> 00:11.080
We're pretty much remote code execution as a service.

00:11.080 --> 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.

00:14.940 --> 00:16.720
Find me on Twitter, Brompony.

00:17.000 --> 00:18.780
But yeah, I like hacking stuff.

00:18.780 --> 00:19.680
I like building stuff.

00:19.680 --> 00:23.100
I am lazy, so I build stuff that helps me hack stuff quicker.

00:23.300 --> 00:26.760
Whether it's web, Windows, Android, and recently I've been looking at containers.

00:26.840 --> 00:28.080
They're a lot of fun.

00:28.100 --> 00:29.620
So this is what we're gonna look at.

00:29.680 --> 00:31.960
Problem, some existing research.

00:32.620 --> 00:33.920
I'll introduce to you Bob.

00:33.920 --> 00:35.680
So it's Bob with a silent T.

00:35.860 --> 00:38.720
And we'll look at some stuff that Bob can do.

00:38.760 --> 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.

00:43.080 --> 00:45.980
So we might deviate a bit, but I'll try to bring it back in.

00:46.180 --> 00:47.500
So what are the problems?

00:47.500 --> 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?

00:59.400 --> 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?

01:06.940 --> 01:11.440
But then in an engineering environment, how do we test, secure, and monitor our containers?

01:11.440 --> 01:16.100
So I come from a red teaming consulting background, and I do more engineering.

01:16.120 --> 01:18.120
So I'm constantly trying to break our platform.

01:18.380 --> 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?

01:23.960 --> 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?

01:32.940 --> 01:37.000
So in terms of existing research, these are just categories of types of tools.

01:37.000 --> 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?

01:44.700 --> 01:49.200
Identify as the SACCOM, CAPS, LXE, or Docker environment that you're in, and it will tell you, very important.

01:49.320 --> 01:51.360
Then there's a whole bunch of Google container tools .

01:51.360 --> 01:53.120
I highly recommend you look at their repo.

01:53.380 --> 01:59.980
Great stuff in terms of static analysis for container images, be it a Docker or an LXE image.

02:00.020 --> 02:04.400
Clay is really good, if you want to look for vulnerabilities in images, it's a really great tool.

02:04.400 --> 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.

02:13.460 --> 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.

02:22.080 --> 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,

02:39.080 --> 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.

02:48.120 --> 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.

02:58.320 --> 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.

03:06.100 --> 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.

03:15.580 --> 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,

03:28.560 --> 03:30.180
and I'll show you what I mean by that.

03:30.300 --> 03:33.600
So that's Bob, like I said we're gonna be pwning stuff.

03:33.800 --> 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.

03:46.660 --> 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.

03:58.000 --> 04:01.180
It's a really fun, you know, way to get into container exploitation.

04:01.320 --> 04:02.080
So how do you do it?

04:02.080 --> 04:03.340
What are the manual steps?

04:03.340 --> 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.

04:10.620 --> 04:15.340
Then you want to interact with the socket with curl or a docker client or netcat.

04:15.860 --> 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.

04:25.200 --> 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.

04:33.120 --> 04:34.540
Um, and there you go.

04:34.540 --> 04:38.700
You are then pretty much root on the host and you have access to the host file system.

04:38.700 --> 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.

04:43.760 --> 04:45.420
So that's the manual step.

04:45.420 --> 04:47.340
Now you don't want to do that all the time.

04:48.140 --> 04:48.980
Excuse me.

04:48.980 --> 04:51.660
But now things get a little bit tricky in containers.

04:52.040 --> 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.

04:58.880 --> 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.

05:05.720 --> 05:08.340
Like what if there's no ifconfig or ipadder.

05:08.340 --> 05:11.920
Sure you can read from procfs but this stuff can slow you down.

05:12.360 --> 05:14.980
Especially if you need to find docker, uh, the docker socket.

05:14.980 --> 05:19.120
It's not always at var on docker.sock, it could be at mu slash bob.

05:19.280 --> 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?

05:23.680 --> 05:25.400
So this is where syscalls come in.

05:25.400 --> 05:28.780
So on the left there, those are the syscalls that the found command makes use of.

05:28.940 --> 05:33.280
And on the right there, that's what bob does in go code to do pretty much the found command.

05:33.280 --> 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.

05:38.980 --> 05:41.280
It won't actually make use of actual shell commands.

05:41.280 --> 05:42.620
Some languages do that.

05:42.620 --> 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.

05:49.540 --> 05:51.860
So that, that's what we do with bob.

05:51.880 --> 05:53.660
And I'm going to show you a demo now.

05:54.260 --> 05:56.640
Um, these are pre-recorded.

05:56.880 --> 06:00.680
I'm done doing live demos because I just ran out of sacrifices all the time.

06:01.100 --> 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.

06:08.240 --> 06:10.920
And we're just going to watch a directory on the host.

06:11.240 --> 06:13.820
Um, so you see there's one file called bob linux.

06:13.820 --> 06:16.500
In the top, we're going to run in, in a container.

06:16.580 --> 06:19.620
So we're just saying a docker run and then we're mounting a socket.

06:20.580 --> 06:21.940
Turn off the light.

06:23.360 --> 06:25.980
Yeah, unfortunately that's, can we turn the lights down?

06:25.980 --> 06:26.540
Can we?

06:26.540 --> 06:27.020
No.

06:27.020 --> 06:27.660
Yes.

06:28.660 --> 06:29.380
Yeah.

06:29.680 --> 06:33.040
Unfortunately I can't make it bigger because the resolution will go off the board.

06:34.060 --> 06:36.000
We can just break the lights.

06:37.440 --> 06:38.300
Ah.

06:39.520 --> 06:40.400
Ooh.

06:42.520 --> 06:46.240
A room full of hackers and you just turn the lights on and you get that reaction.

06:48.900 --> 06:49.900
It's magic.

06:52.200 --> 06:55.200
So we're in a container now and we're going to run bob.

06:55.860 --> 06:59.440
And you know, if you're inside a container, you want to find socket.

06:59.440 --> 07:01.280
So we're just saying dash socket equals true.

07:01.280 --> 07:05.200
And now what Bob's going to do is going to go and look for all the Unix domain sockets.

07:05.200 --> 07:07.040
Now you found a Unix domain socket.

07:07.040 --> 07:07.320
What now?

07:07.320 --> 07:08.140
What do you do?

07:08.160 --> 07:10.620
So of course you want to auto-pwn this stuff.

07:10.620 --> 07:14.220
So I'm now providing dash auto-pwn equals true.

07:14.360 --> 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.

07:18.920 --> 07:21.180
And it's going to try and pop it basically.

07:21.180 --> 07:23.980
And what you'll see now, Bob is now giving me a TTY.

07:24.260 --> 07:27.240
So this terminal that I'm in now is not actually a terminal on the host.

07:27.240 --> 07:29.600
You'll see that that's a OSX host there.

07:29.640 --> 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.

07:37.900 --> 07:40.220
And we'll see that appear in a bit.

07:40.220 --> 07:42.960
So now I'm in a TTY that Bob has provided me.

07:43.020 --> 07:45.980
And you'll see that file has now appeared on the underlying host.

07:45.980 --> 07:47.680
And within the container.

07:47.680 --> 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.

07:52.080 --> 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.

08:01.800 --> 08:06.480
Of course if the docker socket is not authenticated or protected, often it's not.

08:06.500 --> 08:09.920
So automatically just auto-pwn all that stuff.

08:10.020 --> 08:11.860
So it's quite nice to get a TTY on the host.

08:11.860 --> 08:14.560
If you want think pen test, you want to get a shell on the host.

08:14.760 --> 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.

08:26.180 --> 08:31.940
So what we'll do here is we have a CI environment and we're going to run the same thing.

08:31.940 --> 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.

08:40.740 --> 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.

08:48.080 --> 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.

08:54.540 --> 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.

08:59.880 --> 09:01.000
So Bob will do that.

09:01.000 --> 09:03.940
So this is very useful for engineers and for CI environments.

09:04.120 --> 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.

09:17.800 --> 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.

09:23.500 --> 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.

09:30.500 --> 09:35.240
But from an engineering environment, you want to test, you know, are there exposed docker sockets?

09:35.240 --> 09:36.680
Is this thing pwnable?

09:36.760 --> 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.

09:45.900 --> 09:48.040
So it's very useful in CI environments.

09:48.320 --> 09:52.260
But of course, there's more to pwn, there's more to will than docker sockets.

09:52.400 --> 09:54.000
It's called privileged containers.

09:54.000 --> 09:56.720
Anybody raise a hand, privileged container in here?

09:56.980 --> 09:57.620
Cool.

09:57.640 --> 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.

10:04.620 --> 10:05.680
It's always the worst.

10:05.680 --> 10:10.660
But, um, privileged containers are pretty much the worst thing in the world of containers.

10:10.660 --> 10:11.060
Why?

10:12.860 --> 10:14.180
Cue awkward silence.

10:14.700 --> 10:19.660
The case for that is, I know, I just try to hide behind comedy and it's always an epic fail.

10:19.920 --> 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.

10:26.040 --> 10:30.820
Um, and it's very dangerous when it comes to your syscalls that you have access to and the Linux capabilities.

10:31.040 --> 10:34.840
And this basically means very, very easy container escapes.

10:34.840 --> 10:38.180
But now you're in a privileged container, how do you break out?

10:38.180 --> 10:41.120
So, I'm going to show you a new feature that I released this week.

10:41.120 --> 10:48.220
Um, what this does is Bob makes use of C group controllers and we're inside a privileged container.

10:48.320 --> 10:53.300
And what we're going to do is we're going to abuse the C group Linux release agent, uh, capability.

10:53.740 --> 10:58.000
And what that means is that we're going to get command execution on the underlying host.

10:58.000 --> 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.

11:07.180 --> 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.

11:13.320 --> 11:17.400
So you'll see now I'm using the pwn group, uh, host, uh, command.

11:17.400 --> 11:21.880
I'm saying hostname and I've got a hostname of, uh, docker desktop.

11:21.880 --> 11:24.180
So now I'm getting command execution, blah, blah, blah.

11:24.180 --> 11:24.700
Fun stuff.

11:24.700 --> 11:25.700
Let's get a shell.

11:25.700 --> 11:29.440
So at the bottom, I'm on my jump box, standard Netcat listener.

11:29.480 --> 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.

11:38.900 --> 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.

11:45.580 --> 11:46.300
The evil command.

11:46.300 --> 11:48.780
You do not want Netcat on your boxes with that.

11:48.800 --> 11:52.340
So it makes getting shells really easy.

11:52.360 --> 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.

12:06.100 --> 12:09.660
And in an OS X environment, that's basically game overs.

12:09.760 --> 12:12.600
So, cause we're running in a privileged container, this is really easy.

12:12.600 --> 12:14.740
Trail of bits did a great write up on this.

12:14.740 --> 12:17.920
Uh, C group , uh, pwnage, um, it's really interesting.

12:17.920 --> 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.

12:22.020 --> 12:26.440
If you see that host name, that is the VM that, uh, Docker for OS X uses.

12:26.480 --> 12:28.480
And now we're in the host file system.

12:28.500 --> 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.

12:37.620 --> 12:39.260
That's where your container is living.

12:39.420 --> 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.

12:50.240 --> 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.

13:00.040 --> 13:05.640
So basically, pwning C group, you break out of the container, and you basically root on underlying host.

13:05.640 --> 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.

13:12.320 --> 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.

13:19.900 --> 13:22.980
So you wouldn't be getting shells, we can just execute a command that you want.

13:22.980 --> 13:26.380
So pretty useful, privileged containers, um, they are out there.

13:26.380 --> 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.

13:35.560 --> 13:39.000
So there's good old env, if you type that in the terminal, that's what you'll get.

13:39.000 --> 13:41.020
But there's also the procfs in Linux.

13:41.140 --> 13:45.420
Procfs, it, it, it, it's given me a lot of this hair loss that you see over here today.

13:45.600 --> 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.

13:52.920 --> 13:59.760
Now this gets interesting, because env is not always cleared, and things might be living in proc PID.

13:59.760 --> 14:02.380
And this is when, uh, ephemerality becomes a problem.

14:02.380 --> 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.

14:12.880 --> 14:14.900
So you gotta be really quick when you're doing this.

14:15.020 --> 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.

14:24.780 --> 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.

14:32.020 --> 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.

14:39.880 --> 14:44.780
So that's pretty much what the Go code looks like if you want to process procfs.

14:44.840 --> 14:46.480
It's really nice and minimal.

14:46.560 --> 14:50.400
Um, I'm a big fan of Go, um, as you can probably hear or see.

14:50.400 --> 14:51.940
But how do we actually go about doing this?

14:51.940 --> 14:57.660
So we're gonna run a container, and I should probably press play, that's a good place to start.

14:57.760 --> 15:00.700
And we're gonna add in an environment variable.

15:00.700 --> 15:03.680
So it's called touch of approval and super secret password.

15:04.020 --> 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.

15:14.000 --> 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.

15:26.020 --> 15:27.360
And that's by default.

15:27.360 --> 15:31.060
But what you can also do with Bob is you can also supply a word list.

15:31.060 --> 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.

15:40.920 --> 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.

15:51.280 --> 15:54.760
Now, this is where, uh, return codes also happen.

15:54.760 --> 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.

16:01.060 --> 16:02.780
That's what I'm gonna show you now.

16:02.780 --> 16:05.620
So now you're gonna use a word list where there's nothing inside.

16:05.620 --> 16:10.420
And you can see Bob didn't find any of the entries inside the word list, inside any of the processes.

16:10.420 --> 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.

16:16.460 --> 16:19.560
So that's all fine and dandy.

16:20.220 --> 16:22.520
How do we also do this in a CI environment?

16:22.540 --> 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.

16:30.000 --> 16:35.500
So in this case, and these configs are all the same on the, uh, CI environments that you're using.

16:35.500 --> 16:38.360
So we're using a shell script here and we're gonna be running two Bob commands.

16:38.360 --> 16:40.520
So we're gonna be doing the socket auto-po.

16:40.520 --> 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.

16:45.360 --> 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.

16:52.120 --> 16:56.520
So let me just fast forward this.

16:56.640 --> 17:02.140
This is, in true Chris fashion, I made too much content for what I have.

17:02.140 --> 17:04.900
So I'm like, let's get to the really cool fun stuff.

17:05.340 --> 17:08.560
And of course you can't double up speed with the videos that I make.

17:08.560 --> 17:10.380
I'm just challenged in that way.

17:10.660 --> 17:14.100
So in every CI environment, Bob is gonna look for these key terms.

17:14.100 --> 17:15.280
It is regex as well.

17:15.280 --> 17:19.020
So you can say, okay, look for S3 tokens or whatever.

17:19.020 --> 17:20.180
It's, it's regex.

17:20.300 --> 17:22.260
Um, the world will definitely burn at some point.

17:22.420 --> 17:25.000
So we can see Bob has gone ahead and run those two commands.

17:25.200 --> 17:31.660
And the test will pass because from the previous tests, we know that there are no exploitable docker sockets.

17:32.080 --> 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.

17:37.880 --> 17:38.820
That's how we configured it.

17:38.820 --> 17:43.420
And now we know great stuff that test passed our containers in pre-production.

17:43.420 --> 17:45.680
Do not have exploitable docker sockets.

17:45.780 --> 17:50.280
And the environment variables that are there do not have any of the key terms that we specified.

17:50.940 --> 17:54.280
But of course, clouds, uh, clouds, yeah.

17:54.400 --> 17:56.520
Clouds love to host containers.

17:56.640 --> 17:59.400
Um, and of course we've got metadata services.

17:59.480 --> 18:05.120
So the 169254 address, it exists in GCP or AWS, Azure.

18:05.260 --> 18:07.900
And basically if you can get access to this, you can do a whole bunch of stuff.

18:07.900 --> 18:09.480
It depends on the platform.

18:09.480 --> 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.

18:15.800 --> 18:16.720
It'll, it changes.

18:16.720 --> 18:18.120
It varies on GCP.

18:18.320 --> 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.

18:23.900 --> 18:24.660
Excuse me.

18:24.660 --> 18:26.940
So you really want to find these things.

18:26.940 --> 18:30.800
But also, if you think Kubernetes, there's also APIs out there.

18:30.800 --> 18:32.840
Metadata service is basically an API.

18:33.060 --> 18:34.620
And you want to look for these things.

18:34.620 --> 18:37.780
Also you want to find out what is on your network ranges for your containers.

18:37.860 --> 18:40.780
For example, EC2 classic, still around.

18:40.780 --> 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.

18:49.000 --> 18:49.660
Yes, I know.

18:49.660 --> 18:50.840
What year is this?

18:50.900 --> 18:56.480
Um, so if you are running anything on EC2 classic, your host is exposed on that 10 range.

18:56.480 --> 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.

19:02.500 --> 19:07.760
But if we go back to the container quirks now, you might not have nmap in the container.

19:07.760 --> 19:09.300
You might not have wget or cull.

19:09.300 --> 19:14.100
You might not have the tools that you need to do the um, foot printing that you want to do.

19:14.100 --> 19:18.780
So of course, uh, Bob has a useful feature.

19:18.780 --> 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.

19:28.340 --> 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.

19:38.640 --> 19:43.540
So you can see now in this point, in this container, those two endpoints weren't there.

19:43.540 --> 19:49.040
But now we're going to tell Bob, use the word list and see if the container can hit heroku.com.

19:49.060 --> 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?

19:58.720 --> 19:59.460
And there we go.

19:59.460 --> 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.

20:04.700 --> 20:07.000
So you can use this in your CI environments as well.

20:07.000 --> 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.

20:14.340 --> 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.

20:22.420 --> 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.

20:30.840 --> 20:32.980
So there's also binary hijacking.

20:32.980 --> 20:38.600
This is awesome because a lot of orchestration environments explicitly trust the commands that they provide with.

20:38.600 --> 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?

20:46.440 --> 20:47.620
It just runs ls.

20:47.620 --> 20:51.540
So if you're in control of that container, you can overwrite the ls command to write your command.

20:51.540 --> 20:53.520
And we can do some pretty cool stuff with that.

20:54.200 --> 20:58.380
An example is kubectl or kubectl, there's another pronunciation.

20:58.560 --> 21:00.560
You learn something new in Vegas every year.

21:00.560 --> 21:07.060
So with kubectl, it executes the containers or the, the pods, um, tar command.

21:07.060 --> 21:13.080
That was recently exploited and used in an interesting chain by Twistlock, I highly recommend.

21:13.080 --> 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.

21:19.940 --> 21:22.080
So, pretty interesting.

21:22.440 --> 21:27.540
Important to remember that at some point in a container's lifetime, a binary might be executed.

21:27.540 --> 21:28.600
By binary I mean command.

21:28.600 --> 21:33.600
So maybe the power off command or the IP adder command might be executed in your container.

21:33.600 --> 21:34.620
So what do we do?

21:34.660 --> 21:36.380
We hijack all the binaries.

21:36.920 --> 21:42.280
So be careful, you can really break stuff here, uh, you're overwriting binaries.

21:42.460 --> 21:46.060
Um, so it's not too friendly for production environments, um, so I've been told.

21:46.400 --> 21:48.180
So, if you want to do this, what do you do?

21:48.180 --> 21:49.240
So these are the manual steps.

21:49.240 --> 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.

21:54.280 --> 21:56.800
You want to create a malicious executable that does something.

21:56.800 --> 22:02.460
So either a webhook to verify execution or you want to fuzz something, you can go ahead and do that.

22:02.460 --> 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.

22:12.980 --> 22:16.300
So, in terms of payloads, Bob will do this by default.

22:16.360 --> 22:17.680
We use webhooks, why?

22:17.680 --> 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.

22:27.040 --> 22:30.580
Webhooks are useful because it will, it will confirm exploits ability.

22:30.740 --> 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.

22:36.680 --> 22:37.980
That's how you would do it in bash.

22:37.980 --> 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.

22:43.380 --> 22:46.640
Um, so how do we actually do this and what do we get from this?

22:46.640 --> 22:51.780
So you could get a callback in one minute or five minute or next week, it really depends.

22:52.060 --> 22:58.520
Um, I've, what I've successfully achieved with this kind of attack is getting, uh, tokens provided to call commands.

22:58.520 --> 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.

23:06.640 --> 23:10.340
And of course, you know, it's not an open S3 bucket, they authenticate it as they should.

23:10.340 --> 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.

23:23.660 --> 23:26.300
So you can find some interesting stuff over there.

23:26.380 --> 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.

23:37.800 --> 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.

23:47.520 --> 23:50.440
And general blockage, you can really break stuff with this kind of stuff.

23:50.440 --> 23:52.460
So hijacking binaries, it's fun.

23:52.800 --> 23:56.300
So enough of me talking, let's actually see this in action.

23:58.580 --> 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.

24:10.980 --> 24:18.580
But we're telling Bob, hijack all the binaries in the host, in the container, and execute this command.

24:18.580 --> 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.

24:28.700 --> 24:33.420
So I executed the ID command and you'll see that I got a call back over here.

24:33.420 --> 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.

24:43.260 --> 24:47.880
So what does it look like if we were to run maybe docker exec on this running container?

24:48.360 --> 24:50.220
So that's what we're going to do now.

24:50.560 --> 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.

25:03.220 --> 25:06.720
So that gets a lot of fun, that gets pretty interesting.

25:06.720 --> 25:10.460
I enjoy doing that, you'd be surprised as to what you can get.

25:10.520 --> 25:13.080
So Bob automates that whole task and it's a lot of fun.

25:13.180 --> 25:14.800
But of course, there's more.

25:15.440 --> 25:19.280
What about all the CVs and all the lovely stuff that we have in docker?

25:19.280 --> 25:24.960
Yes, you did just see shell shock and bash bug and you probably like what year is it?

25:24.980 --> 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.

25:34.400 --> 25:38.680
So that's a good payload to know, especially in container environments, especially for LXC containers.

25:38.680 --> 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.

25:48.500 --> 25:54.940
Basically similar to hijacking binaries but here you are hijacking the run C binary on the underlying host.

25:54.940 --> 25:56.740
That's what the vulnerability allows you to do.

25:56.740 --> 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.

26:06.460 --> 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.

26:16.160 --> 26:20.320
For docker and LXC it gets a bit tricky, sometimes you need to be a privileged container, sometimes you need root.

26:20.320 --> 26:23.640
This is because LXC and docker treat privileged containers very differently.

26:23.640 --> 26:25.860
I won't get into that but it's really interesting.

26:26.200 --> 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.

26:36.620 --> 26:41.260
The payload is only executed in this vulnerability when someone runs a command inside your container.

26:41.260 --> 26:47.520
So if someone's running a kubectl copy or someone's running a docker exec.

26:47.540 --> 26:48.760
So you could wait.

26:48.780 --> 26:53.480
So in this case we're going to give a very nice webhook.

26:54.780 --> 26:59.960
So we're going to tell Bob, oh I hate cotton mouth, sorry excuse me.

27:00.520 --> 27:03.400
And I should probably play, auto play.

27:03.400 --> 27:05.420
If only someone invented that by now.

27:07.600 --> 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.

27:15.540 --> 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.

27:25.140 --> 27:26.540
So that will be the terminal on the left.

27:26.640 --> 27:30.100
So that's our curl command we're saying execute this.

27:30.100 --> 27:31.380
So now we've run the payload.

27:31.940 --> 27:33.460
Now you got to wait with this payload.

27:33.460 --> 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.

27:38.180 --> 27:41.060
So you can't trigger this.

27:41.340 --> 27:44.460
And basically I'm going to run an exec and I'm just going to get a shell.

27:44.460 --> 27:48.340
Because you know I want to administer this container that I'm working from.

27:48.500 --> 27:52.140
So I'm going to run bin sh and you'll see Bob will exit at the top.

27:52.140 --> 27:55.620
So it says finished and now we've got a call back in the bottom left.

27:55.620 --> 28:01.840
So now that tells us okay this particular container was vulnerable to that CVE and we now got a call back.

28:01.840 --> 28:07.640
So now you could go ahead and get another container on that platform and then you know give your shell payload.

28:07.800 --> 28:09.580
So pretty useful.

28:09.580 --> 28:13.520
If you want to do that exploit manually there is a bit of work to it.

28:13.520 --> 28:15.520
But Bob will take care of that for you.

28:16.340 --> 28:17.100
Awesome.

28:17.140 --> 28:18.020
Conclusion.

28:18.080 --> 28:21.140
Yes and I haven't had my time cut yet because that always happens.

28:21.300 --> 28:25.140
So Bob can be used by both pen testers and engineers as you can see.

28:25.140 --> 28:28.860
I can use it to get shells um or to verify exploits ability.

28:28.920 --> 28:34.260
Uh you can also use it within your SDLC environment so security at scale is really really hard.

28:34.460 --> 28:40.820
And quite an important point here is that we are testing for two kinds of vulnerabilities.

28:41.080 --> 28:46.280
Immediate, so like getting a shell immediately or we are also getting delayed.

28:46.280 --> 28:49.940
So remember the hijacking binaries or the rancy that is delayed.

28:49.940 --> 28:51.120
I have ten minutes.

28:51.120 --> 28:52.720
Was that ten minutes Jeff?

28:52.740 --> 28:53.360
Awesome.

28:53.360 --> 28:54.960
This is like, this never happens.

28:54.960 --> 28:55.620
I apologize.

28:55.620 --> 28:57.860
Your ears must be, I'm going really fast as well.

28:57.980 --> 29:00.560
Caffeine, I blame that.

29:00.560 --> 29:02.480
And of course it being ten o'clock in the morning.

29:02.480 --> 29:05.580
It's like ah get everything out before everyone falls asleep.

29:05.780 --> 29:07.180
So you see I digress.

29:07.180 --> 29:08.120
Now I need to come back.

29:08.120 --> 29:09.280
Yes Chris what were you saying?

29:09.280 --> 29:10.740
Feedback, yes that thing.

29:10.740 --> 29:14.240
So you gonna be able to get feedback on two kinds of vulnerabilities.

29:14.520 --> 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.

29:21.400 --> 29:24.920
There are a couple other features that I have not touched on today.

29:24.920 --> 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.

29:30.400 --> 29:32.260
I added that recently to Bob.

29:32.340 --> 29:35.180
Um there's also quite a cool way that you can scrape metadata stuff.

29:35.180 --> 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.

29:40.720 --> 29:45.280
There's a nice trick that you can do on GCP uh legacy metadata services.

29:45.280 --> 29:47.960
You just basically connect on port 80 with net cat.

29:47.960 --> 29:49.500
Don't send the host header.

29:49.620 --> 29:51.620
Enter, enter and blah.

29:51.620 --> 29:53.280
All the metadata stuff is yours.

29:53.280 --> 29:55.760
So I built that into Bob to do it automatically.

29:55.900 --> 29:57.160
So yeah there's a couple other things.

29:57.160 --> 29:59.920
It's all on the GitHub repo.

29:59.920 --> 30:01.980
So all the documentation is there.

30:02.160 --> 30:04.740
Um I haven't gone through all the functionality.

30:04.800 --> 30:05.860
But yeah it's all there.

30:05.860 --> 30:06.660
You can find it.

30:06.660 --> 30:09.000
Uh all the binary releases are there.

30:09.000 --> 30:11.780
And yes I thank you for your time.

30:11.780 --> 30:13.200
It's early Saturday morning.

30:13.420 --> 30:14.680
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

