WEBVTT

00:07.360 --> 00:13.840
Thank you for joining to our talk, your CI-CD pipeline is vulnerable, but it's not your fault.

00:13.860 --> 00:17.020
So, without further ado, let's move on.

00:17.160 --> 00:22.600
So, my name is Elad, I'm a security researcher at SciCode with 7 years of experience.

00:22.600 --> 00:27.590
I'm mainly focusing on web application security and supply chain security.

00:28.060 --> 00:34.520
And I'm love hacking random stuff, basically everything with an IP.

00:34.560 --> 00:36.340
And I'm from SciCode.

00:37.720 --> 00:42.200
Hi, my name is Orin, I hope the presentation will work.

00:42.200 --> 00:49.680
So, I have also 7 years of experience in cyber security.

00:49.740 --> 00:53.000
In my background, I used to research Kerberos and networking.

00:53.000 --> 00:58.980
But currently, I focus on supply chain security on the same research team with Elad.

01:00.020 --> 01:01.620
Thank you, Orin.

01:01.740 --> 01:06.540
So, for our agenda today, we're going to start and speak about CI-CD platforms.

01:06.540 --> 01:08.660
About GitHub actions.

01:08.900 --> 01:12.300
Then, we'll speak about command injections 101.

01:12.300 --> 01:18.360
And see how command injections appears and takes place in CI-CD platforms.

01:18.360 --> 01:22.040
Then, we'll tell the story of Buzzer.

01:22.040 --> 01:29.980
How we found a critical vulnerability, a CI-CD vulnerability, in a major Google-owned open source project.

01:29.980 --> 01:32.280
We'll continue with the demo.

01:32.320 --> 01:37.040
And then, we'll go home with some takeaways and a recap.

01:37.980 --> 01:42.280
So, starting with GitHub actions and CI-CD platforms.

01:42.440 --> 01:46.380
So, what is even CI-CD platforms?

01:46.460 --> 01:50.220
So, they are a building and testing tool.

01:50.220 --> 01:55.780
Meaning, they can do all the manual actions that we, as a person, do.

01:55.780 --> 01:57.640
And they are event triggers.

01:57.640 --> 02:03.460
Meaning, we have different SCMs, like GitHub, GitLab, and Bitbucket.

02:03.460 --> 02:06.440
And they have some sort of features, right?

02:06.440 --> 02:08.020
You can create a pull request.

02:08.020 --> 02:09.280
You can create an issue.

02:09.280 --> 02:11.280
You can create anything else.

02:11.280 --> 02:14.820
And those events will trigger that pipeline.

02:15.740 --> 02:19.060
So, there are many, many CI-CD platforms.

02:19.060 --> 02:22.600
GitHub CI, GitHub actions, Jenkins.

02:22.600 --> 02:26.600
And today, we are going to speak about GitHub actions.

02:26.960 --> 02:30.040
And why we chose GitHub actions?

02:30.040 --> 02:32.900
There are so many, Jenkins and others.

02:32.980 --> 02:40.560
Because GitHub actions have 4 million public pipelines around the ecosystem.

02:40.600 --> 02:47.980
That is huge, and it's appealing for attack, in a huge attack vectors for attackers.

02:48.560 --> 02:51.900
So, let's a little bit visualize this, right?

02:51.900 --> 02:56.060
So, we have all the events in the left side of the screen.

02:56.060 --> 02:58.540
We can create a new commit to the repository.

02:58.580 --> 03:00.260
We can create a new issue.

03:00.260 --> 03:02.260
We can create a new pull request.

03:02.480 --> 03:07.860
Then, we have the pipeline that will be triggered based on those events.

03:08.120 --> 03:13.500
Then, we can create any action that we want to do.

03:13.500 --> 03:19.000
Meaning, we can create a task that is logging in to our Google Cloud.

03:19.000 --> 03:24.320
We can create a task that builds a Docker image and push that to the registry.

03:24.340 --> 03:29.980
So, basically, we can do anything that we want during that pipeline run.

03:30.800 --> 03:36.480
And just to understand how the basic flow works, let's imagine that.

03:36.940 --> 03:40.100
We have a new push to the repository, right?

03:40.100 --> 03:43.560
New commit to the main branch, maybe a side branch.

03:43.560 --> 03:44.860
Everything is okay.

03:44.860 --> 03:49.280
Based on that, the pipeline will start to run.

03:50.420 --> 03:54.400
That pipeline will log in to our cloud environment.

03:54.400 --> 03:55.940
It could be any one of them.

03:55.940 --> 03:59.170
And maybe we'll create a new blob in a bucket.

03:59.400 --> 04:01.860
So, pretty easy, right?

04:03.140 --> 04:09.000
But, how does the pipeline itself log in to our cloud environment?

04:09.000 --> 04:12.920
Because we, ourselves, need some authentication tokens, right?

04:12.920 --> 04:14.280
Access tokens.

04:14.280 --> 04:24.510
So, GitHub Actions has a key store that encrypts and saves those access tokens and decrypts them at runtime.

04:24.860 --> 04:33.100
So, all the secrets are being saved, encrypted, and during runtime, they are being decrypted and being used.

04:33.300 --> 04:43.420
So, we can have our production environment, staging environment keys, DB access tokens, all of those inside our pipeline key store.

04:43.420 --> 04:49.590
And, probably think about that, it's a peeling target for attackers.

04:49.940 --> 05:02.080
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?

05:02.660 --> 05:07.800
And among those tokens, we have a special one.

05:08.100 --> 05:09.600
The GitHub token.

05:09.600 --> 05:18.760
That GitHub token spawns in every pipeline that we create and can do any action in the repository itself.

05:18.820 --> 05:26.660
It can create new commits, it can create new releases, it can create new actions, new pull requests, based on these permissions.

05:26.660 --> 05:36.360
So, from an attacker perspective, if he steals that token, he can do whatever the maintainer does, whatever the owner can do.

05:37.120 --> 05:40.400
That GitHub token has a variety of permissions.

05:40.480 --> 05:44.880
It can do all that I mentioned previously, and way more.

05:44.880 --> 05:46.420
So, think about that.

05:46.420 --> 06:04.580
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.

06:05.420 --> 06:14.700
So, to understand how attackers are able to take over those pipelines, Erwin will take the stage.

06:17.230 --> 06:19.210
Thank you, Elad.

06:20.390 --> 06:36.310
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.

06:37.150 --> 06:40.810
So, just for example, I have this PHP code.

06:40.810 --> 06:43.030
It's not related to pipeline yet.

06:43.130 --> 06:46.950
Raise your hand if you ever encountered this kind of vulnerability.

06:47.670 --> 06:49.570
If you ever seen it.

06:49.750 --> 06:50.550
Okay.

06:51.290 --> 06:52.010
Perfect.

06:52.010 --> 06:55.750
So, about half of the people have seen this vulnerable code.

06:55.750 --> 06:57.330
And what is the problem here?

06:57.690 --> 07:00.570
The problem is simple.

07:01.610 --> 07:08.970
This website will execute a command using unsanitized user-controlled input.

07:09.350 --> 07:10.110
Right ?

07:10.110 --> 07:20.810
So, what that means is that a user could perform a command injection attack by providing a malicious user name.

07:22.230 --> 07:23.970
Very bad.

07:23.970 --> 07:26.010
We don't want that in our pipeline.

07:26.010 --> 07:29.870
And the same logic goes for pipelines.

07:30.270 --> 07:49.950
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.

07:49.950 --> 07:53.550
So, we would definitely don't want this to happen.

07:53.670 --> 07:54.950
Right?

07:56.770 --> 08:06.890
To understand how GitHub Pipelines injections look like, we first have to get familiar with GitHub Workflows.

08:07.430 --> 08:11.850
So, GitHub Workflow is a single step of the entire pipeline.

08:12.210 --> 08:14.850
And it is a YAML configuration file.

08:14.850 --> 08:15.430
That's it.

08:15.430 --> 08:17.370
That's everything we have to know.

08:18.030 --> 08:24.330
To see our first example of a GitHub Workflow, this GitHub Workflow is called test-issue.

08:25.150 --> 08:28.050
And we can see the on-entry.

08:28.050 --> 08:32.730
On-entry means on what triggers will this pipeline be executed.

08:32.850 --> 08:43.650
So, since it is using the issues keyword, it means that any issue-related event on the repository will trigger the pipeline.

08:43.650 --> 08:50.130
So, whether an issue is opened, assigned to someone else, closed, the pipeline will run.

08:50.570 --> 08:53.830
And here we can see a step of the pipeline.

08:54.330 --> 09:02.290
A step is a single instruction of the pipeline, and it will, of course, run under the same VM of the pipeline.

09:02.810 --> 09:08.730
And the run keyword means that we're simply going to use a bash command.

09:09.470 --> 09:10.250
Okay?

09:10.330 --> 09:17.070
So, here we can see echo, which is print, and it will print the issue's title.

09:17.590 --> 09:19.950
That's still basics.

09:20.090 --> 09:30.170
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.

09:31.350 --> 09:51.570
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.

09:53.530 --> 10:04.110
So, for example, I can have that issue title, or that issue title, and I can also have emojis in the issue title.

10:04.110 --> 10:12.930
I don't know if it will print them or not, but another example for a totally valid issue title would be that one.

10:16.010 --> 10:17.230
It works.

10:17.230 --> 10:19.310
It works totally fine on GitHub.

10:19.310 --> 10:21.630
Because it is not their fault.

10:21.630 --> 10:29.090
And what will happen here is the same idea from what we've previously seen in the PHP code.

10:29.090 --> 10:53.390
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.

10:53.630 --> 10:57.690
So that's an example for something you wouldn't want to have in your organization.

10:58.090 --> 11:10.710
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.

11:12.270 --> 11:15.930
So, what is the solution for that?

11:15.930 --> 11:17.910
The solution is pretty simple.

11:18.430 --> 11:21.970
It is from the GitHub official documentation.

11:22.390 --> 11:35.530
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.

11:36.310 --> 11:42.070
That's a simple solution for bash injection in general, and it also works in pipeline.

11:43.050 --> 11:44.790
Okay, that's it.

11:44.790 --> 11:46.130
Thank you very much.

11:53.630 --> 11:58.030
Well, if we were not protected, we wouldn't be here today, right?

11:59.290 --> 12:22.070
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,

12:22.070 --> 12:26.850
which could affect millions of end-users if being compromised.

12:28.310 --> 12:31.630
So, let's begin with the story of Bazel.

12:33.850 --> 12:41.970
This is the same workflow as we have seen before, and it will again be triggered on issue events.

12:43.270 --> 12:56.930
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.

12:57.470 --> 13:01.670
But then, we have this new step.

13:01.670 --> 13:04.670
And here we can see the user's keyword.

13:04.790 --> 13:13.470
And what the user's keyword means is that we are importing logic from something called CostumeAction to our project.

13:14.090 --> 13:23.730
So now it means that I can get vulnerable code that someone else has written, and that will run under my pipeline's permissions.

13:24.810 --> 13:30.050
So, CostumeAction, in a word, it is pre-built logic.

13:30.050 --> 13:33.550
It's like you can think about it like a dependency in code.

13:33.550 --> 13:52.670
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.

13:52.850 --> 13:53.670
And that's it.

13:53.670 --> 13:54.350
Perfect.

13:55.610 --> 14:13.790
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.

14:14.010 --> 14:17.690
Well, you can work better, but safer?

14:17.790 --> 14:21.010
We'll have to figure out.

14:21.930 --> 14:25.170
So let's take my workflow, for example.

14:25.170 --> 14:45.070
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,

14:45.070 --> 14:58.370
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?

14:58.370 --> 15:01.050
Then I'm in real trouble, right?

15:01.050 --> 15:13.770
Because that means that now, by injecting code, I could affect the pipeline because everything you see here is part of my dependencies.

15:13.770 --> 15:29.190
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.

15:29.830 --> 15:33.550
So how would it look like from the code's perspective?

15:34.250 --> 15:40.910
Let's say we have a workflow, and it is importing Action1.

15:40.990 --> 15:53.750
Action1 is using Action2, and Action2 contains the same vulnerability from the previous chapter.

15:53.750 --> 16:03.990
So that means that now my pipeline has command injection vulnerability, even though it's not my fault.

16:04.610 --> 16:08.250
That brought the next question.

16:08.250 --> 16:13.280
Thank you, Lorin.

16:13.280 --> 16:19.760
So it's all working fine in this demo lab and visualization, right?

16:19.760 --> 16:24.860
But how do we exploit this in scale?

16:25.180 --> 16:39.620
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?

16:39.620 --> 16:41.760
It's not going to work.

16:41.840 --> 16:46.440
So we talked about different methods.

16:47.020 --> 17:01.900
The first phase, we are going to index all the GitHub atmosphere, meaning all the workflows, all the custom actions, everything into one place.

17:01.900 --> 17:04.260
And how are we going to do that?

17:04.260 --> 17:05.940
Using Raven.

17:05.940 --> 17:21.820
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.

17:22.140 --> 17:28.000
So just a quick recap about Raven, which is an open source project now.

17:28.000 --> 17:34.320
It will download all the workflows in one GitHub ecosystem into a Redis DB.

17:34.320 --> 17:39.800
Then it will index them to a GraphDB, a Neo4j one.

17:39.920 --> 17:45.820
And then we will be able to query anything that we want based on that results.

17:46.460 --> 17:48.600
And that's how it looks like.

17:49.020 --> 17:59.400
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.

17:59.400 --> 18:00.700
That's amazing.

18:00.700 --> 18:03.080
And just a closer look.

18:03.080 --> 18:07.720
We have all the workflows, which are connected to some steps.

18:07.720 --> 18:12.800
And in the end goal, they are importing a single custom action.

18:13.040 --> 18:23.060
So by finding a vulnerability inside that action, we'll gain us a vulnerability inside all of those workflows.

18:23.140 --> 18:24.220
Insane.

18:24.660 --> 18:27.500
Second part, querying.

18:27.500 --> 18:30.140
Querying based on those results.

18:30.760 --> 18:33.980
We queried thousands of workflows.

18:33.980 --> 18:37.540
High-star rating in GitHub Atmosphere.

18:37.540 --> 18:43.780
So it will be an important one that will affect millions, probably, of users.

18:44.140 --> 18:49.460
We found thousands of vulnerabilities in different severity levels.

18:49.880 --> 18:54.100
And today I want to talk about one of them.

18:54.480 --> 18:55.580
Bazel.

18:56.340 --> 19:00.860
Bazel is a build and test tool that is widely used among the community.

19:01.420 --> 19:03.620
It's a project owned by Google.

19:03.620 --> 19:06.520
It's a flagship by them.

19:06.520 --> 19:12.420
It's used by Google internally and a few other companies that you probably heard of.

19:13.760 --> 19:16.520
And now for the exploitation phase.

19:16.600 --> 19:21.140
How do we take that finding and exploit it?

19:22.280 --> 19:30.560
Navigating to the repository itself and to the workflow itself, we see that that workflow doesn't seem vulnerable to anything.

19:30.560 --> 19:38.840
We saw how command injections looks like by utilizing user input inside the workflow itself.

19:38.840 --> 19:41.280
So we don't have nothing like that.

19:42.060 --> 19:54.540
We only have a custom action in another repository, managed by other maintainers and other developers, and it passes two inputs.

19:54.660 --> 19:57.400
The first one, issue title.

19:57.520 --> 19:59.660
The second one, issue body.

20:00.000 --> 20:03.280
So, probably makes you think, right?

20:03.600 --> 20:08.320
Navigating to the custom action, and that's where we have it.

20:09.200 --> 20:16.780
The custom action was vulnerable to a command injection vulnerability, like we saw before.

20:16.920 --> 20:19.600
But wait a minute, not only that.

20:19.600 --> 20:22.540
Remember the GitHub token that we saw before?

20:22.940 --> 20:40.580
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.

20:42.060 --> 20:44.040
Let's move to the demo, right?

20:45.080 --> 20:48.980
So, in the demo, we'll have two sides of the screen.

20:49.100 --> 20:52.720
In the left side, we'll have a repository, a vulnerable one.

20:52.720 --> 21:02.300
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.

21:03.900 --> 21:10.760
So, at the left side of the screen, as I said before, we have a repository.

21:11.560 --> 21:17.940
Navigating to that repository, and we'll be able to see that it's a pretty empty one.

21:17.980 --> 21:24.560
It doesn't have any releases, none at all, and the readme is pretty empty.

21:24.560 --> 21:26.500
Keep that in mind.

21:27.360 --> 21:33.540
Scrolling back, and a maintainer saw a new issue in that repository.

21:33.640 --> 21:53.840
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.

21:53.840 --> 21:58.320
So, by clicking milestone, the pipeline starts to run.

21:58.820 --> 22:03.960
Running the pipeline will execute our command injection.

22:04.420 --> 22:23.400
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.

22:23.960 --> 22:36.240
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.

22:36.600 --> 22:41.400
Scrolling down, and we have the AppSec Village picture, right in there.

22:42.040 --> 22:55.640
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.

22:56.260 --> 23:16.400
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.

23:16.460 --> 23:17.840
That is insane.

23:17.840 --> 23:27.960
So, not only hurting the repository itself, that has 22,000 stars, it will hurt millions of end-users down the line.

23:28.480 --> 23:29.660
Insane.

23:30.340 --> 23:33.800
So, for some wake-up and takeaways.

23:34.860 --> 23:41.880
The takeaways are separated to a blue and red theme, so everybody can take something from that.

23:42.160 --> 23:45.020
First one, insecure input.

23:45.040 --> 23:50.060
Don't just pass insecure input, just to an inline script.

23:50.060 --> 23:58.120
Like you do in code and other methods, don't use untrusted user input, in untrusted ways.

23:58.280 --> 24:03.620
The second one is custom actions, and particularly composite actions.

24:03.620 --> 24:07.480
They are importing logic to inside your pipeline.

24:07.480 --> 24:18.020
So, be careful about that, and make sure that you're not running a vulnerable one, that will compromise your entire GitHub workflow.

24:18.580 --> 24:21.820
And the last one, do I need to stress that enough?

24:21.820 --> 24:27.860
Like, everything in cybersecurity, least privilege principle.

24:27.940 --> 24:35.200
So, make sure your workflow has the minimum privilege it needs to be for each one.

24:35.200 --> 24:40.620
So, no extra permissions, and that's it.

24:40.620 --> 24:42.420
Thank you for listening to us.

24:42.420 --> 24:43.840
We have more details.

24:43.840 --> 24:44.680
Thank you.

24:52.250 --> 25:03.250
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.

25:03.250 --> 25:13.430
So , if you want to use it either for bad bounties, red team, or for internal security, you are more than welcome.

25:13.430 --> 25:16.930
We will share the QR code for the GitHub repository as well.

25:16.930 --> 25:18.010
Thank you.

