[00:00.000 --> 00:02.120] Hello everyone, and thanks for joining this talk. [00:02.140 --> 00:04.360] Today, we're going to talk about Kubernetes, [00:04.360 --> 00:08.480] and specifically, how you can run successful attack simulation exercises. [00:08.780 --> 00:11.460] First of all, a few words about myself. 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:19.340] I'm focusing mostly on threat simulation and, generally speaking, [00:19.340 --> 00:21.100] collaborative security assessments. [00:21.100 --> 00:25.980] So, one challenge that our clients at WithSecure typically come to us with is [00:25.980 --> 00:30.420] how can we measure our capability to detect attacks in X environment? [00:30.620 --> 00:32.980] And the environments we typically see are of all sorts, [00:32.980 --> 00:36.680] Windows, Linux, mobile, macOS, on-prem cloud, [00:36.680 --> 00:39.640] and even container orchestration environments like Kubernetes. [00:39.880 --> 00:43.600] So, when a while ago, one of our more mature clients [00:43.600 --> 00:47.000] were looking to assess and improve their blue team capability [00:47.000 --> 00:49.920] against attacks in a Kubernetes environment, [00:49.920 --> 00:51.840] we approached this as we usually do, [00:51.840 --> 00:53.880] with a three-fold adversary simulation assessment. [00:53.880 --> 00:56.320] So, first, we did some threat modeling, [00:56.320 --> 00:59.380] 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:07.260] And finally, we executed the test cases we designed, [01:07.260 --> 01:10.480] side-by-side with the blue team, [01:10.480 --> 01:13.980] researching along the way for means to improve visibility and alerting [01:13.980 --> 01:16.360] 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:22.740] We kept working on it in the background, [01:22.740 --> 01:24.420] 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:29.480] I know this is Adversary Village. 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:35.440] We'll talk about the threats posed to a Kubernetes cluster, [01:35.440 --> 01:39.160] 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:46.000] And we're going to look at tools, operational, planning, [01:46.000 --> 01:47.440] and eventually execution. [01:48.060 --> 01:51.000] And this talk isn't only for offensive security practitioners. [01:51.000 --> 01:54.720] So, we'll cover some basic Kubernetes detection concepts as well, [01:54.720 --> 01:57.200] 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:04.960] And finally, we'll demonstrate everything in an end-to-end simulation [02:04.960 --> 02:07.040] of an attack against the cluster, [02:07.040 --> 02:09.980] 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:19.080] We do that in order to introduce all the things that will come into play later, [02:19.080 --> 02:21.060] both in the slides and in the demo. [02:21.960 --> 02:25.160] But the thing is, if you're even remotely familiar with Kubernetes, [02:25.160 --> 02:27.040] 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:36.760] In fact, it's probably going to be the fastest introduction to Kubernetes ever given, [02:36.760 --> 02:38.100] so please bear with me. [02:38.760 --> 02:42.000] So, our system in question, the Kubernetes cluster, [02:42.000 --> 02:43.760] 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 --> 02:55.720] And in order to run workloads, they need to have a container runtime installed, [02:55.720 --> 02:59.040] such as container D, or in older versions, Docker, [02:59.040 --> 03:01.540] as well as an agent called the kubelet, [03:01.540 --> 03:04.600] which communicates with the control plane and specifically the API server [03:04.600 --> 03:06.220] to receive instructions. [03:06.420 --> 03:09.080] Now, this component that I mentioned, the API server, [03:09.080 --> 03:10.260] 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:16.780] It exposes a REST API, which clients can talk to [03:16.780 --> 03:18.700] 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:26.980] But it's important to remember that humans most commonly use kubectl [03:26.980 --> 03:29.700] instead of just sending raw HTTP requests. [03:30.240 --> 03:32.160] Now, when it comes to running applications, [03:32.160 --> 03:35.000] the basic building block in Kubernetes is a pod. [03:35.000 --> 03:37.560] A pod can consist of one or more containers [03:37.560 --> 03:40.200] whose images are pulled from registries, [03:40.200 --> 03:42.580] as well as volumes, storage resources. [03:42.600 --> 03:44.420] What usually happens in the real world [03:44.420 --> 03:48.620] is that workloads aren't actually deployed as individual pods, [03:48.620 --> 03:52.740] but as managed collections of pods, like daemon certs or deployments. [03:53.560 --> 03:55.220] But beyond pods and deployments, [03:55.220 --> 03:58.520] there's a few more types of objects that Kubernetes understands, [03:58.520 --> 04:01.540] or resources, such as secrets or services. [04:01.540 --> 04:04.500] And all these resources can then be logically grouped [04:04.500 --> 04:07.140] into different namespaces for each different project, [04:07.140 --> 04:10.100] which you can think of like tenants in the cloud world. [04:10.460 --> 04:12.780] And finally, there's a third layer besides the physical [04:12.780 --> 04:15.540] and the logical, that of authorization, [04:15.540 --> 04:17.860] with the most common authorization model being RBAC, [04:17.860 --> 04:19.560] role-based access control. [04:19.820 --> 04:21.360] RBAC defines the potential entities [04:21.360 --> 04:23.960] and allows you to write policies for the permissions [04:23.960 --> 04:26.960] that these entities will have against resources. [04:26.960 --> 04:29.020] So in the context of RBAC, [04:29.020 --> 04:31.500] humans are represented as user objects [04:31.500 --> 04:34.040] that can authenticate using various mechanisms [04:34.040 --> 04:38.760] like MTLS client certificates, Active Directory, IAM roles, and so on. [04:38.760 --> 04:41.120] And you also get pods or external services [04:41.120 --> 04:43.360] that are associated with service accounts. [04:43.360 --> 04:45.440] And service accounts authenticate using tokens, [04:45.440 --> 04:47.540] JSON web tokens, JWTs. [04:48.560 --> 04:52.080] Okay, that was easy, right? [04:52.340 --> 04:54.760] One thing to remember, though, is that in Kubernetes, [04:54.760 --> 04:57.480] everything can be replaced. It's built to be extensible. [04:57.480 --> 05:00.780] So it is 100% certain that your mileage will vary [05:00.780 --> 05:03.020] and you will have numerous third-party technologies [05:03.020 --> 05:04.600] running in your cluster. [05:04.620 --> 05:07.520] Technologies like the ones tracked in the CNCF landscape, [05:07.520 --> 05:09.200] which introduce their own set of risks [05:09.200 --> 05:10.980] when deployed inside your cluster. [05:10.980 --> 05:13.840] So in order to tailor any security exercise [05:13.840 --> 05:16.360] to your environment with its own intricacies, [05:16.360 --> 05:19.020] it's essential you perform some threat modeling first. [05:19.020 --> 05:20.560] And that means answering a few questions [05:20.560 --> 05:22.900] 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:31.820] This will also help us understand [05:31.820 --> 05:33.800] which levels we must execute in [05:33.800 --> 05:36.280] if we're looking to simulate these attacks. [05:36.840 --> 05:38.660] In the most typical scenario, [05:38.660 --> 05:41.040] attacks will originate from the container level, [05:41.040 --> 05:42.500] the code running within the pod. [05:42.500 --> 05:44.940] For example, think of a compromised web service [05:45.580 --> 05:46.660] or a backdoored image [05:46.660 --> 05:49.180] that found its way into your cluster somehow. [05:49.460 --> 05:51.780] And if that pod is assigned a service account, [05:51.780 --> 05:53.200] the attacker can talk to the control plane [05:53.200 --> 05:56.280] in a limited security context, hopefully, [05:56.280 --> 05:58.280] unless they manage to break out of the container. [05:58.700 --> 06:01.500] That way, they're on the node, the underlying host, [06:01.500 --> 06:03.740] with potential access to other Kubernetes resources [06:03.740 --> 06:04.760] from other namespaces [06:04.760 --> 06:06.940] and with even higher security privileges [06:06.940 --> 06:09.660] as they will most likely impersonate the kubelet. [06:10.180 --> 06:12.400] And of course, there's always a threat of attacks [06:12.400 --> 06:13.960] from the outside world. [06:14.080 --> 06:17.000] Think of scenarios like leaked or stolen credentials, [06:17.020 --> 06:18.840] a compromised service, a malicious user, [06:18.920 --> 06:20.880] a coerced user, and so on and so on. [06:21.380 --> 06:23.200] So once they're inside your cluster, [06:23.200 --> 06:24.260] 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:31.900] If Kubernetes is the underlying platform [06:31.900 --> 06:34.460] that your critical workloads are running in, [06:34.460 --> 06:36.420] then it's a way into them. [06:36.420 --> 06:38.600] It's a way into the workload. [06:38.600 --> 06:41.080] So compromising Kubernetes could result [06:41.080 --> 06:43.480] in unauthorized access to the data. [06:43.480 --> 06:45.120] And we're talking about potentially sensitive data [06:45.120 --> 06:48.160] that the apps may be handling, like proprietary software, [06:48.160 --> 06:49.360] as you can see on this slide, [06:49.360 --> 06:51.040] that can be stolen or even backdoored [06:51.040 --> 06:53.300] to achieve a supply chain compromise. [06:54.140 --> 06:56.780] But actually, that's not the most common incentive. [06:57.200 --> 06:58.740] In the age of cryptocurrency, [06:58.740 --> 07:01.120] every compute resource makes for an attractive target [07:01.120 --> 07:04.880] 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:09.900] And you'll see that various instances [07:09.900 --> 07:12.240] have been recorded with this particular objective. [07:13.380 --> 07:15.260] Kubernetes clusters are usually also deployed [07:15.260 --> 07:17.120] as managed cloud services, [07:17.120 --> 07:19.920] or broadly speaking, in cloud infrastructure. [07:19.920 --> 07:22.160] So instead of going for the applications, [07:22.260 --> 07:24.040] a Kubernetes attacker might actually be looking [07:24.040 --> 07:25.720] for a way into the cloud infrastructure, [07:25.720 --> 07:28.600] into the underlying infrastructure. [07:28.600 --> 07:30.960] But we've also seen Kubernetes attack techniques [07:30.960 --> 07:33.280] across all phases of the intrusion lifecycle, [07:33.280 --> 07:34.580] including persistence methods [07:34.580 --> 07:36.980] that could enable APT-like surveillance [07:36.980 --> 07:39.400] through a long-term infection, [07:39.400 --> 07:41.200] and even for defense evasion purposes, [07:41.200 --> 07:44.260] as, after all, Kubernetes is yet another platform [07:44.260 --> 07:46.220] where an intruder can dwell in. [07:46.480 --> 07:48.840] And usually, it's a less monitored platform, [07:48.840 --> 07:50.240] which makes it a great place to hide [07:50.240 --> 07:52.280] 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:05.840] And instead of a stealthy, objective-based exercise, [08:05.840 --> 08:08.220] we chose to adopt more of a Purple Team methodology. [08:08.560 --> 08:10.600] And I know different people define Purple Teams differently, [08:10.600 --> 08:13.660] so let me use the definition given by the guys over at SpectreOps. [08:13.720 --> 08:16.020] It talks about collaboration between offense and defense [08:16.020 --> 08:19.220] with the aim to increase familiarity with TDPs. [08:19.360 --> 08:21.640] And for a novel environment like Kubernetes, [08:21.640 --> 08:23.540] we similarly decided it's more valuable [08:23.540 --> 08:25.240] to opt for a collaborative engagement [08:25.240 --> 08:27.520] and try to help the blue team understand [08:27.520 --> 08:29.800] 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:34.500] So when we're planning a Purple Team exercise, [08:34.500 --> 08:37.380] we do it in one of two ways, depending on what we want to achieve. [08:37.380 --> 08:40.700] So we could either aim to cover as many TDPs as possible, [08:40.700 --> 08:42.960] executing them one after the other in isolation, [08:42.960 --> 08:45.300] or we could chain a few attacks, [08:45.300 --> 08:47.360] similar to how a threat actor would move, [08:47.360 --> 08:49.180] 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:56.520] Okay, let's look at these two options in a bit more detail [08:56.520 --> 08:58.540] in the context of a Kubernetes exercise. [08:59.600 --> 09:01.440] So for Kubernetes specifically, [09:01.440 --> 09:03.940] we found that there aren't as many campaigns documented [09:03.940 --> 09:06.340] 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:12.780] So when incidents do happen in other organizations, [09:12.780 --> 09:15.160] they make for a good opportunity for your organization [09:15.160 --> 09:18.160] to perform an emulation cycle, to perform a campaign. [09:18.260 --> 09:20.400] In that case, you probably know already [09:20.400 --> 09:22.620] which threat actor you want to emulate. [09:22.620 --> 09:25.000] But if not, the security researchers over at Wiz [09:25.000 --> 09:27.640] maintain this great matrix of cloud threats. [09:27.640 --> 09:29.880] And that also covers Kubernetes incidents. [09:30.300 --> 09:33.400] So it aggregates threat intelligence from various blog posts, [09:33.400 --> 09:35.880] like Unit 42, Aqua, Sysdig, CrowdStrike, [09:35.880 --> 09:37.300] all the ones we saw before. [09:37.580 --> 09:40.820] And you can collect all this threat intelligence, [09:40.820 --> 09:43.600] analyze it, and finally recreate an attack chain [09:43.600 --> 09:46.060] and execute this inside your cluster. [09:46.180 --> 09:49.420] Now, a nice way of documenting these different emulation plans [09:49.420 --> 09:51.140] is Jupyter Notebooks. [09:51.140 --> 09:52.780] And we've seen a bit in the demo [09:52.780 --> 09:55.200] how Jupyter Notebooks can also streamline execution [09:55.200 --> 09:56.940] of the attack simulation. [09:56.940 --> 09:59.580] But for more of a one-off assessment, [09:59.580 --> 10:01.140] or if you're looking to build a baseline [10:01.140 --> 10:05.080] of your detection capability against all the possible TDPs, [10:05.080 --> 10:07.300] then you first need a list of all the different TDPs [10:07.300 --> 10:08.920] for the platform in question. [10:09.100 --> 10:12.840] In 2020, Microsoft released the third matrix for Kubernetes, [10:12.840 --> 10:14.900] which was the first systematic categorization [10:14.900 --> 10:17.640] of Kubernetes techniques observed until then. [10:17.640 --> 10:19.500] And it seems to be actively maintained. [10:19.800 --> 10:22.680] There's also a Mitre ATT&CK matrix for containers, [10:22.680 --> 10:25.460] but it doesn't really care about the orchestration platform. [10:25.460 --> 10:27.700] And I actually got some very good ideas for attacks [10:27.700 --> 10:29.320] by looking at KubeHunter. [10:29.680 --> 10:31.320] Although it's a vulnerability scanner, [10:31.320 --> 10:33.120] it just had a long list of checks supported, [10:33.120 --> 10:34.920] so it gave me some very good ideas. [10:35.380 --> 10:39.300] But for more technical instructions on how to execute each TDP, [10:39.300 --> 10:41.180] I found the KubeNomicon to be a good source, [10:41.180 --> 10:44.160] so shout out to Graham Helton from Google for his project. [10:44.780 --> 10:46.780] And once you've designed these test cases, [10:46.780 --> 10:50.080] one good way of describing them is via a code format, [10:50.080 --> 10:53.620] 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 --> 10:58.580] You know, attack definitions as code, detections as code, [10:58.580 --> 11:00.260] we can apply it here as well. [11:00.640 --> 11:03.440] This way, as your Kubernetes environment evolves, [11:03.440 --> 11:06.460] so does your repository of attacker test cases. [11:07.300 --> 11:10.080] Fantastic. 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:16.180] No, that wouldn't scale very easily, [11:16.180 --> 11:18.520] but thankfully there are a few simulation frameworks out there [11:18.520 --> 11:20.680] 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:30.360] Although it does support a few test cases on the container level, [11:30.360 --> 11:32.680] it's not really built for cloud environments, [11:32.680 --> 11:36.320] so it doesn't really support attacks against the Kubernetes control plane. [11:36.420 --> 11:40.120] On the other hand, Stratus Red Team was specifically made for the cloud [11:40.120 --> 11:42.040] and for attack simulations, [11:42.040 --> 11:45.360] 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:52.560] However, you will find it's not very easy to write new test cases, [11:52.560 --> 11:54.320] and the fact that it runs outside of your cluster [11:54.320 --> 11:57.880] kind of restricts the number of different levels that it can execute in. [11:58.480 --> 12:01.280] One tool that can, in fact, run from within the cluster [12:01.280 --> 12:03.380] 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:14.760] But once again, the attacks it supports are hard-coded, [12:14.760 --> 12:17.700] and the tool itself doesn't really allow for customization. [12:18.840 --> 12:21.720] So overall, when we were doing this research, [12:21.720 --> 12:24.800] 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:30.620] So we decided to extend our own existing tool, Leonidas, [12:30.620 --> 12:32.120] 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:37.640] It's not named after me. 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 --> 12:49.940] What made Leonidas attractive [12:50.380 --> 12:52.360] for the challenge of Kubernetes attack simulations [12:52.360 --> 12:54.500] was some of its core principles, [12:54.500 --> 12:57.180] like the fact that it was built with extensibility in mind, [12:57.180 --> 12:59.900] and how friendly it was to write new disk cases [12:59.900 --> 13:01.340] without having to be a developer, [13:01.340 --> 13:03.920] as well as the ability to run within your environment [13:03.920 --> 13:05.880] and manage its own resources. [13:06.340 --> 13:08.300] And these were the concepts that we applied [13:08.300 --> 13:10.440] when building Kubernetes support for it. [13:10.440 --> 13:12.800] We wanted something running within the cluster, [13:12.800 --> 13:14.680] distributed as a disposable image, [13:14.680 --> 13:16.080] as an ephemeral image. [13:16.080 --> 13:18.080] We wanted something that analysts or threat hunters [13:18.080 --> 13:20.780] could trivially write new TDPs for. [13:21.460 --> 13:23.040] But we also wanted purple teams [13:23.640 --> 13:25.680] to have an easy way to execute them [13:25.680 --> 13:27.820] by just interacting with an API, [13:27.820 --> 13:30.300] as well as a way for operators and defenders [13:30.300 --> 13:33.520] to track execution of each action. [13:33.520 --> 13:34.960] And we can do that through the logs [13:34.960 --> 13:37.520] that are stored and shipped to the scene, [13:37.520 --> 13:40.700] along with all the other telemetry that the cluster generates. [13:41.060 --> 13:43.000] Now, alongside this new version of Leonidas, [13:43.000 --> 13:45.480] we are also releasing a set of Kubernetes test cases, [13:45.480 --> 13:48.140] 17 in total, not only to help you get started [13:48.140 --> 13:49.760] writing attack definitions, [13:49.760 --> 13:51.720] but also to showcase the tool's capabilities, [13:51.720 --> 13:54.400] 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:01.280] Okay, lastly, I want to talk about operations teams [14:01.280 --> 14:04.060] and how they can apply the security monitoring concepts [14:04.060 --> 14:05.620] of the traditional SOC [14:05.620 --> 14:07.660] into container orchestration environment. [14:07.980 --> 14:09.460] You know, after all, the goal of any exercise [14:09.460 --> 14:11.620] is to upskill defenders and build the capability. [14:12.860 --> 14:15.580] The most important building block of security monitoring [14:15.580 --> 14:17.660] is arguably logs, all right? [14:17.700 --> 14:20.840] If you look at the official Kubernetes documentation, however, [14:20.840 --> 14:23.660] you'll find there are plenty of log sources available, [14:23.660 --> 14:24.960] but no standard architecture [14:24.960 --> 14:27.120] 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:32.280] Roughly speaking, from all the different types, [14:32.280 --> 14:34.360] let's say we can categorize all of them [14:34.360 --> 14:36.180] into three different types of log sources. [14:36.180 --> 14:38.820] So first, we have logs from your application, [14:38.820 --> 14:39.780] logs from the code, [14:39.780 --> 14:42.840] which are exposed to container logs and pod logs. [14:42.840 --> 14:45.660] You can collect them with the kubectl logs commands, [14:45.660 --> 14:46.820] but they are ephemeral, [14:46.820 --> 14:48.760] which means that if the pod terminates, [14:48.760 --> 14:50.080] the logs are gone. [14:50.680 --> 14:53.040] We also have logs from Kubernetes components, [14:53.040 --> 14:55.920] like the API server, the kubelet, the container runtime. [14:55.920 --> 14:57.520] Just like container logs, [14:57.520 --> 15:00.140] these ones are also stored on the nodes, [15:00.140 --> 15:03.760] which means that, actually, in a production cluster, [15:03.760 --> 15:05.760] 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:13.480] And thankfully, there's lots of solutions out there, [15:13.480 --> 15:15.980] agent-based solutions like Fluentd that can do that. [15:16.420 --> 15:20.480] And finally, we have logs that aren't particularly native to Kubernetes, [15:20.480 --> 15:23.740] but are still of interest for the security of the overall ecosystem. [15:23.860 --> 15:27.420] If your cluster is a managed service from a public cloud provider, [15:27.420 --> 15:29.880] then that cloud provider's logging and monitoring solutions [15:30.800 --> 15:32.340] are also crucial to monitor, [15:32.340 --> 15:34.760] like IAM logs or GuardDuty and stuff like that. [15:34.760 --> 15:38.120] And similarly, if you host your own internal image repositories, [15:38.120 --> 15:41.200] we found that logs from these image repositories [15:41.200 --> 15:44.540] could allow the correlation of certain attacker actions, [15:44.540 --> 15:46.660] and that's not even half of it. [15:46.660 --> 15:50.380] There's just a ridiculous amount of logs flowing throughout your cluster, [15:50.660 --> 15:53.560] 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 --> 15:59.060] It's those that answer not so much why something happened, [15:59.060 --> 16:02.480] 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:08.600] If you remember from the previous slide, [16:08.600 --> 16:11.260] which provides us visibility on the container level, [16:11.260 --> 16:13.700] on the node level, and the control plane level. [16:14.300 --> 16:17.220] And alongside those, I've also highlighted the cloud IAM logs, [16:17.220 --> 16:18.520] because if you're running a managed cluster, [16:18.520 --> 16:21.140] identity is always of security interest. [16:21.800 --> 16:24.760] I want to take a couple of slides to zoom in on the most important log source, [16:24.760 --> 16:28.480] the true MVP of Kubernetes attack detection, the audit log. [16:28.560 --> 16:32.480] You can consider the audit log as the access logs of the API server, [16:32.480 --> 16:35.040] which simply means that if you're interacting with a control plane, [16:35.040 --> 16:37.800] you're getting recorded, with some exceptions. [16:37.980 --> 16:40.720] The resulting events can be formatted in JSON, [16:40.720 --> 16:43.900] 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:52.060] To enable them, you need to define a node policy and reconfigure the API server, [16:52.060 --> 16:54.840] but you can't always do that, for example, in managed clusters. [16:54.900 --> 16:57.780] Some events will be very noisy, others will be more important, [16:57.780 --> 16:59.480] so you want to have more detail. [16:59.600 --> 17:01.720] And that's why there's a few different verbosity levels [17:01.720 --> 17:06.140] that you can set for each different type, each different event type. [17:06.160 --> 17:09.320] You can easily find a sample policy to get started with, [17:09.320 --> 17:11.580] like the one I'm linking in the bottom of the slide, [17:11.580 --> 17:15.440] but it's going to take some tuning to find the perfect mix. [17:16.100 --> 17:19.500] The API server can also be configured to store audit logs locally [17:19.500 --> 17:24.120] or send them to a hook, and both of these ways allow for wording to a scene. [17:24.620 --> 17:29.000] Once you do that, you now have the ability to write alert queries upon these logs, [17:29.000 --> 17:31.580] which brings us to the topic of detection engineering. [17:32.040 --> 17:35.340] In its simplest form, an alert for suspicious control plane activity [17:35.340 --> 17:39.860] could be captured by the verb and the resource, such as list, secrets. [17:40.380 --> 17:42.860] And this behavior can then be defined in a SIGMA rule [17:42.860 --> 17:44.940] 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:50.720] In fact, there weren't any SIGMA rules out there available [17:50.720 --> 17:55.060] that operated on Kubernetes audit logs, so we published a few. [17:55.060 --> 17:58.980] And since this log source didn't really exist, we also introduced it [17:58.980 --> 18:02.300] by contributing a backend pipeline to the SIGMA ecosystem [18:02.300 --> 18:05.660] in order to convert rules to actual alerts that a scene can understand. [18:06.140 --> 18:09.000] But attacks could not only target the control plane, [18:09.000 --> 18:10.080] if you remember from the previous slide, [18:10.080 --> 18:12.440] they could originate from within the container. [18:12.460 --> 18:14.940] But luckily, there's a lot of research in this area, [18:14.940 --> 18:17.820] many solutions available, like Falco or Tetragon, [18:17.820 --> 18:21.060] that monitor containers by tapping into the kernel of the underlying node [18:21.060 --> 18:22.660] using eBPF. [18:22.960 --> 18:26.140] And this enables EDR-style analysis of the syscalls, [18:26.140 --> 18:29.220] which then allows the authoring of rules in an easy format [18:29.220 --> 18:34.760] for suspicious process command lines, for suspicious network activity, [18:34.760 --> 18:36.800] and other system-level events. [18:37.780 --> 18:39.980] All right, now it is time for the demo. [18:39.980 --> 18:42.500] So in the upcoming video, we'll see how we can simulate [18:42.700 --> 18:44.660] a fictitious threat actor who gets access to a cluster [18:44.660 --> 18:45.800] and performs some attacks. [18:45.800 --> 18:48.200] We'll do that using Leonidas for Kubernetes. [18:48.260 --> 18:50.820] And after we run the attack chain, we'll put our blue hats on, [18:50.820 --> 18:53.820] we'll put our defender hats on, the Viking hat, [18:53.820 --> 18:58.060] and look at Elastic and Falco, which we have set up, [18:58.060 --> 18:59.960] 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:11.270] All right, so first thing we're going to do [20:11.270 --> 20:13.210] 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:19.890] We also have the dashboard up and running, [20:19.890 --> 20:24.430] and you can see we have a couple of namespaces already there, [20:24.430 --> 20:26.210] including one called DharmaProds, [20:26.210 --> 20:28.470] which has just one deployment in there. [20:28.470 --> 20:30.470] It's called HVACController, and once we click it, [20:30.470 --> 20:32.550] we'll see that it includes a couple of pods, [20:32.550 --> 20:34.210] one looking like a database, and the other one [20:34.210 --> 20:36.910] potentially doing something sensitive, HVACController. [20:37.430 --> 20:39.410] And now we're going to go ahead and deploy Leonidas [20:39.410 --> 20:40.790] into that cluster. [20:40.790 --> 20:43.190] To do that, we'll run a couple of generator commands. [20:43.190 --> 20:45.650] Generator is an accompanying tool [20:45.650 --> 20:48.610] that allows deployment of Leonidas. [20:48.650 --> 20:50.770] First, we're going to generate the Python code [20:50.770 --> 20:53.330] from the attack definitions that we have previously defined, [20:53.330 --> 20:56.010] and then we're going to generate the Kubernetes resources [20:56.010 --> 20:58.730] in the standard YAML manifest. [20:58.730 --> 21:00.850] These resources will then go ahead [21:00.850 --> 21:04.010] and kubectl apply into our cluster [21:04.010 --> 21:06.610] so that we can create the Leonidas deployment [21:06.610 --> 21:09.030] into our namespace, into DharmaProds. [21:09.030 --> 21:10.790] And you'll see that it started running. [21:10.790 --> 21:13.810] Once it's completed, once deployment is completed, [21:13.810 --> 21:16.630] 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:23.250] And we bring it locally to port 5000 [21:23.250 --> 21:25.030] so we can interact with it. [21:25.310 --> 21:26.810] And once this is done, [21:26.810 --> 21:29.370] 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:37.730] One of them is via this very simple client, [21:37.730 --> 21:39.750] providing the values in all these fields [21:39.750 --> 21:41.310] 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:47.990] And in order to do that, [21:47.990 --> 21:50.710] 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 --> 21:57.790] Once we click it, we'll see the web UI of Jupyter, [21:57.790 --> 22:00.810] navigate to the right directory of the threat actors notebooks, [22:00.810 --> 22:03.110] 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:08.370] Like we said before, [22:08.370 --> 22:10.230] execute some attacks against the Kubernetes cluster [22:10.230 --> 22:11.830] 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:22.070] Actually, before we get to these attacks, [22:22.070 --> 22:23.410] let's look at the Defender tech, [22:23.410 --> 22:25.590] 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:44.610] And just to make sure that nothing has fired just yet, [22:44.610 --> 22:47.570] 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:54.090] We've configured this on the nodes of the cluster to monitor the containers, [22:54.090 --> 22:55.150] like we said before. [22:55.650 --> 22:58.530] Cool. All right, let's start running the attack step-by-step then. [22:58.530 --> 23:01.650] So if we navigate back to the Jupyter Notebook, [23:01.650 --> 23:04.450] 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:16.350] And this token is what we're going to instantiate a client with, [23:16.530 --> 23:17.930] a client to Leonidas. [23:17.930 --> 23:21.490] So behind the scenes, this Jupyter Notebook is running some Python, [23:21.490 --> 23:22.470] 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:30.530] So the first thing, once the attacker has obtained access, [23:30.530 --> 23:33.410] 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:08.430] With some processing, with some post-processing, [24:08.430 --> 24:12.550] 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:47.210] 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 [24:47.210 --> 24:52.410] for good bookkeeping, timestamps, success status, and the name of the test case. [24:52.790 --> 25:02.010] Cool. So, we'll now, as promised, return back to the detection capabilities, Blue Team Solutions, [25:02.010 --> 25:05.010] 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:26.130] And that wraps up the demo. I do have one more slide. [25:37.900 --> 25:38.860] Awesome. [25:51.480 --> 25:56.020] All right, that one last slide. Hopefully you can see just the slide, not the speaking notes. [25:56.020 --> 26:00.060] Cool. All right. 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:15.300] Once this is done, we saw how the concepts and the methods of collaborative attack simulation can be applied to this world as well, [26:15.300 --> 26:17.560] in order to build defenses proactively. [26:17.980 --> 26:23.860] To this end, we're giving the world a Kubernetes native attack simulation framework, Leonidas for Kubernetes, [26:23.980 --> 26:29.500] a set of test cases to get started, along with their corresponding Sigma rules as a building block for detections. [26:30.040 --> 26:32.380] And that's all from me. 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.