Thank you for joining to our talk, your CI-CD pipeline is vulnerable, but it's not your fault. So, without further ado, let's move on. So, my name is Elad, I'm a security researcher at SciCode with 7 years of experience. I'm mainly focusing on web application security and supply chain security. And I'm love hacking random stuff, basically everything with an IP. And I'm from SciCode. Hi, my name is Orin, I hope the presentation will work. So, I have also 7 years of experience in cyber security. In my background, I used to research Kerberos and networking. But currently, I focus on supply chain security on the same research team with Elad. Thank you, Orin. So, for our agenda today, we're going to start and speak about CI-CD platforms. About GitHub actions. Then, we'll speak about command injections 101. And see how command injections appears and takes place in CI-CD platforms. Then, we'll tell the story of Buzzer. How we found a critical vulnerability, a CI-CD vulnerability, in a major Google-owned open source project. We'll continue with the demo. And then, we'll go home with some takeaways and a recap. So, starting with GitHub actions and CI-CD platforms. So, what is even CI-CD platforms? So, they are a building and testing tool. Meaning, they can do all the manual actions that we, as a person, do. And they are event triggers. Meaning, we have different SCMs, like GitHub, GitLab, and Bitbucket. And they have some sort of features, right? You can create a pull request. You can create an issue. You can create anything else. And those events will trigger that pipeline. So, there are many, many CI-CD platforms. GitHub CI, GitHub actions, Jenkins. And today, we are going to speak about GitHub actions. And why we chose GitHub actions? There are so many, Jenkins and others. Because GitHub actions have 4 million public pipelines around the ecosystem. That is huge, and it's appealing for attack, in a huge attack vectors for attackers. So, let's a little bit visualize this, right? So, we have all the events in the left side of the screen. We can create a new commit to the repository. We can create a new issue. We can create a new pull request. Then, we have the pipeline that will be triggered based on those events. Then, we can create any action that we want to do. Meaning, we can create a task that is logging in to our Google Cloud. We can create a task that builds a Docker image and push that to the registry. So, basically, we can do anything that we want during that pipeline run. And just to understand how the basic flow works, let's imagine that. We have a new push to the repository, right? New commit to the main branch, maybe a side branch. Everything is okay. Based on that, the pipeline will start to run. That pipeline will log in to our cloud environment. It could be any one of them. And maybe we'll create a new blob in a bucket. So, pretty easy, right? But, how does the pipeline itself log in to our cloud environment? Because we, ourselves, need some authentication tokens, right? Access tokens. So, GitHub Actions has a key store that encrypts and saves those access tokens and decrypts them at runtime. So, all the secrets are being saved, encrypted, and during runtime, they are being decrypted and being used. So, we can have our production environment, staging environment keys, DB access tokens, all of those inside our pipeline key store. And, probably think about that, it's a peeling target for attackers. 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? And among those tokens, we have a special one. The GitHub token. That GitHub token spawns in every pipeline that we create and can do any action in the repository itself. It can create new commits, it can create new releases, it can create new actions, new pull requests, based on these permissions. So, from an attacker perspective, if he steals that token, he can do whatever the maintainer does, whatever the owner can do. That GitHub token has a variety of permissions. It can do all that I mentioned previously, and way more. So, think about that. 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. So, to understand how attackers are able to take over those pipelines, Erwin will take the stage. Thank you, Elad. 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. So, just for example, I have this PHP code. It's not related to pipeline yet. Raise your hand if you ever encountered this kind of vulnerability. If you ever seen it. Okay. Perfect. So, about half of the people have seen this vulnerable code. And what is the problem here? The problem is simple. This website will execute a command using unsanitized user-controlled input. Right ? So, what that means is that a user could perform a command injection attack by providing a malicious user name. Very bad. We don't want that in our pipeline. And the same logic goes for pipelines. 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. So, we would definitely don't want this to happen. Right? To understand how GitHub Pipelines injections look like, we first have to get familiar with GitHub Workflows. So, GitHub Workflow is a single step of the entire pipeline. And it is a YAML configuration file. That's it. That's everything we have to know. To see our first example of a GitHub Workflow, this GitHub Workflow is called test-issue. And we can see the on-entry. On-entry means on what triggers will this pipeline be executed. So, since it is using the issues keyword, it means that any issue-related event on the repository will trigger the pipeline. So, whether an issue is opened, assigned to someone else, closed, the pipeline will run. And here we can see a step of the pipeline. A step is a single instruction of the pipeline, and it will, of course, run under the same VM of the pipeline. And the run keyword means that we're simply going to use a bash command. Okay? So, here we can see echo, which is print, and it will print the issue's title. That's still basics. 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. 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. So, for example, I can have that issue title, or that issue title, and I can also have emojis in the issue title. I don't know if it will print them or not, but another example for a totally valid issue title would be that one. It works. It works totally fine on GitHub. Because it is not their fault. And what will happen here is the same idea from what we've previously seen in the PHP code. 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. So that's an example for something you wouldn't want to have in your organization. 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. So, what is the solution for that? The solution is pretty simple. It is from the GitHub official documentation. 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. That's a simple solution for bash injection in general, and it also works in pipeline. Okay, that's it. Thank you very much. Well, if we were not protected, we wouldn't be here today, right? 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, which could affect millions of end-users if being compromised. So, let's begin with the story of Bazel. This is the same workflow as we have seen before, and it will again be triggered on issue events. 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. But then, we have this new step. And here we can see the user's keyword. And what the user's keyword means is that we are importing logic from something called CostumeAction to our project. So now it means that I can get vulnerable code that someone else has written, and that will run under my pipeline's permissions. So, CostumeAction, in a word, it is pre-built logic. It's like you can think about it like a dependency in code. 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. And that's it. Perfect. 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. Well, you can work better, but safer? We'll have to figure out. So let's take my workflow, for example. 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, 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? Then I'm in real trouble, right? Because that means that now, by injecting code, I could affect the pipeline because everything you see here is part of my dependencies. 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. So how would it look like from the code's perspective? Let's say we have a workflow, and it is importing Action1. Action1 is using Action2, and Action2 contains the same vulnerability from the previous chapter. So that means that now my pipeline has command injection vulnerability, even though it's not my fault. That brought the next question. Thank you, Lorin. So it's all working fine in this demo lab and visualization, right? But how do we exploit this in scale? 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? It's not going to work. So we talked about different methods. The first phase, we are going to index all the GitHub atmosphere, meaning all the workflows, all the custom actions, everything into one place. And how are we going to do that? Using Raven. 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. So just a quick recap about Raven, which is an open source project now. It will download all the workflows in one GitHub ecosystem into a Redis DB. Then it will index them to a GraphDB, a Neo4j one. And then we will be able to query anything that we want based on that results. And that's how it looks like. 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. That's amazing. And just a closer look. We have all the workflows, which are connected to some steps. And in the end goal, they are importing a single custom action. So by finding a vulnerability inside that action, we'll gain us a vulnerability inside all of those workflows. Insane. Second part, querying. Querying based on those results. We queried thousands of workflows. High-star rating in GitHub Atmosphere. So it will be an important one that will affect millions, probably, of users. We found thousands of vulnerabilities in different severity levels. And today I want to talk about one of them. Bazel. Bazel is a build and test tool that is widely used among the community. It's a project owned by Google. It's a flagship by them. It's used by Google internally and a few other companies that you probably heard of. And now for the exploitation phase. How do we take that finding and exploit it? Navigating to the repository itself and to the workflow itself, we see that that workflow doesn't seem vulnerable to anything. We saw how command injections looks like by utilizing user input inside the workflow itself. So we don't have nothing like that. We only have a custom action in another repository, managed by other maintainers and other developers, and it passes two inputs. The first one, issue title. The second one, issue body. So, probably makes you think, right? Navigating to the custom action, and that's where we have it. The custom action was vulnerable to a command injection vulnerability, like we saw before. But wait a minute, not only that. Remember the GitHub token that we saw before? 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. 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 have a repository, a vulnerable one. 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. So, at the left side of the screen, as I said before, we have a repository. Navigating to that repository, and we'll be able to see that it's a pretty empty one. It doesn't have any releases, none at all, and the readme is pretty empty. Keep that in mind. Scrolling back, and a maintainer saw a new issue in that repository. 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. So, by clicking milestone, the pipeline starts to run. Running the pipeline will execute our command injection. 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. 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. Scrolling down, and we have the AppSec Village picture, right in there. 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. 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. That is insane. So, not only hurting the repository itself, that has 22,000 stars, it will hurt millions of end-users down the line. Insane. So, for some wake-up and takeaways. The takeaways are separated to a blue and red theme, so everybody can take something from that. First one, insecure input. Don't just pass insecure input, just to an inline script. Like you do in code and other methods, don't use untrusted user input, in untrusted ways. The second one is custom actions, and particularly composite actions. They are importing logic to inside your pipeline. So, be careful about that, and make sure that you're not running a vulnerable one, that will compromise your entire GitHub workflow. And the last one, do I need to stress that enough? Like, everything in cybersecurity, least privilege principle. So, make sure your workflow has the minimum privilege it needs to be for each one. So, no extra permissions, and that's it. Thank you for listening to us. We have more details. Thank you. 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. So , if you want to use it either for bad bounties, red team, or for internal security, you are more than welcome. We will share the QR code for the GitHub repository as well. Thank you.