1 00:00:00,000 --> 00:00:02,120 Hello everyone, and thanks for joining this talk. 2 00:00:02,140 --> 00:00:08,480 Today, we're going to talk about Kubernetes, and specifically, how you can run successful attack simulation exercises. 3 00:00:08,780 --> 00:00:10,660 First of all, a few words about myself. 4 00:00:10,660 --> 00:00:11,460 My name is Leo. 5 00:00:11,460 --> 00:00:15,140 I'm a Senior Security Consultant at WithSecure, based in Manchester, UK. 6 00:00:15,240 --> 00:00:21,100 I'm focusing mostly on threat simulation and, generally speaking, collaborative security assessments. 7 00:00:21,100 --> 00: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? 8 00:00:30,620 --> 00: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. 9 00:00:39,880 --> 00: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. 10 00:00:53,880 --> 00:00:59,380 So, first, we did some threat modeling, just to better understand the risks to this novel platform. 11 00:00:59,500 --> 00:01:04,160 Then, we wrote some tooling in order to simulate some attacks at scale. 12 00:01:04,160 --> 00: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. 13 00:01:16,520 --> 00:01:18,900 But this research didn't really stop there. 14 00:01:18,900 --> 00:01:20,380 It didn't stop after that project. 15 00:01:20,380 --> 00:01:24,420 We kept working on it in the background, and this is what we're talking about today. 16 00:01:24,460 --> 00:01:27,100 We'll start with a very gentle introduction to Kubernetes. 17 00:01:27,100 --> 00:01:28,340 I know this is Adversary Village. 18 00:01:28,340 --> 00:01:29,480 It's not a cloud conference. 19 00:01:29,480 --> 00:01:32,180 So, if you're not familiar with Kubernetes, fear not. 20 00:01:32,560 --> 00: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. 21 00:01:39,620 --> 00:01:43,040 And then we'll dive headfirst into Kubernetes attack simulation topics. 22 00:01:43,040 --> 00:01:47,440 And we're going to look at tools, operational, planning, and eventually execution. 23 00:01:48,060 --> 00:01:51,000 And this talk isn't only for offensive security practitioners. 24 00:01:51,000 --> 00:01:57,200 So, we'll cover some basic Kubernetes detection concepts as well, to see things from the perspective of the SOC. 25 00:01:57,260 --> 00:02:01,040 We'll look at things like log sources, detection engineering, and so on. 26 00:02:01,400 --> 00: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. 27 00:02:11,300 --> 00:02:15,180 Okay, as promised, let's start with some introductions. 28 00:02:15,420 --> 00: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. 29 00:02:21,960 --> 00:02:27,040 But the thing is, if you're even remotely familiar with Kubernetes, you will know that it's complicated. 30 00:02:27,260 --> 00:02:28,980 So, just a word of caution. 31 00:02:29,020 --> 00:02:30,980 This is not going to be an in-depth analysis. 32 00:02:31,040 --> 00:02:32,640 It will be deliberately incomplete. 33 00:02:33,060 --> 00:02:38,100 In fact, it's probably going to be the fastest introduction to Kubernetes ever given, so please bear with me. 34 00:02:38,760 --> 00:02:43,760 So, our system in question, the Kubernetes cluster, consists of a set of worker machines. 35 00:02:43,760 --> 00:02:45,280 We call them nodes, right? 36 00:02:45,480 --> 00:02:47,780 And these nodes run containerized applications. 37 00:02:47,780 --> 00:02:51,660 They are managed by the control plane, over there on the left of the slide. 38 00:02:51,680 --> 00: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. 39 00:03:06,420 --> 00:03:10,260 Now, this component that I mentioned, the API server, is in the heart of the cluster. 40 00:03:10,260 --> 00:03:14,100 It's the front end that all internal and external parties communicate with. 41 00:03:14,100 --> 00:03:18,700 It exposes a REST API, which clients can talk to if they want to interact with Kubernetes. 42 00:03:18,700 --> 00:03:23,140 And I'm talking about clients like users or services, like CICD pipelines. 43 00:03:23,440 --> 00:03:29,700 But it's important to remember that humans most commonly use kubectl instead of just sending raw HTTP requests. 44 00:03:30,240 --> 00:03:35,000 Now, when it comes to running applications, the basic building block in Kubernetes is a pod. 45 00:03:35,000 --> 00:03:42,580 A pod can consist of one or more containers whose images are pulled from registries, as well as volumes, storage resources. 46 00:03:42,600 --> 00: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. 47 00:03:53,560 --> 00: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. 48 00:04:01,540 --> 00: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. 49 00:04:10,460 --> 00: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. 50 00:04:19,820 --> 00:04:26,960 RBAC defines the potential entities and allows you to write policies for the permissions that these entities will have against resources. 51 00:04:26,960 --> 00: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. 52 00:04:38,760 --> 00:04:43,360 And you also get pods or external services that are associated with service accounts. 53 00:04:43,360 --> 00:04:47,540 And service accounts authenticate using tokens, JSON web tokens, JWTs. 54 00:04:48,560 --> 00:04:52,080 Okay, that was easy, right? 55 00:04:52,340 --> 00:04:56,120 One thing to remember, though, is that in Kubernetes, everything can be replaced. 56 00:04:56,120 --> 00:04:57,480 It's built to be extensible. 57 00:04:57,480 --> 00: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. 58 00:05:04,620 --> 00:05:10,980 Technologies like the ones tracked in the CNCF landscape, which introduce their own set of risks when deployed inside your cluster. 59 00:05:10,980 --> 00: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. 60 00:05:19,020 --> 00:05:22,900 And that means answering a few questions like, what are the assets I must protect? 61 00:05:22,900 --> 00:05:24,820 And where would attacks come from? 62 00:05:24,900 --> 00:05:27,500 And why would attackers target Kubernetes in the first place? 63 00:05:27,880 --> 00:05:30,400 Let's start with an enumeration of the attack surfaces. 64 00:05:30,400 --> 00:05:36,280 This will also help us understand which levels we must execute in if we're looking to simulate these attacks. 65 00:05:36,840 --> 00:05:42,500 In the most typical scenario, attacks will originate from the container level, the code running within the pod. 66 00:05:42,500 --> 00:05:49,180 For example, think of a compromised web service or a backdoored image that found its way into your cluster somehow. 67 00:05:49,460 --> 00: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. 68 00:05:58,700 --> 00: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. 69 00:06:10,180 --> 00:06:13,960 And of course, there's always a threat of attacks from the outside world. 70 00:06:14,080 --> 00: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. 71 00:06:21,380 --> 00:06:24,260 So once they're inside your cluster, what will they move towards? 72 00:06:24,260 --> 00:06:25,880 What's the final objective there? 73 00:06:26,660 --> 00:06:29,180 An obvious answer to this one is, of course, the workloads. 74 00:06:29,660 --> 00:06:36,420 If Kubernetes is the underlying platform that your critical workloads are running in, then it's a way into them. 75 00:06:36,420 --> 00:06:38,600 It's a way into the workload. 76 00:06:38,600 --> 00:06:43,480 So compromising Kubernetes could result in unauthorized access to the data. 77 00:06:43,480 --> 00: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. 78 00:06:54,140 --> 00:06:56,780 But actually, that's not the most common incentive. 79 00:06:57,200 --> 00:07:04,880 In the age of cryptocurrency, every compute resource makes for an attractive target for its immediate potential for financial returns. 80 00:07:04,880 --> 00:07:08,400 A compute, in and of itself, is therefore worth protecting. 81 00:07:08,640 --> 00:07:12,240 And you'll see that various instances have been recorded with this particular objective. 82 00:07:13,380 --> 00:07:19,920 Kubernetes clusters are usually also deployed as managed cloud services, or broadly speaking, in cloud infrastructure. 83 00:07:19,920 --> 00: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. 84 00:07:28,600 --> 00: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. 85 00:07:46,480 --> 00: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. 86 00:07:53,220 --> 00:07:56,580 All right, so we know what adversaries are looking for. 87 00:07:56,580 --> 00:07:58,080 We know where they'll come from. 88 00:07:58,140 --> 00:07:59,660 Let's go ahead and simulate them. 89 00:07:59,660 --> 00:08:02,620 Now, there's a few different approaches to go about this. 90 00:08:02,620 --> 00:08:08,220 And instead of a stealthy, objective-based exercise, we chose to adopt more of a Purple Team methodology. 91 00:08:08,560 --> 00: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. 92 00:08:13,720 --> 00:08:19,220 It talks about collaboration between offense and defense with the aim to increase familiarity with TDPs. 93 00:08:19,360 --> 00: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. 94 00:08:29,800 --> 00:08:32,460 And at WithSecure, we focus a bit more on detection. 95 00:08:32,460 --> 00: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. 96 00:08:37,380 --> 00: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. 97 00:08:49,520 --> 00:08:52,620 And even mimic a specific campaign from the ones we saw before. 98 00:08:53,200 --> 00:08:58,540 Okay, let's look at these two options in a bit more detail in the context of a Kubernetes exercise. 99 00:08:59,600 --> 00:09:06,340 So for Kubernetes specifically, we found that there aren't as many campaigns documented as there are for on-prem infrastructure. 100 00:09:06,460 --> 00:09:09,180 And as a result, there's not a lot of threat intelligence available. 101 00:09:09,380 --> 00: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. 102 00:09:18,260 --> 00:09:22,620 In that case, you probably know already which threat actor you want to emulate. 103 00:09:22,620 --> 00:09:27,640 But if not, the security researchers over at Wiz maintain this great matrix of cloud threats. 104 00:09:27,640 --> 00:09:29,880 And that also covers Kubernetes incidents. 105 00:09:30,300 --> 00:09:37,300 So it aggregates threat intelligence from various blog posts, like Unit 42, Aqua, Sysdig, CrowdStrike, all the ones we saw before. 106 00:09:37,580 --> 00: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. 107 00:09:46,180 --> 00:09:51,140 Now, a nice way of documenting these different emulation plans is Jupyter Notebooks. 108 00:09:51,140 --> 00:09:56,940 And we've seen a bit in the demo how Jupyter Notebooks can also streamline execution of the attack simulation. 109 00:09:56,940 --> 00: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. 110 00:10:09,100 --> 00:10:17,640 In 2020, Microsoft released the third matrix for Kubernetes, which was the first systematic categorization of Kubernetes techniques observed until then. 111 00:10:17,640 --> 00:10:19,500 And it seems to be actively maintained. 112 00:10:19,800 --> 00:10:25,460 There's also a Mitre ATT&CK matrix for containers, but it doesn't really care about the orchestration platform. 113 00:10:25,460 --> 00:10:29,320 And I actually got some very good ideas for attacks by looking at KubeHunter. 114 00:10:29,680 --> 00: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. 115 00:10:35,380 --> 00: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. 116 00:10:44,780 --> 00: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. 117 00:10:53,620 --> 00:10:56,000 And this is a well-known practice in DevSecOps. 118 00:10:56,000 --> 00:11:00,260 You know, attack definitions as code, detections as code, we can apply it here as well. 119 00:11:00,640 --> 00:11:06,460 This way, as your Kubernetes environment evolves, so does your repository of attacker test cases. 120 00:11:07,300 --> 00:11:08,040 Fantastic. 121 00:11:08,040 --> 00:11:10,080 So, we have planned everything. 122 00:11:10,080 --> 00:11:11,620 We are ready to get our hands dirty. 123 00:11:11,620 --> 00:11:13,660 Let's start bashing kubectl commands. 124 00:11:14,480 --> 00: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. 125 00:11:20,680 --> 00:11:24,280 Starting with the familiar ART, Atomic Red Team by Red Canary. 126 00:11:24,440 --> 00:11:26,700 This is out of Citi Village, I'm sure you're all aware of it. 127 00:11:26,700 --> 00: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. 128 00:11:36,420 --> 00: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. 129 00:11:45,360 --> 00:11:48,820 So it's actually a good choice for this particular purpose. 130 00:11:48,820 --> 00: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. 131 00:11:58,480 --> 00:12:03,380 One tool that can, in fact, run from within the cluster is Pirates by InGuardians. 132 00:12:03,460 --> 00:12:04,800 It's also widely known. 133 00:12:04,800 --> 00:12:07,920 Various talks, blog posts, webinars out there talking about it. 134 00:12:07,920 --> 00:12:10,820 It's so well known that it's actually been used by threat actors. 135 00:12:11,240 --> 00:12:17,700 But once again, the attacks it supports are hard-coded, and the tool itself doesn't really allow for customization. 136 00:12:18,840 --> 00:12:24,800 So overall, when we were doing this research, we realized that none of these tools performed exactly what we wanted. 137 00:12:24,800 --> 00:12:27,420 These options all had some limitations. 138 00:12:27,420 --> 00:12:32,120 So we decided to extend our own existing tool, Leonidas, to add Kubernetes support. 139 00:12:32,320 --> 00:12:35,320 And if you're not familiar with it, no, I did not write the original version. 140 00:12:35,380 --> 00:12:36,340 It's not named after me. 141 00:12:36,340 --> 00:12:37,640 That would be a little bit lame. 142 00:12:38,440 --> 00:12:40,420 I don't want to talk too much about Leonidas. 143 00:12:40,420 --> 00:12:42,060 It's an open-source tool. 144 00:12:42,200 --> 00:12:45,600 My colleague Nick Jones originally wrote the AWS version. 145 00:12:45,600 --> 00:12:48,540 And again, various presentations out there talking about it. 146 00:12:48,540 --> 00: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, 147 00:13:01,340 --> 00:13:05,880 as well as the ability to run within your environment and manage its own resources. 148 00:13:06,340 --> 00:13:10,440 And these were the concepts that we applied when building Kubernetes support for it. 149 00:13:10,440 --> 00:13:16,080 We wanted something running within the cluster, distributed as a disposable image, as an ephemeral image. 150 00:13:16,080 --> 00:13:20,780 We wanted something that analysts or threat hunters could trivially write new TDPs for. 151 00:13:21,460 --> 00: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. 152 00:13:33,520 --> 00: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. 153 00:13:41,060 --> 00: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, 154 00:13:54,400 --> 00:13:56,500 and even applying custom YAML manifests. 155 00:13:56,740 --> 00:13:57,940 A lot of different options. 156 00:13:58,500 --> 00: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. 157 00:14:07,980 --> 00:14:11,620 You know, after all, the goal of any exercise is to upskill defenders and build the capability. 158 00:14:12,860 --> 00:14:17,660 The most important building block of security monitoring is arguably logs, all right? 159 00:14:17,700 --> 00: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. 160 00:14:27,120 --> 00:14:29,320 This is left to the users to implement. 161 00:14:29,860 --> 00: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. 162 00:14:36,180 --> 00:14:42,840 So first, we have logs from your application, logs from the code, which are exposed to container logs and pod logs. 163 00:14:42,840 --> 00: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. 164 00:14:50,680 --> 00:14:55,920 We also have logs from Kubernetes components, like the API server, the kubelet, the container runtime. 165 00:14:55,920 --> 00: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. 166 00:15:06,280 --> 00:15:08,840 If the VM is replaced, these logs are also gone. 167 00:15:08,840 --> 00:15:11,540 So you need to take them out of the host while you can. 168 00:15:11,540 --> 00:15:15,980 And thankfully, there's lots of solutions out there, agent-based solutions like Fluentd that can do that. 169 00:15:16,420 --> 00: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. 170 00:15:23,860 --> 00: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. 171 00:15:34,760 --> 00: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. 172 00:15:46,660 --> 00: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. 173 00:15:53,560 --> 00:15:56,180 The ones that are, are those selected here. 174 00:15:56,180 --> 00:16:02,480 It's those that answer not so much why something happened, but rather who, did what, when, and where from. 175 00:16:02,960 --> 00:16:07,100 And these security-relevant log sources map to the execution levels. 176 00:16:07,100 --> 00: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. 177 00:16:14,300 --> 00: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. 178 00:16:21,800 --> 00: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. 179 00:16:28,560 --> 00: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. 180 00:16:37,980 --> 00:16:43,900 The resulting events can be formatted in JSON, and they answer the security investigation questions that we raised before. 181 00:16:44,140 --> 00:16:47,540 Important to mention, though, these are not enabled by default. 182 00:16:47,680 --> 00: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. 183 00:16:54,900 --> 00:16:59,480 Some events will be very noisy, others will be more important, so you want to have more detail. 184 00:16:59,600 --> 00: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. 185 00:17:06,160 --> 00: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. 186 00:17:16,100 --> 00: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. 187 00:17:24,620 --> 00: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. 188 00:17:32,040 --> 00: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. 189 00:17:40,380 --> 00:17:44,940 And this behavior can then be defined in a SIGMA rule for easier management and distribution. 190 00:17:45,460 --> 00:17:48,000 We found that there weren't many SIGMA rules out there available. 191 00:17:48,000 --> 00: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. 192 00:17:55,060 --> 00: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. 193 00:18:06,140 --> 00: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. 194 00:18:12,460 --> 00: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. 195 00:18:22,960 --> 00: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. 196 00:18:37,780 --> 00:18:39,980 All right, now it is time for the demo. 197 00:18:39,980 --> 00: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. 198 00:18:45,800 --> 00:18:48,200 We'll do that using Leonidas for Kubernetes. 199 00:18:48,260 --> 00: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. 200 00:19:00,040 --> 00:19:02,820 All right, let me switch to the demo video. 201 00:19:07,250 --> 00:19:08,910 Can you all see the video? 202 00:19:09,510 --> 00:19:10,390 No? 203 00:19:11,830 --> 00:19:13,230 Good thing I asked. 204 00:19:16,390 --> 00:19:17,970 Is it this way? 205 00:19:20,090 --> 00:19:22,070 Now I can't see how to maximize it all. 206 00:19:22,070 --> 00:19:23,870 Can I have some tech support here? 207 00:19:29,570 --> 00:19:31,990 Yeah, but I can't see the pointer, so I can maximize it. 208 00:19:32,890 --> 00:19:33,850 You reckon? 209 00:19:35,750 --> 00:19:36,470 Nice. 210 00:19:36,990 --> 00:19:38,750 The problem is that I can't see it. 211 00:19:39,290 --> 00:19:40,670 All right, let's do it. 212 00:19:41,730 --> 00:19:42,450 I won't... 213 00:19:43,670 --> 00:19:45,430 Yeah, but I want to talk over it. 214 00:19:57,950 --> 00:20:01,510 You can switch your display settings, so it's, yeah, duplicated. 215 00:20:04,030 --> 00:20:04,930 See it now? 216 00:20:05,670 --> 00:20:06,910 Awesome, fixed. 217 00:20:07,470 --> 00:20:13,210 All right, so first thing we're going to do is confirm connectivity to the Kubernetes cluster. 218 00:20:13,210 --> 00:20:15,290 We'll do that using a cluster info command. 219 00:20:15,450 --> 00:20:18,190 We see that, indeed, the Kubernetes cluster is up and running. 220 00:20:18,190 --> 00: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. 221 00:20:28,470 --> 00: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. 222 00:20:37,430 --> 00:20:40,790 And now we're going to go ahead and deploy Leonidas into that cluster. 223 00:20:40,790 --> 00:20:43,190 To do that, we'll run a couple of generator commands. 224 00:20:43,190 --> 00:20:48,610 Generator is an accompanying tool that allows deployment of Leonidas. 225 00:20:48,650 --> 00: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. 226 00:20:58,730 --> 00: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. 227 00:21:09,030 --> 00:21:10,790 And you'll see that it started running. 228 00:21:10,790 --> 00:21:16,630 Once it's completed, once deployment is completed, we'll then expose the port. 229 00:21:16,630 --> 00:21:18,890 We're using a kubectl port forward command. 230 00:21:18,970 --> 00:21:21,130 KL, by the way, is an alias for kubectl. 231 00:21:21,130 --> 00:21:25,030 And we bring it locally to port 5000 so we can interact with it. 232 00:21:25,310 --> 00:21:29,370 And once this is done, indeed, we can access the API. 233 00:21:29,370 --> 00:21:32,710 It's the familiar API, if you looked at Leonidas before. 234 00:21:32,710 --> 00:21:34,750 There are two ways to interact with Leonidas. 235 00:21:34,770 --> 00:21:41,310 One of them is via this very simple client, providing the values in all these fields and then hitting execute. 236 00:21:42,030 --> 00:21:45,270 But instead, we're going to do it through a Jupyter notebook. 237 00:21:46,510 --> 00:21:50,710 And in order to do that, we first need to start the Jupyter service. 238 00:21:50,710 --> 00:21:54,310 This is going to open the port 8.8.8.8. 239 00:21:54,310 --> 00: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. 240 00:22:03,110 --> 00:22:05,970 Now, OFA-8.15 is our fictitious threat actor. 241 00:22:07,310 --> 00:22:11,830 Like we said before, execute some attacks against the Kubernetes cluster and first get some access to it. 242 00:22:11,830 --> 00:22:14,170 We've got a nice little visualization of it right here. 243 00:22:14,650 --> 00:22:17,150 First step for it is to simulate the initial access. 244 00:22:17,150 --> 00:22:20,130 Now, the typical scenario would be a leaked kubeconfig file. 245 00:22:20,470 --> 00: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. 246 00:22:25,590 --> 00:22:31,190 We do have Elastic, where we're forwarding audit logs from our cluster. 247 00:22:32,670 --> 00:22:35,490 Nicely visualized with the verb resource, like we said before. 248 00:22:35,490 --> 00:22:38,510 And we also have some alert rules configured. 249 00:22:38,890 --> 00:22:41,550 You can see on the right-hand side that these are all enabled. 250 00:22:42,570 --> 00: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. 251 00:22:47,570 --> 00:22:50,250 But before we start executing, let's also look at Falco. 252 00:22:50,250 --> 00:22:55,150 We've configured this on the nodes of the cluster to monitor the containers, like we said before. 253 00:22:55,650 --> 00:22:56,350 Cool. 254 00:22:56,350 --> 00:22:58,530 All right, let's start running the attack step-by-step then. 255 00:22:58,530 --> 00:23:04,450 So if we navigate back to the Jupyter Notebook, we start hitting run through every different cell. 256 00:23:04,450 --> 00:23:06,610 And the first step is to simulate the initial access. 257 00:23:06,810 --> 00:23:08,890 So the typical scenario is a leaked kubeconfig file. 258 00:23:08,890 --> 00:23:12,630 In that kubeconfig file, there might be a service account token, a JWT. 259 00:23:12,630 --> 00:23:17,930 And this token is what we're going to instantiate a client with, a client to Leonidas. 260 00:23:17,930 --> 00:23:22,470 So behind the scenes, this Jupyter Notebook is running some Python, bare-bones Python. 261 00:23:22,470 --> 00:23:24,250 We'll publish all of that, by the way, very soon. 262 00:23:24,250 --> 00:23:27,450 And this interacts with the Leonidas service running within the cluster. 263 00:23:27,510 --> 00: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. 264 00:23:33,710 --> 00:23:36,670 You can do that using the self-subject review API. 265 00:23:36,830 --> 00:23:40,450 So we just run that cell then and look at the results. 266 00:23:40,830 --> 00:23:44,250 We observe in the results that we have some permissions on the pods. 267 00:23:44,250 --> 00:23:48,230 Cool permissions, create, read, update, delete on the right-hand side of the slide. 268 00:23:48,350 --> 00:23:52,470 And we also have some permissions on the secrets, which is already a problem. 269 00:23:52,630 --> 00:23:55,810 So using these permissions, we're going to go ahead and enumerate the pods. 270 00:23:56,270 --> 00:24:01,170 You'll see, like we saw before, patient DB, Leonidas deployment, and the HVAC controller. 271 00:24:01,170 --> 00:24:05,230 And using the permissions we have over the secrets, obviously, we're going to list the secrets. 272 00:24:05,570 --> 00: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. 273 00:24:12,550 --> 00:24:17,350 But putting the pieces together, we have the database pod, we have something that looks like a password. 274 00:24:17,350 --> 00:24:21,550 So why not run a MySQL dump command to get a dump and prepare it for exfiltration? 275 00:24:21,610 --> 00: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. 276 00:24:28,030 --> 00: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. 277 00:24:35,930 --> 00:24:40,330 But this activity will fail because, as we saw before, they do not have the permission to do so. 278 00:24:40,330 --> 00: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. 279 00:24:52,790 --> 00:24:53,170 Cool. 280 00:24:53,170 --> 00: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. 281 00:25:05,010 --> 00:25:12,150 And the same thing stands for Falco, since it detected the MySQL dump command. 282 00:25:12,610 --> 00:25:17,010 Don't worry about the too many lines, it's just a misconfigured rule. 283 00:25:17,010 --> 00:25:22,350 Important thing to notice is that it did capture the MySQL dump command executing within the container. 284 00:25:23,290 --> 00:25:24,710 And that wraps up the demo. 285 00:25:24,710 --> 00:25:26,130 I do have one more slide. 286 00:25:37,900 --> 00:25:38,860 Awesome. 287 00:25:51,480 --> 00:25:53,300 All right, that one last slide. 288 00:25:53,800 --> 00:25:56,020 Hopefully you can see just the slide, not the speaking notes. 289 00:25:56,020 --> 00:25:56,360 Cool. 290 00:25:56,360 --> 00:25:56,880 All right. 291 00:25:57,380 --> 00:26:00,060 I want to close with just a few key takeaways. 292 00:26:00,280 --> 00: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. 293 00:26:08,620 --> 00: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. 294 00:26:17,980 --> 00: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. 295 00:26:30,040 --> 00:26:31,040 And that's all from me. 296 00:26:31,040 --> 00:26:32,380 Thank you very much for your time. 297 00:26:32,380 --> 00: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. 298 00:26:36,680 --> 00:26:38,440 Thanks to Adversary Village for having me.