Round of Applause for Anan all right all right all right everyone I hope everyone had a great lunch and thank you so much for coming to my talk and such a great introduction today I'm going to be talking about the Dark Side of get up actions so quick information about me I do security engineering for my day job but I'm a part time security researcher and all of the information I'm about to talk about today relates to what I've done as an individual I got to say that and I've spoken at both black hat and
Defcon this past year on actions s related to GitHub security research and I also have two cats here's some pictures of them I got to got to show them if I have cats so all right all right I'm going to start off today by talking about some impact these issues I'm going to talk about have some really high impact and I'm going to prove that to you during this presentation but I'm also going to try to give everyone a brief primer on GitHub actions but I'm not going to go in depth because that would be
the whole talk then I'm going to show you how you can find these vulnerabilities using an open source tool that I have on right now that you can download called gate X and then I'm going to go into two in-depth case studies about how I could have used some of these vulnerabilities to cause worldwide impact and then I'm going to end with how you can potentially fix them if you have a company that has uses GitHub action so this this is a really powerful technique someone with malicious motivations could you do use this to conduct
a worldwide attack at black hat I talked about how someone could have attack used a get of actions vulnerability to steal Intel CPU designs from the internet no prerequisites that's pretty scary and then today I'm going to talk about how you could have backdoored software published by one of the world's largest companies and the list just goes on and on now this isn't a complex vulnerability earlier today I saw some attack pads that required a lot of preparation a lot of reverse engineering but this doesn't require any of that the initial act offensive action for
all of this is simply creating a pull request or an issue on GitHub I'm being serious it's that easy so not only is it easy simply by living off the land an attacker has everything they need to conduct these worldwide supply chain attacks just using GitHub they just have to create an account so this leads to this point that GitHub For Better or For Worse has become critical internet infrastructure open source projects around the world typically choose GitHub as their platform of choice there are some exceptions but it's just where the open source Community goes
to develop software and similarly large companies that publish software that happens to be open source often use use GitHub as the platform for active development of that software so GitHub actions is a cicd system that GitHub offers and if you use GitHub repositories for public open source projects you're able to use get up actions for free and this is important because open source projects can choose get up actions they don't have to pay anything but if they use another platform they have to pay money so typically that's what they choose for their tests and often
their releases so I'm going to quickly give an overview of how workflows are in GitHub actions other platforms might call them pipelines but GitHub calls them workflows so workflows are initialized by certain triggers these are all handled by GitHub and happen on github's side of their shared responsibility model so this could be something obvious such as pushing code to a branch or pushing code to a main the primary branch of the repository but there's also triggers that relate to Common interactions as part of Open Source development this could be creating a poll request just cre
creating one creating an issue commenting on a poll request or commenting on an issue you get the picture there's also conditionals that are can be associated with jobs and workflows and these are also handled by GitHub now when a job is initialized and I consider a job as the lowest unit of computation when it comes to looking at gith up Action Security boundaries this is because when a job starts it gets some tokens that are used for internal communication and then also if someone using secrets with those jobs the secrets are sent to the runner
be it self-hosted or on github's infrastructure at that time so if someone is able to get code execution within a single step in a job there are many ways they can get the secrets from the whole job and compromise the output of the job so effectively compromising a single step is compromising the entire job when it comes to the GI up actions security boundary this is important because a lot of the vulnerabilities I'm going to show you later involve compromising a step and then compromising everything from the job so what kind of vulnerabilities are you
going to encounter first I'm going to talk about injection now this is a vulnerability class that's been around for as long as get of actions has been around and it's interesting because it's very easy for developers to introduce it because writing their workflows in this manner is the path of least resistance because of that it's also easy to identify this with static analysis let's St let's look at how this works so in this case you have a workflow with has a run step that's referencing a comment body using a giup actions context expression when this
runs that comment will be expanded into a temp temporary shell script that the GitHub actions Runner executes so if someone makes a comment that's essentially A bash expansion variable payload you could see how this will lead to arbitrary code execution within that step and therefore that job if someone makes a malicious comment and this this is your textbook more simple example of injection so what kind of payload would they use well this is a payload that I've used countless times within my proofer Concepts and what it does is it essentially pulls down a python script
that a security researcher named Nikita stupin wrote and he did a lot of original research with this vulnerability class and I simply added some grip statements to it and basic en code it to save it off then I simply send it off to my exfiltration URL and the final thing it does is I sleep this is important because that GitHub token is only valid for the duration of the job so if I want to do Post exploitation operations with it I need to extend its lifetime another class is called a phone request phone requests run
on a variety of different triggers typically it's it's one of these three but it could be other ones but they're more obscure cases for a pone reest to be a vulnerability what needs to happen is the code needs to run on one of these triggers then the workflow needs to in some form check out code from the fork pull request meaning externally controlled code that the maintainer does not know about then it needs to in again in some form run code from that poll request be through a script or a more subtle means when all
this happens you've got a vulnerability when it comes to checking out code there's the obvious ways so if anyone's using have actions before there's an actions checkout reusable action that if you pass the polar request head shot it's going to check that out there's also using the GitHub CLI within a workflow these are all obvious but then you'll sometimes find workflows that do it in a more obscure Manner and this can sometimes present challenges for static analysis because you'll have some code that pulls information about the pull request formats it in some way saves it
off to a variable and then another step in the job will use it with a checkout so the end result will be the same but finding it will be a bit different with when looking at checkouts sometimes you can also see time of check issues so you'll sometimes encounter workflows that have a maintainer approval requirement because the maintainer knows that when a fork polar Crest runs on a privileged workflow it could conin arbitrary code so they add some kind of approval requirement like adding such as adding a label or making sure that only the maintainer
can trigger the workflow via their comment then it'll the mistake will be that they're going to check out code from the pull request using a branch the problem is a branch is a mutable reference so if an attacker exploits the race window by updating their pull request after the approve maintainer has approved it the workflow will now end up running unreviewed code and you have the same result as a phone request just bypassing the approval requirement there so that's something to watch out for when it comes to running code finally and this is the last
step for it to be a vulnerability the workflow has to run it because if you check how untrusted Cod without running it there's nothing wrong there are obvious ways like running running a script and then also obvious ways like npm install I think that's been understood quite well now but then there are more obscure cases and this usually relates to how GI up actions works so giup actions there are a lot of reusable tools such for different languages such as the setup Ruby action this is essentially a reusable action that sets up the environment for
running or in installing Ruby code in this case there's an optional flag called bundler cache if that's set to true then under the hood it will call the bundler command and that's the and that if you're familiar with Ruby will use the gem file within the gem file you can add a system command and that lets you run arbitrary bash code so that's just one example of a way that you can end up running code without without realizing that you actually are in a privileged workflow and there are many more examples boost security which is
a company that has done a bit of research in this uh they have a good resource called living off the pipeline I really like it uh it's worth checking out if you're looking for tools to escalate privileges after in workflows so let's look at an example in the wild and see how it looks and this is going to be a phone request can you see where the injection Point here is this workflow uses a locally reference action so under the watch exact directory here you're going to see an action. yaml file and if if an
attacker modifies that to contain their own code they can run arbitrary code within this workflow so let's I'm going to show you how I found one of these vulnerabilities and then created a proof of concept with of it using gate X so this is a proof of concept that I did against composable Finance they're actually now banned from uh web 3bg Bon platform called immuni because of how they handled my report so it was interesting to see that but here you can see I'm running G and I'm running against their whole organization so it takes
a second and then it prints some output now this is pretty verbose but the idea here is to give someone who's some familiar with this technique enough context to determine if something's worth investigating or not so here I'm very certain now that it's checking out code from the fork pull request so I'm going to go ahead and show you that same place in the code so I open that PR workflow file and I scroll down and you can see here that it's running it's that same command that got to X picked out is potentially interesting
so there's the sync in watch exec and then there's the checkout right before it so now the next thing I'm going to show you is a video of me exploiting this this is what I sent to composable finance when they didn't believe my initial proof of concept they said oh you hacked hetner I'm like no I this is how I got on your machine so I'm going to go ahead and create a pull request and I'm just going to update the title real quick set it to a draft pull request and for get up actions
attacks draft pull request is important because when you make a draft pull request it doesn't notify the maintainers that something's ready for review because you don't want someone to look at your exploit so here I'm just going to say test for PC and what I'm doing here in this is I'm just adding my public key to their authorized Keys file because it just happens to be a non-al self foled Runner that they're running the SPO request test on has nothing to do with phone requests in general but this is why that payload worked in this
case so at this point the workflow started there's a lot of jobs in this workflow and jobs can happen serially or in parallel depending on how the workflow is configured so here you can see their header runnner is queued okay now it picks it up and at this point you could see my IPA call and some other LS command that I ran here now I'm going to jump forward just a bit because the next thing I do is I take that IP address and just SSH into it so I'm just going to quickly copy and
paste that over there and you're going to see that I can once iump for more all right so I'm I'm going to basically log into this machine and see that work so I was able to get on their Runner using by uploading my public key so that's just an example of how a phone request can read lead to uh compromise now if you want to take this tool and find these kind of vulnerabilities by yourself here are two commands that I've used extensively during bug bounty hunting I mean I've made a lot of money just
using these two commands so it works if you run these you'll find issues I promise you uh and what this does is it pulls a set of candidate repositories using Source graph and then runs deep analysis on it all right now let's get to the real case studies for my first case study I'm going to talk about puppet Forge so puppet Forge if you're not familiar with it is a package repository for the puppet infrastructure Code system so it's running in a privileged area the way they release their official modules is that they build them
on GitHub and release them to puppet forge on puppet Forge there's Community develop modules and then the official ones I'm focusing on the official ones here and these often include modules like the standard lib which other puppet modules even Community ones will build off of so there's a lot of exposure here and there's a lot of downloads the way Puppet Labs had their cicd configured was that they had a central repository called cat kup actions and that contained a lot of reusable workflows that these module repositories referenced and this is how they centralized their configuration
and the releases workflows were set up similarly and when I looked at the release workflow they were using a puppet Forge API token to push those releases and that's going to be interesting to to note later so remember that now this is an example of a workflow present within the Puppet Labs SQL Server module Repository clearly we can see here that it runs on pull request Target and then it references a mend workflow mend is a static analysis tool which is supposedly should be increasing security but let's see what happens inside that workflow all right
so now we're in the mend Ruby workflow called from popit Lab SQL server within this you can see that it's doing some logic to get a ref and then it's calling actions checkout it does call setup Ruby but don't it's not important here because later it calls bundle lock I talked about bundler so this is the same example where the gem file is the injection point so I can use it to capture secrets and the GitHub token from that workflow unfortunately it turned out that they were using the old default setting of GI up of
the giup token that had broad WR permissions there's a lot of nuance to each scope but for this case study the two Scopes that were relevant are going to be actions right and contents right content cont right allows someone to make new branches or modify code with the exception of they can't modify workflow files and they can't modify any protected branches but it provides a broad privilege for off for malicious actions the next thing is the actions right actions rights is interesting because that privilege on the token allows you to create workflow dispatch events using
github's API when you create a workflow dispatch event you can create it against any branch so I could make it I make that event against the branch that I just created with contents right that's exactly what I did so that workflow here references something called This is the release workflow that I talked about so it's here we're in the module release reusable called workflow now there's something interesting going on here this workflow is not checking out and running code from the branch but it's doing something else it's reading a variable out of a metadata. Json
file it's then saving it off to another variable and then setting it to get up output that's essentially a file that is more internal to get up actions Runner that lets you pass information between steps and then in the final step it's referencing it using that same GitHub actions context variable expression that means it's susceptible to injection so I was actually able to get arbitrary code execution in this work work flow using a specially crafted version string with the same curl pipe to bash payload it works really well so I was able to create a
branch and issue a dispatch event to it so what happens next well I did get the puppet 4 JPI token but the final thing I wanted to prove was that I had the Privileges to modify any puppet Forge module not just puppet lab SQL Server so I made a fork of the Puppet Labs XZ scanner the XZ scanner module was used was a small module released to identify backdoored versions of the XC utils Library so I found it was interesting if I could backo something that looks for a back door but so I added I
added the puppet Forge API token to my Fork then I made a small readme change the final thing I did was I triggered the release workflow within my Fork again this because this is in my Fork they don't have any visibility to this the only thing that puppet could see at this point is that someone ran a workflow and it turns out that it worked I was able to prove that I could backd door every single puppet Forge module with that API token that is pretty extreme impact any company using puppet for automation that's pulling
modules from Puppet Forge especially if they're pulling any modules by the latest tag version meaning there's no bake time before they end up pulling in the latest version would mean I could get direct access to their infrastructure and deploy rans somewhere or pretty much whatever I wanted this attack would also be very widespread and it would be hard for anyone to control where it went because and that's just the nature of supply chain attacks so it makes you wonder if something like this is so easy it just takes a basic some moderate knowledge of gith
up actions knowledge of how language tools work and you could have this level of impact without much else perhaps actors who only want to cause destruction might be interested in that should give people concern because if it's this easy to cause so much damage someone could one day decide that that's what they want to do with it so it's good to be protected what are some important things to take away from this well well I think everyone knows that hard-coded SEC excuse me long lived secrets are bad and that when you use the same secret
for all your releases that's a single point of failure but then it's those little things that also come into play often within any system you'll have a lot of vulnerabilities that might not be considered vulnerabilities on their own but when you put them together as part of an initial compromise meaning that phone request that I exploited to get the initial gith up token that could CH and end up leading to a critical compromise had puppet restricted the get up token permissions then the worst this initial vulnerability would have been would have been a low-risk informational
disclosure of their men token it would have stopped there but it didn't because of the lack of defense and depth and finally these attacks are not hard it took me all of five minutes to do that initial proof of concept now what if someone could go ahead and back door releases from a major company not puppet maybe they want to attack companies that are more on The Cutting Edge what would happen there well the next case study I'm going to talk about is brand new no one's seen anything about it outside of a couple teaser
tweets that I've made before rom hack so I hope everyone enjoys this one next one is maybe not surprising to a lot of people but I'm going to be talking about Azure all right well let me finish it first all right so this vulnerability started off with injection in a small repository called Azure AI CLI that had just become public maybe hours or maybe a day before I had found the vulnerability when I saw it I was very excited so there was actually a lot wrong with this one there were all of four injection points
within that workflow with for arbitrary code execution in it and it ended up using some pretty interesting Secrets One for Azure devops and one GitHub personal access token at least that's what the name said I jumped on it very quickly and I made a pro of concept now this is very similar to the injection I've described earlier it's just formatted a bit differently because it was Linux Powershell so I use the same payload as well so that let me get the secrets and there was an Azure Dev token and there was also that g up
personal access token but when you look closer that says GHP so tokens with the GHP uh prefix are classic G up personal access tokens meaning they belong to the user that created them not and they have are not under control by an organization and they are also pretty easy to enumerate with there's no audit log events when you enumerate so I was pretty happy when I saw this and I knew I'd probably have a lot of access and there was one problem though after I created my proof of concept now there's something showing exactly how
to get a fairly privileged token from a Microsoft from an Azure own repository so what I do here well it turns out that that token belonged to the maintainer of the repo who was also an admin and administrators of repositories have the ability to delete issues this something it's odd that only admins SC because people who make issues can't but there was a quirk here that I only had a token so I ended up looking around and there was actually an obscure graphql mutation that you could use to delete because GI up hasn't released a
rest API endpoint for that same functionality but that was simple enough here's an example of what that mutation is and I went ahead and deleted the issue if you go there right now you'll see the same thing um and that also hid the evidence as anything happened which helped justify the impact of thisiss so how have I got where what have I done so far I found injection and then I got some Secrets I could have P tried to Pivot to Azure devops but I didn't and then I was able to clean up after myself
but things really got interesting with the final step looking at what I can get and how I could have customer impact because that's how what I need to prove something impactful so I used what was then the original version of gate it's now got X now but the token was valid and it had the repel scope and it was the user was a member of a few organizations there was some limitation here though it turns out that Microsoft for all of their GitHub tenants enables and enforces something called GitHub Sam saml S SSO this means
that any sessions or tokens created by Microsoft organization members if they want to have access to the that tenant they need to go through saml authentication flow with the linked identity provider that Microsoft uses in this case it's Android ID so that was a bit so I only had access to Azure not the other tenants now the scope here gave me pretty broad flexibility repo scope is fairly common when you have a compromise token because it provides fairly broad access to repositories but it's basically on behalf of that user so you don't get anything else
so you uh that's key to note there because the repo scope could let you do admin actions but if the user isn't an admin on any repository you can't the there's also some access to the organization but one of the primary limitations of just the repo scope is that you can't make modifications to workflow files otherwise I could just steal Secrets by making a modified workflow file and then you having it use the secrets and then stealing them directly however you can trigger new workflow runs using events that the token can perform already such as
making a pushing to a branch or uh workflow dispatch so there's a lot of flexibility there all right so how does SLE SSO work is important to understand this as a defensive mitigation and how it's so powerful to protect you now if someone logs into GitHub or with their personal account and wants to access resources associated with their employer that has samso enabled and enforced they're going to have to go through that authentication flow so without it they can't access any private resources or do any changes make any changes to organization own public repositories if
they don't go ahead and do that flow the only thing they can do with their accounts access is read public repositories so it creates this firewall between employer owned assets and assets that they have with their personal GitHub account for anyone on the red team side what that wants to do Recon this is a way you can check if a GitHub organization has saml SSO enabled you just go to that URL and then when you hit that continue button you get redirected to their identity provider so it's a great way to find out what someone's
using say you're trying to prepare a fishing scenario against developers all right what access that I have and what could I do with it well here's a breakdown of repositories and various star counts of it that this token had access to because that account had access to it there were a lot of public repos and most interestingly the all of azure's Open Source sdks fell within that and this was due to a certain team membership that the user had now the disclosure for this went pretty well so back in Spring I submitted a report they
quickly actioned it and removed the vulnerable workflows and then they marked everything as fixed and I got an email shortly after saying it was deemed to be important elevation of privilege and I was like I I think this might be more than important and surprisingly I was shocked I actually was able to convince msrc that it's critical and they upgraded it which I was like I didn't know that was possible but it happened and here's what I did to convince them well I didn't do anything I just showed them what I could do now in
this case one of the repositories that the user had access to was called Azure communication UI Library it had a decent number of downloads on npm because it push and it pushed an npm package and so I knew that this was a good amount of impact to Microsoft customers and it would be direct so I started off by looking at the release process that this repository used I quickly noticed that they had a long live credential in the F form of a Azure devops token and an Azure service Principal Secret so if you're not familiar
with how Azure Works a service principle secret is essentially like an access key that gives you long lived access until someone revokes it so similar to like you know access keys from another cloud provider and that was interesting cuz I knew I wanted those and then they had had stage release workflows with different protection levels the production release used something called GitHub deployment environments with a two-person review requirement so essentially if someone created a deployment another person would have to approve it for it to go through so that was interesting now were they actually secure
was there actually any difference between Alpha and fraud when it comes to security no turns out that all of the workflows shared the same step they used that long lift credential to log in and then they uploaded a a built tar file to an Azure blob that's like a bucket and it was the same one for all the pipelines so I was like okay this this is interesting and the next thing that the workflows do is that they trigger a pipeline using that Azure devops token now the only thing different here is that they're passing
a tag for Dev when it's an alpha workflow and they're passing the actual release when it's production so they're using the same pipeline the same credentials to upload the the build binary so it's effectively if I get access to the secrets from the alpha pipeline I can just trigger my own production release and impact their customers this is something that actually happens more often than you think and I've seen it quite a bit with GI up actions misconfiguration ations where the it's just imagined it's just a facade that makes someone think that there's security and
then someone with the access to the least privileged pipeline can just push to production if they can just inject arbitrary code into it so this is what I would do if I actually wanted to carry this attack out and this actually would be pretty similar to what happened with uh Puppet Labs so in the main difference here is that I instead of having a GitHub token I have a repo scope classic personal access token so I could just make the branch and then trigger a release and because while it's building it's calling code I would
just get arbitrary code execution there and get the secrets stop the workflow early and I could trigger a production release and end up having the package on npm I didn't do that but it would be very easy now the fix for this is that now the workflow doesn't use long lift credentials they use something called oidc Federation with GitHub actions I and essentially what happens here is GitHub will um excuse let's go back here so they'll essentially get a signed claim from GitHub and then present that to Azure and then Azure will create a session
for them so this is a more secure way of authenticating than having a Long Live service principal key they also added additional approval requirements to even the alpha pipeline so someone couldn't just create a branch with modified code and trigger a workflow on it using that GitHub token so that was good to see as long-term mitigations for this for this vulnerability so again what can you take out out of this again manage your secrets and sometimes when it comes to looking at your attack service it's not just the repositories that have the most amount of
stars the most people using it sometimes it's like those new repos that just become public it's a form of Shadow it where someone can leak a credential or have a credential that can be easily stolen and that could have outsized impact to other repositories and then when looking at how many users have right access to repo if someone's not actively developing on it especially for public repos they might not need right access because in GitHub right access to a repository is very powerful now there was one thing I'm not done yet yeah that happened so
that token stayed valid for four over four months until I told them and this actually again happens more than you think it's not just Microsoft I've had it happen at least three or four times this is because of github's bring your own account approach where people onboard your their own GitHub accounts to their employer organization instead of having an account created for them there is a feature in get up for that but it's only for private repositories so it's a whole different thing to go into another thing here is because you bring your own account
the tokens also belong to your account your employer actually has no way of revoking a classic personal access token belonging to your account unless they have your credentials so if you have a leak credential situation you employers only have a few options they can go and try to get the person to revoke the token and that might not always be possible especially in the case of ir where you can't reveal information about what's going on to someone that doesn't have a need to know if it's privileged so that could be a factor you could commit
it to a public repo or a public Guist and GitHub will Auto revoke it which is kind of ridiculous but that is actually the fastest and only way right now uh or there's another way for only if you have saml SSO enabled and enforced you can just specifically revoke the saml so grant for that token and this is an example where this would really work say you suspect someone has a leaked token you don't know what the token is and the person that might have had the token leaked is on vacation and they don't have
their phone with them or you'll get yelled at if you contact them what do you do one option and I think this is where a lot of people would jump to and maybe it's appropriate is that they would just remove the user quickly from the organization and this would remove all their access and their tokens access and it but the downside here is it would break a lot of things if the user has scheduled workflows that are running as part of automation if they're members of any teams all of that would break and that could
potentially require a lot of work to fix the other option is to go and get that specific Grant and revoke it that will just make it so that the token can no longer access the organization or even the web session can't so uh and in say resetting their credentials that could create a good protection without having to kick them out of the organization imagine if you got fired when someone got malware installed on your laptop now here's how you can do it so and this isn't obvious because I've talked to a lot of people that
don't know this is even possible so as an org admin you can list all of the credential authorizations linked to a particular GitHub user in your your organization that'll give you some IDs and with those IDs you you'll also see the last eight characters I believe of the personal access token and then you can use it to specifically delete the samle SSO Grant associated with that session or personal access token so that's a way that's a way you can mitigate blast radius without having to KCK them out of an org now some of you might
be saying wait didn't you say in SDK that was a library it was small but yeah I did say an SDK if anyone saw my Twitter so let's let's see what happens next that's one of the sdks now let's fast forward a bit so the token's still valid but Azure is also since maybe related to this maybe not added some more protections to a lot of their SDK repos but I wanted to show some impact so I noticed that one of the sdks the python one I showed had a gap in one of their protections
so in GitHub there's something called the code owner protection rule set now the way this works is that when someone creates a pull request and modifies a specific file and that file is listed within the code owner's file and that rule set is active then it'll request those all the code owners to review the pull request one of those code owners needs to review the pull request in order for the normal merge to go through so if it's just one approver then that approver can approve it and merge it and then it's just like falls
back to the normal merge approval requirements this is really good for protecting more sensitive files in a repository so there's one issue Gib specifically calls out that when you have the code owner protection rule set you should also make sure that the code owner's file itself falls under a rule set because otherwise anyone with right access to the repository could simply make a pull request to change that file and then move merge it so this unfortunately for the python SDK repo it didn't have that and this is how the bypass worked for this repository so
you can't create and approve your own create and merge your own approve and merge your own pull request because of the other protection rules however I can just it's a public repo I can make a pull request to my attacker account then this particular repository also used a check enforcer which was linked into the branch protections which meant unit test had to pass in order for the merge to to go through but they also implemented a bypass where you could just comment override and it would just say you're good to go so nothing to see
there the final step use the token to approve and merge at this point I could go ahead with my attacker account and make a new pull request to modify any file within the repository and merge that in as well so I could add malware to their sdk's main branch now to Pro prove it out you can see that override over there and that's the PLL request I used and was in July 28th I approved and merged it with that token that I controlled for I guess it turned out to be a few months and then
it went through so at this point I've merged a small benign change to the code owners file of the Azure python SDK commenting out a couple files those files are important because some of them hold configurations for the internal Azure pipelines that this uh Team used so I had at this point very broad access and I could probably do a lot more what would and I at this point I stopped but what could I have done well I could have taken the gon XZ route and added an OB fiscated back door and then I would
just have to hide in plain sight for a small period of time because sdks have Rapid Release Cadence and then could attack Azure users or I could have modified configuration for internal Azure devops pipelines such as those that push the to pipie then I would just wait until they run and see if I could steal secrets from them and try to Pivot internally I wouldn't really know what Secrets I'd have on where I'd land so it' have to be pretty crafty with my exfiltration to make sure I don't trip alarms and uh stop the stop
the exploit but again all this is theoretical because this this was probably getting too far at this point but there are a lot of options so there's also some other techniques there's self-hosted Runner takeover and I spoke about this at length at black hat so there's not you don't have time to cover that here but the general idea here is that workflows on Fork pull requests run in the context of the fork head Branch when it comes to what code is executing so someone can become a contributor by fixing a typo and that if that
that settings also default then they can get arbitrary code execution and persist on attached non-al cell fulid Runners and that opens up a whole range of attack path so if you're interested in that definitely check out the talks next there's gith up actions cash poisoning this isn't a vulnerability by itself but it's a privilege escalation technique and I'm I was able to actually show that I could have used it to backo a package for kex which is a latek rendering uh library and it has quite a few weekly downloads on PM so the way get
up action caching works is that it's again it's used to speed up builds but it's there's a reusable action called actions cach that is how most people use it but there's also language specific reasonable actions that have caching as an option I talked about that earlier some even such as setup go will have it on by default and you have to force disable it if you don't want caching and then there's also a limit on how big the cash can get per repository so if it exceeds a certain size then GitHub will typically run a
nightly eviction job where it will remove the most recently the least recently used cash entries and this is important because if a cash entry is present you can't just override it in terms of the security boundary the branch where a workflow runs determines how cash poisoning what you can jump to so the main branch or the default Branch depending on what the repository has configured is what every cach will bubble up to if it doesn't have a hit on itself so say someone makes a feature branch and it checks if there's a cash entry if
if that's not there then it's going to go up to the main branch so when you have a hit that's how you can move laterally and I'm going to go into that a bit later and the way it handles cash keying and cash versioning those are the two values that GitHub uses to differentiate cach entries in addition to a branch those are just free form strings and they're all handled on the client side so when you're setting one you can set it to whatever you want so here's an example of a cache hit so you
can see the key there and the version is calculated it's not you don't see it but it's it's just a combination of the version of the cache toolkit and and the OS that's having a cache hit on so if there is a cach hit it'll download it but the way it extracts it is that it's just a tar tcsd archive so it also if you notice it has the- P flag which is preserve paths that means a cash hit on a poison cache is effectively arbitrary file right in the consuming workflow and that is almost
always code execution in get up actions because I can simply overwrite the actions. yaml file associated with the the cleanup step of an action that I that executed and I know one executed because that's how I had a cash hit so it's arbitrary rce in a different workflow that consumes cash if you get code execution in the main branch you can always jump and it's pretty scary how many repositories right now in public have this issue because they think they lock down their phone request the way authentication works and this makes the problem even worse
is that there's a a JWT that is minted when the job starts the problem here is that that it's valid for a very long time and GitHub currently does not revoke it when the job finishes so when you combine that with the 10 gab limit what you do is you fill up the cash to contain a lot of stuff wait for the old entries to get evicted and then set new poisoned entries all within that same six hours which is crazy that it works that way and this is an example of the cash JWT in
the context of kex K deck and you can see that it's associated with the job Branch permission there and if you did math you'd find that that's six hours and that's how it looks like when you just fill up a cash you just fill it with garbage and now you have now you'll wait until the eviction and that'll clear out the reserve cash entries for you to poison now I didn't go through that but if someone wanted to complete this attack they would just craft to payload and then wait until the consuming workflow triggers in
this case it was any push to the main branch and then that because that main branch used npm token to get it and now they could back door a package that has a million weekly downloads the takeaway here and this is the the only fix that the maintainers applied after I reported it is simply not to consume the cash so they technically still have the phone request but they accepted the risk that stealing their browser stack token which is the initial vulnerability is an acceptable risk for their repository all right now where do I think
things are going with this vulnerability class get up actions attacks in general because a lot has changed over the last year even because two years ago you could go out and find just Odes and major companies just sitting there for months but now the landscape's changing tooling is getting a lot better when it comes to identifying and exploiting GI actions vulnerabilities so i i relas gacho x back in back during hacker summer camp in August and that is a fairly powerful tool to detect vulnerabilities that scale you can use it to scan say 5,000 repos
in minutes on with a fast internet connection and it has a higher false positive rate but uh it's tuned to be an operator tool not a SAS tool that cuts tickets but boost security has boutine Sam grap rules are getting better github's working on a big code ql upgrade for actions so that'll probably change things a lot ultimately this will lead to Rapid Discovery already within public repositories if there's a bug Bounty program and there's a pone request committed bug boundy hunters will be on it within hours it probably might even be 30 minutes now
it it's fast it's like subdomain takeover now but there's a caveat here even if a bug Bounty Hunter can identify vulnerability within hours if a malicious hacker jumps on that vulnerability and reports excuse me jumps on that vulnerability and exploits it it doesn't matter because for the hacker there's no duplicate so this will mean that there's more complex cases that require manual analysis and deeper digging to to see if that where for example you might have the vulnerability exist in JavaScript code that's called from a workflow instead of with the workflow file itself so SAS
tools might not pick it up so there's still value in digging deeper when it comes to cicd misconfigurations now if you're a defender or you're someone who wants to prevent these vulnerabilities or you want to what can you do to stop this how can you protect yourself if you have a company that has a big open source footprint or even private Ros because uh if someone gets a developer token compromise a lot of these same attacks apply well learning about these attack classes learning about get up actions learning about what misconfigurations to avoid is very
important a lot especially when it comes to injections or phone request because developers don't need to make a big change to fix it often the fixes for it are one or two lines so it's just a factor of keeping that in mind while developing cicd and then monitoring changes cicd misconfigurations are almost a form of new Shadow it where there's really no oversight to developers when they're updating them they up them they make a change they what their teammates review it it goes through and now they've introduced a vulnerability into the repository because it's not
scrutinized the same way as release code but it's code that does releases so it should be scrutinized if it has privileged Secrets or pushes to customers and finally it's important to have response playbooks ready if you don't have an idea of what to do when you have a pipeline compromise you'll be in the dark and and miss things such as Microsoft and not revoking a token so it's important to have to it's important to know how to scope a pipeline breach and how to respond to it all right thank you very [Applause] much and um
thank you thank you Adnan we have a couple of questions for you so the first one here is um did gab took any action to warn developers who write unsafe workflows okay so if I understand it correctly if I understand the question correctly has GitHub done anything to prevent developers from introducing these vulnerabilities okay so for the most part GitHub has not done any major sweeping changes to limit this vulnerability so they have made some changes for example back in Spring of I think 2023 they made it so the new default for the get up
token is read only but that only applies to repositories or organizations created after that time they also briefly made the cash token valid for 90 minutes but I think they changed it back because it might have broken some some things so it's been minimal they're they're trying GitHub is very afraid to break anything that's just they're very devx and keeping things working focused instead of security and for good reasons they become the company they are because of it yeah and actually we have another one which is how surprised the har most companies when you contact
them the the engineers typically typically companies when it comes to reporting vulnerabilities will not even if they might be surprised internally you're not going to see that that's just how a lot of external contact programs work especially with larger companies because if company says oh my God this is a a very bad vulnerability that could potentially lead to liability if something happened down the road so I think there's a very much like being careful of what you say to in the to a public researcher in that sense but I'm I'm sure some companies are surprised
because I've had I found some pretty pretty impactful issues all right thank you again thank you all right