WEBVTT

00:00.000 --> 00:12.000
So now, this is an interesting timing for a talk, because I want to introduce an old friend of ours who is...

00:12.520 --> 00:23.180
This is the first time we're going to have a talk, but then immediately you're going to have to hop over to the next room for a workshop.

00:23.180 --> 00:27.240
So this is like the prelude to your workshop, isn't it?

00:27.240 --> 00:29.720
Without much ado, Jay Beal, everyone.

00:34.180 --> 00:35.260
Hi, hi.

00:35.860 --> 00:36.640
Hi, hi.

00:36.680 --> 00:40.780
I'm going to try really hard to stay within range of the mic.

00:42.300 --> 00:44.240
And let's see how I can do with that.

00:44.240 --> 00:46.280
I'm not really good at staying in one place.

00:46.280 --> 00:47.840
I kind of like to walk around.

00:48.900 --> 00:52.540
If you've seen me at many DEF CONs in the past, I like to dance.

00:52.660 --> 00:57.460
So anyway, with that said, I'm going to talk to you about attacking and defending Kubernetes.

00:58.100 --> 01:04.320
It's a topic that's become incredibly important to me and dear to me and interesting to me.

01:04.420 --> 01:09.000
So I have a bio slide, but we all know bio slides are just big seas of text.

01:09.100 --> 01:16.000
So I have a graphical bio slide, which basically says, this is stuff I've done or stuff I'm interested in.

01:17.260 --> 01:22.460
I really enjoy... this is stuff kind of going back way back to the...

01:22.460 --> 01:28.860
back in the day writing at Security Focus and doing CIS work and giving some early, early DEF CON talks.

01:28.860 --> 01:40.980
And nowadays teaching a class at Black Hat and enjoying a heck of a lot of work at Engardians as a CTO who likes to still be a very technical CTO.

01:41.040 --> 01:44.800
So anyway, let's get on with what you came for.

01:44.800 --> 01:45.760
So what are we going to see today?

01:45.760 --> 01:48.780
We're going to talk about Kubernetes.

01:49.000 --> 01:51.420
I'm going to do a bunch of demos.

01:52.080 --> 01:54.220
We'll do a little bit of choose-your-own-adventure.

01:54.220 --> 01:59.580
If all my... if the tech works, the choose-your-own-adventure part is entirely new.

01:59.580 --> 02:02.360
So the nice thing is cutting edge fresh.

02:02.360 --> 02:04.480
The downside is, uh-oh.

02:05.240 --> 02:07.700
So hopefully this is... hopefully this goes really well.

02:07.700 --> 02:09.700
So I'm going to talk about what Kubernetes is.

02:09.700 --> 02:14.380
I'm going to talk about how you... what you attack and how you attack it.

02:14.380 --> 02:16.040
And then a little bit about how you defend.

02:16.040 --> 02:17.400
We're going to do some demos.

02:17.940 --> 02:18.940
Let's just start.

02:18.940 --> 02:24.780
So the first thing I do any time I talk about Kubernetes is talk about what the heck this thing is for.

02:25.380 --> 02:30.000
And because... and I want to make sure I'm coming through on the mic.

02:30.100 --> 02:31.820
Am I coming through on the mic in the back of the room?

02:31.820 --> 02:32.420
Perfect.

02:32.660 --> 02:35.120
Okay, so what the heck this thing is for?

02:35.460 --> 02:39.520
And , you know, people are like, I know that this is hot.

02:39.520 --> 02:40.820
I know that I should use it.

02:40.820 --> 02:43.460
That's kind of the same way we all felt about Docker.

02:43.640 --> 02:48.500
So, you know, why do we use this or what's made it so big?

02:48.500 --> 02:56.420
And basically the Kubernetes came out of... in a lot of ways it came out of what Google is doing with the Borg, right?

02:56.420 --> 03:01.820
It's an open source project that initially got released by Google and now has many, many, many contributors.

03:02.320 --> 03:05.080
But Kubernetes basically came out of this need.

03:05.240 --> 03:10.960
We know that Google... we know that Google had just... has a ton of computers and a ton of workloads.

03:11.060 --> 03:17.500
To be clear, you know, it's not exactly the most transparent company all the time, but they have some public statements they've made.

03:17.500 --> 03:23.060
One is back in 2014, they were launching 2 billion containers per week.

03:23.060 --> 03:27.100
If that were evenly distributed, it'd be 3,300 containers per second.

03:27.240 --> 03:28.240
What's a container?

03:28.240 --> 03:29.220
It's like a workload.

03:29.220 --> 03:31.740
It's a program that's going to run for a little while and do something.

03:31.740 --> 03:33.600
We don't know how long that while is.

03:33.620 --> 03:43.100
But if you're launching 3,300 a second, you can't have a human being decide which virtual machine or which host, you know, each program, each workload is going to go on.

03:43.100 --> 03:46.040
So you end up needing a tool for that.

03:46.040 --> 03:48.060
Now, what else?

03:48.420 --> 03:50.080
Well, they did this.

03:50.080 --> 03:54.860
They were launching all of those workloads onto 2.5 million servers.

03:54.860 --> 03:57.200
At least that was their number back in 2016.

03:57.280 --> 04:01.660
And in 2016, hard drive failure rates were just right below 2%.

04:01.660 --> 04:07.220
So if every server had just one drive, and that's a big, you know, hand-waving thing.

04:07.220 --> 04:14.720
But if every server had one drive, that meant they had 133 drive failures a day, or one every nine minutes.

04:14.720 --> 04:18.500
So now you've got a resiliency problem, right?

04:18.500 --> 04:30.660
Like, you wanted to guarantee, you know, you wanted to guarantee so many nines of uptime, and yet your physical machines are going to, you know, entire physical machines are going to die on some regular basis.

04:30.660 --> 04:35.120
Like, say, RAID, notwithstanding, one every nine minutes.

04:35.120 --> 04:50.160
So what features would you want if you wanted to be able to stage a ton of workloads over a ton of servers, figure out how to use the servers at the greatest, as close to their capacity as you could, so you weren't buying lots of extra machines.

04:50.260 --> 04:58.940
And you wanted to make sure that as programs crashed and as hard drives failed and so on, that you still had availability.

04:59.720 --> 05:05.780
So you end up with what Kubernetes is, which is basically a software-defined data center.

05:06.040 --> 05:08.720
And we do that by container orchestration.

05:08.720 --> 05:09.940
So what do you get?

05:09.940 --> 05:12.160
So basically, this is your feature set.

05:12.160 --> 05:13.240
This is what you end up saying.

05:13.240 --> 05:22.140
You end up saying, well, sometimes I have a lot of people checking their email on Gmail or searching right now for the thing that just happened in the news.

05:22.180 --> 05:23.680
And sometimes I don't have as many.

05:23.680 --> 05:25.240
So I'd like a whole lot of scaling.

05:25.240 --> 05:26.680
I'd like that horizontal scaling.

05:27.540 --> 05:29.480
I have four copies of that workload.

05:29.480 --> 05:31.240
No wait, I have 400.

05:31.240 --> 05:32.900
No wait, I have 50.

05:32.960 --> 05:33.760
And so on.

05:33.760 --> 05:40.200
And you get automatic bin packing, which is that, like, which workload should go on which machine so we can keep all the machines as full as we can.

05:40.240 --> 05:42.700
And you get self-healing, like that hard drive crash thing.

05:42.900 --> 05:44.780
And you get a whole bunch of other cool features.

05:44.780 --> 05:55.620
You get, like, automated rollouts and rollbacks where you can basically deploy multiple versions at once and see if one of them ends up producing more sales or more of whatever it is you're trying to produce.

05:55.740 --> 06:01.280
Or see if one's buggy and then be able to basically route all the traffic to the one that isn't and so on.

06:01.320 --> 06:06.460
You get the other kinds of things you would need if you're going to do microservices.

06:06.600 --> 06:09.960
So you get service discovery and you get load balancing.

06:09.980 --> 06:14.200
And then you get orchestration of your storage and you get secrets and configuration management.

06:14.200 --> 06:16.640
So that's kind of, that's what the purpose was.

06:16.640 --> 06:18.160
I'm going to do a little bit more theory.

06:18.160 --> 06:22.280
So just kind of, like, what's a pod, what's a container?

06:22.280 --> 06:26.720
So, right, we, when we're talking about Kubernetes, we're talking about containers.

06:27.220 --> 06:29.260
But we say pods a lot.

06:29.260 --> 06:32.320
And basically pods are the smallest unit of compute in Kubernetes.

06:32.320 --> 06:36.340
So all the containers in a pod are sharing an IP address.

06:36.340 --> 06:43.400
The only reason you put multiple containers in a pod is if you want them to absolutely positively land on the same host.

06:43.400 --> 06:47.880
Like they have need for very, very quick network access or what have you.

06:48.020 --> 06:50.540
Maybe they need the same local storage.

06:51.500 --> 06:55.580
An odd thing about pods is all the containers in a pod share an IP address.

06:56.440 --> 06:58.980
Okay, so then you've got Kubernetes nodes.

06:59.020 --> 07:02.020
Simply put, a node is any system you're going to run Kubernetes on.

07:02.020 --> 07:07.580
A node is any of the systems in your cluster, whether those are virtual machines or physical hardware.

07:07.580 --> 07:15.860
The nodes run a, well, first and foremost, the nodes, to be a node, you have to have a container runtime.

07:15.860 --> 07:18.480
So you have to have something like Docker or RunC or what have you.

07:18.480 --> 07:26.460
Something that's going to basically take instructions from Kubernetes about creating containers and create them.

07:26.460 --> 07:28.800
And maybe destroy them and so on.

07:28.800 --> 07:31.280
You also need a kubelet.

07:31.280 --> 07:36.440
And a kubelet, Kubernetes kubelet, a kubelet is just this thing that runs in every Kubernetes node.

07:36.440 --> 07:43.040
And it ties the container runtime or the node into the rest of Kubernetes.

07:43.040 --> 07:45.680
It talks to the API servers and so on.

07:45.880 --> 07:47.540
Then you've got a kubeproxy.

07:47.540 --> 07:51.780
And that thing manipulates IP tables rules to create cool networking.

07:51.780 --> 07:54.040
It also serves as an actual proxy.

07:54.980 --> 07:58.180
So, yeah, we'll get into that a little bit more.

07:58.400 --> 08:00.340
And then services.

08:01.000 --> 08:10.540
Services are big because in Kubernetes, and services give me a great occasion to kind of describe how you talk about the names of things in Kubernetes.

08:10.540 --> 08:15.620
When we're doing the attack demos, we're going to be talking about this pod and this pod and this pod.

08:15.620 --> 08:20.660
But for the most part in Kubernetes, you don't ever think about which pod names you want.

08:20.660 --> 08:27.160
The whole idea is that the individual pods, the containers, they're very, very much supposed to be cattle.

08:27.160 --> 08:28.560
They're not supposed to have names.

08:28.560 --> 08:30.000
They're supposed to be interchangeable.

08:30.000 --> 08:32.960
I'm supposed to be able to trash them, start new ones up.

08:32.960 --> 08:36.360
I have to... I'm going for... I'm going for that.

08:36.580 --> 08:38.620
So, what does that mean?

08:38.620 --> 08:40.800
I mean, if I want to talk to a pod, what do I do?

08:40.800 --> 08:41.620
You don't.

08:41.640 --> 08:43.800
I mean, you might, but rarely.

08:43.800 --> 08:45.740
Mostly, you talk to a service.

08:45.860 --> 08:48.640
And a service is mapped to multiple pods.

08:48.640 --> 08:50.600
Think of it as an internal load balancer.

08:51.300 --> 08:56.580
Now , if you've got, like, why do I say that would get me into something cool?

08:56.580 --> 08:57.980
That gets me into labels.

08:57.980 --> 09:00.920
And basically, you have a load balancer.

09:00.920 --> 09:04.760
You can't say this load balancer should be pointed at these five pod names, right?

09:04.760 --> 09:06.420
First, you're going to have a whole lot more.

09:06.420 --> 09:07.260
They're going to get added.

09:07.260 --> 09:09.740
Second, those pods are going to die at any moment.

09:09.740 --> 09:11.660
Third, you're trying to go really, really fast.

09:11.660 --> 09:16.380
Remember, you know, 3,300 containers per second being launched, right?

09:16.440 --> 09:18.080
So, what do you do?

09:18.080 --> 09:20.360
You end up basically labeling everything.

09:20.360 --> 09:21.680
So, you label all the pods.

09:21.680 --> 09:22.560
You give them labels.

09:22.560 --> 09:25.300
And those labels are basically... sometimes they're by convention.

09:25.300 --> 09:26.960
Sometimes they're whatever you chose.

09:26.960 --> 09:28.560
But you label the pods.

09:28.560 --> 09:29.860
And then you create a service.

09:29.860 --> 09:34.960
And you say, everything that... you know, this service is going to be a name, an IP address, or port.

09:34.960 --> 09:45.620
And everything that goes to that name and port, or IP address and port, is going to be sent to one of the pods that have the set of labels the service specifies.

09:45.860 --> 09:47.740
It does kind of open an interesting question.

09:47.740 --> 09:59.220
Like, if you are allowed to stage pods onto a cluster, could you start intercepting other people's traffic by just giving yourself the same labels that their services are looking to land things on?

09:59.400 --> 10:00.140
Hmm.

10:00.140 --> 10:00.900
Okay.

10:00.900 --> 10:01.860
Interesting.

10:02.800 --> 10:04.280
Last thing we talk about.

10:04.280 --> 10:09.100
Last big, big, you know, kind of simple glossary concept we need is namespaces.

10:09.160 --> 10:12.340
The namespaces are just a logical grouping for things.

10:12.340 --> 10:13.940
So, we'll see those.

10:14.460 --> 10:24.480
They're often used to separate projects, or to separate teams, to separate an individual, you know, maybe to separate, well, anything you choose.

10:24.480 --> 10:26.880
So, there's some way of chopping things up.

10:26.880 --> 10:42.420
And it's important to say a Kubernetes namespace is not the same as a Docker or Linux namespace, so much so that when I teach classes on this, one of the other folks from Guardians, Jared Fredis, asked if we could please call Kubernetes namespaces, space names,

10:42.420 --> 10:45.720
since Docker and Linux, you know, already have namespaces.

10:45.720 --> 10:48.220
So , it was, you know, don't overload the term.

10:48.460 --> 10:50.440
So, here's a quick glossary slide.

10:50.580 --> 10:55.040
I'm going to say a tiny bit more on theory, and then we'll have some fun.

10:55.380 --> 10:59.880
So, Kubernetes basically works in this declarative model.

10:59.880 --> 11:05.260
You don't generally say, you're going to see me generally, like, hey, do this thing right now.

11:05.260 --> 11:08.120
But you don't generally tell Kubernetes to do a thing right now.

11:08.120 --> 11:14.920
You don't say, hey, take this, you know, take this container image, start a container on that node over there with it, right?

11:14.920 --> 11:19.800
You tend to say, you know, it's very delegating and hands-off, right?

11:19.800 --> 11:24.680
So, the idea is you say, Kubernetes, I have this program.

11:24.680 --> 11:26.240
I've created an image.

11:26.240 --> 11:28.060
Maybe I've placed that image on Docker Hub.

11:28.060 --> 11:30.580
Maybe I've put it on some other container registry.

11:30.580 --> 11:36.900
And I'd like you to now, like, download that image, like, have some nodes, download that image.

11:36.900 --> 11:40.120
I'd like at least, say, five to be running it.

11:40.120 --> 11:42.240
Like, if you need more, scale up.

11:42.420 --> 11:45.220
But, you know, I want five, no less than three.

11:45.220 --> 11:48.260
Like, let's, you know, just do me a favor and get that running.

11:48.260 --> 11:49.460
And Kubernetes says, sure.

11:49.460 --> 11:54.300
And it's got a bunch of, like, control loops that basically first make that the state of the world.

11:54.300 --> 11:55.800
So, you describe the state of the world you want.

11:55.800 --> 12:02.120
It basically spends its whole life trying to keep the state of the world where you've said it has to be.

12:02.120 --> 12:03.500
And then it basically loops.

12:03.500 --> 12:05.180
And it says, ah, a machine fell down.

12:05.180 --> 12:07.440
I guess I'll have to reassign those workloads.

12:07.760 --> 12:11.160
Or, ah, looks like something's not responding.

12:11.160 --> 12:15.000
I'll have to, you know, maybe I'll kill that off and I'll start something else.

12:15.080 --> 12:17.420
So, you describe the state of the world.

12:17.680 --> 12:20.500
I think this is basically my last theory.

12:20.500 --> 12:22.800
And I hope I haven't given you too much.

12:22.800 --> 12:25.820
So, the kind of target components.

12:25.820 --> 12:27.460
There are a bunch of components you'll target.

12:27.460 --> 12:33.320
The big ones that you hear about are especially on the first two slides here.

12:33.320 --> 12:35.480
So, you'll target the API server.

12:35.480 --> 12:44.620
The thing that everybody's basically doing all of these HTTPS and, God forbid, HTTP requests against and asking to do things.

12:44.940 --> 12:51.740
And the kubelet, which we said bridged each node into the system.

12:51.740 --> 12:53.240
The container runtime.

12:53.380 --> 12:58.860
You can often think of Docker, and I'll often say Docker, but there are multiple container runtimes.

12:59.300 --> 13:06.720
And that container runtime is the thing that pulls the container images from the registry, you know, like Docker Hub or what have you, and instructs the kernel to start up a container.

13:07.320 --> 13:10.480
You have an etcd server that maintains all the state.

13:10.480 --> 13:15.620
And if you ever get access to that thing, yeah, there's not really a lot of chopped up authorization.

13:15.620 --> 13:23.400
So, if you get access to it, you kind of own all the, you own all of the persistent idea of what the system is.

13:23.400 --> 13:25.240
And so, that's very good for you.

13:25.380 --> 13:26.860
A Kubernetes dashboard.

13:27.180 --> 13:38.480
That was the thing that got, as I recall, that was the thing that got Tesla in trouble, where their dashboard was available to the internet and, I think, was allowing anonymous access to do anything.

13:38.640 --> 13:42.460
But that's a web interface, as I, I think it's being deprecated.

13:43.440 --> 13:48.140
There's metrics components and different kinds of cluster services that will give you good information.

13:48.740 --> 13:50.900
Those, those are your usual targets.

13:51.100 --> 13:59.660
Just to throw in two more, two more components that people, that it's really helpful just, you know, if you're operating Kubernetes, defending it or attacking it are useful to know.

13:59.660 --> 14:01.260
One is the controller manager.

14:01.260 --> 14:06.960
And the controller manager, it makes it sound like it's, like the controller manager would have lots of separate controller programs.

14:07.040 --> 14:11.860
And it kind of does, but they're all just compiled into one big, you know, they're just compiled into one big program.

14:11.860 --> 14:14.520
So the controller manager has all of the controllers.

14:14.520 --> 14:19.500
The controllers are the things that basically do those loops and say, is everything the way it was supposed to be?

14:19.500 --> 14:21.060
Is everything the way it was supposed to be?

14:21.060 --> 14:22.360
Ah, something's different.

14:22.360 --> 14:23.980
I'm supposed to have five copies of this.

14:23.980 --> 14:24.720
I've got four.

14:24.720 --> 14:31.440
I'll go talk to the next one, the scheduler, and say, excuse me, scheduler, can you find somewhere to, can you find somewhere to put this?

14:31.600 --> 14:34.560
Can you find a node we can put things on?

14:34.640 --> 14:38.060
We tend to target these components only through the API server.

14:39.520 --> 14:45.520
So attacks on Kubernetes, this is where we start to finally get to attack and defense.

14:47.400 --> 14:52.920
Attacks on Kubernetes, they start from, they start from the perspective of compromised pod.

14:52.920 --> 14:58.200
So you can attack, you can attack a Kubernetes cluster from across the network.

14:58.200 --> 15:05.760
And it's even less effective than attacking most companies, you know, across the Internet has been, right, lately.

15:05.760 --> 15:08.000
It's, it's, we've gotten pretty good at perimeters.

15:08.000 --> 15:12.160
Kubernetes is pretty darn good at perimeters because for the most part, it doesn't allow any traffic.

15:12.160 --> 15:20.080
There's nothing, there's no traffic being allowed in unless it's had, unless it's had some kind of ingress defined for it.

15:20.080 --> 15:30.280
So , so for the most part, you attack a Kubernetes cluster from the perspective that you are in a workload, that you're in a container and that container is compromised or otherwise under your control.

15:30.480 --> 15:37.040
So what are the, you know, what are the, what are the, what are the ways the attacker might end up with that kind of control?

15:37.040 --> 15:42.680
Because, yeah, as you'll see in some, in our demos, this is the, this is the vector I like to, I like to show.

15:42.680 --> 15:50.380
It's the, the attacker found a vulnerable thing that you were hosting in Kubernetes, got remote code execution, and now they're in a container.

15:50.380 --> 15:58.440
And from that container, they may have the ability to do much more far ranging things, because we're in an orchestration system, a very automatic one.

15:58.440 --> 16:13.220
They may be able to do far more wide ranging things than if they just busted that, you know, some web server or some, or something that was in a, that was in a cloud environment or in a data, or in a, or in an on-prem data center.

16:13.700 --> 16:16.340
So, how else might the attacker have gotten in?

16:16.340 --> 16:18.280
The attacker might have just phished somebody.

16:19.140 --> 16:35.620
Brad Giesemann, who I'll, whose name I probably just butchered, and whose Twitter handle I'll have at the end of these slides, has a great slide in one of his presentations about how kube control apply, and that a URL is the new curl URL into shell.

16:35.620 --> 16:49.740
Right, if you, one of the great ways to phish somebody would be if you put up a how-to article on Stack Overflow or what have you, and the, you know, part of that article was, oh, just apply my, you know, apply my YAML from this URL.

16:49.980 --> 16:54.840
You can get anyone to apply the YAML from the URL, then you've got places for your crypto mining to go.

16:56.340 --> 17:01.180
So, and our attacker could just be some internal threat actor who's looking to escalate their privileges.

17:01.180 --> 17:07.320
I often, you'll, you'll often hear me use the word user and attacker interchangeably.

17:07.340 --> 17:10.720
On the defense side, that's not really because I think all my users are hostile.

17:10.720 --> 17:12.580
I just don't know which ones of them might be.

17:12.580 --> 17:14.000
I don't know who's being coerced.

17:14.000 --> 17:16.380
I don't know who's, you know, getting curious.

17:16.420 --> 17:19.080
I don't know who's actually got an axe to grind.

17:19.180 --> 17:22.140
And I think we all know least privilege is a good idea at this point.

17:22.400 --> 17:28.880
So, okay, so, so if an attacker's going to be in a pod, what are they going to do with that?

17:28.880 --> 17:31.360
I'm going to give you a few, I'm going to give you a few things.

17:31.360 --> 17:32.780
There's even more, I'm sure.

17:32.780 --> 17:34.560
So this is kind of the general way.

17:34.560 --> 17:41.080
So they could use just the network access that they get provided by the pod to access other services.

17:41.240 --> 17:49.500
And I'll say very, very, very often, especially in the microservice model, a Kubernetes cluster has a bunch of things that are all supposed to talk to each other.

17:49.540 --> 17:57.160
And it's actually, it can be a little difficult or at least take some work to sit down and say, okay, what should and what shouldn't.

17:57.160 --> 18:15.080
So once you're in the cluster, you have access to a whole bunch of things, many of which might not be intended to be communicated with by anyone on the Internet or anyone that the service that you've pwned is trying to serve.

18:15.080 --> 18:16.340
So what else?

18:16.340 --> 18:20.180
So the attacker could attack other containers that are in their same pod.

18:20.440 --> 18:25.600
Multiple containers in a pod, they share, well, I told you, they share an IP address.

18:25.600 --> 18:26.980
They share a local host.

18:27.160 --> 18:32.580
So it's a cool little Linux namespace thing, which we won't get into unless somebody asks me later on.

18:33.380 --> 18:34.240
What else?

18:34.240 --> 18:46.600
So the attacker could make requests to the API server or to a kubelet and ask those to maybe run commands in another pod, maybe even interactively, to start a new pod that has privilege.

18:46.600 --> 18:48.260
And that privilege could be all kinds.

18:48.260 --> 18:56.420
It could be a privileged pod, which means it'll start on the host and have access to system devices and be able to, among other things, maybe mount the hard drive of the node.

18:56.420 --> 19:03.300
But there's just all kinds of privilege you can get out of starting new pods, and I'll show you that.

19:03.300 --> 19:18.320
They might gather secrets that Kubernetes provides to pods because Kubernetes has a whole thing where it needs to provide configurations to pods because you're really supposed to make those pods come up with a static image.

19:18.320 --> 19:26.760
So the idea is the pod starts with a static, totally replaceable image and pulls whatever information it needs from elsewhere.

19:27.280 --> 19:30.120
You might connect to the Kubernetes dashboard to perform actions.

19:30.120 --> 19:32.340
Maybe it wasn't accessible from outside the cluster.

19:32.340 --> 19:34.520
God hope, or gosh hope.

19:35.140 --> 19:36.500
What else?

19:36.500 --> 19:40.880
The attacker might find a way to interact with the etcd server and change the cluster state.

19:40.880 --> 19:48.820
A nice way if there are network access control rules, network policies in place that are getting in your way.

19:48.820 --> 19:54.140
If you can talk to the thing that stores them, yeah, you could potentially change them.

19:54.940 --> 20:08.280
And the other one, the one that's really fun to me for anything that's either in a cloud provider or even in an on-prem cloud, is that the attacker might interact with the cloud service provider.

20:08.380 --> 20:18.000
And because many workloads will, one way or another, and I'll show this to you too, will have privilege on the cloud provider.

20:18.060 --> 20:20.920
So, I'm going to show you a bunch of demos.

20:21.320 --> 20:23.320
And these demos are real.

20:23.320 --> 20:27.240
They're often things that we do in classes I teach.

20:27.240 --> 20:32.760
They're also, I'm going to tell you later on, we have an open source project and it's an intentionally vulnerable Kubernetes cluster.

20:32.760 --> 20:35.420
Call it, like, damn vulnerable Kubernetes cluster.

20:35.420 --> 20:37.380
This one's called BustaKube.

20:38.260 --> 20:43.460
We've got an Easter egg BustaMove video that you can find if you go to the BustaKube.com website.

20:44.240 --> 20:54.400
But, so, some of the things I'm showing you are basically available as scenarios that you can play in this open source, free, damn vulnerable Kubernetes cluster.

20:54.440 --> 20:59.220
So, I've done a thing where I've made my videos part of the slide.

20:59.300 --> 21:02.220
And so now I'm going to see if that actually works.

21:03.200 --> 21:04.580
Please work.

21:06.480 --> 21:10.060
And if it doesn't, we'll have to use YouTube one way or another.

21:10.200 --> 21:12.060
Or something else.

21:14.060 --> 21:15.020
Okay.

21:20.050 --> 21:21.850
Color me very embarrassed.

21:22.390 --> 21:24.470
Let's just see if this one's the one.

21:27.900 --> 21:29.860
You should always test your demos.

21:30.720 --> 21:32.580
Even when you record them.

21:32.700 --> 21:37.840
So , I tell you what, we're going to find another way to do it.

21:38.380 --> 21:44.740
And I am going to, let's see, I'm going to unplug from the projector for a second.

21:44.740 --> 21:49.100
Because that means I'm going to go and look at my own file system and I'd like to not share it.

22:20.880 --> 22:22.100
And here we go.

22:28.060 --> 22:30.360
Just embed the videos in the slides, they said.

22:30.460 --> 22:32.100
It'll be fun, they said.

22:34.640 --> 22:40.160
Anybody old enough to have played Warcraft and you click on the guy and he's like, what?

22:40.160 --> 22:42.100
And you click on him again and he says something else.

22:42.100 --> 22:44.960
And he says, you know, join the army, he said.

22:44.960 --> 22:46.640
See the world, he said.

22:46.640 --> 22:50.080
Okay, so here's our demo.

22:53.340 --> 22:57.420
And hopefully entering, oh, well that's not a demo.

23:02.500 --> 23:04.280
Is that a demo?

23:05.200 --> 23:07.600
That's not a demo either.

23:15.340 --> 23:17.200
Anybody seen my screen?

23:17.360 --> 23:18.660
There we go.

23:18.800 --> 23:22.040
Let's just hit this on mirror and call it a day.

23:23.340 --> 23:24.380
Okay.

23:26.580 --> 23:27.540
Cool.

23:28.900 --> 23:29.540
So...

23:30.360 --> 23:31.760
That's not the right...

23:35.540 --> 23:39.520
Don't mind me, I'm clearly a noob.

23:41.780 --> 23:43.860
I may need alcohol.

23:45.480 --> 23:51.200
So this is one of the BustaCube scenarios.

23:51.200 --> 23:54.380
So you go up and you see a WordPress site.

23:54.380 --> 24:00.040
And the WordPress site, I will tell you, is hosted in Kubernetes.

24:01.840 --> 24:06.640
And you fire up maybe Durbuster to go looking for hidden content.

24:07.320 --> 24:11.840
And Durbuster takes a little bit of time, but we can run it.

24:11.840 --> 24:13.680
And let's go a little faster.

24:13.680 --> 24:16.020
And what we find is backdoor.php.

24:16.180 --> 24:19.940
And so when we surf to backdoor.php, this is what happens.

24:19.940 --> 24:27.600
I get this thing where basically this WordPress instance, like so many other WordPress instances, has been pre-compromised for your convenience.

24:29.300 --> 24:33.900
So I type ID and it says your www data.

24:34.140 --> 24:38.700
And hopefully I shut down Durbuster because it always chews a ton of resources.

24:39.000 --> 24:40.400
Something we always say in class.

24:40.400 --> 24:41.840
My laptop's running slow.

24:41.840 --> 24:43.160
Have you turned off Durbuster?

24:43.160 --> 24:44.100
No!

24:44.140 --> 24:46.340
It's 500 requests a second.

24:46.340 --> 24:48.640
Well, that'll do something.

24:48.640 --> 24:58.420
So I'm going to stand up a quick little web server in Kali because I found that reverse shell.

24:58.420 --> 25:00.500
So I'm going to stand up a little web server.

25:00.500 --> 25:12.520
And my purpose of the web server is to be able to hand a meterpreter or if I wanted a whatever, some other kind of reverse shell.

25:12.520 --> 25:14.500
But I'm going to go for a meterpreter.

25:15.840 --> 25:26.060
And so I just put in here like, hey, could you please pull this meterpreter binary I've created from my web server and while you're at it, make it executable.

25:26.060 --> 25:27.800
And while you're at it, run it.

25:28.120 --> 25:31.280
And I like to fast forward my videos because who doesn't?

25:31.620 --> 25:35.080
And you go look at the web server and Mrs.

25:35.080 --> 25:38.560
Bin has been pulled the meterpreter binary but also a copy of kubectl.

25:38.560 --> 25:46.900
The command line utility that you use to do damage, I mean, to administer or use a Kubernetes cluster.

25:48.060 --> 25:50.300
So I'm going to pull kubectl.

25:50.680 --> 25:54.840
And the other thing I'm going to do is just make sure that it's landed here.

25:54.840 --> 25:55.820
So here's Mrs.

25:55.820 --> 25:57.500
Bin, my meterpreter binary.

25:57.620 --> 25:59.320
Here's kubectl.

25:59.500 --> 26:00.500
Cool.

26:06.090 --> 26:12.910
And now if recordedj will type a little faster, we'll run the meterpreter binary.

26:13.890 --> 26:22.550
And I'm going to go over to my Metasploit console and actually be like, oh, wait, I have an incoming meterpreter that needs to connect to the console.

26:22.550 --> 26:23.910
I should probably start the console.

26:24.890 --> 26:26.750
This ordering is just great, huh?

26:27.550 --> 26:29.270
But that's often how you work.

26:29.370 --> 26:31.550
So I'll interact with that session.

26:34.430 --> 26:36.570
And I'm now in a pod.

26:36.570 --> 26:37.690
I know, it doesn't look like it.

26:37.690 --> 26:42.410
It looks like an ordinary Metasploit, you know, pwned Metasploit instance.

26:43.950 --> 26:46.890
So, but I see my copy of kubectl, I'm happy.

26:46.890 --> 26:50.750
And when I run mount, I get a tremendous number of file systems.

26:50.750 --> 26:53.470
I'm not looking at one hard disk or what have you.

26:53.650 --> 26:58.550
And a bunch of them have been put there by Docker and by Kubernetes.

26:58.550 --> 27:04.650
And so the one that's really interesting to me is this one that says run secrets Kubernetes service count IO service account.

27:04.650 --> 27:11.010
As soon as I see that directory mounted, I know that I'm going to have some level of access to the API server and I'm happy.

27:11.330 --> 27:16.730
So I'm going to go and first I'm just going to go and collect my flag.

27:16.730 --> 27:19.650
I built this scenario as it captured the flag.

27:19.650 --> 27:21.710
So let's look at our little flag.

27:22.510 --> 27:24.610
And it says, hey, you've found the server's backdoor.

27:24.610 --> 27:26.790
You might notice this isn't your usual Linux system.

27:26.790 --> 27:27.610
You're in a cluster, my friend.

27:27.610 --> 27:29.010
It's time to bust a cube.

27:29.010 --> 27:30.830
This container doesn't have any more flags.

27:30.830 --> 27:32.510
Can you find your way to another pod?

27:32.510 --> 27:33.350
Hint, hint.

27:33.650 --> 27:39.710
So cool thing in Kubernetes is, like I said, one of the things you can do is see if you can move to another workload.

27:39.810 --> 27:41.190
So you're in a container.

27:41.190 --> 27:42.710
Can you move to another one?

27:42.710 --> 27:45.310
So I'm going to see what my service count can do.

27:45.310 --> 27:51.090
I'm going to go and look in that directory and that run secrets Kubernetes IO service count directory.

27:51.090 --> 27:54.530
If recorded J, we'll type just a little bit faster.

27:57.270 --> 28:00.910
And I look at that namespace and it says you're in the marketing namespace.

28:00.910 --> 28:03.010
So that directory has a token.

28:03.070 --> 28:05.930
It has the certificate authorities public cert.

28:06.330 --> 28:10.070
And it has a description of what namespace you're in.

28:10.070 --> 28:12.710
And that namespace, like I said, is kind of a way of organizing.

28:12.710 --> 28:14.310
So we're in the marketing namespace.

28:14.310 --> 28:15.670
We'll come back to that later.

28:15.670 --> 28:20.270
And then I'm also going to go and look at the environment variables that get pushed into every pod.

28:20.270 --> 28:24.970
And my environment variables will tell me where to find the Kubernetes API server.

28:25.090 --> 28:30.290
So there's this assumption in Kubernetes that every workload will need to ask Kubernetes to do things.

28:30.530 --> 28:33.370
I don't know if that's really the greatest assumption.

28:33.370 --> 28:36.850
But I think let's just call it not the strongest of defaults.

28:37.050 --> 28:40.990
So I've got the API server's IP address and port.

28:44.580 --> 28:45.980
And I'll clear my screen.

28:45.980 --> 28:53.100
And I'm going to set up a quick little kubectl where I'm saying alias kubectl to the path to kubectl.

28:53.100 --> 28:56.820
The token pasted in from this long path to the token.

28:56.820 --> 28:58.460
The certificate authority path.

28:58.580 --> 28:59.940
The namespace.

28:59.940 --> 29:01.740
And the server that I just got.

29:01.880 --> 29:05.160
And so every time I type kubectl, all that stuff will be passed in.

29:07.660 --> 29:11.000
So let's just kind of skip and let's see what did I do.

29:11.060 --> 29:13.860
So I said let's do a quick get pods.

29:13.860 --> 29:18.780
And get pods is honestly my go-to just to figure out if my setup is working.

29:19.000 --> 29:20.600
And so it says, oh, there's two pods.

29:20.600 --> 29:21.780
You're the WordPress one.

29:21.780 --> 29:24.080
And I ran host name and it says that's the one you're in.

29:24.120 --> 29:26.160
And then the WordPress MySQL one.

29:26.740 --> 29:27.820
And that's another one.

29:27.820 --> 29:29.180
So let me see if I can move over to it.

29:29.180 --> 29:30.620
Because that was what the hint said.

29:30.860 --> 29:32.900
So I'll do kubectl exec it.

29:32.900 --> 29:35.000
Looks a whole lot like docker exec it.

29:36.580 --> 29:38.920
And what program I'd like to add to that container.

29:38.920 --> 29:39.980
I'm going to add a shell.

29:40.100 --> 29:43.240
I get this kind of error, but I'm in the container.

29:43.240 --> 29:44.660
I've just moved over.

29:44.660 --> 29:46.660
And I've probably moved over to a different host.

29:46.660 --> 29:48.700
Like I'm probably somewhere else in the data center now.

29:49.460 --> 29:51.200
So there's another flag.

29:51.420 --> 29:52.980
And we'll go get our flag.

29:58.450 --> 30:00.730
And I can't clear my screen because my terminal is not set.

30:00.730 --> 30:04.450
So I set it to vt100 because that was one of my first back in the DBS days.

30:04.830 --> 30:06.870
Because I'm exceedingly old.

30:07.530 --> 30:10.050
And it says, hey, you found your way to another container.

30:10.050 --> 30:12.170
Actually, you're on a whole new virtual machine.

30:12.890 --> 30:16.490
Moving from one container to another in a Kubernetes system often means switching nodes.

30:16.490 --> 30:20.070
Your end goal is to get to the developer's non-containerized host.

30:20.070 --> 30:27.710
So it's to get not just to own the cluster potentially, but to get to a machine that's not in the cluster.

30:27.730 --> 30:29.810
So to get there, you're going to want to see if you can hop tenants.

30:29.810 --> 30:32.470
Tenants are usually separated by namespaces.

30:32.890 --> 30:34.930
So let's see what we can do.

30:36.910 --> 30:39.630
I know I'm fast-forwarding through my stuff, but...

30:39.630 --> 30:44.150
So I'm in the other... I'm in that MySQL one.

30:44.150 --> 30:45.290
I try to get pods.

30:45.290 --> 30:48.330
And the problem I'm running into is, hey, you're not allowed to get pods.

30:48.590 --> 30:51.270
So the cool thing is, I'm in a different service account.

30:51.270 --> 30:53.890
I was in the marketing WordPress service account.

30:53.890 --> 30:55.150
It's allowed to get pods.

30:55.310 --> 30:57.470
The marketing MySQL one can't.

30:58.070 --> 31:03.190
So over time, I might want to go around and pick up all these service accounts and hold on to them.

31:03.190 --> 31:04.370
Remember, it was just tokens.

31:04.370 --> 31:11.710
So if I can store all the tokens, I can end up building privilege wider than just what one thing had.

31:11.710 --> 31:15.130
So I did get nodes, and I found out the IP address for a node.

31:15.410 --> 31:18.230
Here's a name, but this node has an IP address.

31:20.130 --> 31:24.770
This one is running in a cloud provider.

31:25.090 --> 31:26.350
And there's a cool thing.

31:26.350 --> 31:28.730
So you can talk to the kubelet.

31:28.770 --> 31:33.570
And this is, thank gosh, finally not a default, but some clusters will have it.

31:33.570 --> 31:38.670
You can talk to the kubelet on, it's got a couple ports, 10.2.50.

31:38.670 --> 31:40.950
I'm going to go and say, can you give me a list of running pods?

31:40.970 --> 31:44.650
And it gives me JSON, because everything in Kubernetes is JSON and YAML.

31:44.950 --> 31:49.610
So I'll take that, and I'll run that again.

31:49.650 --> 31:52.350
And I apologize for this big block here.

31:52.350 --> 31:55.670
So I'll run that again, and I'll add some JQ, JSON query.

31:55.730 --> 31:57.250
Really good tool to learn.

31:57.250 --> 32:03.150
And I'm going to say, give me all the pods, kind of better formatted, give me their name and their namespace.

32:03.550 --> 32:10.130
And what I'm looking for is to see if there's a pod that's in another namespace besides the marketing one.

32:10.130 --> 32:11.490
And I quickly find one.

32:11.490 --> 32:12.790
There's a devpod.

32:22.030 --> 32:24.090
And that devpod...

32:24.090 --> 32:29.710
So Kubernetes loves to tell you about anything you want, and that's really, really nice as an attacker, especially if you can script it.

32:30.030 --> 32:32.910
So I've got devsync, I've got devweb.

32:32.910 --> 32:35.950
These are two containers that are running in the same pod.

32:35.950 --> 32:38.470
I've got the image they came from, so they're up on Docker Hub.

32:38.470 --> 32:40.110
You could pull them yourself if you wanted.

32:42.190 --> 32:46.210
And as an attacker, that's often what you're doing, is basically saying, well, what workloads are running?

32:46.210 --> 32:50.330
And can I go look in container images and see if there are any secrets or anything that would be really helpful to me?

32:50.410 --> 32:54.830
It's very, very nice of the defenders to hand you descriptions of their workloads.

32:56.410 --> 32:57.750
So I'm going to look at that.

32:57.750 --> 32:59.810
I'm going to run another command, and this is...

32:59.810 --> 33:00.810
I did running pods.

33:00.810 --> 33:05.310
I'm going to tell the kubelet, hey, would you mind just executing a command for me?

33:05.310 --> 33:10.230
So I'm going to pass it run, and then the namespace, the pod, and the container name.

33:10.430 --> 33:13.470
And I'll do command equals id.

33:13.850 --> 33:16.090
And I get an error code that says basically no.

33:16.090 --> 33:19.530
Either there's no shell in there, or I'm not allowed.

33:19.530 --> 33:22.110
I will tell you that there's no shell in there.

33:22.630 --> 33:25.730
But remember, there were two containers in that pod.

33:25.730 --> 33:32.690
So I saw devsync and devweb, and that's a really common thing you see outside of containerized environments.

33:32.690 --> 33:40.250
Like you have a web server, and you have something that's there to pull it content in from wherever that content's being created or stored.

33:40.370 --> 33:46.270
So I was hoping I could get to devsync, because it'll have the credentials for pulling content.

33:46.270 --> 33:47.710
It'll have an SSH key.

33:47.790 --> 33:50.290
I couldn't, so let me try devweb.

33:55.690 --> 33:57.350
So devweb I can run commands in.

33:57.350 --> 33:58.110
I ran id.

33:58.110 --> 34:00.630
It says, yeah, that thing's even running as root.

34:00.630 --> 34:01.650
Very nice.

34:05.420 --> 34:06.940
And so let's try a different command.

34:06.980 --> 34:08.380
Let's look at the file system.

34:08.380 --> 34:09.560
Oh, look, another flag.

34:11.280 --> 34:12.500
I like flags.

34:14.200 --> 34:20.620
I love doing CTFs, and I love doing CTFs actually, like, first doing them as an attacker, and then going and basically doing them as a defender.

34:20.620 --> 34:25.820
How much of the attack can I break with proactive stuff?

34:25.820 --> 34:29.360
With stuff that you could have thought of before you knew that you had the vulnerability?

34:29.640 --> 34:32.240
So this thing says, hey, you're not in the marketing department anymore.

34:32.240 --> 34:34.220
You're in the development department's namespace.

34:34.320 --> 34:37.900
So can you go take over the development department's non-containerized machines?

34:37.900 --> 34:46.280
And they're big fans of The Matrix, so it's named Mainframe, named for the machine's mainframe that may or may not have been in the second and third movie, depending on your religious beliefs.

34:46.280 --> 34:56.000
There are many people I know who acknowledge the truth as they believe it, that there were no second and third Matrix movies.

34:57.080 --> 34:59.320
Only quests for more money.

34:59.700 --> 35:00.700
So here we go.

35:00.700 --> 35:04.940
So we've got... we're trying to do a get pods.

35:04.940 --> 35:18.040
So I'm in one pod asking the kubelet on another host if it minds running commands in another pod, and I'm asking that pod to run kube control commands.

35:18.420 --> 35:24.240
I find out, okay, dev app isn't allowed to list pods, but it's kind of cool.

35:24.240 --> 35:26.280
I now know that I've got a third service account.

35:26.280 --> 35:28.940
I've got the dev dev app one.

35:28.940 --> 35:30.660
So I'll try get secrets.

35:30.940 --> 35:32.540
Let's see what secrets are available.

35:32.540 --> 35:33.280
Oh, nice.

35:33.280 --> 35:36.220
There's a mainframe login and an SSH key.

35:36.520 --> 35:42.960
Well, the two pods in there, the two containers in there are going to likely have access to the same secret.

35:43.800 --> 35:45.520
They've been placed in the same place.

35:45.520 --> 35:48.520
They don't necessarily need it in dev web, but what the hell.

35:49.000 --> 35:51.420
Let's go and ask for a copy of that secret.

35:54.260 --> 35:58.620
And I promise the next demo is hackers themed and choose your own adventure.

35:58.620 --> 36:00.360
So we're going to have some fun.

36:02.440 --> 36:04.340
So here's our SSH key.

36:04.340 --> 36:05.960
And you're like, that doesn't look like an SSH key.

36:05.960 --> 36:07.480
And that's because it's a secret.

36:07.720 --> 36:10.200
It's opaquely encoded.

36:10.260 --> 36:11.900
It's base 64 encoded.

36:11.900 --> 36:14.100
So we can decode it.

36:15.080 --> 36:17.660
And boom, there's our SSH private key.

36:18.060 --> 36:21.640
And we can do the same thing with the other secret here.

36:21.640 --> 36:24.440
So we can find out basically what is it used for.

36:24.440 --> 36:33.140
So I'm just going to fast forward a little bit and tell you that it's a user and a host in AWS.

36:33.580 --> 36:35.420
But not part of the cluster.

36:35.660 --> 36:38.600
So now we could SSH into that.

36:38.620 --> 36:40.980
And we're in the developer's mainframe.

36:41.000 --> 36:43.240
And it says, hey, you made it to the machine mainframe.

36:43.240 --> 36:46.940
Can you, for extra credit, can you get credentials to take over the whole cloud environment?

36:47.740 --> 36:49.260
And we can do that.

36:49.260 --> 36:54.380
But I'm going to set the rest of that aside because we do that in another demo.

36:54.760 --> 36:57.020
So let's see.

36:58.300 --> 37:00.480
Let me go back to the slides for a second.

37:03.260 --> 37:07.360
And here was our... and I'm sure that I'll be...

37:07.360 --> 37:15.460
because of the vagaries of having the videos in a separate program, I'm sure I'm going to be doing a little bit of going back and forth and having the whole screen do this.

37:15.460 --> 37:17.100
So here's our attack path.

37:17.100 --> 37:19.380
We got an interpreter in the WordPress container.

37:19.480 --> 37:22.120
We moved in the MySQL container with the kubectl exec.

37:22.220 --> 37:32.280
We used the MySQL container's totally unfettered network access inside the cluster to reach a kubelet that we wouldn't have been able to reach from outside the cluster on the master node.

37:32.280 --> 37:36.740
And that kubelet let us basically take a look at...

37:37.840 --> 37:41.680
run commands in another container in another namespace.

37:41.720 --> 37:47.400
And from that other container in that other namespace, we figured out there were secrets.

37:47.400 --> 37:48.440
There was an SSH key.

37:48.440 --> 37:49.740
So we got that SSH key.

37:49.740 --> 37:52.960
We authenticated to the high-value developer machine.

37:53.180 --> 37:57.240
And later on, we ended up getting to take control of the AWS account.

37:57.240 --> 38:01.780
And we're going to skip that right now because we're going to do that in a much more fun way.

38:02.760 --> 38:05.800
So we're going to play Hacker's Choose Your Own Adventure.

38:06.540 --> 38:09.340
And I'm going to drink some water for a second because whoa.

38:12.120 --> 38:12.640
So...

38:14.400 --> 38:15.960
I like the movie Hackers.

38:15.960 --> 38:17.780
It's a fun movie.

38:18.120 --> 38:19.740
It is an oldie but goodie.

38:19.740 --> 38:21.720
It is thoroughly realistic.

38:21.720 --> 38:32.260
We all know that whenever we're hacking, we see strange translucent 3D models of buildings, and we fly through a city, and it's really cool.

38:32.260 --> 38:38.100
And all of that was clearly done with the technology that had Apple IIs and floppy disks.

38:39.580 --> 38:42.660
So, I mean, I remember 3D rendering back then.

38:42.660 --> 38:43.260
I wasn't doing it.

38:43.260 --> 38:44.620
I was watching people do it.

38:44.620 --> 38:46.880
And yeah, no, none of that.

38:47.160 --> 38:48.540
So here we go.

38:48.540 --> 38:50.100
So we're going to start here.

38:50.560 --> 38:53.940
And again, this is where I have embedded video.

38:54.580 --> 38:57.840
So we will, unless I click on that and it works.

38:58.440 --> 38:59.520
Let's see.

39:00.340 --> 39:01.840
Oh, hey, look at that.

39:03.100 --> 39:06.060
Now, can we full screen that?

39:07.980 --> 39:09.720
Is there a way?

39:10.060 --> 39:13.380
No, so we're going back to oldie but goodie.

39:14.000 --> 39:15.680
And here we are.

39:15.680 --> 39:19.080
So first, this is going to look a little familiar.

39:19.560 --> 39:23.220
So we've got a, we've got, what's that?

39:24.380 --> 39:28.500
Oh, well, you're on the slide and I'm on the video.

39:28.500 --> 39:30.340
Okay, boom.

39:32.960 --> 39:34.760
And switch.

39:35.340 --> 39:36.620
Come on.

39:37.460 --> 39:39.620
I'm going to Windows computers soon.

39:41.540 --> 39:44.140
And that's a lot for me to say, trust me.

39:44.140 --> 39:46.380
So anyway, here we go.

39:46.840 --> 39:50.760
So we've got the, we've got the Gibson control room.

39:50.760 --> 40:05.340
We have Penn from Penn and Tower, who's apparently a techno weenie, according to Ben from Short Circuit, who somehow was playing an Indian and talking about Mr.

40:05.340 --> 40:06.380
Johnny Five.

40:06.440 --> 40:07.320
But Mr.

40:07.320 --> 40:09.100
Johnny Five here was the plague.

40:09.620 --> 40:14.720
And , and we have this nice little form that's called the Gibson control room.

40:14.720 --> 40:18.260
And the Gibson control room clearly lets you like leave a message.

40:18.260 --> 40:24.140
So it's based on a, it's based on a actual, on a Kubernetes documentation vulnerable app.

40:24.140 --> 40:27.660
They didn't mean for it to be vulnerable, but it's only a little vulnerable.

40:27.660 --> 40:29.700
So I've added a vulnerability to that.

40:29.780 --> 40:39.720
So the, so what we've got is I look at the source on that page and I find that the form is basically being provided by some JavaScript.

40:39.720 --> 40:54.060
So if I go look at that JavaScript, what happens when you submit the form is you're, you're referencing guestbook.php, you're sending to guestbook.php, you're saying, hey, command set, key messages, value this.

40:54.420 --> 40:55.340
Okay, really?

40:55.340 --> 41:00.900
You're going to let me, you're going to let me decide what, what key I'm going to set?

41:00.900 --> 41:04.960
You're not just going to have me set whatever key, you know, was meant to be set by this form?

41:05.000 --> 41:06.560
So that was their bug.

41:07.760 --> 41:13.920
And what I've added to it is I have something that actually runs code out of a different Redis key in this, you know, back in Redis database.

41:14.180 --> 41:16.500
So we go and take the Gibson control room.

41:16.760 --> 41:22.540
And if we were to type a message, you know, it shows up, this is the intended, this is the intended purpose.

41:22.880 --> 41:31.700
But instead, we're going to paste that same thing that happens when you submit the form, except instead of the message key, we're going to try a different key.

41:31.700 --> 41:34.440
Or we'll try a, let's see how it works.

41:34.440 --> 41:35.620
We're going to hit foo.

41:37.640 --> 41:40.660
And we'll put in just some key, some random key.

41:40.660 --> 41:41.520
Oh, cool.

41:41.520 --> 41:44.340
Okay, so JavaScript's probably updating that key.

41:44.600 --> 41:47.220
Let's try going to status PHP.

41:47.220 --> 41:51.300
So I'm asking you to imagine that we did a DurrBuster or looked at robots.txt.

41:51.300 --> 41:52.860
We found a status PHP.

41:52.860 --> 41:56.080
I'm not doing it because, well, I'd like to spend our time on Kubernetes.

41:56.220 --> 41:58.040
So I go to the status PHP page.

41:58.040 --> 41:59.440
It says, hey, no command to run.

41:59.440 --> 42:05.740
I'm going to set the Redis key, the Redis command key to this so that you can reload the page and that will get run.

42:05.840 --> 42:11.040
So if I reload the page, I get the output of, you know, I get the output of crawling that web server.

42:11.040 --> 42:17.460
It says all services are operational here at, what was it, Ellington Mineral or Ellington Mineral?

42:17.460 --> 42:18.520
Ellington, I think.

42:19.620 --> 42:23.300
So, well, as long as there's a command key, let's go and set it.

42:23.300 --> 42:33.160
And I've set my command key now to environments, to run environments, like we did before, to find a Kubernetes cluster, to find the Kubernetes API server.

42:33.160 --> 42:34.400
And here we go.

42:34.400 --> 42:42.880
So we know that once we're in a workload, if we reach out to 10.96.01, we'll get to the Kubernetes API server.

42:42.880 --> 42:45.540
So I'm going to go a little further, kind of similar to last time.

42:45.540 --> 42:47.180
I'm going to curl in.

42:47.180 --> 42:53.260
I'm going to tell this thing, excuse me, would you just pull in a reterpreter binary I created and connect back to me?

42:53.620 --> 42:55.920
So I have it pull it in.

42:55.920 --> 42:57.500
I set that key.

42:57.500 --> 42:59.820
And now when I run status, the page hangs.

42:59.840 --> 43:05.260
I love when pages hang when I've just given them binaries because it generally means the binary is running successfully.

43:05.600 --> 43:11.780
So if I go over to my terminal where I've got a Metasploit handler waiting this time, I find there's a session waiting for me.

43:11.780 --> 43:24.460
And the first thing I'm going to do before I start interacting with a shell there is I'm going to upload a copy of kubectl, which I've stored on this Kali system in this directory.

43:24.460 --> 43:28.280
So I put kubectl and I'm going to upload some YAML, which we'll get to later.

43:30.500 --> 43:34.680
So I've uploaded some YAML, which we may or may not get to later, depending on your choices.

43:34.680 --> 43:37.720
And I've asked for a shell, hit PWD.

43:38.460 --> 43:40.960
Looks like my video is cut off by one character.

43:40.960 --> 43:41.580
I hit ID.

43:41.580 --> 43:43.700
It says you're wwwdata user.

43:45.280 --> 43:47.120
I try SSHing.

43:47.840 --> 43:52.500
Well, I don't know what I tried because that was the end of that part.

43:52.500 --> 43:56.740
And now we're going to do this part so that we're a little bit gentler.

43:57.140 --> 44:00.920
I'm going to ask you, so do you want to try...

44:00.920 --> 44:05.960
The YAML files that I put up were ones that would mount a volume on the...

44:05.960 --> 44:07.940
that would try to mount a volume on the host.

44:07.940 --> 44:10.300
Like they'd try to mount the host's own directory.

44:10.300 --> 44:14.700
The old, you know, Docker, you know, start a container mounting the host.

44:14.700 --> 44:21.680
So do you want us to start the host mounting pod and see if we can take over a node?

44:21.720 --> 44:23.960
Or do you want us to exec into another pod?

44:26.450 --> 44:30.690
I heard the host mount first, so we'll try that.

44:30.690 --> 44:32.850
So let's see.

44:38.520 --> 44:39.540
Boom.

44:39.760 --> 44:40.740
And boom.

44:40.740 --> 44:42.020
Here we are.

44:42.600 --> 44:44.320
Run that front end.

44:45.340 --> 44:49.680
And we'll set kubectl executable so we can run it.

44:49.960 --> 44:53.160
We'll go and set up our kubectl.

44:53.460 --> 44:55.800
We'll try to run kubectl apply.

44:55.800 --> 44:58.720
Realize, wait, we've got to set all those parameters we set before.

44:58.780 --> 45:00.300
Sometimes you get lucky.

45:00.300 --> 45:09.580
And so I'm going to take that same directory, that same run secrets kubernetes.io service account that's being mounted into the pod.

45:09.860 --> 45:16.040
I'll set a variable called dir to that, export dir to that, just to make this a little bit easier to type, a little more manageable.

45:16.940 --> 45:21.580
So if I look at the dir, got the cacert, namespace, token, just like before.

45:22.440 --> 45:24.500
Let's go and run.

45:24.680 --> 45:28.220
Alias kubectl is going to mean that, same way we did before.

45:33.150 --> 45:36.130
So server's out on 1096.01.

45:36.130 --> 45:38.190
That was what we found from that environment variable.

45:38.430 --> 45:42.110
And now let's look at our alias.

45:42.110 --> 45:44.290
That's that token being pasted in.

45:44.290 --> 45:46.090
So kubectl get pods.

45:46.170 --> 45:47.790
Cool, we've got front ends.

45:47.790 --> 45:49.030
We've got front end pods.

45:49.030 --> 45:50.530
We've got a Redis master.

45:50.750 --> 45:54.130
We've got an Apache status, that thing we saw before.

45:54.130 --> 45:55.610
We're in the front end.

45:55.930 --> 45:58.730
So let's try launching a pod.

45:58.730 --> 46:01.550
kubectl apply.

46:02.670 --> 46:04.170
I like it as kubectl attack.

46:04.460 --> 46:05.670
Attack pod.

46:05.670 --> 46:11.990
And it says, sorry, your service count, front end, isn't allowed to create resources.

46:12.290 --> 46:13.790
Wah, wah.

46:15.210 --> 46:15.870
So...

46:16.550 --> 46:19.850
And this is where I get to my slide.

46:21.590 --> 46:24.450
So we'll do that real quick.

46:27.360 --> 46:30.040
I was considering for this one...

46:30.040 --> 46:31.260
Oh, damn it.

46:31.260 --> 46:33.480
Let's just keep the screen mirrored.

46:33.640 --> 46:40.200
So I was considering for this one doing a spandex quote from the movie.

46:40.200 --> 46:44.280
And I decided that wasn't a sentiment I wanted to voice.

46:45.640 --> 46:46.160
So...

46:47.100 --> 46:50.840
I see that I'm going to make sure that I'm moving on time.

46:50.840 --> 46:53.620
So at this point, we'll go back to our original...

46:53.920 --> 46:55.760
We'll go back to the other thing we could do.

46:55.760 --> 46:58.040
So our two options, where do we want to launch a pod?

46:58.040 --> 46:59.320
Or exec in a back end?

46:59.460 --> 47:01.380
So let's exec in a back end.

47:02.300 --> 47:04.600
Or let's try execing into another pod.

47:04.980 --> 47:08.360
So we'll go like we did in our other demo.

47:08.360 --> 47:09.980
We'll try execing into a pod.

47:11.840 --> 47:13.800
Keep wishing we had a better terminal.

47:17.440 --> 47:18.460
kubectl get pods.

47:18.460 --> 47:21.260
I see that there's a Redis, that Redis setup.

47:21.260 --> 47:24.040
Remember I was pushing Redis keys.

47:24.040 --> 47:28.080
I might try to investigate the Redis and see what else.

47:28.080 --> 47:30.680
Now that I've got more direct access to it.

47:30.900 --> 47:35.120
Because Redis is very often, well almost always, unauthenticated.

47:35.920 --> 47:38.140
But let's go into the Redis pod.

47:38.140 --> 47:39.440
So I'm rooted in there.

47:39.440 --> 47:40.680
I'm Redis master.

47:40.680 --> 47:43.080
I'll grab a copy of the meterpreter binary I've been using.

47:43.080 --> 47:46.460
Just because that's a very convenient way of putting files into something.

47:46.780 --> 47:48.620
And I'll background that.

47:48.620 --> 47:51.420
And I'm going to switch over.

47:51.420 --> 47:56.600
Now that I've got the Redis master, that pod running my meterpreter.

47:56.600 --> 48:00.820
So I'm going to switch over and catch that session.

48:02.520 --> 48:09.920
And so in that session, I'll go and upload the same kubectl that I did before.

48:09.940 --> 48:13.020
I'll also upload that attack pod that I just used before.

48:13.020 --> 48:16.140
And I'll also add something called attack daemon set.

48:16.460 --> 48:18.300
Just in case we need it.

48:18.300 --> 48:24.950
So now we get another choice.

48:24.950 --> 48:26.370
So you're in the back end.

48:26.370 --> 48:28.470
Do you want to try host mounting pods?

48:28.470 --> 48:31.250
Or do you want to check out the cloud APIs?

48:33.030 --> 48:34.250
Cloud APIs.

48:34.550 --> 48:35.310
Cool.

48:35.410 --> 48:37.570
Okay, so here we are.

48:41.020 --> 48:43.680
And I'm going to show you this in two ways.

48:45.360 --> 48:48.120
And can I get a rough time check?

48:48.120 --> 48:49.800
How much time will you let me be late?

48:49.800 --> 48:51.960
Oh, less than five.

48:51.960 --> 48:56.360
Okay, so this is where I normally kick on the speed control.

48:56.660 --> 48:58.280
So, okay, so we're in a pod.

48:58.280 --> 48:59.940
We're in that Redis master pod.

49:00.220 --> 49:03.280
And we say, hey, I'd like to talk to the metadata API.

49:03.280 --> 49:07.780
So every cloud provider gives you 169254, 169254.

49:07.780 --> 49:09.020
That part's common.

49:09.100 --> 49:12.460
What the calls are that you make against it, they document wonderfully.

49:12.520 --> 49:14.040
And you read the documentation.

49:14.080 --> 49:16.400
So this is on GCP.

49:17.000 --> 49:21.400
So I'm going to go and say, can you tell me what the project ID is?

49:21.400 --> 49:24.180
I need that project ID to do API calls.

49:24.320 --> 49:37.800
But then the more interesting one is usually where you say, would you mind, in addition to the project ID, which I'm going to set into a variable, would you mind telling me what service accounts are assigned to the machine I'm on?

49:37.800 --> 49:39.560
So the machine this pod's running on.

49:39.560 --> 49:42.340
And there are two, but default is mapped to that other one.

49:42.340 --> 49:44.680
So I'm just going to use default because it's easier typing.

49:45.820 --> 49:54.520
And I'm going to go and say, okay, for that service account, would you do me a favor and just give me a bearer token that I can use to act as that service account?

49:54.900 --> 49:56.060
And it says, sure.

49:56.760 --> 49:57.920
Here's your token.

49:57.920 --> 50:02.600
It expires in like a half an hour or an hour, but I've got a token.

50:02.600 --> 50:04.440
So I'll set a variable to that.

50:05.220 --> 50:11.500
And now what I'm going to do is say, let's go and I've set that token to that.

50:11.540 --> 50:13.200
And I need to refresh that token.

50:13.200 --> 50:17.260
So most of my commands will pull that token over and over, every command.

50:17.260 --> 50:22.100
So I'm going to use that token, type out authorization bearer token where the token's provided.

50:22.100 --> 50:28.160
Say I'll take JSON and now I'll say, hey, for this project, I'd like a list of buckets.

50:28.160 --> 50:30.060
And it says, oh, there's only one.

50:30.320 --> 50:32.400
Okay, well, what's in that bucket?

50:32.700 --> 50:35.820
And so I basically say, give me a list of objects.

50:37.060 --> 50:41.420
And the way I do that is it's like slash B for a list of buckets.

50:41.420 --> 50:45.440
Then it's the slash B, that bucket slash O for a list of objects.

50:45.440 --> 50:48.240
And then for those objects, I can run through them.

50:48.660 --> 50:53.700
Now, on this one, I don't find anything that's all that useful.

50:53.700 --> 50:57.660
I don't find, I find, I don't find what I find in some cloud environments.

50:57.660 --> 51:00.620
I'm going to show you in another demo somehow.

51:01.640 --> 51:04.300
And, but I do find a kubenv.

51:04.460 --> 51:10.960
So I can pull in a metadata instance for this cluster that was set by the installer.

51:10.960 --> 51:18.320
And when I do that, what I get out of it is, among other things, a couple service count tokens for the cluster.

51:18.320 --> 51:23.880
And that ends up leading, which I won't now show you, but that ends up leading to win.

51:23.960 --> 51:33.880
And so just for the end of our, for the end of that, that then leads to our crash and burn.

51:35.440 --> 51:42.020
So if, if Ming will let me have one more minute, I will show you a cooler version of that.

51:42.020 --> 51:47.380
We have a tool that we're, that we keep soft-releasing, but never kind of like putting up on Twitter.

51:47.380 --> 52:02.980
So it's called Paradis and Paradis will, if I, if I actually just, I'm just nervous.

52:02.980 --> 52:06.280
So it's in here, but somehow I'm,

52:12.160 --> 52:15.240
let's do this.

52:16.540 --> 52:22.680
So Paradis is basically a remote access Trojan for, for Kubernetes.

52:22.680 --> 52:25.540
You run this and it does all kinds of things.

52:25.820 --> 52:36.460
And I'm going to start this from the beginning, but it is under two minutes and then I will get the heck off the stage and tell you that you should ask me for stickers.

52:36.700 --> 52:38.180
So it's got a bunch of things.

52:38.180 --> 52:43.100
One of those I had said, okay, 13, go get the IM credentials from GCP.

52:43.240 --> 52:45.620
The same thing we just did, get the cloud service account.

52:45.620 --> 52:50.840
And then, come on Jay, type faster, highlight faster.

52:50.840 --> 52:53.260
So that's for that same one I just got.

52:53.540 --> 53:03.280
And now let's take that and let's pull, let's go looking in GCS in the storage buckets for service count tokens.

53:03.280 --> 53:15.020
Oh look, this installer, this one was COPS and left, left service count tokens there for all the components, including a cluster admin, which would be perfectly useful.

53:15.020 --> 53:33.260
And so that's the, like, basically, that's probably roughly what happened to Capital One recently, where it was talk to the metadata API, get your cloud account, use that to go rating for information or access.

53:33.940 --> 53:39.220
So anyway, so now once I've done that, Paradis will basically store every account it gets.

53:39.220 --> 53:42.100
And then you basically say, okay, I'm going to switch contexts.

53:42.100 --> 53:45.760
And you go and you go through and you collect all of the service count tokens.

53:45.760 --> 53:50.000
And then you basically have this big old store, that's your loot, and it keeps it in memory.

53:50.860 --> 53:54.140
And you run around and basically get more access and get more access.

53:54.140 --> 54:00.400
We've even got a, this video will be up on YouTube, but we've even got something that basically takes over the nodes.

54:00.480 --> 54:10.220
If it's allowed to mount a host path volume, it'll go and add a cron job that will send a netcat shell back to your, back to the IP address of your choice.

54:10.220 --> 54:17.420
So once we have this cluster admin, we're allowed to, we can go and do everything which included like, hey, now show me all the secrets.

54:17.420 --> 54:22.060
And all the secrets includes all of the tokens, all the service counts for every component.

54:23.220 --> 54:27.980
And Paradis will not just grab, will not just list these and get them, but it'll also store them and let you use them.

54:28.040 --> 54:29.960
So it's a fun little pen test tool.

54:30.780 --> 54:34.320
And it's up on GitHub, we'd love some help, we'd love some help producing it.

54:34.320 --> 54:37.980
So it's an NGuardians tool, we do a ton of Kubernetes work in NGuardians.

54:37.980 --> 54:41.680
And I will now get off the stage and take questions all the way out in the hallway.

54:41.860 --> 54:43.920
So if you see me, please ask me for a sticker.

54:47.140 --> 54:48.100
Thank you.

