start	end	text
7360	13840	Thank you for joining to our talk, your CI-CD pipeline is vulnerable, but it's not your fault.
13860	17020	So, without further ado, let's move on.
17160	22600	So, my name is Elad, I'm a security researcher at SciCode with 7 years of experience.
22600	27590	I'm mainly focusing on web application security and supply chain security.
28060	34520	And I'm love hacking random stuff, basically everything with an IP.
34560	36340	And I'm from SciCode.
37720	42200	Hi, my name is Orin, I hope the presentation will work.
42200	49680	So, I have also 7 years of experience in cyber security.
49740	53000	In my background, I used to research Kerberos and networking.
53000	58980	But currently, I focus on supply chain security on the same research team with Elad.
60020	61620	Thank you, Orin.
61740	66540	So, for our agenda today, we're going to start and speak about CI-CD platforms.
66540	68660	About GitHub actions.
68900	72300	Then, we'll speak about command injections 101.
72300	78360	And see how command injections appears and takes place in CI-CD platforms.
78360	82040	Then, we'll tell the story of Buzzer.
82040	89980	How we found a critical vulnerability, a CI-CD vulnerability, in a major Google-owned open source project.
89980	92280	We'll continue with the demo.
92320	97040	And then, we'll go home with some takeaways and a recap.
97980	102280	So, starting with GitHub actions and CI-CD platforms.
102440	106380	So, what is even CI-CD platforms?
106460	110220	So, they are a building and testing tool.
110220	115780	Meaning, they can do all the manual actions that we, as a person, do.
115780	117640	And they are event triggers.
117640	123460	Meaning, we have different SCMs, like GitHub, GitLab, and Bitbucket.
123460	126440	And they have some sort of features, right?
126440	128020	You can create a pull request.
128020	129280	You can create an issue.
129280	131280	You can create anything else.
131280	134820	And those events will trigger that pipeline.
135740	139060	So, there are many, many CI-CD platforms.
139060	142600	GitHub CI, GitHub actions, Jenkins.
142600	146600	And today, we are going to speak about GitHub actions.
146960	150040	And why we chose GitHub actions?
150040	152900	There are so many, Jenkins and others.
152980	160560	Because GitHub actions have 4 million public pipelines around the ecosystem.
160600	167980	That is huge, and it's appealing for attack, in a huge attack vectors for attackers.
168560	171900	So, let's a little bit visualize this, right?
171900	176060	So, we have all the events in the left side of the screen.
176060	178540	We can create a new commit to the repository.
178580	180260	We can create a new issue.
180260	182260	We can create a new pull request.
182480	187860	Then, we have the pipeline that will be triggered based on those events.
188120	193500	Then, we can create any action that we want to do.
193500	199000	Meaning, we can create a task that is logging in to our Google Cloud.
199000	204320	We can create a task that builds a Docker image and push that to the registry.
204340	209980	So, basically, we can do anything that we want during that pipeline run.
210800	216480	And just to understand how the basic flow works, let's imagine that.
216940	220100	We have a new push to the repository, right?
220100	223560	New commit to the main branch, maybe a side branch.
223560	224860	Everything is okay.
224860	229280	Based on that, the pipeline will start to run.
230420	234400	That pipeline will log in to our cloud environment.
234400	235940	It could be any one of them.
235940	239170	And maybe we'll create a new blob in a bucket.
239400	241860	So, pretty easy, right?
243140	249000	But, how does the pipeline itself log in to our cloud environment?
249000	252920	Because we, ourselves, need some authentication tokens, right?
252920	254280	Access tokens.
254280	264510	So, GitHub Actions has a key store that encrypts and saves those access tokens and decrypts them at runtime.
264860	273100	So, all the secrets are being saved, encrypted, and during runtime, they are being decrypted and being used.
273300	283420	So, we can have our production environment, staging environment keys, DB access tokens, all of those inside our pipeline key store.
283420	289590	And, probably think about that, it's a peeling target for attackers.
289940	302080	Because if an attacker will be able to control over our pipeline, he will be able to steal those tokens and do whatever he wants, right?
302660	307800	And among those tokens, we have a special one.
308100	309600	The GitHub token.
309600	318760	That GitHub token spawns in every pipeline that we create and can do any action in the repository itself.
318820	326660	It can create new commits, it can create new releases, it can create new actions, new pull requests, based on these permissions.
326660	336360	So, from an attacker perspective, if he steals that token, he can do whatever the maintainer does, whatever the owner can do.
337120	340400	That GitHub token has a variety of permissions.
340480	344880	It can do all that I mentioned previously, and way more.
344880	346420	So, think about that.
346420	364580	Stealing the GitHub action, the GitHub token, with a privileged permission, could gain an attacker a privileged permission to the repository itself, hurting everybody that is using that repository, and all of its end users down the line.
365420	374700	So, to understand how attackers are able to take over those pipelines, Erwin will take the stage.
377230	379210	Thank you, Elad.
380390	396310	So, after understanding the basics of pipelines, what permissions they have, and how do they run, now we can dive into the more interesting part of how command injections come into a form in CICD pipelines.
397150	400810	So, just for example, I have this PHP code.
400810	403030	It's not related to pipeline yet.
403130	406950	Raise your hand if you ever encountered this kind of vulnerability.
407670	409570	If you ever seen it.
409750	410550	Okay.
411290	412010	Perfect.
412010	415750	So, about half of the people have seen this vulnerable code.
415750	417330	And what is the problem here?
417690	420570	The problem is simple.
421610	428970	This website will execute a command using unsanitized user-controlled input.
429350	430110	Right ?
430110	440810	So, what that means is that a user could perform a command injection attack by providing a malicious user name.
442230	443970	Very bad.
443970	446010	We don't want that in our pipeline.
446010	449870	And the same logic goes for pipelines.
450270	469950	Because if we will use in our pipeline a user-controlled input in an unsanitized way, that means that an attacker could gain access to our pipeline and extract the secrets and run inside our environment and do all the malicious things Elad have described before.
469950	473550	So, we would definitely don't want this to happen.
473670	474950	Right?
476770	486890	To understand how GitHub Pipelines injections look like, we first have to get familiar with GitHub Workflows.
487430	491850	So, GitHub Workflow is a single step of the entire pipeline.
492210	494850	And it is a YAML configuration file.
494850	495430	That's it.
495430	497370	That's everything we have to know.
498030	504330	To see our first example of a GitHub Workflow, this GitHub Workflow is called test-issue.
505150	508050	And we can see the on-entry.
508050	512730	On-entry means on what triggers will this pipeline be executed.
512850	523650	So, since it is using the issues keyword, it means that any issue-related event on the repository will trigger the pipeline.
523650	530130	So, whether an issue is opened, assigned to someone else, closed, the pipeline will run.
530570	533830	And here we can see a step of the pipeline.
534330	542290	A step is a single instruction of the pipeline, and it will, of course, run under the same VM of the pipeline.
542810	548730	And the run keyword means that we're simply going to use a bash command.
549470	550250	Okay?
550330	557070	So, here we can see echo, which is print, and it will print the issue's title.
557590	559950	That's still basics.
560090	570170	And what will happen is, before the pipeline will run, GitHub will replace that placeholder, the GitHub event issue title, with the actual issue's title.
571350	591570	So, for example, if someone has created this is a new issue, it will create an event that will trigger our pipeline, and then, in the build logs, we will see that this is a new issue was printed because the pipeline used the user-controlled input to run a command.
593530	604110	So, for example, I can have that issue title, or that issue title, and I can also have emojis in the issue title.
604110	612930	I don't know if it will print them or not, but another example for a totally valid issue title would be that one.
616010	617230	It works.
617230	619310	It works totally fine on GitHub.
619310	621630	Because it is not their fault.
621630	629090	And what will happen here is the same idea from what we've previously seen in the PHP code.
629090	653390	Here, the pipeline will run this command under the run execution entry, and it will concatenate more commands after the echo command, which will dump the memory of the pipeline, and then send all the secrets to an attacker-controlled server.
653630	657690	So that's an example for something you wouldn't want to have in your organization.
658090	670710	Because then, an attacker will receive your PyP token, your Docker Hub token, your GCP token, your GitHub token, so, basically, whatever you use in your pipeline.
672270	675930	So, what is the solution for that?
675930	677910	The solution is pretty simple.
678430	681970	It is from the GitHub official documentation.
682390	695530	You just have to first set the value of the user-controlled input to an environment variable, and then use the environment variable in the command execution.
696310	702070	That's a simple solution for bash injection in general, and it also works in pipeline.
703050	704790	Okay, that's it.
704790	706130	Thank you very much.
713630	718030	Well, if we were not protected, we wouldn't be here today, right?
719290	742070	Now, after understanding the basics of command injection attacks, we can now explain the new attack vector we have invented that allowed us to find thousands of vulnerabilities in open-source projects, and also in the Bazel project, which is a flagship repository of Google,
742070	746850	which could affect millions of end-users if being compromised.
748310	751630	So, let's begin with the story of Bazel.
753850	761970	This is the same workflow as we have seen before, and it will again be triggered on issue events.
763270	776930	And since we're taking security very seriously in our organization, we follow the official documentation, and before executing the command, we have first set the user-controlled input to an environment variable.
777470	781670	But then, we have this new step.
781670	784670	And here we can see the user's keyword.
784790	793470	And what the user's keyword means is that we are importing logic from something called CostumeAction to our project.
794090	803730	So now it means that I can get vulnerable code that someone else has written, and that will run under my pipeline's permissions.
804810	810050	So, CostumeAction, in a word, it is pre-built logic.
810050	813550	It's like you can think about it like a dependency in code.
813550	832670	Someone else has written a module, a CostumeAction, and then, to create pipelines faster, I can just import it to my project and use it, and I can pass parameters to it, like I do to a function, it will return something, or it can be like a void CostumeAction that will just perform something.
832850	833670	And that's it.
833670	834350	Perfect.
835610	853790	And for that reason, GitHub has created the GitHub Marketplace, which is like the ecosystem for pipelines, and there are many open-source CostumeActions, and there are thousands over thousands, and you can just import and use them and deploy faster and work better.
854010	857690	Well, you can work better, but safer?
857790	861010	We'll have to figure out.
861930	865170	So let's take my workflow, for example.
865170	885070	I've written a workflow, and I'm using one CostumeAction as a dependency, but what happens is that this CostumeAction happens to use another dependency itself, and that CostumeAction dependency has three more dependencies, and this has more dependencies and more dependencies,
885070	898370	and the next thing you know, you have tons of dependencies, and what could happen if one of the dependencies brings command vulnerability to my project?
898370	901050	Then I'm in real trouble, right?
901050	913770	Because that means that now, by injecting code, I could affect the pipeline because everything you see here is part of my dependencies.
913770	929190	Everything runs on my pipeline's permission and environment, so dumping secrets from there could mean that an attacker gains control to my organization, and I wouldn't even know that I have imported this vulnerability.
929830	933550	So how would it look like from the code's perspective?
934250	940910	Let's say we have a workflow, and it is importing Action1.
940990	953750	Action1 is using Action2, and Action2 contains the same vulnerability from the previous chapter.
953750	963990	So that means that now my pipeline has command injection vulnerability, even though it's not my fault.
964610	968250	That brought the next question.
968250	973280	Thank you, Lorin.
973280	979760	So it's all working fine in this demo lab and visualization, right?
979760	984860	But how do we exploit this in scale?
985180	999620	Meaning, going over the UI and going over one by one and checking all those custom actions and navigating to different GitHub repositories, it's not scalable, right?
999620	1001760	It's not going to work.
1001840	1006440	So we talked about different methods.
1007020	1021900	The first phase, we are going to index all the GitHub atmosphere, meaning all the workflows, all the custom actions, everything into one place.
1021900	1024260	And how are we going to do that?
1024260	1025940	Using Raven.
1025940	1041820	Raven will allow us to query all GitHub atmosphere into a single DB and will query and search results and vulnerabilities based on that DB.
1042140	1048000	So just a quick recap about Raven, which is an open source project now.
1048000	1054320	It will download all the workflows in one GitHub ecosystem into a Redis DB.
1054320	1059800	Then it will index them to a GraphDB, a Neo4j one.
1059920	1065820	And then we will be able to query anything that we want based on that results.
1066460	1068600	And that's how it looks like.
1069020	1079400	So we have all the connections, all the custom actions, all the workflows, all the jobs, all the steps, everything that we mentioned in a single place.
1079400	1080700	That's amazing.
1080700	1083080	And just a closer look.
1083080	1087720	We have all the workflows, which are connected to some steps.
1087720	1092800	And in the end goal, they are importing a single custom action.
1093040	1103060	So by finding a vulnerability inside that action, we'll gain us a vulnerability inside all of those workflows.
1103140	1104220	Insane.
1104660	1107500	Second part, querying.
1107500	1110140	Querying based on those results.
1110760	1113980	We queried thousands of workflows.
1113980	1117540	High-star rating in GitHub Atmosphere.
1117540	1123780	So it will be an important one that will affect millions, probably, of users.
1124140	1129460	We found thousands of vulnerabilities in different severity levels.
1129880	1134100	And today I want to talk about one of them.
1134480	1135580	Bazel.
1136340	1140860	Bazel is a build and test tool that is widely used among the community.
1141420	1143620	It's a project owned by Google.
1143620	1146520	It's a flagship by them.
1146520	1152420	It's used by Google internally and a few other companies that you probably heard of.
1153760	1156520	And now for the exploitation phase.
1156600	1161140	How do we take that finding and exploit it?
1162280	1170560	Navigating to the repository itself and to the workflow itself, we see that that workflow doesn't seem vulnerable to anything.
1170560	1178840	We saw how command injections looks like by utilizing user input inside the workflow itself.
1178840	1181280	So we don't have nothing like that.
1182060	1194540	We only have a custom action in another repository, managed by other maintainers and other developers, and it passes two inputs.
1194660	1197400	The first one, issue title.
1197520	1199660	The second one, issue body.
1200000	1203280	So, probably makes you think, right?
1203600	1208320	Navigating to the custom action, and that's where we have it.
1209200	1216780	The custom action was vulnerable to a command injection vulnerability, like we saw before.
1216920	1219600	But wait a minute, not only that.
1219600	1222540	Remember the GitHub token that we saw before?
1222940	1240580	That workflow had a full permission to the repository, meaning exploiting that vulnerability will gain us a full permission to the repository, not only compromising the repository itself, but compromising everyone that are using it.
1242060	1244040	Let's move to the demo, right?
1245080	1248980	So, in the demo, we'll have two sides of the screen.
1249100	1252720	In the left side, we'll have a repository, a vulnerable one.
1252720	1262300	And in the right side, we'll have an attacker server that is waiting to get a connection, and waiting to run malicious commands inside that pipeline.
1263900	1270760	So, at the left side of the screen, as I said before, we have a repository.
1271560	1277940	Navigating to that repository, and we'll be able to see that it's a pretty empty one.
1277980	1284560	It doesn't have any releases, none at all, and the readme is pretty empty.
1284560	1286500	Keep that in mind.
1287360	1293540	Scrolling back, and a maintainer saw a new issue in that repository.
1293640	1313840	That issue will contain some build logs and some events on the host machine, and what it doesn't know, it has one malicious command that will compromise the entire pipeline, inject malicious code, will connect to a remote server, and will execute some more commands.
1313840	1318320	So, by clicking milestone, the pipeline starts to run.
1318820	1323960	Running the pipeline will execute our command injection.
1324420	1343400	It will bring a malicious script from the attacker server, as we can see, and will dump all the secrets in the memory of that pipeline, and will use that to create new releases, inject malicious code to that repository, and way more.
1343960	1356240	After the injection was successfully completed, we are navigating back to the repository itself, and we can see we have a new release, by a GitHub Action user, not even our user.
1356600	1361400	Scrolling down, and we have the AppSec Village picture, right in there.
1362040	1375640	And, from the user perspective, not only will it hurt the repository itself, we can see that the user will clone the latest version, and will do a simple make build command.
1376260	1396400	But, what he doesn't know, that in the moment he will do a make build command, all of his environment variables will be sent to a remote attacker server, along with some system information, private keys, DB information, and everything that he has in his environment.
1396460	1397840	That is insane.
1397840	1407960	So, not only hurting the repository itself, that has 22,000 stars, it will hurt millions of end-users down the line.
1408480	1409660	Insane.
1410340	1413800	So, for some wake-up and takeaways.
1414860	1421880	The takeaways are separated to a blue and red theme, so everybody can take something from that.
1422160	1425020	First one, insecure input.
1425040	1430060	Don't just pass insecure input, just to an inline script.
1430060	1438120	Like you do in code and other methods, don't use untrusted user input, in untrusted ways.
1438280	1443620	The second one is custom actions, and particularly composite actions.
1443620	1447480	They are importing logic to inside your pipeline.
1447480	1458020	So, be careful about that, and make sure that you're not running a vulnerable one, that will compromise your entire GitHub workflow.
1458580	1461820	And the last one, do I need to stress that enough?
1461820	1467860	Like, everything in cybersecurity, least privilege principle.
1467940	1475200	So, make sure your workflow has the minimum privilege it needs to be for each one.
1475200	1480620	So, no extra permissions, and that's it.
1480620	1482420	Thank you for listening to us.
1482420	1483840	We have more details.
1483840	1484680	Thank you.
1492250	1503250	We also want to say that Raven is open source, and it is equipped with a query library from our previous two years of research, GitHub Actions.
1503250	1513430	So , if you want to use it either for bad bounties, red team, or for internal security, you are more than welcome.
1513430	1516930	We will share the QR code for the GitHub repository as well.
1516930	1518010	Thank you.
