[00:00.720 --> 00:09.780] Yeah, yeah, yeah. What's up? Good to go? Okay. So, hi everybody. Today's talk is called [00:09.780 --> 00:16.860] Ohm IDC, where we're going to learn and see how we can abuse IDC set ups in the context of CI. [00:17.760 --> 00:22.900] This is extremely exciting for me. That's my first time speaking in the con, so thank you very [00:22.900 --> 00:28.260] much for showing up. And thank you very much for having me. That was the first voice [00:28.260 --> 00:33.420] breakdown, so it's fine. Okay, by the way, if Adnan and John are here, thank you for the [00:33.420 --> 00:40.940] build up. I hope I'll satisfy that. So, I'll present myself. My name is Aviad Hachami. This is [00:40.940 --> 00:48.880] my Twitter handler. I do security research at Palo Alto. I do CI domain mainly. I welcome you [00:48.880 --> 00:57.400] to check my latest publication. This is Azure CLI information leakage with 8.6 core somehow. But [00:57.400 --> 01:04.120] it probably affected all your ASG usages. I also do bug bounty, I DJ, I do graph theory, and [01:04.120 --> 01:12.060] FPV drones. Not necessarily in this order. Okay. So, before we go into the agenda, I want to [01:12.060 --> 01:17.860] try and convince you why you should listen. So, first thing first, if you are completely new [01:17.860 --> 01:23.320] to this world or you have like a rough idea of what OIDC is, I hope you get today the full [01:23.320 --> 01:32.460] context of what's up with that, what's up internally, and how does it play. If you're already a [01:32.460 --> 01:36.620] user, I hope you're going to learn some pitfalls and misconfiguration. I hope I'm going to [01:36.620 --> 01:42.460] save you some weekends. And if you're a bounty hunter, like most of us here, I hope you're [01:42.460 --> 01:51.760] going to get some new ideas for exploitation. All right. So, with that, let's go into the [01:51.760 --> 01:57.120] overview. Okay. For those of you who are familiar with this topic, hold on tight for a sec. [01:57.580 --> 02:05.240] After this, we're going to move into no configs. This is just a word term I set up. I'm going to [02:05.240 --> 02:10.160] explain about it soon enough. We're going to move into advanced configurations, [02:10.160 --> 02:16.380] misconfigurations, and we're going to learn what happens when the CI vendor makes a [02:16.380 --> 02:21.740] misconfig and why do we care about the CI vendor in that context. All right. So, [02:21.740 --> 02:27.560] first things first, let's begin with an OIDC overview. So, when I actually rehearsed this [02:27.560 --> 02:33.580] talk to some of my friends, some of them are good researchers, I used terms like [02:33.580 --> 02:40.560] workflow, job, the CI config, et cetera, et cetera, and they said at some point, this is nice, [02:40.560 --> 02:45.940] but I'm not sure how CI works. So, in the case you're like my friend and you slept under a [02:45.940 --> 02:50.440] rock for the past ten years, I'm going to show you what CI is in one slide so we can move [02:50.440 --> 02:56.320] on. So, extremely quickly, what is CI? Assuming you're a developer, you perform some [02:56.320 --> 03:02.120] Git operation, maybe push, pull requests, et cetera, this was pushed to your VCS provider, [03:02.120 --> 03:07.300] GitHub, GitLab, you name it, and it was reflected in your online repository. So far, so [03:07.300 --> 03:11.800] good. Now, since you've configured your CI provider, because this is what we care about, [03:11.800 --> 03:16.940] then the VCS provider notified the OCI provider that something happened using a web hook [03:16.940 --> 03:24.760] with payload, nothing special here. In turn, the CI provider spinned a machine for you, it [03:24.760 --> 03:31.700] can be any OS according to your configuration, aka workflow. These machines do whatever [03:31.700 --> 03:38.060] you want. It can be lints, builds, compilations, and since we're in 2024, they also push to [03:38.060 --> 03:43.980] your cloud environments. It can be GCP, AWS, Docker Hub, basically everything out there. [03:44.630 --> 03:49.560] This is CI, welcome. So, something I want to emphasize is that those are all split [03:49.560 --> 03:53.120] entities, okay? We're going to come into that later on, we're going to show this diagram [03:53.120 --> 03:59.200] again, but I want you to remember that these are split entities. Cool. Our problem space is [03:59.200 --> 04:03.960] this small arrow, welcome to the OIDC and CI niche. This small arrow, which basically [04:04.500 --> 04:09.980] makes us ask an important question, we're in a machine-to-machine world, so how does [04:09.980 --> 04:17.020] authentication happen, right? How can we access Docker Hub, for example? An easy answer, [04:17.020 --> 04:21.600] right, will be to hard-code your secrets. This is great for my bug bounty, please do that. [04:22.020 --> 04:27.220] But, yeah, continue. The second option will be secrets, right? This is a feature by the CI [04:27.220 --> 04:31.900] providers, etc. But we all know that at some point or another it's going to leak, right? [04:31.900 --> 04:36.100] We're going to see some article saying company whatever was leaked was breached because [04:36.100 --> 04:44.100] of a leakage. So we don't want to do that anymore. And then OIDC comes in to help. So OIDC [04:44.100 --> 04:50.660] is open identity, this is initials for open identity, something I forgot because I'm stressed [04:50.660 --> 04:54.920] obviously, but that's fine. But what I want to emphasize is that it's a simple OAuth [04:54.920 --> 04:59.440] extension. I believe most of you know what OAuth is at this point in time. If you're on [04:59.440 --> 05:05.540] YouTube and you're not familiar with, pause now, go learn OAuth, come back. Yeah, it's the [05:05.540 --> 05:09.380] basics. So OIDC comes in to help and going to help us solve this whole credentials [05:09.380 --> 05:14.020] problem and it's going to allow us to use something called identities that we're going to [05:14.020 --> 05:19.280] see in a second. So what is this OIDC flow? We're going to learn the vanilla version and [05:19.280 --> 05:23.200] then the CI version because they're a bit different. This is just a slide taken from [05:23.200 --> 05:29.320] Microsoft. You are all familiar with the try to log in, go to the identity provider, get [05:29.320 --> 05:33.900] like the token, come back, exchange it. But now we see something different. Instead of [05:33.900 --> 05:39.180] access token and refresh token, we're relying on something called ID token. Welcome. So [05:39.180 --> 05:43.120] we're going to learn what ID tokens are in a second, but I just want to plug in some [05:43.120 --> 05:47.280] terminology. This is the auth n part, the authentication where you actually put [05:47.280 --> 05:53.300] credentials. And this is the auth z part where you actually authorize someone to access [05:53.300 --> 05:56.560] something. Regardless of their authentication state, obviously they should be [05:56.560 --> 06:05.380] authenticated by this point in time. So ID tokens. Standard JWTs, base 64, we're going to [06:05.380 --> 06:09.780] decode them and we're going to get the header which we don't care about for the sake of [06:09.780 --> 06:15.460] this talk. I'll just add that this is how you verify the integrity of an incoming ID token, [06:15.460 --> 06:20.440] but I'm not going to touch this any further. Don't care symbol. And the second part is [06:20.440 --> 06:24.960] the actually ID token body and we're going to dive into the contents of it in a sec, but [06:24.960 --> 06:31.580] for the purpose of this slide, I want you to remember that ID tokens, the body of it is a [06:31.580 --> 06:35.820] simple dictionary where each key is called claim. So now onwards I'm going to say the [06:35.820 --> 06:42.300] token claims something. Okay? Good. So let's conclude the OIDC in the vanilla version of [06:42.300 --> 06:47.120] it. It's an OAuth extension and it allows us to rely on short-lived tokens that are based [06:47.120 --> 06:52.700] on identity. That's it. TLDR of the whole magic. Right. So let's put it in the context of [06:52.700 --> 06:58.200] CICD. If I'm bringing back this small snippet here, right, and I told you this is our [06:58.200 --> 07:04.140] problem space, we have two important questions now. First, this is a machine. How does it [07:04.140 --> 07:09.960] authenticate? We no longer have credentials. So how do we log in? Second question is, [07:09.960 --> 07:15.860] assuming this ID token, how do we verify it? What do we verify it and who does this for us? [07:15.860 --> 07:22.040] Okay? So let's address these questions. This is the diagram that you all saw like a few [07:22.040 --> 07:26.980] slides ago. And if I'm going to call her back, who's in charge of what? And we see that the [07:26.980 --> 07:35.140] only entity that is in charge of the CI machine is the CI provider. Right? So what actually [07:35.140 --> 07:39.500] happens behind the scene, and again I'm going to pop up this question, how do we get the [07:39.500 --> 07:46.800] credentials? The CI provider reacts in accordance to our configuration. Right? And when we [07:46.800 --> 07:51.780] were configured, we were authenticated to the CI provider. So in a sense you can say that [07:51.780 --> 07:56.880] when a CI executes, the machine runs on our behalf. Hence, it's associated with our [07:56.880 --> 08:02.800] identity. And this is important to remember. A CI invocation is in the context of the owner [08:02.800 --> 08:09.620] of the CI integration. So in the context of CICD, the CI vendor also gets to be the identity [08:09.620 --> 08:14.520] provider. It's the only one that can give this machine who it is. Okay? Otherwise it's just an [08:14.520 --> 08:17.700] ephemeral machine, right? Nobody knows what it is. Like why should I give you access to [08:17.700 --> 08:24.540] something? So this is the first question answered. Now the second question was, assuming I do [08:24.540 --> 08:31.460] have this ID token, who authorizes this and how exactly? So, I'm going to close the global [08:31.460 --> 08:38.080] protect. So, um, I'm going to bring back this ID token and this, the auth Z part is actually [08:38.080 --> 08:43.280] composed of 2 components. The first is the ID token and this is an example ID token that is [08:43.280 --> 08:47.480] shipped by, uh, GitHub's identity provider. Most of these, uh, examples are going to be on [08:47.480 --> 08:52.880] GitHub. I really like you folks. Um, so, and if you look at the contents, you see various [08:52.880 --> 08:57.340] claims like, uh, the git sha, the repository name, run ID, et cetera, et cetera. So that's, [08:57.340 --> 09:03.620] like, claims. And the most important for us to remember is, to note, sorry, is the sub. Sub [09:03.620 --> 09:09.360] short for subject. And this is the default property to assert. When the, uh, basically when we [09:09.360 --> 09:15.320] check those claims, it's called assertion, um, and this is the default property to assert. Now, [09:15.320 --> 09:20.340] if we actually dissect this for a second, we know the following. The repo, short for [09:20.340 --> 09:26.940] repository, contains the value of the repository claim, okay? And the ref, right, the ref [09:26.940 --> 09:32.980] prefix contains the value of the git ref coming from the ref claim. So, we can actually see [09:32.980 --> 09:37.960] that there's a format behind the scenes and we're going to come back to that later on. So, [09:37.960 --> 09:43.020] an ID token, in the context of CI, I'm going to summarize that, contains information about the [09:43.020 --> 09:47.280] git event that triggered the pipeline, uh, alongside other vendor information. And we're [09:47.280 --> 09:53.520] going to see later on what this other vendor information, where exactly does it bite us. The [09:53.520 --> 09:57.880] second part, the second component of the AuthZ, is the something called identity [09:57.880 --> 10:03.780] federation. As the name implies, it, uh, it federates identities coming in. Um, this is an [10:03.780 --> 10:10.380] example configuration, uh, for AWS specifically. And the file is pretty simple. Um, you have [10:10.380 --> 10:15.240] the identity name, just a string, the identity provider, this is usually the URL of it. Um, and [10:15.240 --> 10:21.480] then you set up conditions for who can claim to be this identity. Um, then we see what [10:21.480 --> 10:27.300] claims we assert, right? We have the sub, does it work? Okay. We have the sub and then we [10:27.300 --> 10:31.380] have the odd, odd short for audience by the way. And then we see that there, we can define [10:31.380 --> 10:36.640] the comparators, right? We can do string like or string equals and set the values. Okay, so [10:36.640 --> 10:42.820] this is roughly, this is how it goes. So, per the question, how exactly do we authorize [10:42.820 --> 10:47.520] someone? Then we have this entity called identity federation and it's going to assert tokens [10:47.520 --> 10:54.300] claims coming, uh, from, uh, CI machines. In this case, obviously. Alright, so now that we [10:54.300 --> 10:59.180] know that the CI provider is also the identity provider, right? This is something new. And we [10:59.180 --> 11:05.580] also know that this, uh, we have this federation. Then let's redraw the, the OIDC flow in [11:05.580 --> 11:12.080] the context of CI. So in the context of CI, we actually have this diagram. Now the CI [11:12.080 --> 11:17.500] provider also gets to be the identity provider. So it hosts both, uh, like both the CI and [11:17.500 --> 11:23.120] itself, the identity. And also we see on the cloud provider, we have the federation. So the [11:23.120 --> 11:28.280] flow is as follows. You ask for an ID token, you get an ID token, you go to your cloud, you [11:28.280 --> 11:33.540] say I want to access. The clouds verify the integrity. This is done using the header. And [11:34.120 --> 11:38.540] then it's going to assert the incoming token against its policies. And assuming everything [11:38.540 --> 11:42.900] was fine, you're going to get a set of short-lived credentials. This, this microphone [11:42.900 --> 11:51.640] hiccups, right? Right? Uh, oops. The mic hiccups. It doesn't work. Roughly. Halfway. Okay. [11:51.640 --> 11:57.700] I'll say take care of that. Okay. Um, I'm going to plug back in the terminology. This is the [11:57.700 --> 12:05.000] auth N bit. Okay? And this is the auth Z bit. Now, since the flow is different, what does it [12:05.000 --> 12:12.480] imply? I'm going to border this square and let's zoom in. Since everything here happens within [12:12.480 --> 12:18.240] the CI provider, if we are able to trigger a CI pipeline, we basically granted the owner's [12:18.240 --> 12:25.540] identity. Okay? Now, you can limit that using, you can limit that using specific, uh, uh, [12:25.540 --> 12:30.140] orders we'll see later on. But if you're able to trigger a CI machine, you're basically [12:30.140 --> 12:36.560] passed the auth N part. Okay? This leaves us with the auth Z part to guard everything [12:36.560 --> 12:42.080] basically, cause we have the CI machine running. And in a sense, if we're able to trigger a CI [12:42.080 --> 12:46.440] pipeline, all that stands between us and accessing a target's resources is just the policy [12:46.440 --> 12:51.680] pattern matching, right? So, you can see on the bottom part, examples for, uh, sub-claims. [12:51.680 --> 12:57.720] It can begin with repo, a multi-banana Zurich, um, the name of the, uh, uh, repository, the [12:57.720 --> 13:01.980] git ref. And on the right-hand side, you can see an example of assertion. For example, [13:01.980 --> 13:09.340] repo colon star and where star will expand to everything using pattern matching. Okay? So, [13:09.340 --> 13:14.000] this was the summary for, uh, OIDC in the context of CI. This is how it works. This is the [13:14.000 --> 13:19.660] whole magic. So, in the context of CI, we can say that it is done by asserting incoming ID [13:19.660 --> 13:26.280] tokens from CI machine using an identity federation in exchange for credentials. That's it. [13:26.700 --> 13:33.660] Easy. Cool. We can move on to the no configs. And let's have some fun. So, no configs is [13:33.660 --> 13:38.620] basically when there is no one at the door. If you think about the auth Z as the bouncer, if [13:38.620 --> 13:44.820] the bouncers allows anyone into the club, then anybody can get in, right? So, a no config is a [13:44.820 --> 13:50.380] state, uh, where the federator is asserting lax rules, if any. Um, and they will, it will [13:50.380 --> 13:56.260] authorize almost any ID token. Okay? What does it mean? So, let's take a look at these three [13:56.260 --> 14:01.000] snippets. These are snippets from the identity federation example you just saw, but different [14:01.000 --> 14:06.020] assertions. So, the first one, we have, uh, an asterisk, right? Using pattern matching and [14:06.020 --> 14:11.000] gonna expand to anything. Obviously, you didn't check anything here. Um, second option, [14:11.000 --> 14:15.360] repo column stars. So, everything begins with repo. There's nothing specific to your account [14:15.360 --> 14:19.760] here. So, again, you didn't check anything. And the last one is everything that begins with [14:19.760 --> 14:25.280] my org and something to note, there's no slash between the org and the stars. So, if you [14:25.280 --> 14:31.840] open a GitHub organization called my org one, it will satisfy this as well. Cool. Now, this [14:31.840 --> 14:37.080] was already talked about in, uh, in, uh, two talks. One by, uh, Rojan of Tinder and one by [14:37.080 --> 14:43.000] Christoph that maybe sits in the audience here. So, hi Christoph. Um, I also talked about it, [14:43.000 --> 14:48.940] uh, on the latest, um, b-sides. And basically, I, I really, I highly recommend watching these [14:48.940 --> 14:54.460] talks. They explain exactly how those misconfigs look like, okay? And how to hunt for them and [14:54.460 --> 14:59.140] how to exploit them. I'm not gonna talk about, uh, when there's no config kind of situation, [14:59.140 --> 15:05.440] um, and yes, go ahead and watch them. So, since we're not talking about the no config [15:05.440 --> 15:11.340] situation, what happens when I have partial configs? How safe are they, if at all? Let's zoom [15:11.340 --> 15:16.400] in. So, the first one we're gonna assert everybody in the org name, right? Repo colon org name. [15:16.400 --> 15:22.160] Let's say I can say anybody in Palo Alto can access this identity. Is this okay? Is this safe? [15:22.160 --> 15:27.740] What about everybody in Palo with respect to a branch? So, the answer is, the first one is [15:27.740 --> 15:32.060] potentially unsafe, so does the second one. We're gonna see later how we can exploit and abuse [15:32.060 --> 15:39.000] such cases. And the workflow example is actually the worst. This is very bad. If you configure [15:39.000 --> 15:43.740] using the workflow, you're exploited immediately, okay? And we're gonna see how. And another [15:43.740 --> 15:48.680] thing you gotta ask yourself, how come this claim begins with workflow? All you've seen was [15:48.680 --> 15:54.580] repo colon. How come we're at workflow colon? What happened here? Alright, so let's move to [15:54.580 --> 16:00.780] misconfiguration when you do some configurations but they're insufficient. Uh, we're gonna see [16:00.780 --> 16:05.000] some pitfalls for advanced configurations including a demo. And then we're gonna see how you [16:05.000 --> 16:10.960] can abuse, uh, pipelines. This is partially what Adnan, uh, talked about in the, in the last [16:10.960 --> 16:16.560] talk. Um, but we're gonna see how we can abuse lax policies and access, uh, um, various [16:16.560 --> 16:27.080] identities. So, misconfigs. We're gonna start with a short demo. Um, and just click here. Okay, [16:27.080 --> 16:32.240] so what you see here is a video that was uploaded by, uh, JFrog explaining to their customers [16:32.240 --> 16:38.120] how to configure OIDC in front of, uh, JFrog. So you can access the artifactory, x-ray, [16:38.120 --> 16:42.280] etcetera. So this is a great feature by the way, nothing bad to say about them. And what we [16:42.280 --> 16:48.140] see in this example is how they configure the identity provider on JFrog's side and how they [16:48.140 --> 16:53.780] configure the identity. Here we see the example, uh, claims GitHub allows us to rely upon. And [16:53.780 --> 16:59.220] we can see on the right hand side that they instruct us to assert workflow equals JFrog NPM. [16:59.220 --> 17:05.340] This is according to their video. Alright, um, I'm a naive user. I'm gonna copy paste that, [17:05.340 --> 17:12.000] right? Uh, I just learned OAuth and, and OIDC. So, this is me creating the same identity [17:12.000 --> 17:17.080] provider at JFrog. Um, just naming it my provider, etcetera, etcetera, nothing fancy, and [17:17.080 --> 17:22.920] some arbitrary, arbitrary identity. And I'm gonna do the same instruction. I'm gonna assert [17:22.920 --> 17:28.200] that the workflow equals core pre-usable workflow. This is coming from my corporation. [17:28.440 --> 17:35.060] Alright. Uh, I'm gonna save it, uh, and then I'm gonna copy the snippet. This is for GitHub [17:35.060 --> 17:39.440] Actions. Uh, for those of you who are unfamiliar somehow with this product, this is GitHub's [17:39.440 --> 17:46.180] CI. Um, once I saved it, I'm gonna go to my leaking pond repository and I'm gonna create a [17:46.180 --> 17:50.820] new GitHub Actions file. I'm gonna commit everything. If you are unfamiliar with how the [17:50.820 --> 17:54.900] workflows of GitHub Action looks like, then this is it. This is the recipe. And all you gotta [17:54.900 --> 18:01.100] know for the sake of this demo is that assuming a success, the machine invocation as a whole [18:01.100 --> 18:07.380] will be successful, otherwise it will fail. So, uh, I've committed the CI reacts to my [18:07.380 --> 18:12.700] Git event, so it fires. Um, we're gonna see a machine being run and then we're gonna see [18:12.700 --> 18:17.880] that this account, as the video instruct us, was indeed able to access GitHub. Now let's [18:17.880 --> 18:23.140] exploit that, okay? We're gonna use this special technique called copy-paste. I'm gonna [18:23.140 --> 18:28.440] copy the exact same workflow configuration file and I'm gonna commit it to my own private, [18:28.440 --> 18:34.300] uh, uh, account, which I was told that it's not safe to do at DefCon, but whatever. Um, gonna [18:34.300 --> 18:39.840] do a special commit message cause it's important for nothing and in reaction the CI will [18:39.840 --> 18:45.140] trigger again. Now what we will see, uh, we're gonna go into this logs, we're gonna count [18:45.140 --> 18:49.360] 1, 2, 3, worker's gonna pick it up, and we were able to successfully access the same [18:49.360 --> 18:56.080] account, right? From a different account. Amazing, magic. What happened? Right? What [18:56.080 --> 19:02.420] happened here? On JFrog's end, we defined the identity federation to be something, [19:02.420 --> 19:06.300] whatever the name of the provider, but workflow. I'm gonna set the workflow to be [19:06.300 --> 19:13.080] corp usable workflow, correct? Good. When my token showed up and said hi, I'm coming from a [19:13.080 --> 19:18.400] repository, et cetera, et cetera, and the workflow is called corp usable workflow, so the [19:18.400 --> 19:23.120] federation said yeah, it's the same claim, get in. And you gotta ask yourself where is this [19:23.120 --> 19:28.980] value coming from? And the answer is, as always, user input. So you can just, this is the [19:28.980 --> 19:36.140] name of the workflow, you can put any string there and yeah. So, copy paste for the win. [19:36.880 --> 19:42.220] And we can see by showing one example that not all claims are safe, right? I've showed you [19:42.220 --> 19:48.360] once, this is sufficient to say that not all are safe. If we look into the RFC of OIDC, then [19:48.360 --> 19:53.240] basically we're instructed to have five required claims, issuer, subject, audience, [19:53.240 --> 19:58.260] expiration, and issued at, let's translate them to an attacker point of view, the URL of the [19:58.260 --> 20:03.160] provider, the target, just a string that you can modify if you have an RC in the case of [20:03.160 --> 20:08.440] odd, expiration time for the OIDC token is roughly four minutes and nobody cares when it [20:08.440 --> 20:16.360] was issued. On top of these five claims, we have a plethora of other custom claims. These are [20:16.360 --> 20:21.920] given by the CI vendors, which get to be the identity providers, right? For example, GitHub [20:22.480 --> 20:27.060] supplies with various claims, but all of these are unique to GitHub, right? Repository [20:27.060 --> 20:32.080] owner, runner, environment, run number, whatever, whatever, these are all GitHub unique. If [20:32.080 --> 20:36.320] we go to Circle, they have their own world, right? Workflow ID, VCS origin, whatever, [20:36.320 --> 20:43.960] and GitLab has their own stuff, right? Nobody, like, what's going on? So it adds up to a lot of [20:43.960 --> 20:48.380] confusion. If you're a DevOps for a company and you're trying to set up using custom claims, [20:48.380 --> 20:53.320] you can get lost really quickly, because you have so many and there's almost zero instructions [20:53.320 --> 20:59.640] on which values are safe in this context. So if you'd like to avoid a situation like I just [20:59.640 --> 21:05.600] showed, a rule of thumb for using custom claims coming from the vendor is to remember that [21:05.600 --> 21:10.020] they're provided regardless of their strength. By strength, I mean how hard they are to [21:10.020 --> 21:18.920] fraud. So check where the values come from, okay? Now, a hidden pitfall of this behavior, or [21:18.920 --> 21:28.080] this basically behavior, is the custom claim format feature, okay? So as the name suggests, [21:28.080 --> 21:34.240] it's a custom format, and it comes to answer a problem where some federators do not assert [21:34.240 --> 21:39.120] custom claims directly, like we saw with JFrog asserting workflow. Some just don't want to do [21:39.120 --> 21:44.540] that. Why? I don't know. It's just a JSON. But therefore, some identity providers allow [21:44.540 --> 21:49.640] reformatting the structure of the subclaim to contain custom claims values, okay? What do I [21:49.640 --> 21:55.240] mean by that? Consider the top option. This is what you're familiar with. It begins with [21:55.240 --> 22:00.120] repo and then the ref, right? The git ref. But now you can put actor ID, this is in GitHub's [22:00.120 --> 22:04.740] world, so now you can put actor ID and repository ID, and it will be later populated with the [22:04.740 --> 22:11.820] values with respect to where this was fired from, where the CI ran from. So something that [22:11.820 --> 22:17.980] can be easily missed with this feature is that the claims order is critical, all right? Let's [22:17.980 --> 22:24.080] see why. Consider this format and this claim. So we're going to have repo, my org, and then [22:24.080 --> 22:29.620] the name of the workflow, Makat Shemesh, fine. So we all know by now that this is very unsafe, [22:29.620 --> 22:35.240] right? I just showed you how it can be abused. But this one is actually safe. The prefix [22:35.240 --> 22:39.480] is safe. Why? Because GitHub will actually put the name of the organization and repository, [22:39.480 --> 22:43.980] you can't just fake that, at least not in this talk. But you can't just fake that. So [22:43.980 --> 22:49.500] this is fine. This is an example of fine, although it relies on unsafe claim for the [22:49.500 --> 22:54.780] second half of it. If you flip it, however, then you're done with, okay? So let's see [22:54.780 --> 23:01.900] how. In order to abuse such a case, basically all you have to do is create a workflow, name [23:01.900 --> 23:08.120] it everything after the workflow prefix, go to your favorite CI provider, change the sub [23:08.120 --> 23:13.680] claim to be workflow only, and they will grant you with a pretty and beautiful signed token [23:13.680 --> 23:18.180] that has the exact same claim like the other organization asserts. And obviously you can [23:18.180 --> 23:25.300] put whatever my org in Palo Alto, Microsoft, you can just write whatever. So a rule of [23:25.300 --> 23:28.980] thumb for this feature is that the claims order is critical. I haven't seen even one [23:28.980 --> 23:33.200] manual page that mentions that. When you use custom claims, they just let you use it, but [23:33.200 --> 23:40.060] they don't tell you what not to do. So the order is critical. In order to help everybody [23:40.060 --> 23:46.440] here to either escape from these bugs or to exploit them, I've created this tool. You [23:46.440 --> 23:53.480] can scan the QR code to get the latest zero click for your Android. But basically it [23:53.480 --> 23:57.200] allows you to enlist all the GitHub possible custom claims with information about the [23:57.200 --> 24:01.300] strength of each one. This is a nice guide I composed. It can check your sub claim format [24:01.300 --> 24:06.120] for safety, and it will allow you to modify the sub claim if you want to attack with it or [24:06.120 --> 24:09.660] you just want to fix it for your organization or repository. There is some hierarchy [24:09.660 --> 24:14.580] option, so it's interesting. This is how the tool looks like. All you've got to bring is [24:14.580 --> 24:19.380] your favorite GitHub token with admin permissions, not necessarily of your organization, [24:19.380 --> 24:24.600] but yeah. And for example, in the inspect mode, you can see that these are the claims, and [24:24.600 --> 24:32.180] they're not safe because it's set right, so go ahead, get a zero click, and yeah. Okay. [24:32.800 --> 24:39.520] Now this is behind us. And let's move into pipeline abuses that can lead to OIDC abuse. [24:39.520 --> 24:45.480] Basically misconfigs that lead to abuses, abusage, sorry, of lax policies. So we saw that [24:45.480 --> 24:51.920] this was very bad, right? We now know why this sucks. But what about these two? We did [24:52.480 --> 24:58.600] just say that, for example, saying everybody in Apollo is fine, right? Or not? So let's [24:58.600 --> 25:04.660] abuse those. The answer is pretty simple. Poison pipeline execution, which is the most [25:04.660 --> 25:11.120] common entry vector for CIs, right? And lax policies. So let's explain for a second. Uh, a [25:11.120 --> 25:15.680] PPE is a pull request from a fork that will trigger a vulnerable CI execution in the [25:15.680 --> 25:20.680] context of the target, right? We're all familiar with this by now. I hope so. Um, the second [25:20.680 --> 25:25.760] bit, the lax policies, um, they will allow a token from the same, uh, from the targeted [25:26.080 --> 25:30.640] organization, sorry, to slip through lax policies. Okay? Now what do I mean by that? Let's [25:30.640 --> 25:37.760] see how it plays. Demo. In order to demo that, we have to define a few entities, right? Let's [25:37.760 --> 25:41.600] begin with the identity federation on the resource side. So we're gonna set up something [25:41.600 --> 25:47.640] like this. We wanna assert that the audience equals, uh, the Amazon AWS thing. Um, and [25:47.640 --> 25:52.680] we wanna assert that all the identities coming in from the banana multi organization are [25:52.680 --> 25:57.680] okay to go in. This is the federation. If you put it, by the way, on AWS, it's gonna look [25:57.680 --> 26:02.960] something like this. And although AWS did some changes in order to enforce more strict [26:02.960 --> 26:09.860] policies, they will allow you to do that. This is fine by AWS. Now for the git part. Let's [26:09.860 --> 26:15.820] see what's our setup. We have this organization called banana multi and we have two, uh, [26:15.820 --> 26:21.660] basically pipelines including the git repo itself. And let's explain. So the upper one, um, [26:21.660 --> 26:27.940] is a pipeline that is configured to connect using OIDC to an S3 role that is, uh, an admin. Um, [26:27.940 --> 26:33.520] this policy is the policy that we just saw. So it's lax. Um, and this is our target. The [26:33.520 --> 26:38.740] second pipeline is called any updateser and, uh, it contains, it's connected to a vulnerable [26:38.740 --> 26:45.420] pipeline and then it's using an OIDC token again to access a restricted S3, uh, uh, bucket [26:45.420 --> 26:52.180] or a role and we obviously cannot use that. So let's see our attack vector. Pretty simple. We're [26:52.180 --> 26:59.500] gonna fork the any updateser and we're gonna, uh, um, basically invoke the CI machine of the, the [26:59.500 --> 27:04.760] CI workflow, sorry, of, uh, and we're gonna invoke the vulnerable CI workflow and we'll try to [27:04.760 --> 27:10.700] access the other accounts. Um, the workflow, by the way, looks something like this. It has to [27:10.700 --> 27:15.720] react to pull request, maybe pull request or pull request target for the GitHub world. Um, and [27:15.720 --> 27:22.740] you have to specify that you want an ID token that the workflow has to say. Um, the pipeline is [27:22.740 --> 27:26.580] gonna check out the fork. This is the head for the pull request. Uh, we're gonna skip the part [27:26.580 --> 27:31.500] where it actually assumed the AWS role. We don't, we can't use that so we don't care. And then [27:31.500 --> 27:37.340] there's an invocation of a file from the file system which was just cloned from the fork and [27:37.340 --> 27:43.020] yeah, we have RCE. So what we need to do now is make the fork pull request. This is what's [27:43.020 --> 27:49.300] called IPP, indirect points of pipeline execution. And this is the exploit script. Don't [27:49.300 --> 27:54.840] rush and, and, and take pictures. It's just chat GPT. Um, but basically all you have to do [27:54.840 --> 28:00.080] before you make this exploit code, you have to, uh, to do some recon and collect various [28:00.080 --> 28:06.480] id- accounts that are, are connected through using OIDC. Okay? I'm not gonna talk about it in [28:06.480 --> 28:10.460] this talk but this is something you have to do. In this example, I'm having 2 roles at the top [28:10.460 --> 28:16.720] that I'm gonna try to exploit. Let's see it in action. So this is the prepare.sh file that is [28:16.720 --> 28:23.260] gonna be invoked at some point. Uh, this is my fork. Any updates sir? And I'm gonna open a [28:23.260 --> 28:28.760] pull request. So, uh, hello it's me. The diff is the same file. Nothing but this file. And I'm [28:28.760 --> 28:35.900] gonna open the pull request and it's gonna invoke the CI in response to the trigger. Cool. [28:35.900 --> 28:43.180] 3 seconds from now we're gonna see the machine logs. 1, 2, 3, as I promised. And, uh, now in [28:43.180 --> 28:48.640] the logs we will see in the prepare step that it, we will see the output of my script and if [28:48.640 --> 28:54.160] we're successful we'll see sets of credentials. And I wouldn't be here if it would work so, [28:54.160 --> 28:58.260] yeah, we have sets of credentials. So we were able to assume a role that was not allocated to [28:58.260 --> 29:02.180] the pipeline we were running at. Well we were not able to assert others but again you can [29:02.180 --> 29:07.740] just spray OIDC tokens. So this is a very nice technique. You can just collect tokens, find [29:07.740 --> 29:12.720] vulnerable pipelines and start spraying for, to find the logs policies internally, right? [29:12.720 --> 29:21.100] You're already past the auth end. You have the credentials. So give it a shot. 1 second. [29:22.100 --> 29:27.880] Okay, uh, some nice disclosure. I was able to, this is by the way from last year already and, and [29:27.880 --> 29:32.760] I was able to find this, uh, a month ago in Azure and this allowed to access basically all the [29:32.760 --> 29:38.520] identities that had Azure slash star. So, yeah, nice technique. Um, the rest did not allow [29:38.520 --> 29:46.780] disclosure but you're out there. Cool, so rule of thumb in order to avoid this type of stuff, one [29:46.780 --> 29:53.820] is for the CI, please follow the best practices. We're 2024, um, we, my team, we've released [29:53.820 --> 29:59.860] plenty of guides on how to, uh, harden your pipelines. Please do so. The second thing, [29:59.860 --> 30:06.500] uh, pursue, uh, policies that are not with wildcards as much as you can or, uh, use other [30:06.500 --> 30:14.420] claims that are safe in order to assert identities. Okay, this brings us to our last topic [30:14.420 --> 30:18.020] of the day and this is when, when the vendor misconfigures. Now that you know that the [30:18.020 --> 30:22.820] vendor, the CI vendor is also the identity provider, now they have to put, to give more [30:22.820 --> 30:27.800] attention to the details, right? They have various products at their hand now and they have [30:27.800 --> 30:34.200] to be very careful. So, this is a disclosure for, uh, Circle CI, um, and basically if you're [30:34.200 --> 30:39.080] unfamiliar with Circle, they're a great CI product. Um, they provide various machines, right, [30:39.080 --> 30:43.540] in order for you to run your workloads and they're super nice and professional folks on a [30:43.540 --> 30:49.560] personal level. Okay? When I looked into, oh, just to explain, uh, Circle, sorry, um, this is [30:49.560 --> 30:53.580] you, you perform git push, you're all familiar with this diagram by now, well, you notify [30:53.580 --> 30:58.300] Circle with a payload and they did your CI thing for you. Now, when GitHub notifies Circle, [30:58.300 --> 31:03.260] by the way, they do that with the web hook and the payload is everything that was, that is [31:03.260 --> 31:08.780] in your git context. So, in a way, and just to add to the confusion, Circle can supply you [31:08.780 --> 31:12.960] with a super set of claims on top of GitHub's claims, if you think about it. Just to add to [31:12.960 --> 31:18.240] the confusion from earlier, I see your faces, so yeah, it's confusing. Um, okay, so when I [31:18.240 --> 31:22.700] looked into Circle's CI system state, I noted the following. First, pipelines reacted to [31:22.700 --> 31:28.500] fork pull request if and only if, there's no typo, uh, the project is configured to do so. Now, [31:28.500 --> 31:31.980] this is actually a good limitation, right? We don't want anybody on the internet to run [31:31.980 --> 31:37.560] machines for us. Putting aside security, someone's gotta pay for that. Okay, but second [31:37.560 --> 31:42.460] thing that I noted is that pipelines were triggered, uh, on a workflow change, even from a [31:42.460 --> 31:47.780] fork. Okay? And this is not good. Why? This implies every pull request can be an RCE, you [31:47.780 --> 31:55.220] can just commit, basically pull request a malicious workflow. Okay, doesn't look good, but [31:55.220 --> 32:00.340] the third part was the, the cherry on top. An IDC token was always granted to the machine [32:00.340 --> 32:07.100] regardless of anything. And this is credentials mishandle and misuse. Okay? So, combining [32:07.100 --> 32:12.540] those, I was granted an ID token in the context of any Circle CI project that allowed fork [32:12.540 --> 32:17.120] pull requests. Okay? What does it imply? What does it mean? Is that I was able to access [32:17.680 --> 32:22.680] OIDC gated resources of any Circle CI organization that allowed fork pull requests. Right? [32:22.680 --> 32:29.780] That's basically everybody on Circle that has pull requests and OIDC. Nice amount. Um, the [32:29.780 --> 32:33.660] attack flow is pretty simple, you just saw a demo of that using, uh, another file, right? The [32:33.660 --> 32:38.120] prepare, so I'm not gonna show the same thing, all you've, you had to do basically is, uh, pull [32:38.120 --> 32:41.780] request the workflow. So, I'm not gonna show that. I will talk about the disclosure, [32:41.780 --> 32:47.500] however. So, in order to show Circle CI that this was indeed a bug, I looked for instances in [32:47.500 --> 32:54.260] the wild to support my case. Um, it wasn't long ago until I found this file. Now, this was by a [32:54.260 --> 33:00.560] company called Darklang. Anybody here familiar with those folks? Hands up? No? Okay. Um, just [33:00.560 --> 33:04.880] to explain this file, this is an identity federation for, uh, GCP. And even though you don't [33:04.880 --> 33:09.260] know this, this cell language, uh, GCP's language, you can understand the mapping here, right? [33:09.260 --> 33:14.060] We know that CircleCI.com, we know this is the provider, and we know project ID is the claim, [33:14.060 --> 33:18.900] and we're gonna map it to project, audience to organization ID, and sub to sub, right? We now [33:18.900 --> 33:23.960] know what these claims are. Um, per the condition, the condition was that any one of these [33:23.960 --> 33:31.080] three project IDs is okay to access. And something that I cared but then didn't care for the [33:31.080 --> 33:37.500] exploitation was that the issue URL and the allowed audience had to be the organization, uh, [33:37.500 --> 33:42.060] ID. Now this is fine as long as you create a pull request within the organization, Circle will [33:42.060 --> 33:46.260] just provide you with the ID, right? You're in the context of the organization. So this part is [33:46.260 --> 33:52.400] fine, we don't need to care about that. Um, so basically, a fork PR to any of those projects, [33:52.400 --> 33:57.780] uh, which indeed they allowed fork PRs, uh, granted access to their clouds. That was it, as [33:57.780 --> 34:03.520] simple. Okay, just detect the misconfig, pull request, enjoy the cloud account. So good [34:03.520 --> 34:08.060] summary and me, I'll disclose to the company so they can fix it and meanwhile, meanwhile I'll go [34:08.060 --> 34:14.800] to Circle. I went to DarkLang's, uh, Discord asking for, uh, bug bounty cause I like it, and [34:14.800 --> 34:20.540] but there was none, so I was told to DM, um, DM someone. Um, this is the someone, PBigger, I [34:20.540 --> 34:24.500] don't know if someone is familiar with this name, but yeah, we're gonna see exactly how you [34:24.500 --> 34:29.260] are familiar. But, um, yeah, he told me DM me, which I did, I sent, uh, I sent them [34:29.260 --> 34:33.680] everything and I also added the line, the reason, at the bottom, sorry, the reason is not safe, [34:33.680 --> 34:36.740] it's not because of you, it's because of a bug in Circle, right? I mean, you're fine, just [34:36.740 --> 34:42.100] defend yourself, it's them, not you. Um, I also asked them to not disclose right now. I don't [34:42.100 --> 34:46.120] know who is aware of that, I don't want anybody to exploit, I'm, uh, white hat at that point. [34:46.360 --> 34:51.060] Uh, I don't want anybody to exploit, um, so don't talk to anybody. Um, PBigger replied that he [34:51.060 --> 34:54.840] was investigating and then he confirmed it and blocked all access. By the way, this is [34:54.840 --> 35:00.780] exactly where OIDC kicks in. By ticking one box, he was able to kill all the GitHub, uh, [35:00.780 --> 35:05.820] basically all the, um, OIDC connections coming from Circle. Okay, this is very powerful. No [35:05.820 --> 35:12.440] rotations needed, no credential changes, just one box. Um, he was fixing that, we were, we [35:12.440 --> 35:16.920] continued chatting, later on he said again that he was very happy to seal it, to which I [35:16.920 --> 35:22.540] replied, no problem. To which he replied, uh, by the way, I sent a note to the security folks [35:22.540 --> 35:34.660] at CircleCI, I wasn't sure if you knew, but I founded Circle. Yeah. So, just a random dude on [35:34.660 --> 35:41.620] Discord, right? So, a good advice here would be to attempt to not disclose directly to the [35:41.620 --> 35:48.380] board member or the CEO, it can be a bit awkward and odd. So, yeah. This was, uh, June 23, [35:48.380 --> 35:53.380] Circle since then fixed this bug and sealed it, and now if you look into their OIDC page, you see [35:53.380 --> 35:58.640] this message, what about forks, and basically, uh, you have to opt in now. Like in GitHub, I [35:58.640 --> 36:02.880] told you you have to set up ID token, right? This is the same thing, you have to opt in, this is [36:02.880 --> 36:08.340] done in a different manner, but the same idea, you have to opt in in order to provide a fork, a [36:08.340 --> 36:13.980] machine that is running for a fork pull request, an OIDC token. Um, this changes this state [36:13.980 --> 36:20.440] and now we have a proper handling. You can see that, um, part two is still there. Uh, some [36:20.440 --> 36:28.160] integrations in Circle still react to that, so enjoy the misconfig. Um, and this is roughly, [36:28.160 --> 36:32.500] this is our conclusions and takeaways. So, first of all, I hope that now you know what OIDC is. [36:32.500 --> 36:37.020] It's not that hard, right? I was talking to folks before and they were giving me weird faces, [36:37.020 --> 36:42.520] like, yeah, I know, know OIDC, know. So, I hope you know it now, relax, it's fine, it's chill, [36:42.520 --> 36:49.120] okay? Um, plus you already learned OAuth, this is the big thing to, to swallow here. Um, second [36:49.120 --> 36:54.400] thing, and this is actual takeaways, so for in using OIDC and CI, do the following, uh, learn [36:54.400 --> 36:58.920] the origin of each claims, I've provided the tool for GitHub again, but, um, learn the claims [36:58.920 --> 37:04.600] for your identity providers, uh, pursue policies without wildcards, and always think, always [37:04.600 --> 37:11.340] think, which other identities can satisfy my conditions? Last bit, please harden your [37:11.340 --> 37:18.960] pipelines, sometimes it's too easy. That's it. So, yeah. Um, and yeah, but that's basically it. [37:18.960 --> 37:31.280] Thank you very much. Um, yeah, I'm here for questions, if there are any. Questions? Beers? [37:31.280 --> 37:34.180] Shots? No? See you around.