start	end	text
13610	19430	Yeah, hear me. Thank you guys for joining us today. It's the last day of DEF CON. Appreciate
19430	25310	that. And thank you for joining to our talk. Your CI CD pipeline is vulnerable but it's not
25310	41360	your fault. So without further ado, let's move on. We are not moving on. So my name is
41360	46520	Elad, I'm a security researcher at PsyCode with seven years of experience. I'm mainly
46520	54700	focusing on web application security and supply chain security and I'm love hacking random
54700	63680	stuff, basically everything with an IP and I'm from PsyCode. Hi, my name is Orin. I hope the
63680	71340	presentation will work. So I have also seven years of experience in cyber security and I'm
71360	76200	working in cyber security. In my background I used to research Kerberos and networking but
76200	84720	currently I focus on supply chain security on the same research team with Elad. Thank you Orin.
84720	90520	So for our agenda today we're going to start and speak about CI CD platforms, about GitHub
90520	98420	actions. Then we'll speak about command injections 101 and see how command injections appears and
98420	106440	takes place in CI CD platforms. Then we'll tell the story of Buzzle, how we found a critical
106440	113780	vulnerability, a CI CD vulnerability in a major Google owned open source project. We'll
113780	122280	continue with the demo and then we'll go home with some take up, takeaways and a recap. So starting
122280	131580	with GitHub actions and CI CD platforms. So what is even CI CD platforms? So they are building
131580	139620	and testing uh tool meaning they can do all the manual actions that we as a person do. And there
139620	146920	are events trigger meaning we have different SCMs like GitHub, GitLab and Bitbucket and they
146920	152260	have some sort of features right? You can create a pull request, you can create an issue,
152260	160440	you can create anything else and those events will trigger that pipeline. So there are many,
160440	167020	many CI CD platforms. There are GitLab CI, GitHub actions, Jenkins and today we are going to
167020	174660	speak about GitHub actions. And why we chose GitHub actions? There are so many Jenkins and
174660	184080	others because GitHub actions have four million public pipelines around the ecosystem. That is
184080	193020	huge and it's appealing for attack for in a huge attack vectors for attackers. So let's a little
193020	199240	bit visualize this, right? So we have all the events in the left side of the screen. We can
199240	204300	create a new commit to the repository, we can create a new issue, we can create a new pull
204300	211920	request. Then we have the pipeline that will be triggered based on that, on those events. Then we
211920	219840	can create any, any uh action that we wanna do. Meaning we can create a task that is logging in
219840	226300	to our Google Cloud. We can create a task that builds a Docker image and push that to the
226300	234280	registry. So basically we can do anything that we, that we want doing that pipeline one. And just
234300	241660	to understand how the basic flow works, let's imagine that. We have a push, new push to the
241660	248760	repository, right? New commit to the main branch, maybe a side branch, everything is okay. Based
248760	257280	on that, the pipeline will start to run. That pipeline will log in to our cloud environment,
257280	263860	could be any one of them, and maybe we'll create a new blob in a bucket. So pretty, pretty easy
263860	273880	right? But how does the pipeline itself logs in to our cloud environment? Because we ourselves need
273880	280120	some authentication tokens, right? Access tokens. So GitHub Actions have a key store that
280120	289240	encrypt, encrypt and save those access tokens and decrypt them one time. So all the secrets are
289240	296380	being saved, encrypted, and during one time they are being decrypted and being, and being used. So
296900	303560	we can have our production environment, a staging environment keys, DB access tokens, all of
303560	311160	those inside our pipeline key store. And probably think about that. It's appealing target for an
311160	318480	attack, for attackers. Because if an attacker will be able to control over our pipeline, it will
318480	329580	be able to steal those tokens and do whatever he wants, right? And among those tokens, we have a
329580	339240	special one. The GitHub token. That GitHub token spawns in every pipeline that we create and can do
339240	345340	any action in the repository itself. It can create new permits, it can create new releases, it can
345340	350700	create new actions, new pull requests based on these permissions. So from an attacker
350700	358020	perspective, if he steals that token, he can do whatever the maintainer does, whatever the owner
358020	365360	can do. That GitHub token has a variety of permissions. It can do all that I mentioned uh
365360	372980	previously and way more. So think about that. Stealing the GitHub action, the GitHub token with
372980	379860	privileged permissions could gain an attacker a privileged permission to the repository itself
380520	389900	helping everybody that is using that repository and all of its end users down the line. So to
390560	397500	understand how attackers are able to take over those pipelines, Erwin will take the stage.
397500	408650	Thank you Elad. So after understanding the basics of pipelines, what permissions they have and
408650	415990	how do they run, now we can dive into the more interesting part of how command injections come
415990	424550	into a form in CICD pipelines. So just for example I have this PHP code. It's not related to
424550	431090	pipeline yet. Raise your hand if you ever encountered this kind of vulnerability. If you
431090	438610	ever seen it. Okay. Perfect. So about half of the people has seen this vulnerable code. And
438610	448210	what is the problem here? The problem is simple. This website will execute a command using
448210	456950	unsanitized user controlled input. Right? So what that means is that a user could perform a
456950	468250	command injection attack by providing a malicious user name. Very bad. We don't want that in our
468250	476550	pipeline. And the same logic goes for pipelines. Because if we will use in our pipeline a user
476550	484190	controlled input in an unsanitized way, that means that an attacker could gain access to our
484190	490930	pipeline and extract the secrets and run inside our environment and do all the malicious things
490930	500130	Elad have described before. So we would definitely don't want this to happen. Right? To
500130	508390	understand how GitHub pipelines injections look like, we'll first have to get familiar with GitHub
508390	515990	workflows. So GitHub workflow is a single step of the entire pipeline. And it is a YAML
515990	523270	configuration file. That's it. That's everything we have to know. To see our first example of a
523270	530110	GitHub workflow, this GitHub workflow is called test issue. And we can see the on end
530130	537510	tree. On end tree means on what triggers will this pipeline be executed. So since it is using the
537510	545470	issues keyword, it means that any issue related event on the repository will trigger the
545470	552710	pipeline. So whether an issue is opened, assigned to someone else, closed, the pipeline will run.
553430	560110	And here we can see a step of the pipeline. A step is a single instruction of the pipeline,
560130	568470	and it will of course run under the same VM of the pipeline. And the run keyword means that we're
568470	577770	simply going to use a bash command. Okay? So here we can see echo, which is print. And it will print
577770	585610	the issues title. Okay? That's still basics. And what will happen is before the pipeline will run,
585610	592770	GitHub will replace that placeholder, the GitHub event issue title, with the actual issues title.
593910	603230	So for example, if someone has created this is a new issue, it will create an event that will trigger
603230	610510	our pipeline. And then in the bit logs we will see that this is a new issue was printed because the
610510	619270	pipeline used the user controlled input to run a command. So for example, I can have that issue
619270	627850	title or that issue title. And I can also have emojis in the issue title. I don't know if it will print
627850	640030	them or not. But another example for totally valid issue title would be that one. It works. It
640030	648210	works totally fine on GitHub. Because it is not their fault. And what will happen here is the same idea
648210	657490	from what we've previously seen in the PHP code. Here the pipeline will run this command under the
657490	667010	run execution entry. Right? And it will concatenate more commands after the echo command, which
667010	674770	will dump the memory of the pipeline and then send all the secrets to the to an attacker controlled
674770	681090	server. So that's an example for something you wouldn't want to have in your organization. Because
681090	688370	then an attacker will receive your PyP token, your Docker hub token, your GCP token, your GitHub
688370	696990	token. So basically whatever you use in your pipeline. So what is the solution? The solution is
698170	709950	pretty simple. It is from the GitHub official documentation. You just have to first set the value of the
709950	716630	user controlled input to an environment variable. And then use the environment variable in the
716630	723310	command execution. Okay? That's a simple solution for bash injection in general. And it also works
723310	738930	in pipeline. Okay. That's it. Thank you very much. I mean, well, if it were not protected, we
738930	745490	wouldn't be here today, right? So now after understanding the basics of command injection
745490	753290	attacks, we can now explain the new attack vector we have invented that allowed us to find
753310	762150	thousands of vulnerabilities in open source projects. And also in the Basel project, which is a
762150	771910	flagship repository of Google which could affect millions of end users if being compromised. So
771910	780210	let's begin with the story of Basel. This is the same workflow as we have seen before. And it will
780210	789030	again be triggered on issue events. And since we're taking security very seriously in our
789030	794650	organization, we follow the official documentation and before executing the command, we have
794650	803950	first set uh the user controlled input to an environment variable. But then we have this new step.
804520	810110	And here we can see the users keyword. And what the users keyword means is that we are
810110	818330	importing logic from something called costume action to our project. So now it means that I can
818830	826150	get vulnerable code that someone else has written and that will run under my pipeline's permissions.
827530	834250	So costume actions in a word, it is pre-built logic. It's like you can think about it like a
834250	841630	dependency in code. Someone else has written a module, a costume action, and then to create pipelines
841630	847850	faster, I can just import it to my project and use it and I can pass parameters to it like I do to a
847850	854570	function. It will return something or it can be like a void costume action that will just perform
854570	863030	something. And that's it. Perfect. And for that reason, GitHub has created the GitHub marketplace,
863030	869430	which is like the ecosystem for pipelines and there are many open source costume actions and there are
869430	877290	thousands over thousands and you can just import and use them and deploy faster and work better. Well, you
877290	887730	can work better, but safer? We'll have to figure out. So let's take my workflow, for example. I've
887730	895410	written a workflow and I'm using one costume action as a dependency. But what happens is that this
895410	902730	costume action happens to use another dependency itself. And that costume action dependency has three
902730	908670	more dependencies. And this has more dependencies and more dependencies. And the next thing you know,
909390	917710	you have tons of dependencies. And what could happen if one of the dependencies brings commands
917730	926150	vulnerability to my project? Then I'm in real trouble, right? Because that means that now by injecting
926150	936250	code, I could affect the pipeline because everything you see here is part of my dependencies. Everything
936250	944130	runs on my pipeline's permission and environment. So dumping the secrets from there could mean that an
944130	949350	attacker gained control to my organization and I wouldn't even know that I have imported this
949350	958910	vulnerability. So how would it look like from the code's perspective? Let's say we have a workflow and it
958910	969650	is using, importing action one. Action one is using action two. And action two contains the same
969650	980290	vulnerability from the first, from the previous chapter. So that means that now, that means that now my
980290	989110	pipeline has command injection vulnerability even though it's not my fault. So that brought the next
989110	990410	question.
993620	1002440	Thank you, Erwin. So it's all working fine in this demo lab and visualization, right? But we are
1002460	1012680	going to look at how do we exploit this in scale? Meaning going over the UI and going over one by one
1012680	1020120	and checking all those post actions and navigating to different GitHub repositories, it's not
1020120	1031280	scalable, right? It won't work. So we thought about different methods. The first phase, we are going to
1031280	1042520	index all the GitHub atmosphere. Meaning all the workflows, all the custom actions, everything into one
1042520	1052860	place. And how are we going to do that? Using Raven. Raven will allow us, will allow us to query all
1052860	1061260	GitHub atmosphere into a single DB and will query and search result and vulnerability. And we
1061280	1068140	will query all the activities based on that DB. So just a quick recap about Raven, which is an
1068140	1075500	open source project now. It will download all the workflows in one GitHub ecosystem into a Redis
1075500	1085640	DB. Then it will index them to a graph DB. And then we will be able to query anything that we want
1085640	1094440	based on that results. And that's how it looks like. So we have all the connections, all the custom
1094440	1101480	actions, all the workflows, all the jobs, all the steps, everything that we mentioned in a single place.
1101480	1110260	That's amazing. And just a closer look, we have all the workflows which are connected to some steps and in
1110260	1118860	the end of go, they are importing a single custom action. So by finding a vulnerability inside that
1118860	1129220	action, will gain us a vulnerability inside all of those workflows. Insane. Second part, querying.
1129220	1138080	Querying based of those results. We queried thousands of workflows. I start waiting in GitHub
1138080	1147120	atmosphere. Meaning, so it will be an important one that will affect millions probably users. We found
1147120	1156060	thousands of vulnerability in different severity levels. And today, I want to talk about one of them.
1156520	1164960	Bazel. Bazel is a build and test tool that is widely used among the community. It's a project owned by
1164960	1172880	Google. It's a flagship by them. It's used by Google internally. And a few other companies that you
1172880	1183160	probably heard of. And now, for the exploitation phase. How do we take that finding and exploit it?
1184320	1190940	Navigating to the repository itself and to the workflow itself, we see that that workflow doesn't seem
1190940	1198660	vulnerable to anything. Right? We saw how command injections looks like by utilizing a user input
1198660	1207260	inside the workflow itself. So, we don't have nothing like that. We only have a custom action in another
1207260	1218160	repository managed by other maintainers and other developers and it passes two inputs. The first one,
1218160	1226980	issue title. The second one, issue body. So, probably makes you think, right? Navigating to the custom
1226980	1234780	action and that's we have it. The custom action, well, vulnerable, was vulnerable to a command
1234780	1242840	injection vulnerability like we saw before. But wait a minute. Not only that. Remember the GitHub token
1242840	1248140	that we saw before? That workflow has a full permission to the repository. So, we have to
1248160	1253160	exploit that vulnerability. Meaning, exploiting that vulnerability will gain us a full permission to the
1253160	1262560	repository. Not only compromising the repository itself, but compromising everyone that are using it.
1263940	1272080	Let's move to the demo, right? So, in the demo, we'll have two sides of the screen. In the left side, we'll
1272080	1278140	have a repository. A vulnerable one. And in the right side, we'll have an attacker server that's
1278160	1287300	waiting to get a connection and waiting to run malicious commands inside that pipeline. So, at the
1287300	1295760	left side of the screen, as I said before, we have a repository. Navigating to that repository and
1295760	1304080	we'll be able to see that it's pretty empty one. It doesn't have any releases, none at all. And
1304080	1313860	there with me is pretty empty. Keep that in mind. Scrolling back and a maintainer saw a new issue in
1313860	1321600	that repository. That issue will contain some build logs and some events on the OS machine and what it
1321600	1327940	doesn't know, it has one malicious command that will compromise the entire pipeline, inject
1327940	1336560	malicious code, will connect to a remote server and will execute some more commands. So, by
1336560	1344660	clicking milestone, the pipeline starts to run. Running the pipeline will execute our command
1344660	1353120	injection. It will bring a malicious script from the attacker server as we can see and will dump all
1353120	1360240	the secrets in the memory of that pipeline and will use that to create new releases, inject
1360240	1369680	malicious code to that repository and way more. After the injection was successfully completed, we
1369680	1375240	are navigating back to the repository itself. And you can see we have new release. By a GitHub
1375240	1382260	action user, not even our user. Scrolling down and we have that APSEC village picture right in
1382260	1390920	there. And from the user perspective, it's not only will hurt the repository itself, we can see
1390920	1399260	that the user will clone the latest version and will do a simple make build command. But what he
1399260	1404420	doesn't know that in the moment he will do a make build command, all of his environment
1404420	1411260	variables will be sent to a remote attacker server with along with some system information, public
1411720	1420400	private keys, DB information and everything that he has in his environment. That is insane. So not
1420400	1428580	only hurting the repository itself that has 22,000 stars, it will hurt millions of end users down
1428580	1440760	the line. Insane. So, so some recap and takeaways. The takeaways are separated to a blue and
1440760	1447940	red. So everybody can take something from that. First one, insecure input. Don't just pass
1447940	1455460	insecure input just to an inline script. Like you do in code and other methods, don't use
1455460	1464280	untrusted user input in untrusted ways. The second one is custom actions and particularly composite
1464280	1470740	actions. They are importing logic to inside your pipeline. So, be careful about that. Don't
1472600	1481780	run a vulnerable one that will compromise your entire GitHub workflow. And the last one, do I
1481780	1490520	need to stress that enough? Like everything in cyber security, least privilege principle. So, make
1490520	1498540	sure your workflow has the minimum privilege it needs to be for each one. So, no extra
1498540	1505980	permissions and that's it. Thank you for listening to us. We have more details, thank you.
1513890	1521710	We also want to say that Raven is open source and it is equipped with uh a query library from our
1521710	1528930	previous two years of research, GitHub action. So, if you want to use it either for um for bad
1528930	1536230	bounties, red team or for internal uh security, you are more than welcome. We will share the QR
1536230	1539670	code for the GitHub repository as well. Thank you.
