WEBVTT

00:00.000 --> 00:02.120
Hello everyone, and thanks for joining this talk.

00:02.140 --> 00:08.480
Today, we're going to talk about Kubernetes, and specifically, how you can run successful attack simulation exercises.

00:08.780 --> 00:10.660
First of all, a few words about myself.

00:10.660 --> 00:11.460
My name is Leo.

00:11.460 --> 00:15.140
I'm a Senior Security Consultant at WithSecure, based in Manchester, UK.

00:15.240 --> 00:21.100
I'm focusing mostly on threat simulation and, generally speaking, collaborative security assessments.

00:21.100 --> 00:30.420
So, one challenge that our clients at WithSecure typically come to us with is how can we measure our capability to detect attacks in X environment?

00:30.620 --> 00:39.640
And the environments we typically see are of all sorts, Windows, Linux, mobile, macOS, on-prem cloud, and even container orchestration environments like Kubernetes.

00:39.880 --> 00:53.880
So, when a while ago, one of our more mature clients were looking to assess and improve their blue team capability against attacks in a Kubernetes environment, we approached this as we usually do, with a three-fold adversary simulation assessment.

00:53.880 --> 00:59.380
So, first, we did some threat modeling, just to better understand the risks to this novel platform.

00:59.500 --> 01:04.160
Then, we wrote some tooling in order to simulate some attacks at scale.

01:04.160 --> 01:16.360
And finally, we executed the test cases we designed, side-by-side with the blue team, researching along the way for means to improve visibility and alerting within the Kubernetes ecosystem.

01:16.520 --> 01:18.900
But this research didn't really stop there.

01:18.900 --> 01:20.380
It didn't stop after that project.

01:20.380 --> 01:24.420
We kept working on it in the background, and this is what we're talking about today.

01:24.460 --> 01:27.100
We'll start with a very gentle introduction to Kubernetes.

01:27.100 --> 01:28.340
I know this is Adversary Village.

01:28.340 --> 01:29.480
It's not a cloud conference.

01:29.480 --> 01:32.180
So, if you're not familiar with Kubernetes, fear not.

01:32.560 --> 01:39.160
We'll talk about the threats posed to a Kubernetes cluster, and why threat modeling is essential for the success of any security exercise.

01:39.620 --> 01:43.040
And then we'll dive headfirst into Kubernetes attack simulation topics.

01:43.040 --> 01:47.440
And we're going to look at tools, operational, planning, and eventually execution.

01:48.060 --> 01:51.000
And this talk isn't only for offensive security practitioners.

01:51.000 --> 01:57.200
So, we'll cover some basic Kubernetes detection concepts as well, to see things from the perspective of the SOC.

01:57.260 --> 02:01.040
We'll look at things like log sources, detection engineering, and so on.

02:01.400 --> 02:09.980
And finally, we'll demonstrate everything in an end-to-end simulation of an attack against the cluster, using the tool we will be releasing shortly after this talk.

02:11.300 --> 02:15.180
Okay, as promised, let's start with some introductions.

02:15.420 --> 02:21.060
We do that in order to introduce all the things that will come into play later, both in the slides and in the demo.

02:21.960 --> 02:27.040
But the thing is, if you're even remotely familiar with Kubernetes, you will know that it's complicated.

02:27.260 --> 02:28.980
So, just a word of caution.

02:29.020 --> 02:30.980
This is not going to be an in-depth analysis.

02:31.040 --> 02:32.640
It will be deliberately incomplete.

02:33.060 --> 02:38.100
In fact, it's probably going to be the fastest introduction to Kubernetes ever given, so please bear with me.

02:38.760 --> 02:43.760
So, our system in question, the Kubernetes cluster, consists of a set of worker machines.

02:43.760 --> 02:45.280
We call them nodes, right?

02:45.480 --> 02:47.780
And these nodes run containerized applications.

02:47.780 --> 02:51.660
They are managed by the control plane, over there on the left of the slide.

02:51.680 --> 03:06.220
And in order to run workloads, they need to have a container runtime installed, such as container D, or in older versions, Docker, as well as an agent called the kubelet, which communicates with the control plane and specifically the API server to receive instructions.

03:06.420 --> 03:10.260
Now, this component that I mentioned, the API server, is in the heart of the cluster.

03:10.260 --> 03:14.100
It's the front end that all internal and external parties communicate with.

03:14.100 --> 03:18.700
It exposes a REST API, which clients can talk to if they want to interact with Kubernetes.

03:18.700 --> 03:23.140
And I'm talking about clients like users or services, like CICD pipelines.

03:23.440 --> 03:29.700
But it's important to remember that humans most commonly use kubectl instead of just sending raw HTTP requests.

03:30.240 --> 03:35.000
Now, when it comes to running applications, the basic building block in Kubernetes is a pod.

03:35.000 --> 03:42.580
A pod can consist of one or more containers whose images are pulled from registries, as well as volumes, storage resources.

03:42.600 --> 03:52.740
What usually happens in the real world is that workloads aren't actually deployed as individual pods, but as managed collections of pods, like daemon certs or deployments.

03:53.560 --> 04:01.540
But beyond pods and deployments, there's a few more types of objects that Kubernetes understands, or resources, such as secrets or services.

04:01.540 --> 04:10.100
And all these resources can then be logically grouped into different namespaces for each different project, which you can think of like tenants in the cloud world.

04:10.460 --> 04:19.560
And finally, there's a third layer besides the physical and the logical, that of authorization, with the most common authorization model being RBAC, role-based access control.

04:19.820 --> 04:26.960
RBAC defines the potential entities and allows you to write policies for the permissions that these entities will have against resources.

04:26.960 --> 04:38.760
So in the context of RBAC, humans are represented as user objects that can authenticate using various mechanisms like MTLS client certificates, Active Directory, IAM roles, and so on.

04:38.760 --> 04:43.360
And you also get pods or external services that are associated with service accounts.

04:43.360 --> 04:47.540
And service accounts authenticate using tokens, JSON web tokens, JWTs.

04:48.560 --> 04:52.080
Okay, that was easy, right?

04:52.340 --> 04:56.120
One thing to remember, though, is that in Kubernetes, everything can be replaced.

04:56.120 --> 04:57.480
It's built to be extensible.

04:57.480 --> 05:04.600
So it is 100% certain that your mileage will vary and you will have numerous third-party technologies running in your cluster.

05:04.620 --> 05:10.980
Technologies like the ones tracked in the CNCF landscape, which introduce their own set of risks when deployed inside your cluster.

05:10.980 --> 05:19.020
So in order to tailor any security exercise to your environment with its own intricacies, it's essential you perform some threat modeling first.

05:19.020 --> 05:22.900
And that means answering a few questions like, what are the assets I must protect?

05:22.900 --> 05:24.820
And where would attacks come from?

05:24.900 --> 05:27.500
And why would attackers target Kubernetes in the first place?

05:27.880 --> 05:30.400
Let's start with an enumeration of the attack surfaces.

05:30.400 --> 05:36.280
This will also help us understand which levels we must execute in if we're looking to simulate these attacks.

05:36.840 --> 05:42.500
In the most typical scenario, attacks will originate from the container level, the code running within the pod.

05:42.500 --> 05:49.180
For example, think of a compromised web service or a backdoored image that found its way into your cluster somehow.

05:49.460 --> 05:58.280
And if that pod is assigned a service account, the attacker can talk to the control plane in a limited security context, hopefully, unless they manage to break out of the container.

05:58.700 --> 06:09.660
That way, they're on the node, the underlying host, with potential access to other Kubernetes resources from other namespaces and with even higher security privileges as they will most likely impersonate the kubelet.

06:10.180 --> 06:13.960
And of course, there's always a threat of attacks from the outside world.

06:14.080 --> 06:20.880
Think of scenarios like leaked or stolen credentials, a compromised service, a malicious user, a coerced user, and so on and so on.

06:21.380 --> 06:24.260
So once they're inside your cluster, what will they move towards?

06:24.260 --> 06:25.880
What's the final objective there?

06:26.660 --> 06:29.180
An obvious answer to this one is, of course, the workloads.

06:29.660 --> 06:36.420
If Kubernetes is the underlying platform that your critical workloads are running in, then it's a way into them.

06:36.420 --> 06:38.600
It's a way into the workload.

06:38.600 --> 06:43.480
So compromising Kubernetes could result in unauthorized access to the data.

06:43.480 --> 06:53.300
And we're talking about potentially sensitive data that the apps may be handling, like proprietary software, as you can see on this slide, that can be stolen or even backdoored to achieve a supply chain compromise.

06:54.140 --> 06:56.780
But actually, that's not the most common incentive.

06:57.200 --> 07:04.880
In the age of cryptocurrency, every compute resource makes for an attractive target for its immediate potential for financial returns.

07:04.880 --> 07:08.400
A compute, in and of itself, is therefore worth protecting.

07:08.640 --> 07:12.240
And you'll see that various instances have been recorded with this particular objective.

07:13.380 --> 07:19.920
Kubernetes clusters are usually also deployed as managed cloud services, or broadly speaking, in cloud infrastructure.

07:19.920 --> 07:28.600
So instead of going for the applications, a Kubernetes attacker might actually be looking for a way into the cloud infrastructure, into the underlying infrastructure.

07:28.600 --> 07:46.220
But we've also seen Kubernetes attack techniques across all phases of the intrusion lifecycle, including persistence methods that could enable APT-like surveillance through a long-term infection, and even for defense evasion purposes, as, after all, Kubernetes is yet another platform where an intruder can dwell in.

07:46.480 --> 07:52.280
And usually, it's a less monitored platform, which makes it a great place to hide if you want to evade containment measures.

07:53.220 --> 07:56.580
All right, so we know what adversaries are looking for.

07:56.580 --> 07:58.080
We know where they'll come from.

07:58.140 --> 07:59.660
Let's go ahead and simulate them.

07:59.660 --> 08:02.620
Now, there's a few different approaches to go about this.

08:02.620 --> 08:08.220
And instead of a stealthy, objective-based exercise, we chose to adopt more of a Purple Team methodology.

08:08.560 --> 08:13.660
And I know different people define Purple Teams differently, so let me use the definition given by the guys over at SpectreOps.

08:13.720 --> 08:19.220
It talks about collaboration between offense and defense with the aim to increase familiarity with TDPs.

08:19.360 --> 08:29.800
And for a novel environment like Kubernetes, we similarly decided it's more valuable to opt for a collaborative engagement and try to help the blue team understand attacker behaviors instead of vulnerabilities.

08:29.800 --> 08:32.460
And at WithSecure, we focus a bit more on detection.

08:32.460 --> 08:37.380
So when we're planning a Purple Team exercise, we do it in one of two ways, depending on what we want to achieve.

08:37.380 --> 08:49.180
So we could either aim to cover as many TDPs as possible, executing them one after the other in isolation, or we could chain a few attacks, similar to how a threat actor would move, to make it as realistic as possible.

08:49.520 --> 08:52.620
And even mimic a specific campaign from the ones we saw before.

08:53.200 --> 08:58.540
Okay, let's look at these two options in a bit more detail in the context of a Kubernetes exercise.

08:59.600 --> 09:06.340
So for Kubernetes specifically, we found that there aren't as many campaigns documented as there are for on-prem infrastructure.

09:06.460 --> 09:09.180
And as a result, there's not a lot of threat intelligence available.

09:09.380 --> 09:18.160
So when incidents do happen in other organizations, they make for a good opportunity for your organization to perform an emulation cycle, to perform a campaign.

09:18.260 --> 09:22.620
In that case, you probably know already which threat actor you want to emulate.

09:22.620 --> 09:27.640
But if not, the security researchers over at Wiz maintain this great matrix of cloud threats.

09:27.640 --> 09:29.880
And that also covers Kubernetes incidents.

09:30.300 --> 09:37.300
So it aggregates threat intelligence from various blog posts, like Unit 42, Aqua, Sysdig, CrowdStrike, all the ones we saw before.

09:37.580 --> 09:46.060
And you can collect all this threat intelligence, analyze it, and finally recreate an attack chain and execute this inside your cluster.

09:46.180 --> 09:51.140
Now, a nice way of documenting these different emulation plans is Jupyter Notebooks.

09:51.140 --> 09:56.940
And we've seen a bit in the demo how Jupyter Notebooks can also streamline execution of the attack simulation.

09:56.940 --> 10:08.920
But for more of a one-off assessment, or if you're looking to build a baseline of your detection capability against all the possible TDPs, then you first need a list of all the different TDPs for the platform in question.

10:09.100 --> 10:17.640
In 2020, Microsoft released the third matrix for Kubernetes, which was the first systematic categorization of Kubernetes techniques observed until then.

10:17.640 --> 10:19.500
And it seems to be actively maintained.

10:19.800 --> 10:25.460
There's also a Mitre ATT&CK matrix for containers, but it doesn't really care about the orchestration platform.

10:25.460 --> 10:29.320
And I actually got some very good ideas for attacks by looking at KubeHunter.

10:29.680 --> 10:34.920
Although it's a vulnerability scanner, it just had a long list of checks supported, so it gave me some very good ideas.

10:35.380 --> 10:44.160
But for more technical instructions on how to execute each TDP, I found the KubeNomicon to be a good source, so shout out to Graham Helton from Google for his project.

10:44.780 --> 10:53.620
And once you've designed these test cases, one good way of describing them is via a code format, allowing them to be maintained in a version control system like Git.

10:53.620 --> 10:56.000
And this is a well-known practice in DevSecOps.

10:56.000 --> 11:00.260
You know, attack definitions as code, detections as code, we can apply it here as well.

11:00.640 --> 11:06.460
This way, as your Kubernetes environment evolves, so does your repository of attacker test cases.

11:07.300 --> 11:08.040
Fantastic.

11:08.040 --> 11:10.080
So, we have planned everything.

11:10.080 --> 11:11.620
We are ready to get our hands dirty.

11:11.620 --> 11:13.660
Let's start bashing kubectl commands.

11:14.480 --> 11:20.680
No, that wouldn't scale very easily, but thankfully there are a few simulation frameworks out there to make our lives a bit easier.

11:20.680 --> 11:24.280
Starting with the familiar ART, Atomic Red Team by Red Canary.

11:24.440 --> 11:26.700
This is out of Citi Village, I'm sure you're all aware of it.

11:26.700 --> 11:36.320
Although it does support a few test cases on the container level, it's not really built for cloud environments, so it doesn't really support attacks against the Kubernetes control plane.

11:36.420 --> 11:45.360
On the other hand, Stratus Red Team was specifically made for the cloud and for attack simulations, so it even supports eight pure Kubernetes test cases.

11:45.360 --> 11:48.820
So it's actually a good choice for this particular purpose.

11:48.820 --> 11:57.880
However, you will find it's not very easy to write new test cases, and the fact that it runs outside of your cluster kind of restricts the number of different levels that it can execute in.

11:58.480 --> 12:03.380
One tool that can, in fact, run from within the cluster is Pirates by InGuardians.

12:03.460 --> 12:04.800
It's also widely known.

12:04.800 --> 12:07.920
Various talks, blog posts, webinars out there talking about it.

12:07.920 --> 12:10.820
It's so well known that it's actually been used by threat actors.

12:11.240 --> 12:17.700
But once again, the attacks it supports are hard-coded, and the tool itself doesn't really allow for customization.

12:18.840 --> 12:24.800
So overall, when we were doing this research, we realized that none of these tools performed exactly what we wanted.

12:24.800 --> 12:27.420
These options all had some limitations.

12:27.420 --> 12:32.120
So we decided to extend our own existing tool, Leonidas, to add Kubernetes support.

12:32.320 --> 12:35.320
And if you're not familiar with it, no, I did not write the original version.

12:35.380 --> 12:36.340
It's not named after me.

12:36.340 --> 12:37.640
That would be a little bit lame.

12:38.440 --> 12:40.420
I don't want to talk too much about Leonidas.

12:40.420 --> 12:42.060
It's an open-source tool.

12:42.200 --> 12:45.600
My colleague Nick Jones originally wrote the AWS version.

12:45.600 --> 12:48.540
And again, various presentations out there talking about it.

12:48.540 --> 13:01.340
What made Leonidas attractive for the challenge of Kubernetes attack simulations was some of its core principles, like the fact that it was built with extensibility in mind, and how friendly it was to write new disk cases without having to be a developer,

13:01.340 --> 13:05.880
as well as the ability to run within your environment and manage its own resources.

13:06.340 --> 13:10.440
And these were the concepts that we applied when building Kubernetes support for it.

13:10.440 --> 13:16.080
We wanted something running within the cluster, distributed as a disposable image, as an ephemeral image.

13:16.080 --> 13:20.780
We wanted something that analysts or threat hunters could trivially write new TDPs for.

13:21.460 --> 13:33.520
But we also wanted purple teams to have an easy way to execute them by just interacting with an API, as well as a way for operators and defenders to track execution of each action.

13:33.520 --> 13:40.700
And we can do that through the logs that are stored and shipped to the scene, along with all the other telemetry that the cluster generates.

13:41.060 --> 13:54.400
Now, alongside this new version of Leonidas, we are also releasing a set of Kubernetes test cases, 17 in total, not only to help you get started writing attack definitions, but also to showcase the tool's capabilities, like running kubectl commands, running OS level commands,

13:54.400 --> 13:56.500
and even applying custom YAML manifests.

13:56.740 --> 13:57.940
A lot of different options.

13:58.500 --> 14:07.660
Okay, lastly, I want to talk about operations teams and how they can apply the security monitoring concepts of the traditional SOC into container orchestration environment.

14:07.980 --> 14:11.620
You know, after all, the goal of any exercise is to upskill defenders and build the capability.

14:12.860 --> 14:17.660
The most important building block of security monitoring is arguably logs, all right?

14:17.700 --> 14:27.120
If you look at the official Kubernetes documentation, however, you'll find there are plenty of log sources available, but no standard architecture for what we call cluster-level logging.

14:27.120 --> 14:29.320
This is left to the users to implement.

14:29.860 --> 14:36.180
Roughly speaking, from all the different types, let's say we can categorize all of them into three different types of log sources.

14:36.180 --> 14:42.840
So first, we have logs from your application, logs from the code, which are exposed to container logs and pod logs.

14:42.840 --> 14:50.080
You can collect them with the kubectl logs commands, but they are ephemeral, which means that if the pod terminates, the logs are gone.

14:50.680 --> 14:55.920
We also have logs from Kubernetes components, like the API server, the kubelet, the container runtime.

14:55.920 --> 15:05.760
Just like container logs, these ones are also stored on the nodes, which means that, actually, in a production cluster, nodes will be disposable.

15:06.280 --> 15:08.840
If the VM is replaced, these logs are also gone.

15:08.840 --> 15:11.540
So you need to take them out of the host while you can.

15:11.540 --> 15:15.980
And thankfully, there's lots of solutions out there, agent-based solutions like Fluentd that can do that.

15:16.420 --> 15:23.740
And finally, we have logs that aren't particularly native to Kubernetes, but are still of interest for the security of the overall ecosystem.

15:23.860 --> 15:34.760
If your cluster is a managed service from a public cloud provider, then that cloud provider's logging and monitoring solutions are also crucial to monitor, like IAM logs or GuardDuty and stuff like that.

15:34.760 --> 15:46.660
And similarly, if you host your own internal image repositories, we found that logs from these image repositories could allow the correlation of certain attacker actions, and that's not even half of it.

15:46.660 --> 15:53.560
There's just a ridiculous amount of logs flowing throughout your cluster, but not all of them are useful for detecting attacks.

15:53.560 --> 15:56.180
The ones that are, are those selected here.

15:56.180 --> 16:02.480
It's those that answer not so much why something happened, but rather who, did what, when, and where from.

16:02.960 --> 16:07.100
And these security-relevant log sources map to the execution levels.

16:07.100 --> 16:13.700
If you remember from the previous slide, which provides us visibility on the container level, on the node level, and the control plane level.

16:14.300 --> 16:21.140
And alongside those, I've also highlighted the cloud IAM logs, because if you're running a managed cluster, identity is always of security interest.

16:21.800 --> 16:28.480
I want to take a couple of slides to zoom in on the most important log source, the true MVP of Kubernetes attack detection, the audit log.

16:28.560 --> 16:37.800
You can consider the audit log as the access logs of the API server, which simply means that if you're interacting with a control plane, you're getting recorded, with some exceptions.

16:37.980 --> 16:43.900
The resulting events can be formatted in JSON, and they answer the security investigation questions that we raised before.

16:44.140 --> 16:47.540
Important to mention, though, these are not enabled by default.

16:47.680 --> 16:54.840
To enable them, you need to define a node policy and reconfigure the API server, but you can't always do that, for example, in managed clusters.

16:54.900 --> 16:59.480
Some events will be very noisy, others will be more important, so you want to have more detail.

16:59.600 --> 17:06.140
And that's why there's a few different verbosity levels that you can set for each different type, each different event type.

17:06.160 --> 17:15.440
You can easily find a sample policy to get started with, like the one I'm linking in the bottom of the slide, but it's going to take some tuning to find the perfect mix.

17:16.100 --> 17:24.120
The API server can also be configured to store audit logs locally or send them to a hook, and both of these ways allow for wording to a scene.

17:24.620 --> 17:31.580
Once you do that, you now have the ability to write alert queries upon these logs, which brings us to the topic of detection engineering.

17:32.040 --> 17:39.860
In its simplest form, an alert for suspicious control plane activity could be captured by the verb and the resource, such as list, secrets.

17:40.380 --> 17:44.940
And this behavior can then be defined in a SIGMA rule for easier management and distribution.

17:45.460 --> 17:48.000
We found that there weren't many SIGMA rules out there available.

17:48.000 --> 17:55.060
In fact, there weren't any SIGMA rules out there available that operated on Kubernetes audit logs, so we published a few.

17:55.060 --> 18:05.660
And since this log source didn't really exist, we also introduced it by contributing a backend pipeline to the SIGMA ecosystem in order to convert rules to actual alerts that a scene can understand.

18:06.140 --> 18:12.440
But attacks could not only target the control plane, if you remember from the previous slide, they could originate from within the container.

18:12.460 --> 18:22.660
But luckily, there's a lot of research in this area, many solutions available, like Falco or Tetragon, that monitor containers by tapping into the kernel of the underlying node using eBPF.

18:22.960 --> 18:36.800
And this enables EDR-style analysis of the syscalls, which then allows the authoring of rules in an easy format for suspicious process command lines, for suspicious network activity, and other system-level events.

18:37.780 --> 18:39.980
All right, now it is time for the demo.

18:39.980 --> 18:45.800
So in the upcoming video, we'll see how we can simulate a fictitious threat actor who gets access to a cluster and performs some attacks.

18:45.800 --> 18:48.200
We'll do that using Leonidas for Kubernetes.

18:48.260 --> 18:59.960
And after we run the attack chain, we'll put our blue hats on, we'll put our defender hats on, the Viking hat, and look at Elastic and Falco, which we have set up, just to see what alerts have been raised.

19:00.040 --> 19:02.820
All right, let me switch to the demo video.

19:07.250 --> 19:08.910
Can you all see the video?

19:09.510 --> 19:10.390
No?

19:11.830 --> 19:13.230
Good thing I asked.

19:16.390 --> 19:17.970
Is it this way?

19:20.090 --> 19:22.070
Now I can't see how to maximize it all.

19:22.070 --> 19:23.870
Can I have some tech support here?

19:29.570 --> 19:31.990
Yeah, but I can't see the pointer, so I can maximize it.

19:32.890 --> 19:33.850
You reckon?

19:35.750 --> 19:36.470
Nice.

19:36.990 --> 19:38.750
The problem is that I can't see it.

19:39.290 --> 19:40.670
All right, let's do it.

19:41.730 --> 19:42.450
I won't...

19:43.670 --> 19:45.430
Yeah, but I want to talk over it.

19:57.950 --> 20:01.510
You can switch your display settings, so it's, yeah, duplicated.

20:04.030 --> 20:04.930
See it now?

20:05.670 --> 20:06.910
Awesome, fixed.

20:07.470 --> 20:13.210
All right, so first thing we're going to do is confirm connectivity to the Kubernetes cluster.

20:13.210 --> 20:15.290
We'll do that using a cluster info command.

20:15.450 --> 20:18.190
We see that, indeed, the Kubernetes cluster is up and running.

20:18.190 --> 20:28.470
We also have the dashboard up and running, and you can see we have a couple of namespaces already there, including one called DharmaProds, which has just one deployment in there.

20:28.470 --> 20:36.910
It's called HVACController, and once we click it, we'll see that it includes a couple of pods, one looking like a database, and the other one potentially doing something sensitive, HVACController.

20:37.430 --> 20:40.790
And now we're going to go ahead and deploy Leonidas into that cluster.

20:40.790 --> 20:43.190
To do that, we'll run a couple of generator commands.

20:43.190 --> 20:48.610
Generator is an accompanying tool that allows deployment of Leonidas.

20:48.650 --> 20:58.730
First, we're going to generate the Python code from the attack definitions that we have previously defined, and then we're going to generate the Kubernetes resources in the standard YAML manifest.

20:58.730 --> 21:09.030
These resources will then go ahead and kubectl apply into our cluster so that we can create the Leonidas deployment into our namespace, into DharmaProds.

21:09.030 --> 21:10.790
And you'll see that it started running.

21:10.790 --> 21:16.630
Once it's completed, once deployment is completed, we'll then expose the port.

21:16.630 --> 21:18.890
We're using a kubectl port forward command.

21:18.970 --> 21:21.130
KL, by the way, is an alias for kubectl.

21:21.130 --> 21:25.030
And we bring it locally to port 5000 so we can interact with it.

21:25.310 --> 21:29.370
And once this is done, indeed, we can access the API.

21:29.370 --> 21:32.710
It's the familiar API, if you looked at Leonidas before.

21:32.710 --> 21:34.750
There are two ways to interact with Leonidas.

21:34.770 --> 21:41.310
One of them is via this very simple client, providing the values in all these fields and then hitting execute.

21:42.030 --> 21:45.270
But instead, we're going to do it through a Jupyter notebook.

21:46.510 --> 21:50.710
And in order to do that, we first need to start the Jupyter service.

21:50.710 --> 21:54.310
This is going to open the port 8.8.8.8.

21:54.310 --> 22:03.110
Once we click it, we'll see the web UI of Jupyter, navigate to the right directory of the threat actors notebooks, and open our own notebook for OFA-8.15.

22:03.110 --> 22:05.970
Now, OFA-8.15 is our fictitious threat actor.

22:07.310 --> 22:11.830
Like we said before, execute some attacks against the Kubernetes cluster and first get some access to it.

22:11.830 --> 22:14.170
We've got a nice little visualization of it right here.

22:14.650 --> 22:17.150
First step for it is to simulate the initial access.

22:17.150 --> 22:20.130
Now, the typical scenario would be a leaked kubeconfig file.

22:20.470 --> 22:25.590
Actually, before we get to these attacks, let's look at the Defender tech, the Defender solutions we have up there, up and running.

22:25.590 --> 22:31.190
We do have Elastic, where we're forwarding audit logs from our cluster.

22:32.670 --> 22:35.490
Nicely visualized with the verb resource, like we said before.

22:35.490 --> 22:38.510
And we also have some alert rules configured.

22:38.890 --> 22:41.550
You can see on the right-hand side that these are all enabled.

22:42.570 --> 22:47.570
And just to make sure that nothing has fired just yet, we're going to refresh that page, see no hits, and we're ready to go.

22:47.570 --> 22:50.250
But before we start executing, let's also look at Falco.

22:50.250 --> 22:55.150
We've configured this on the nodes of the cluster to monitor the containers, like we said before.

22:55.650 --> 22:56.350
Cool.

22:56.350 --> 22:58.530
All right, let's start running the attack step-by-step then.

22:58.530 --> 23:04.450
So if we navigate back to the Jupyter Notebook, we start hitting run through every different cell.

23:04.450 --> 23:06.610
And the first step is to simulate the initial access.

23:06.810 --> 23:08.890
So the typical scenario is a leaked kubeconfig file.

23:08.890 --> 23:12.630
In that kubeconfig file, there might be a service account token, a JWT.

23:12.630 --> 23:17.930
And this token is what we're going to instantiate a client with, a client to Leonidas.

23:17.930 --> 23:22.470
So behind the scenes, this Jupyter Notebook is running some Python, bare-bones Python.

23:22.470 --> 23:24.250
We'll publish all of that, by the way, very soon.

23:24.250 --> 23:27.450
And this interacts with the Leonidas service running within the cluster.

23:27.510 --> 23:33.410
So the first thing, once the attacker has obtained access, would be to list their own permissions, just to see what they can do.

23:33.710 --> 23:36.670
You can do that using the self-subject review API.

23:36.830 --> 23:40.450
So we just run that cell then and look at the results.

23:40.830 --> 23:44.250
We observe in the results that we have some permissions on the pods.

23:44.250 --> 23:48.230
Cool permissions, create, read, update, delete on the right-hand side of the slide.

23:48.350 --> 23:52.470
And we also have some permissions on the secrets, which is already a problem.

23:52.630 --> 23:55.810
So using these permissions, we're going to go ahead and enumerate the pods.

23:56.270 --> 24:01.170
You'll see, like we saw before, patient DB, Leonidas deployment, and the HVAC controller.

24:01.170 --> 24:05.230
And using the permissions we have over the secrets, obviously, we're going to list the secrets.

24:05.570 --> 24:12.550
With some processing, with some post-processing, we'll see that one of them looks like a password, but we don't know yet.

24:12.550 --> 24:17.350
But putting the pieces together, we have the database pod, we have something that looks like a password.

24:17.350 --> 24:21.550
So why not run a MySQL dump command to get a dump and prepare it for exfiltration?

24:21.610 --> 24:27.970
Sure enough, we provide the password on the command line, the dump is being generated, and we're ready to send that back.

24:28.030 --> 24:35.930
Now, before we finish up with this attack, the attacker also tries to perform some destructive activity just to delete a deployment.

24:35.930 --> 24:40.330
But this activity will fail because, as we saw before, they do not have the permission to do so.

24:40.330 --> 24:52.410
And finally, just to wrap it up, just to wrap up the threat, the Jupyter Notebook will print the table of all the test cases that we executed for good bookkeeping, timestamps, success status, and the name of the test case.

24:52.790 --> 24:53.170
Cool.

24:53.170 --> 25:05.010
So, we'll now, as promised, return back to the detection capabilities, Blue Team Solutions, and we'll see that two alerts have actually fired, as promised.

25:05.010 --> 25:12.150
And the same thing stands for Falco, since it detected the MySQL dump command.

25:12.610 --> 25:17.010
Don't worry about the too many lines, it's just a misconfigured rule.

25:17.010 --> 25:22.350
Important thing to notice is that it did capture the MySQL dump command executing within the container.

25:23.290 --> 25:24.710
And that wraps up the demo.

25:24.710 --> 25:26.130
I do have one more slide.

25:37.900 --> 25:38.860
Awesome.

25:51.480 --> 25:53.300
All right, that one last slide.

25:53.800 --> 25:56.020
Hopefully you can see just the slide, not the speaking notes.

25:56.020 --> 25:56.360
Cool.

25:56.360 --> 25:56.880
All right.

25:57.380 --> 26:00.060
I want to close with just a few key takeaways.

26:00.280 --> 26:08.120
Now, building Kubernetes' detective capability is a journey, and the first step towards it is to understand the threats posed to your environment.

26:08.620 --> 26:17.560
Once this is done, we saw how the concepts and the methods of collaborative attack simulation can be applied to this world as well, in order to build defenses proactively.

26:17.980 --> 26:29.500
To this end, we're giving the world a Kubernetes native attack simulation framework, Leonidas for Kubernetes, a set of test cases to get started, along with their corresponding Sigma rules as a building block for detections.

26:30.040 --> 26:31.040
And that's all from me.

26:31.040 --> 26:32.380
Thank you very much for your time.

26:32.380 --> 26:36.680
You can find the links mentioned in this QR code, and you can find me on Twitter if you want to discuss further.

26:36.680 --> 26:38.440
Thanks to Adversary Village for having me.

