start	end	text
720	9780	Yeah, yeah, yeah. What's up? Good to go? Okay. So, hi everybody. Today's talk is called
9780	16860	Ohm IDC, where we're going to learn and see how we can abuse IDC set ups in the context of CI.
17760	22900	This is extremely exciting for me. That's my first time speaking in the con, so thank you very
22900	28260	much for showing up. And thank you very much for having me. That was the first voice
28260	33420	breakdown, so it's fine. Okay, by the way, if Adnan and John are here, thank you for the
33420	40940	build up. I hope I'll satisfy that. So, I'll present myself. My name is Aviad Hachami. This is
40940	48880	my Twitter handler. I do security research at Palo Alto. I do CI domain mainly. I welcome you
48880	57400	to check my latest publication. This is Azure CLI information leakage with 8.6 core somehow. But
57400	64120	it probably affected all your ASG usages. I also do bug bounty, I DJ, I do graph theory, and
64120	72060	FPV drones. Not necessarily in this order. Okay. So, before we go into the agenda, I want to
72060	77860	try and convince you why you should listen. So, first thing first, if you are completely new
77860	83320	to this world or you have like a rough idea of what OIDC is, I hope you get today the full
83320	92460	context of what's up with that, what's up internally, and how does it play. If you're already a
92460	96620	user, I hope you're going to learn some pitfalls and misconfiguration. I hope I'm going to
96620	102460	save you some weekends. And if you're a bounty hunter, like most of us here, I hope you're
102460	111760	going to get some new ideas for exploitation. All right. So, with that, let's go into the
111760	117120	overview. Okay. For those of you who are familiar with this topic, hold on tight for a sec.
117580	125240	After this, we're going to move into no configs. This is just a word term I set up. I'm going to
125240	130160	explain about it soon enough. We're going to move into advanced configurations,
130160	136380	misconfigurations, and we're going to learn what happens when the CI vendor makes a
136380	141740	misconfig and why do we care about the CI vendor in that context. All right. So,
141740	147560	first things first, let's begin with an OIDC overview. So, when I actually rehearsed this
147560	153580	talk to some of my friends, some of them are good researchers, I used terms like
153580	160560	workflow, job, the CI config, et cetera, et cetera, and they said at some point, this is nice,
160560	165940	but I'm not sure how CI works. So, in the case you're like my friend and you slept under a
165940	170440	rock for the past ten years, I'm going to show you what CI is in one slide so we can move
170440	176320	on. So, extremely quickly, what is CI? Assuming you're a developer, you perform some
176320	182120	Git operation, maybe push, pull requests, et cetera, this was pushed to your VCS provider,
182120	187300	GitHub, GitLab, you name it, and it was reflected in your online repository. So far, so
187300	191800	good. Now, since you've configured your CI provider, because this is what we care about,
191800	196940	then the VCS provider notified the OCI provider that something happened using a web hook
196940	204760	with payload, nothing special here. In turn, the CI provider spinned a machine for you, it
204760	211700	can be any OS according to your configuration, aka workflow. These machines do whatever
211700	218060	you want. It can be lints, builds, compilations, and since we're in 2024, they also push to
218060	223980	your cloud environments. It can be GCP, AWS, Docker Hub, basically everything out there.
224630	229560	This is CI, welcome. So, something I want to emphasize is that those are all split
229560	233120	entities, okay? We're going to come into that later on, we're going to show this diagram
233120	239200	again, but I want you to remember that these are split entities. Cool. Our problem space is
239200	243960	this small arrow, welcome to the OIDC and CI niche. This small arrow, which basically
244500	249980	makes us ask an important question, we're in a machine-to-machine world, so how does
249980	257020	authentication happen, right? How can we access Docker Hub, for example? An easy answer,
257020	261600	right, will be to hard-code your secrets. This is great for my bug bounty, please do that.
262020	267220	But, yeah, continue. The second option will be secrets, right? This is a feature by the CI
267220	271900	providers, etc. But we all know that at some point or another it's going to leak, right?
271900	276100	We're going to see some article saying company whatever was leaked was breached because
276100	284100	of a leakage. So we don't want to do that anymore. And then OIDC comes in to help. So OIDC
284100	290660	is open identity, this is initials for open identity, something I forgot because I'm stressed
290660	294920	obviously, but that's fine. But what I want to emphasize is that it's a simple OAuth
294920	299440	extension. I believe most of you know what OAuth is at this point in time. If you're on
299440	305540	YouTube and you're not familiar with, pause now, go learn OAuth, come back. Yeah, it's the
305540	309380	basics. So OIDC comes in to help and going to help us solve this whole credentials
309380	314020	problem and it's going to allow us to use something called identities that we're going to
314020	319280	see in a second. So what is this OIDC flow? We're going to learn the vanilla version and
319280	323200	then the CI version because they're a bit different. This is just a slide taken from
323200	329320	Microsoft. You are all familiar with the try to log in, go to the identity provider, get
329320	333900	like the token, come back, exchange it. But now we see something different. Instead of
333900	339180	access token and refresh token, we're relying on something called ID token. Welcome. So
339180	343120	we're going to learn what ID tokens are in a second, but I just want to plug in some
343120	347280	terminology. This is the auth n part, the authentication where you actually put
347280	353300	credentials. And this is the auth z part where you actually authorize someone to access
353300	356560	something. Regardless of their authentication state, obviously they should be
356560	365380	authenticated by this point in time. So ID tokens. Standard JWTs, base 64, we're going to
365380	369780	decode them and we're going to get the header which we don't care about for the sake of
369780	375460	this talk. I'll just add that this is how you verify the integrity of an incoming ID token,
375460	380440	but I'm not going to touch this any further. Don't care symbol. And the second part is
380440	384960	the actually ID token body and we're going to dive into the contents of it in a sec, but
384960	391580	for the purpose of this slide, I want you to remember that ID tokens, the body of it is a
391580	395820	simple dictionary where each key is called claim. So now onwards I'm going to say the
395820	402300	token claims something. Okay? Good. So let's conclude the OIDC in the vanilla version of
402300	407120	it. It's an OAuth extension and it allows us to rely on short-lived tokens that are based
407120	412700	on identity. That's it. TLDR of the whole magic. Right. So let's put it in the context of
412700	418200	CICD. If I'm bringing back this small snippet here, right, and I told you this is our
418200	424140	problem space, we have two important questions now. First, this is a machine. How does it
424140	429960	authenticate? We no longer have credentials. So how do we log in? Second question is,
429960	435860	assuming this ID token, how do we verify it? What do we verify it and who does this for us?
435860	442040	Okay? So let's address these questions. This is the diagram that you all saw like a few
442040	446980	slides ago. And if I'm going to call her back, who's in charge of what? And we see that the
446980	455140	only entity that is in charge of the CI machine is the CI provider. Right? So what actually
455140	459500	happens behind the scene, and again I'm going to pop up this question, how do we get the
459500	466800	credentials? The CI provider reacts in accordance to our configuration. Right? And when we
466800	471780	were configured, we were authenticated to the CI provider. So in a sense you can say that
471780	476880	when a CI executes, the machine runs on our behalf. Hence, it's associated with our
476880	482800	identity. And this is important to remember. A CI invocation is in the context of the owner
482800	489620	of the CI integration. So in the context of CICD, the CI vendor also gets to be the identity
489620	494520	provider. It's the only one that can give this machine who it is. Okay? Otherwise it's just an
494520	497700	ephemeral machine, right? Nobody knows what it is. Like why should I give you access to
497700	504540	something? So this is the first question answered. Now the second question was, assuming I do
504540	511460	have this ID token, who authorizes this and how exactly? So, I'm going to close the global
511460	518080	protect. So, um, I'm going to bring back this ID token and this, the auth Z part is actually
518080	523280	composed of 2 components. The first is the ID token and this is an example ID token that is
523280	527480	shipped by, uh, GitHub's identity provider. Most of these, uh, examples are going to be on
527480	532880	GitHub. I really like you folks. Um, so, and if you look at the contents, you see various
532880	537340	claims like, uh, the git sha, the repository name, run ID, et cetera, et cetera. So that's,
537340	543620	like, claims. And the most important for us to remember is, to note, sorry, is the sub. Sub
543620	549360	short for subject. And this is the default property to assert. When the, uh, basically when we
549360	555320	check those claims, it's called assertion, um, and this is the default property to assert. Now,
555320	560340	if we actually dissect this for a second, we know the following. The repo, short for
560340	566940	repository, contains the value of the repository claim, okay? And the ref, right, the ref
566940	572980	prefix contains the value of the git ref coming from the ref claim. So, we can actually see
572980	577960	that there's a format behind the scenes and we're going to come back to that later on. So,
577960	583020	an ID token, in the context of CI, I'm going to summarize that, contains information about the
583020	587280	git event that triggered the pipeline, uh, alongside other vendor information. And we're
587280	593520	going to see later on what this other vendor information, where exactly does it bite us. The
593520	597880	second part, the second component of the AuthZ, is the something called identity
597880	603780	federation. As the name implies, it, uh, it federates identities coming in. Um, this is an
603780	610380	example configuration, uh, for AWS specifically. And the file is pretty simple. Um, you have
610380	615240	the identity name, just a string, the identity provider, this is usually the URL of it. Um, and
615240	621480	then you set up conditions for who can claim to be this identity. Um, then we see what
621480	627300	claims we assert, right? We have the sub, does it work? Okay. We have the sub and then we
627300	631380	have the odd, odd short for audience by the way. And then we see that there, we can define
631380	636640	the comparators, right? We can do string like or string equals and set the values. Okay, so
636640	642820	this is roughly, this is how it goes. So, per the question, how exactly do we authorize
642820	647520	someone? Then we have this entity called identity federation and it's going to assert tokens
647520	654300	claims coming, uh, from, uh, CI machines. In this case, obviously. Alright, so now that we
654300	659180	know that the CI provider is also the identity provider, right? This is something new. And we
659180	665580	also know that this, uh, we have this federation. Then let's redraw the, the OIDC flow in
665580	672080	the context of CI. So in the context of CI, we actually have this diagram. Now the CI
672080	677500	provider also gets to be the identity provider. So it hosts both, uh, like both the CI and
677500	683120	itself, the identity. And also we see on the cloud provider, we have the federation. So the
683120	688280	flow is as follows. You ask for an ID token, you get an ID token, you go to your cloud, you
688280	693540	say I want to access. The clouds verify the integrity. This is done using the header. And
694120	698540	then it's going to assert the incoming token against its policies. And assuming everything
698540	702900	was fine, you're going to get a set of short-lived credentials. This, this microphone
702900	711640	hiccups, right? Right? Uh, oops. The mic hiccups. It doesn't work. Roughly. Halfway. Okay.
711640	717700	I'll say take care of that. Okay. Um, I'm going to plug back in the terminology. This is the
717700	725000	auth N bit. Okay? And this is the auth Z bit. Now, since the flow is different, what does it
725000	732480	imply? I'm going to border this square and let's zoom in. Since everything here happens within
732480	738240	the CI provider, if we are able to trigger a CI pipeline, we basically granted the owner's
738240	745540	identity. Okay? Now, you can limit that using, you can limit that using specific, uh, uh,
745540	750140	orders we'll see later on. But if you're able to trigger a CI machine, you're basically
750140	756560	passed the auth N part. Okay? This leaves us with the auth Z part to guard everything
756560	762080	basically, cause we have the CI machine running. And in a sense, if we're able to trigger a CI
762080	766440	pipeline, all that stands between us and accessing a target's resources is just the policy
766440	771680	pattern matching, right? So, you can see on the bottom part, examples for, uh, sub-claims.
771680	777720	It can begin with repo, a multi-banana Zurich, um, the name of the, uh, uh, repository, the
777720	781980	git ref. And on the right-hand side, you can see an example of assertion. For example,
781980	789340	repo colon star and where star will expand to everything using pattern matching. Okay? So,
789340	794000	this was the summary for, uh, OIDC in the context of CI. This is how it works. This is the
794000	799660	whole magic. So, in the context of CI, we can say that it is done by asserting incoming ID
799660	806280	tokens from CI machine using an identity federation in exchange for credentials. That's it.
806700	813660	Easy. Cool. We can move on to the no configs. And let's have some fun. So, no configs is
813660	818620	basically when there is no one at the door. If you think about the auth Z as the bouncer, if
818620	824820	the bouncers allows anyone into the club, then anybody can get in, right? So, a no config is a
824820	830380	state, uh, where the federator is asserting lax rules, if any. Um, and they will, it will
830380	836260	authorize almost any ID token. Okay? What does it mean? So, let's take a look at these three
836260	841000	snippets. These are snippets from the identity federation example you just saw, but different
841000	846020	assertions. So, the first one, we have, uh, an asterisk, right? Using pattern matching and
846020	851000	gonna expand to anything. Obviously, you didn't check anything here. Um, second option,
851000	855360	repo column stars. So, everything begins with repo. There's nothing specific to your account
855360	859760	here. So, again, you didn't check anything. And the last one is everything that begins with
859760	865280	my org and something to note, there's no slash between the org and the stars. So, if you
865280	871840	open a GitHub organization called my org one, it will satisfy this as well. Cool. Now, this
871840	877080	was already talked about in, uh, in, uh, two talks. One by, uh, Rojan of Tinder and one by
877080	883000	Christoph that maybe sits in the audience here. So, hi Christoph. Um, I also talked about it,
883000	888940	uh, on the latest, um, b-sides. And basically, I, I really, I highly recommend watching these
888940	894460	talks. They explain exactly how those misconfigs look like, okay? And how to hunt for them and
894460	899140	how to exploit them. I'm not gonna talk about, uh, when there's no config kind of situation,
899140	905440	um, and yes, go ahead and watch them. So, since we're not talking about the no config
905440	911340	situation, what happens when I have partial configs? How safe are they, if at all? Let's zoom
911340	916400	in. So, the first one we're gonna assert everybody in the org name, right? Repo colon org name.
916400	922160	Let's say I can say anybody in Palo Alto can access this identity. Is this okay? Is this safe?
922160	927740	What about everybody in Palo with respect to a branch? So, the answer is, the first one is
927740	932060	potentially unsafe, so does the second one. We're gonna see later how we can exploit and abuse
932060	939000	such cases. And the workflow example is actually the worst. This is very bad. If you configure
939000	943740	using the workflow, you're exploited immediately, okay? And we're gonna see how. And another
943740	948680	thing you gotta ask yourself, how come this claim begins with workflow? All you've seen was
948680	954580	repo colon. How come we're at workflow colon? What happened here? Alright, so let's move to
954580	960780	misconfiguration when you do some configurations but they're insufficient. Uh, we're gonna see
960780	965000	some pitfalls for advanced configurations including a demo. And then we're gonna see how you
965000	970960	can abuse, uh, pipelines. This is partially what Adnan, uh, talked about in the, in the last
970960	976560	talk. Um, but we're gonna see how we can abuse lax policies and access, uh, um, various
976560	987080	identities. So, misconfigs. We're gonna start with a short demo. Um, and just click here. Okay,
987080	992240	so what you see here is a video that was uploaded by, uh, JFrog explaining to their customers
992240	998120	how to configure OIDC in front of, uh, JFrog. So you can access the artifactory, x-ray,
998120	1002280	etcetera. So this is a great feature by the way, nothing bad to say about them. And what we
1002280	1008140	see in this example is how they configure the identity provider on JFrog's side and how they
1008140	1013780	configure the identity. Here we see the example, uh, claims GitHub allows us to rely upon. And
1013780	1019220	we can see on the right hand side that they instruct us to assert workflow equals JFrog NPM.
1019220	1025340	This is according to their video. Alright, um, I'm a naive user. I'm gonna copy paste that,
1025340	1032000	right? Uh, I just learned OAuth and, and OIDC. So, this is me creating the same identity
1032000	1037080	provider at JFrog. Um, just naming it my provider, etcetera, etcetera, nothing fancy, and
1037080	1042920	some arbitrary, arbitrary identity. And I'm gonna do the same instruction. I'm gonna assert
1042920	1048200	that the workflow equals core pre-usable workflow. This is coming from my corporation.
1048440	1055060	Alright. Uh, I'm gonna save it, uh, and then I'm gonna copy the snippet. This is for GitHub
1055060	1059440	Actions. Uh, for those of you who are unfamiliar somehow with this product, this is GitHub's
1059440	1066180	CI. Um, once I saved it, I'm gonna go to my leaking pond repository and I'm gonna create a
1066180	1070820	new GitHub Actions file. I'm gonna commit everything. If you are unfamiliar with how the
1070820	1074900	workflows of GitHub Action looks like, then this is it. This is the recipe. And all you gotta
1074900	1081100	know for the sake of this demo is that assuming a success, the machine invocation as a whole
1081100	1087380	will be successful, otherwise it will fail. So, uh, I've committed the CI reacts to my
1087380	1092700	Git event, so it fires. Um, we're gonna see a machine being run and then we're gonna see
1092700	1097880	that this account, as the video instruct us, was indeed able to access GitHub. Now let's
1097880	1103140	exploit that, okay? We're gonna use this special technique called copy-paste. I'm gonna
1103140	1108440	copy the exact same workflow configuration file and I'm gonna commit it to my own private,
1108440	1114300	uh, uh, account, which I was told that it's not safe to do at DefCon, but whatever. Um, gonna
1114300	1119840	do a special commit message cause it's important for nothing and in reaction the CI will
1119840	1125140	trigger again. Now what we will see, uh, we're gonna go into this logs, we're gonna count
1125140	1129360	1, 2, 3, worker's gonna pick it up, and we were able to successfully access the same
1129360	1136080	account, right? From a different account. Amazing, magic. What happened? Right? What
1136080	1142420	happened here? On JFrog's end, we defined the identity federation to be something,
1142420	1146300	whatever the name of the provider, but workflow. I'm gonna set the workflow to be
1146300	1153080	corp usable workflow, correct? Good. When my token showed up and said hi, I'm coming from a
1153080	1158400	repository, et cetera, et cetera, and the workflow is called corp usable workflow, so the
1158400	1163120	federation said yeah, it's the same claim, get in. And you gotta ask yourself where is this
1163120	1168980	value coming from? And the answer is, as always, user input. So you can just, this is the
1168980	1176140	name of the workflow, you can put any string there and yeah. So, copy paste for the win.
1176880	1182220	And we can see by showing one example that not all claims are safe, right? I've showed you
1182220	1188360	once, this is sufficient to say that not all are safe. If we look into the RFC of OIDC, then
1188360	1193240	basically we're instructed to have five required claims, issuer, subject, audience,
1193240	1198260	expiration, and issued at, let's translate them to an attacker point of view, the URL of the
1198260	1203160	provider, the target, just a string that you can modify if you have an RC in the case of
1203160	1208440	odd, expiration time for the OIDC token is roughly four minutes and nobody cares when it
1208440	1216360	was issued. On top of these five claims, we have a plethora of other custom claims. These are
1216360	1221920	given by the CI vendors, which get to be the identity providers, right? For example, GitHub
1222480	1227060	supplies with various claims, but all of these are unique to GitHub, right? Repository
1227060	1232080	owner, runner, environment, run number, whatever, whatever, these are all GitHub unique. If
1232080	1236320	we go to Circle, they have their own world, right? Workflow ID, VCS origin, whatever,
1236320	1243960	and GitLab has their own stuff, right? Nobody, like, what's going on? So it adds up to a lot of
1243960	1248380	confusion. If you're a DevOps for a company and you're trying to set up using custom claims,
1248380	1253320	you can get lost really quickly, because you have so many and there's almost zero instructions
1253320	1259640	on which values are safe in this context. So if you'd like to avoid a situation like I just
1259640	1265600	showed, a rule of thumb for using custom claims coming from the vendor is to remember that
1265600	1270020	they're provided regardless of their strength. By strength, I mean how hard they are to
1270020	1278920	fraud. So check where the values come from, okay? Now, a hidden pitfall of this behavior, or
1278920	1288080	this basically behavior, is the custom claim format feature, okay? So as the name suggests,
1288080	1294240	it's a custom format, and it comes to answer a problem where some federators do not assert
1294240	1299120	custom claims directly, like we saw with JFrog asserting workflow. Some just don't want to do
1299120	1304540	that. Why? I don't know. It's just a JSON. But therefore, some identity providers allow
1304540	1309640	reformatting the structure of the subclaim to contain custom claims values, okay? What do I
1309640	1315240	mean by that? Consider the top option. This is what you're familiar with. It begins with
1315240	1320120	repo and then the ref, right? The git ref. But now you can put actor ID, this is in GitHub's
1320120	1324740	world, so now you can put actor ID and repository ID, and it will be later populated with the
1324740	1331820	values with respect to where this was fired from, where the CI ran from. So something that
1331820	1337980	can be easily missed with this feature is that the claims order is critical, all right? Let's
1337980	1344080	see why. Consider this format and this claim. So we're going to have repo, my org, and then
1344080	1349620	the name of the workflow, Makat Shemesh, fine. So we all know by now that this is very unsafe,
1349620	1355240	right? I just showed you how it can be abused. But this one is actually safe. The prefix
1355240	1359480	is safe. Why? Because GitHub will actually put the name of the organization and repository,
1359480	1363980	you can't just fake that, at least not in this talk. But you can't just fake that. So
1363980	1369500	this is fine. This is an example of fine, although it relies on unsafe claim for the
1369500	1374780	second half of it. If you flip it, however, then you're done with, okay? So let's see
1374780	1381900	how. In order to abuse such a case, basically all you have to do is create a workflow, name
1381900	1388120	it everything after the workflow prefix, go to your favorite CI provider, change the sub
1388120	1393680	claim to be workflow only, and they will grant you with a pretty and beautiful signed token
1393680	1398180	that has the exact same claim like the other organization asserts. And obviously you can
1398180	1405300	put whatever my org in Palo Alto, Microsoft, you can just write whatever. So a rule of
1405300	1408980	thumb for this feature is that the claims order is critical. I haven't seen even one
1408980	1413200	manual page that mentions that. When you use custom claims, they just let you use it, but
1413200	1420060	they don't tell you what not to do. So the order is critical. In order to help everybody
1420060	1426440	here to either escape from these bugs or to exploit them, I've created this tool. You
1426440	1433480	can scan the QR code to get the latest zero click for your Android. But basically it
1433480	1437200	allows you to enlist all the GitHub possible custom claims with information about the
1437200	1441300	strength of each one. This is a nice guide I composed. It can check your sub claim format
1441300	1446120	for safety, and it will allow you to modify the sub claim if you want to attack with it or
1446120	1449660	you just want to fix it for your organization or repository. There is some hierarchy
1449660	1454580	option, so it's interesting. This is how the tool looks like. All you've got to bring is
1454580	1459380	your favorite GitHub token with admin permissions, not necessarily of your organization,
1459380	1464600	but yeah. And for example, in the inspect mode, you can see that these are the claims, and
1464600	1472180	they're not safe because it's set right, so go ahead, get a zero click, and yeah. Okay.
1472800	1479520	Now this is behind us. And let's move into pipeline abuses that can lead to OIDC abuse.
1479520	1485480	Basically misconfigs that lead to abuses, abusage, sorry, of lax policies. So we saw that
1485480	1491920	this was very bad, right? We now know why this sucks. But what about these two? We did
1492480	1498600	just say that, for example, saying everybody in Apollo is fine, right? Or not? So let's
1498600	1504660	abuse those. The answer is pretty simple. Poison pipeline execution, which is the most
1504660	1511120	common entry vector for CIs, right? And lax policies. So let's explain for a second. Uh, a
1511120	1515680	PPE is a pull request from a fork that will trigger a vulnerable CI execution in the
1515680	1520680	context of the target, right? We're all familiar with this by now. I hope so. Um, the second
1520680	1525760	bit, the lax policies, um, they will allow a token from the same, uh, from the targeted
1526080	1530640	organization, sorry, to slip through lax policies. Okay? Now what do I mean by that? Let's
1530640	1537760	see how it plays. Demo. In order to demo that, we have to define a few entities, right? Let's
1537760	1541600	begin with the identity federation on the resource side. So we're gonna set up something
1541600	1547640	like this. We wanna assert that the audience equals, uh, the Amazon AWS thing. Um, and
1547640	1552680	we wanna assert that all the identities coming in from the banana multi organization are
1552680	1557680	okay to go in. This is the federation. If you put it, by the way, on AWS, it's gonna look
1557680	1562960	something like this. And although AWS did some changes in order to enforce more strict
1562960	1569860	policies, they will allow you to do that. This is fine by AWS. Now for the git part. Let's
1569860	1575820	see what's our setup. We have this organization called banana multi and we have two, uh,
1575820	1581660	basically pipelines including the git repo itself. And let's explain. So the upper one, um,
1581660	1587940	is a pipeline that is configured to connect using OIDC to an S3 role that is, uh, an admin. Um,
1587940	1593520	this policy is the policy that we just saw. So it's lax. Um, and this is our target. The
1593520	1598740	second pipeline is called any updateser and, uh, it contains, it's connected to a vulnerable
1598740	1605420	pipeline and then it's using an OIDC token again to access a restricted S3, uh, uh, bucket
1605420	1612180	or a role and we obviously cannot use that. So let's see our attack vector. Pretty simple. We're
1612180	1619500	gonna fork the any updateser and we're gonna, uh, um, basically invoke the CI machine of the, the
1619500	1624760	CI workflow, sorry, of, uh, and we're gonna invoke the vulnerable CI workflow and we'll try to
1624760	1630700	access the other accounts. Um, the workflow, by the way, looks something like this. It has to
1630700	1635720	react to pull request, maybe pull request or pull request target for the GitHub world. Um, and
1635720	1642740	you have to specify that you want an ID token that the workflow has to say. Um, the pipeline is
1642740	1646580	gonna check out the fork. This is the head for the pull request. Uh, we're gonna skip the part
1646580	1651500	where it actually assumed the AWS role. We don't, we can't use that so we don't care. And then
1651500	1657340	there's an invocation of a file from the file system which was just cloned from the fork and
1657340	1663020	yeah, we have RCE. So what we need to do now is make the fork pull request. This is what's
1663020	1669300	called IPP, indirect points of pipeline execution. And this is the exploit script. Don't
1669300	1674840	rush and, and, and take pictures. It's just chat GPT. Um, but basically all you have to do
1674840	1680080	before you make this exploit code, you have to, uh, to do some recon and collect various
1680080	1686480	id- accounts that are, are connected through using OIDC. Okay? I'm not gonna talk about it in
1686480	1690460	this talk but this is something you have to do. In this example, I'm having 2 roles at the top
1690460	1696720	that I'm gonna try to exploit. Let's see it in action. So this is the prepare.sh file that is
1696720	1703260	gonna be invoked at some point. Uh, this is my fork. Any updates sir? And I'm gonna open a
1703260	1708760	pull request. So, uh, hello it's me. The diff is the same file. Nothing but this file. And I'm
1708760	1715900	gonna open the pull request and it's gonna invoke the CI in response to the trigger. Cool.
1715900	1723180	3 seconds from now we're gonna see the machine logs. 1, 2, 3, as I promised. And, uh, now in
1723180	1728640	the logs we will see in the prepare step that it, we will see the output of my script and if
1728640	1734160	we're successful we'll see sets of credentials. And I wouldn't be here if it would work so,
1734160	1738260	yeah, we have sets of credentials. So we were able to assume a role that was not allocated to
1738260	1742180	the pipeline we were running at. Well we were not able to assert others but again you can
1742180	1747740	just spray OIDC tokens. So this is a very nice technique. You can just collect tokens, find
1747740	1752720	vulnerable pipelines and start spraying for, to find the logs policies internally, right?
1752720	1761100	You're already past the auth end. You have the credentials. So give it a shot. 1 second.
1762100	1767880	Okay, uh, some nice disclosure. I was able to, this is by the way from last year already and, and
1767880	1772760	I was able to find this, uh, a month ago in Azure and this allowed to access basically all the
1772760	1778520	identities that had Azure slash star. So, yeah, nice technique. Um, the rest did not allow
1778520	1786780	disclosure but you're out there. Cool, so rule of thumb in order to avoid this type of stuff, one
1786780	1793820	is for the CI, please follow the best practices. We're 2024, um, we, my team, we've released
1793820	1799860	plenty of guides on how to, uh, harden your pipelines. Please do so. The second thing,
1799860	1806500	uh, pursue, uh, policies that are not with wildcards as much as you can or, uh, use other
1806500	1814420	claims that are safe in order to assert identities. Okay, this brings us to our last topic
1814420	1818020	of the day and this is when, when the vendor misconfigures. Now that you know that the
1818020	1822820	vendor, the CI vendor is also the identity provider, now they have to put, to give more
1822820	1827800	attention to the details, right? They have various products at their hand now and they have
1827800	1834200	to be very careful. So, this is a disclosure for, uh, Circle CI, um, and basically if you're
1834200	1839080	unfamiliar with Circle, they're a great CI product. Um, they provide various machines, right,
1839080	1843540	in order for you to run your workloads and they're super nice and professional folks on a
1843540	1849560	personal level. Okay? When I looked into, oh, just to explain, uh, Circle, sorry, um, this is
1849560	1853580	you, you perform git push, you're all familiar with this diagram by now, well, you notify
1853580	1858300	Circle with a payload and they did your CI thing for you. Now, when GitHub notifies Circle,
1858300	1863260	by the way, they do that with the web hook and the payload is everything that was, that is
1863260	1868780	in your git context. So, in a way, and just to add to the confusion, Circle can supply you
1868780	1872960	with a super set of claims on top of GitHub's claims, if you think about it. Just to add to
1872960	1878240	the confusion from earlier, I see your faces, so yeah, it's confusing. Um, okay, so when I
1878240	1882700	looked into Circle's CI system state, I noted the following. First, pipelines reacted to
1882700	1888500	fork pull request if and only if, there's no typo, uh, the project is configured to do so. Now,
1888500	1891980	this is actually a good limitation, right? We don't want anybody on the internet to run
1891980	1897560	machines for us. Putting aside security, someone's gotta pay for that. Okay, but second
1897560	1902460	thing that I noted is that pipelines were triggered, uh, on a workflow change, even from a
1902460	1907780	fork. Okay? And this is not good. Why? This implies every pull request can be an RCE, you
1907780	1915220	can just commit, basically pull request a malicious workflow. Okay, doesn't look good, but
1915220	1920340	the third part was the, the cherry on top. An IDC token was always granted to the machine
1920340	1927100	regardless of anything. And this is credentials mishandle and misuse. Okay? So, combining
1927100	1932540	those, I was granted an ID token in the context of any Circle CI project that allowed fork
1932540	1937120	pull requests. Okay? What does it imply? What does it mean? Is that I was able to access
1937680	1942680	OIDC gated resources of any Circle CI organization that allowed fork pull requests. Right?
1942680	1949780	That's basically everybody on Circle that has pull requests and OIDC. Nice amount. Um, the
1949780	1953660	attack flow is pretty simple, you just saw a demo of that using, uh, another file, right? The
1953660	1958120	prepare, so I'm not gonna show the same thing, all you've, you had to do basically is, uh, pull
1958120	1961780	request the workflow. So, I'm not gonna show that. I will talk about the disclosure,
1961780	1967500	however. So, in order to show Circle CI that this was indeed a bug, I looked for instances in
1967500	1974260	the wild to support my case. Um, it wasn't long ago until I found this file. Now, this was by a
1974260	1980560	company called Darklang. Anybody here familiar with those folks? Hands up? No? Okay. Um, just
1980560	1984880	to explain this file, this is an identity federation for, uh, GCP. And even though you don't
1984880	1989260	know this, this cell language, uh, GCP's language, you can understand the mapping here, right?
1989260	1994060	We know that CircleCI.com, we know this is the provider, and we know project ID is the claim,
1994060	1998900	and we're gonna map it to project, audience to organization ID, and sub to sub, right? We now
1998900	2003960	know what these claims are. Um, per the condition, the condition was that any one of these
2003960	2011080	three project IDs is okay to access. And something that I cared but then didn't care for the
2011080	2017500	exploitation was that the issue URL and the allowed audience had to be the organization, uh,
2017500	2022060	ID. Now this is fine as long as you create a pull request within the organization, Circle will
2022060	2026260	just provide you with the ID, right? You're in the context of the organization. So this part is
2026260	2032400	fine, we don't need to care about that. Um, so basically, a fork PR to any of those projects,
2032400	2037780	uh, which indeed they allowed fork PRs, uh, granted access to their clouds. That was it, as
2037780	2043520	simple. Okay, just detect the misconfig, pull request, enjoy the cloud account. So good
2043520	2048060	summary and me, I'll disclose to the company so they can fix it and meanwhile, meanwhile I'll go
2048060	2054800	to Circle. I went to DarkLang's, uh, Discord asking for, uh, bug bounty cause I like it, and
2054800	2060540	but there was none, so I was told to DM, um, DM someone. Um, this is the someone, PBigger, I
2060540	2064500	don't know if someone is familiar with this name, but yeah, we're gonna see exactly how you
2064500	2069260	are familiar. But, um, yeah, he told me DM me, which I did, I sent, uh, I sent them
2069260	2073680	everything and I also added the line, the reason, at the bottom, sorry, the reason is not safe,
2073680	2076740	it's not because of you, it's because of a bug in Circle, right? I mean, you're fine, just
2076740	2082100	defend yourself, it's them, not you. Um, I also asked them to not disclose right now. I don't
2082100	2086120	know who is aware of that, I don't want anybody to exploit, I'm, uh, white hat at that point.
2086360	2091060	Uh, I don't want anybody to exploit, um, so don't talk to anybody. Um, PBigger replied that he
2091060	2094840	was investigating and then he confirmed it and blocked all access. By the way, this is
2094840	2100780	exactly where OIDC kicks in. By ticking one box, he was able to kill all the GitHub, uh,
2100780	2105820	basically all the, um, OIDC connections coming from Circle. Okay, this is very powerful. No
2105820	2112440	rotations needed, no credential changes, just one box. Um, he was fixing that, we were, we
2112440	2116920	continued chatting, later on he said again that he was very happy to seal it, to which I
2116920	2122540	replied, no problem. To which he replied, uh, by the way, I sent a note to the security folks
2122540	2134660	at CircleCI, I wasn't sure if you knew, but I founded Circle. Yeah. So, just a random dude on
2134660	2141620	Discord, right? So, a good advice here would be to attempt to not disclose directly to the
2141620	2148380	board member or the CEO, it can be a bit awkward and odd. So, yeah. This was, uh, June 23,
2148380	2153380	Circle since then fixed this bug and sealed it, and now if you look into their OIDC page, you see
2153380	2158640	this message, what about forks, and basically, uh, you have to opt in now. Like in GitHub, I
2158640	2162880	told you you have to set up ID token, right? This is the same thing, you have to opt in, this is
2162880	2168340	done in a different manner, but the same idea, you have to opt in in order to provide a fork, a
2168340	2173980	machine that is running for a fork pull request, an OIDC token. Um, this changes this state
2173980	2180440	and now we have a proper handling. You can see that, um, part two is still there. Uh, some
2180440	2188160	integrations in Circle still react to that, so enjoy the misconfig. Um, and this is roughly,
2188160	2192500	this is our conclusions and takeaways. So, first of all, I hope that now you know what OIDC is.
2192500	2197020	It's not that hard, right? I was talking to folks before and they were giving me weird faces,
2197020	2202520	like, yeah, I know, know OIDC, know. So, I hope you know it now, relax, it's fine, it's chill,
2202520	2209120	okay? Um, plus you already learned OAuth, this is the big thing to, to swallow here. Um, second
2209120	2214400	thing, and this is actual takeaways, so for in using OIDC and CI, do the following, uh, learn
2214400	2218920	the origin of each claims, I've provided the tool for GitHub again, but, um, learn the claims
2218920	2224600	for your identity providers, uh, pursue policies without wildcards, and always think, always
2224600	2231340	think, which other identities can satisfy my conditions? Last bit, please harden your
2231340	2238960	pipelines, sometimes it's too easy. That's it. So, yeah. Um, and yeah, but that's basically it.
2238960	2251280	Thank you very much. Um, yeah, I'm here for questions, if there are any. Questions? Beers?
2251280	2254180	Shots? No? See you around.
