Yeah, hear me. Thank you guys for joining us today. It's the last day of DEF CON. Appreciate that. And 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. We are not moving on. So my name is Elad, I'm a security researcher at PsyCode with seven 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 PsyCode. Hi, my name is Orin. I hope the presentation will work. So I have also seven years of experience in cyber security and I'm working 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 Buzzle, 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 take up, takeaways and a recap. So starting with GitHub actions and CI CD platforms. So what is even CI CD platforms? So they are building and testing uh tool meaning they can do all the manual actions that we as a person do. And there are events trigger 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. There are GitLab 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 four million public pipelines around the ecosystem. That is huge and it's appealing for attack for 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 that, on those events. Then we can create any, any uh action that we wanna 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, that we want doing that pipeline one. And just to understand how the basic flow works, let's imagine that. We have a push, 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, could be any one of them, and maybe we'll create a new blob in a bucket. So pretty, pretty easy right? But how does the pipeline itself logs in to our cloud environment? Because we ourselves need some authentication tokens, right? Access tokens. So GitHub Actions have a key store that encrypt, encrypt and save those access tokens and decrypt them one time. So all the secrets are being saved, encrypted, and during one time they are being decrypted and being, and being used. So we can have our production environment, a staging environment keys, DB access tokens, all of those inside our pipeline key store. And probably think about that. It's appealing target for an attack, for attackers. Because if an attacker will be able to control over our pipeline, it 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 permits, 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 uh previously and way more. So think about that. Stealing the GitHub action, the GitHub token with privileged permissions could gain an attacker a privileged permission to the repository itself helping 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 has 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'll 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 end tree. On end tree 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 issues title. Okay? 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 issues 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 bit 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 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. Right? 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 the 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? 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. Okay? That's a simple solution for bash injection in general. And it also works in pipeline. Okay. That's it. Thank you very much. I mean, well, if it were not protected, we wouldn't be here today, right? So 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 Basel 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 Basel. 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 uh the user controlled input to an environment variable. But then we have this new step. And here we can see the users keyword. And what the users keyword means is that we are importing logic from something called costume action 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 costume actions 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 costume action, 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 costume action 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 costume actions 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 costume action as a dependency. But what happens is that this costume action happens to use another dependency itself. And that costume action 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 commands 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 the secrets from there could mean that an attacker gained 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 using, importing action one. Action one is using action two. And action two contains the same vulnerability from the first, from the previous chapter. So that means that now, that means that now my pipeline has command injection vulnerability even though it's not my fault. So that brought the next question. Thank you, Erwin. So it's all working fine in this demo lab and visualization, right? But we are going to look at how do we exploit this in scale? Meaning going over the UI and going over one by one and checking all those post actions and navigating to different GitHub repositories, it's not scalable, right? It won't work. So we thought 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, will allow us to query all GitHub atmosphere into a single DB and will query and search result and vulnerability. And we will query all the activities 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 graph DB. 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 of go, they are importing a single custom action. So by finding a vulnerability inside that action, will gain us a vulnerability inside all of those workflows. Insane. Second part, querying. Querying based of those results. We queried thousands of workflows. I start waiting in GitHub atmosphere. Meaning, so it will be an important one that will affect millions probably users. We found thousands of vulnerability 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. Right? We saw how command injections looks like by utilizing a 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 we have it. The custom action, well, vulnerable, 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 has a full permission to the repository. So, we have to exploit that vulnerability. 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's 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 pretty empty one. It doesn't have any releases, none at all. And there with me 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 OS 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 you can see we have new release. By a GitHub action user, not even our user. Scrolling down and we have that APSEC village picture right in there. And from the user perspective, it's not only will 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 with along with some system information, public 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, so some recap and takeaways. The takeaways are separated to a blue and red. 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. Don't run a vulnerable one that will compromise your entire GitHub workflow. And the last one, do I need to stress that enough? Like everything in cyber security, 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 uh a query library from our previous two years of research, GitHub action. So, if you want to use it either for um for bad bounties, red team or for internal uh security, you are more than welcome. We will share the QR code for the GitHub repository as well. Thank you.