[00:01.900 --> 00:04.800] All right. Hello, everyone. [00:04.800 --> 00:07.620] All right, let's address the burning question in the room. [00:07.620 --> 00:11.420] No, we did not get access to the source code for Grand Theft Auto VI, [00:11.420 --> 00:13.880] nor do we know if the game will ever be released. [00:13.880 --> 00:16.440] Maybe in the following presentation, but not today. [00:16.860 --> 00:21.280] This is Grand Theft Actions abusing self-hosted GitHub runners at scale. [00:21.840 --> 00:23.240] Hello, everybody. [00:23.580 --> 00:26.780] Before we get started, we read online that as long as we have a disclaimer, [00:26.780 --> 00:29.640] nobody's allowed to sue us, so here we go. [00:29.640 --> 00:32.520] All vulnerabilities mentioned during this talk have been remediated. [00:32.740 --> 00:34.980] The views and opinions expressed are solely our own, [00:34.980 --> 00:37.080] and the content is not endorsed by, [00:37.080 --> 00:39.020] nor does it represent the views of our employers. [00:40.080 --> 00:42.140] All right. Whoa, there we go. [00:42.320 --> 00:44.060] Adnan, I think we're good to go. [00:46.900 --> 00:50.600] All right, if you're wondering about us, so my name is Adnan Khan. [00:50.600 --> 00:52.900] For my day job, I work as a security engineer. [00:52.900 --> 00:56.000] I'm also a security researcher and bug bounty hunter on the side, [00:56.000 --> 00:57.920] and you can find some of my socials below. [00:57.920 --> 00:59.800] My name is John Stawinski. [00:59.800 --> 01:01.940] I'm a red team security engineer at Praetorian. [01:02.120 --> 01:05.280] I also do CICD security research on the side. [01:05.320 --> 01:08.640] In the last year, I've watched Avatar the Last Airbender three times, [01:08.640 --> 01:12.520] the animated version, and in a past life, I was a collegiate wrestler. [01:13.900 --> 01:14.900] All right. [01:14.920 --> 01:18.280] All right, so we're going to be talking a lot about self-hosted runners today, [01:18.280 --> 01:20.400] so I want to make sure everyone has a background understanding [01:20.400 --> 01:22.040] of how GitHub runners work. [01:22.040 --> 01:24.360] On one side, you have GitHub-hosted runners. [01:24.360 --> 01:27.160] These are built by GitHub, updated frequently, [01:27.160 --> 01:30.980] and as of writing, cover a wide variety of operating systems and architectures. [01:30.980 --> 01:35.220] The key thing with GitHub-hosted runners is that they are ephemeral, [01:35.220 --> 01:38.900] meaning they are torn down at the conclusion of each workflow job. [01:38.900 --> 01:41.600] On the other hand, you have self-hosted runners. [01:41.600 --> 01:45.320] These are managed and secured entirely by the end user, [01:45.320 --> 01:49.080] and it's not surprising here that the path of least resistance [01:49.080 --> 01:51.880] when configuring one of these self-hosted runners [01:51.880 --> 01:56.500] is a non-ephemeral self-hosted runner that is actually the least secure. [01:56.500 --> 02:01.180] Both GitHub-hosted and self-hosted runners work to service GitHub Actions workflows [02:01.180 --> 02:04.060] that are triggered from repositories on GitHub. [02:04.720 --> 02:06.460] So, why are we here today? [02:06.460 --> 02:10.260] Well, all the organizations and projects that you see on the screen here [02:10.260 --> 02:15.300] use or at one point use self-hosted runners on their public GitHub repositories. [02:15.300 --> 02:18.040] Not only that, but they use them in an insecure manner, [02:18.040 --> 02:21.180] and over the last 12 months, we were able to identify vulnerabilities [02:21.180 --> 02:24.880] in these organizations and many more that we can't talk about. [02:24.880 --> 02:29.340] Some of these cases could have led to widespread critical supply chain attacks. [02:30.320 --> 02:34.800] You may be wondering if we just showed that last slide to flex our cool bones at DEF CON, [02:34.800 --> 02:39.480] and I just want to go on record saying that, yeah, pretty much. [02:39.660 --> 02:42.360] But it also raises a bigger question. [02:42.360 --> 02:46.520] Why were we in a position to execute supply chain attacks on all of these companies? [02:46.520 --> 02:50.840] And the reason behind that is that GitHub Actions provides this broad attack surface [02:50.840 --> 02:53.520] that exposes these organizations to compromise, [02:53.520 --> 02:56.380] especially when they use self-hosted runners. [02:57.360 --> 03:01.440] All right, so how do we get started with our vulnerability research campaign? [03:01.440 --> 03:04.540] Well, it all started all the way back in August of 2022 [03:04.540 --> 03:07.980] when I was working on a red team with my former employer. [03:07.980 --> 03:09.600] I was fairly new to red teaming at the time, [03:09.600 --> 03:11.900] and I tripped a canary and got us kicked out of the client network. [03:11.900 --> 03:13.460] Maybe that's happened to some of y'all. [03:13.720 --> 03:16.200] But while trying to get back in, we did some social engineering, [03:16.200 --> 03:19.200] and I found that we could use a GitHub access token that we obtained [03:19.200 --> 03:22.700] to execute a workflow and persist on a non-ephemeral self-hosted runner [03:22.700 --> 03:24.240] inside that client's network. [03:24.240 --> 03:26.520] And that got us back in, and we reached objective. [03:26.600 --> 03:30.080] That led to a talk at ShmooCon called Phantom of the Pipeline [03:30.080 --> 03:31.960] that was given in January of 2023, [03:31.960 --> 03:34.780] and the release of the original Gato tool. [03:35.520 --> 03:40.300] Around the time that Anand, Mason Davis, and Matt Chakassi were developing Gato, [03:40.300 --> 03:43.300] I joined them on the red team, and Gato was my entry to CICD security. [03:43.300 --> 03:46.720] So I started using Gato to identify GitHub Actions vulnerabilities [03:46.720 --> 03:48.380] during red team engagements. [03:48.380 --> 03:51.820] And then we started diving deeper into GitHub Actions abuse, [03:51.820 --> 03:53.940] especially around post-exploitation. [03:54.080 --> 03:55.240] And as we were doing our research, [03:55.240 --> 03:57.800] we were trying to brainstorm ways to blow this up [03:57.800 --> 04:01.300] and bring it from internal red team engagements to everybody. [04:01.300 --> 04:04.220] And Anand had an idea that really took it to the next level. [04:04.420 --> 04:07.520] So one of the little asterisks at the end of the ShmooCon presentation [04:07.520 --> 04:10.460] was that if you fixed a typo on a public repository [04:10.460 --> 04:13.000] that was using a non-ephemeral self-hosted runner, [04:13.000 --> 04:15.620] you could just make a pull request and modify the workflow file [04:15.620 --> 04:16.900] and get persistence. [04:16.900 --> 04:20.140] I demonstrated that vulnerability against GitHub Actions [04:20.140 --> 04:21.780] runner images repository, [04:21.780 --> 04:24.560] which was accepted as a critical vulnerability. [04:25.780 --> 04:28.360] After Anand hacked GitHub Actions runner images, [04:28.360 --> 04:30.940] we started looking at all public repositories [04:30.940 --> 04:33.300] and realized that these misconfigurations were everywhere. [04:33.300 --> 04:34.820] So we decided to team up. [04:34.820 --> 04:37.660] Our first joint operation was breaching Microsoft's perimeter [04:37.660 --> 04:40.100] by getting code execution on a domain-joined machine [04:40.100 --> 04:41.780] through Microsoft DeepSpeed. [04:41.780 --> 04:44.940] And then we launched a series of attacks, [04:44.940 --> 04:47.920] the next one of which we will cover today. [04:47.920 --> 04:49.920] Alright, so at a high level, [04:49.920 --> 04:53.340] there's three steps to discovering this vulnerability at scale. [04:53.340 --> 04:56.060] The first step is to search for candidate repositories [04:56.060 --> 04:58.260] that might be using a self-hosted runner. [04:58.260 --> 05:01.140] To do this, we used a combination of GitHub CodeSearch [05:01.140 --> 05:04.040] and Sourcegraph CodeSearch dorks. [05:04.040 --> 05:07.060] Both have pros and cons, so we used both [05:07.060 --> 05:09.820] and deduplicated the results to get a nice list [05:09.820 --> 05:12.460] of candidate repositories for further analysis. [05:12.660 --> 05:16.120] To do this, use the tool that's open source right now [05:16.120 --> 05:17.440] called GatoX. [05:17.440 --> 05:20.040] It uses automated workflow run log analysis [05:20.040 --> 05:21.780] to determine if there's a non-ephemeral [05:21.780 --> 05:23.440] self-hosted runner in use. [05:23.440 --> 05:26.560] Once you have the results, you can plan your next step, [05:26.560 --> 05:28.580] which is essentially, can you hack it [05:28.580 --> 05:30.820] and can you hack it for some good impact? [05:31.940 --> 05:35.160] Self-hosted runner takeover is a special case [05:35.160 --> 05:37.840] of public Poison Pipeline execution. [05:37.840 --> 05:40.120] So, Poison Pipeline execution at a high level [05:40.120 --> 05:42.440] is anytime you can get your own code executed [05:42.960 --> 05:44.940] by a GitHub Actions workflow, [05:44.940 --> 05:47.180] you can conduct a Poison Pipeline attack. [05:47.180 --> 05:48.620] In the case of self-hosted runner, [05:48.620 --> 05:50.080] we'll use this to deploy persistence [05:50.080 --> 05:51.980] on the self-hosted runner via a pull request [05:51.980 --> 05:54.860] and that opens up a ton of lateral movement [05:54.860 --> 05:56.340] and privilege escalation paths. [05:56.340 --> 05:58.620] So, the first two aspects of this diagram [05:58.620 --> 05:59.920] are pretty straightforward. [06:00.040 --> 06:03.260] This last section, the GitHub Actions post-exploitation, [06:03.260 --> 06:05.280] is where we focus most of our research. [06:06.040 --> 06:08.820] Alright, so it's a tale as old as Unix time itself. [06:09.160 --> 06:12.000] Misconfigurations are amplified by insecure defaults. [06:12.140 --> 06:15.040] So, the default setting for a pull request approval [06:15.040 --> 06:16.400] on the pull request trigger [06:16.400 --> 06:18.420] is that it only requires approval [06:18.420 --> 06:20.720] for first-time contributors. [06:20.720 --> 06:22.200] So, if someone has a pull request, [06:22.200 --> 06:23.420] no matter how trivial, [06:23.420 --> 06:24.960] merged into the default branch, [06:24.960 --> 06:27.600] they won't need approval for workload executions [06:27.600 --> 06:29.380] on their pull requests. [06:29.640 --> 06:32.740] This is that bad insecure default. [06:34.440 --> 06:37.580] Today, we're going to walk through playing with fire, [06:37.580 --> 06:39.840] which is what we've called our supply chain attack [06:39.840 --> 06:41.600] on the PyTorch repository, [06:41.600 --> 06:44.580] which began by compromising self-hosted runners. [06:44.580 --> 06:46.960] This is one of our more complex and more... [06:47.440 --> 06:48.740] more intricate attacks, [06:48.740 --> 06:49.960] so we're going to use it as a case study [06:49.960 --> 06:52.620] to teach technical TTPs of GitHub Actions [06:52.620 --> 06:55.200] exploitation and post-exploitation as we go. [06:55.700 --> 06:57.760] Alright, so, what is PyTorch? [06:57.760 --> 06:59.260] I'm sure a lot of you already know what it is, [06:59.260 --> 07:00.420] but it's a machine learning framer [07:00.420 --> 07:03.020] originally developed by Meta that's been open-sourced, [07:03.020 --> 07:04.700] and it's used by companies around the world [07:04.700 --> 07:07.400] like Google, Lockheed Martin, OpenAI, and more. [07:07.400 --> 07:09.280] If someone were to backdoor PyTorch, [07:09.280 --> 07:10.980] this could allow compromising developers [07:10.980 --> 07:12.960] and organizations in that very much [07:12.960 --> 07:15.320] red-hot AIML space right now. [07:16.040 --> 07:18.180] In all seriousness, [07:18.500 --> 07:20.820] probably the hardest part of compromising PyTorch [07:20.820 --> 07:23.460] was searching through their workflows. [07:23.460 --> 07:26.180] They had something like over 90 workflows, [07:26.180 --> 07:27.740] over 15 GitHub secrets, [07:27.740 --> 07:29.320] and more than five self-hosted runners [07:29.320 --> 07:31.080] on their public repository. [07:31.240 --> 07:33.500] And I vividly remember sitting at my desk, [07:33.500 --> 07:35.700] I had like three different notebooks out, [07:35.700 --> 07:37.760] and I was manually, pen and paper, [07:37.760 --> 07:39.240] mapping out the data flow [07:39.240 --> 07:40.480] through all these workflows, [07:40.600 --> 07:42.040] a lot of which were nested, [07:42.040 --> 07:43.400] in preparing for this attack, [07:43.400 --> 07:45.400] so that we could try to figure out the potential impact [07:45.400 --> 07:46.880] before we actually started. [07:47.800 --> 07:49.600] When we confirm that a repository [07:49.600 --> 07:51.300] has a self-hosted runner, [07:51.300 --> 07:52.980] we look at the workflow logs, [07:52.980 --> 07:54.440] like Adnan talked about earlier. [07:54.440 --> 07:57.020] So here's an example of the PyTorch repository, [07:57.020 --> 07:58.400] and in this screenshot, [07:58.400 --> 07:59.620] you can see in the workflow log, [07:59.620 --> 08:00.980] it has the runner name, [08:00.980 --> 08:01.840] the runner group name, [08:01.840 --> 08:02.620] and the machine name. [08:02.620 --> 08:04.780] So we see that this is a Jenkins runner, [08:04.780 --> 08:05.680] it's a self-hosted runner [08:05.680 --> 08:07.080] attached to their public repository [08:07.520 --> 08:09.100] in the default group, [08:09.100 --> 08:10.300] and this is one of the runners [08:10.300 --> 08:11.760] that we ended up compromising. [08:12.540 --> 08:15.500] Alright, remember that default approval requirement? [08:15.500 --> 08:17.800] Well, for certain repositories that are very busy, [08:17.800 --> 08:19.180] you can often determine that [08:19.180 --> 08:21.140] just using contextual analysis. [08:21.140 --> 08:21.820] And let me tell you, [08:21.820 --> 08:23.540] PyTorch was very busy. [08:23.540 --> 08:25.420] So what you look for is a pull request [08:25.420 --> 08:26.880] submitted by a previous contributor [08:26.880 --> 08:28.620] that's from a fork pull request. [08:28.620 --> 08:30.400] You check that the workflow run [08:30.400 --> 08:32.220] associated with it was not approved, [08:32.220 --> 08:35.680] and that it ran on the pull request trigger. [08:35.680 --> 08:37.080] When all these things come together, [08:37.080 --> 08:39.360] it's very likely that the default approval requirements [08:39.360 --> 08:40.300] are in place. [08:41.780 --> 08:43.700] GitHub warns against attaching [08:43.700 --> 08:45.580] self-hosted runners to public repositories [08:45.580 --> 08:46.720] for obvious reasons, [08:46.720 --> 08:48.780] but they don't make their documentation [08:48.780 --> 08:49.760] and their warnings obvious, [08:49.760 --> 08:51.080] and you kind of have to go out of your way. [08:51.080 --> 08:52.640] So part of the reason we think that [08:52.640 --> 08:54.900] so many repos publicly use self-hosted runners [08:54.900 --> 08:56.040] is because they don't end up [08:56.040 --> 08:57.420] seeing this documentation. [08:57.800 --> 08:58.720] In this next slide, [08:58.720 --> 09:00.240] we'll just walk through what it looks like [09:00.240 --> 09:01.540] to register a self-hosted runner [09:01.540 --> 09:03.440] and see what documentation [09:03.440 --> 09:05.460] you come across as a developer. [09:06.240 --> 09:07.960] So in my GitHub repository, [09:07.960 --> 09:09.380] I'm going to actions panel, [09:09.380 --> 09:11.140] I'm trying to register a self-hosted runner, [09:11.140 --> 09:12.000] but first, [09:12.000 --> 09:13.280] I'm going to look through their documentation, [09:13.280 --> 09:14.400] because I'm a good developer. [09:14.580 --> 09:16.000] And I click on these links, [09:16.000 --> 09:17.520] I don't see anything security related, [09:17.520 --> 09:18.760] so I click on this other link, [09:18.760 --> 09:20.680] and we get to a lot of GitHub [09:20.680 --> 09:22.560] self-hosted runner documentation. [09:22.600 --> 09:24.820] We learn about auto-scaling, [09:24.820 --> 09:26.200] usage limits, [09:26.200 --> 09:28.180] I think it lists architecture stuff, [09:28.180 --> 09:29.840] and then every API that the runner [09:29.840 --> 09:31.640] is going to use in its lifetime. [09:31.980 --> 09:33.040] And then, [09:33.040 --> 09:34.360] way down here at the bottom, [09:34.360 --> 09:36.480] it talks about self-hosted runner security. [09:36.480 --> 09:38.420] And so, GitHub does clearly say [09:38.420 --> 09:40.240] they don't recommend using [09:40.240 --> 09:42.900] self-hosted GitHub runners on public repositories. [09:42.900 --> 09:44.920] And they have other articles out there, too, [09:44.920 --> 09:47.020] elaborating on this. [09:47.020 --> 09:49.060] But the point we want to drive is [09:49.060 --> 09:50.820] it's not obvious. [09:50.820 --> 09:51.700] So chances are, [09:51.700 --> 09:53.180] if you're just registering a self-hosted runner [09:53.180 --> 09:54.420] to a public repo, [09:54.420 --> 09:56.420] you're not going to come across this documentation. [09:57.260 --> 09:59.520] Alright, the first step was to infiltrate [09:59.520 --> 10:00.820] the contributor list. [10:00.820 --> 10:02.640] This is what's important to take advantage [10:02.640 --> 10:04.520] of those default approval settings. [10:05.120 --> 10:06.880] To infiltrate the contributor list, [10:06.880 --> 10:08.200] if you've been following our blogs at all, [10:08.200 --> 10:09.840] we always call the grammar police. [10:09.840 --> 10:12.180] So the grammar police is me and Adnan. [10:12.180 --> 10:13.220] We show up, [10:13.220 --> 10:15.040] and we run all their markdown files [10:15.040 --> 10:16.240] through Grammarly. [10:16.240 --> 10:18.120] Again, fixing a typo here [10:18.120 --> 10:19.580] and finding a grammatical error [10:19.580 --> 10:20.760] doesn't matter at all. [10:20.760 --> 10:22.580] To become a contributor, [10:22.580 --> 10:24.380] we also could make a legitimate, [10:24.380 --> 10:25.660] substantial code contribution [10:25.660 --> 10:27.260] to the PyTorch repository. [10:27.520 --> 10:29.600] But, that's a lot of work. [10:29.860 --> 10:31.400] So, what we do instead is [10:31.400 --> 10:34.160] we notice resolve was in the past tense, [10:34.160 --> 10:35.640] and it should have been in the present tense. [10:35.640 --> 10:38.180] So, we fix that for them, [10:38.180 --> 10:39.680] we did a pull request, [10:39.680 --> 10:40.460] and a few days later, [10:40.460 --> 10:42.200] it got merged by the maintainers. [10:42.480 --> 10:44.520] And then we are now officially contributors, [10:44.520 --> 10:46.060] which is not a security boundary. [10:46.220 --> 10:47.400] And this is the same process [10:47.400 --> 10:49.120] we did with all of our exploits. [10:49.420 --> 10:51.580] All right, so this is where the hacking starts. [10:51.580 --> 10:53.080] So, the step phase two [10:53.080 --> 10:54.560] was to install command and control [10:54.560 --> 10:56.820] on those non-ephemeral self-hosted runners [10:56.820 --> 10:58.400] attached to PyTorch. [10:58.400 --> 10:59.780] To do this, we leverage something [10:59.780 --> 11:01.880] we like to call runner-on-runner. [11:01.960 --> 11:03.060] In a nutshell, what that is, [11:03.060 --> 11:05.120] is we install another self-hosted runner [11:05.120 --> 11:07.000] on their self-hosted runner. [11:07.000 --> 11:09.160] This has the benefit of sending all traffic [11:09.160 --> 11:11.700] to the same domains and IP addresses [11:11.700 --> 11:14.000] that the original self-hosted runner uses. [11:14.000 --> 11:16.440] So, if there is any EDR or monitoring software [11:16.440 --> 11:17.120] on that runner, [11:17.120 --> 11:18.240] it's very likely that it will fly [11:18.240 --> 11:19.440] right under the radar. [11:19.680 --> 11:21.080] Oh yeah, so remember that default? [11:21.080 --> 11:22.080] This is where those defaults [11:22.080 --> 11:23.680] lead to an actual compromise. [11:23.680 --> 11:25.140] To do this, we just modified [11:25.620 --> 11:26.880] the workflow in our fork [11:26.880 --> 11:29.520] and had it just install our C2. [11:30.180 --> 11:32.100] The second runner is attached [11:32.100 --> 11:33.460] to our private C2 repository, [11:33.460 --> 11:35.740] so we can task it to execute commands. [11:35.740 --> 11:37.340] It's essentially a web shell. [11:37.800 --> 11:39.120] Using this web shell, [11:39.120 --> 11:41.180] we're able to look around the file system [11:41.180 --> 11:43.160] and learn about the host. [11:43.160 --> 11:44.420] And all of this is in preparation [11:44.420 --> 11:46.120] for phase three. [11:46.840 --> 11:49.060] Phase three is the most important phase [11:49.060 --> 11:51.540] of all of our CICD compromise. [11:51.540 --> 11:53.880] So, the great secret heist, [11:54.340 --> 11:56.060] self-hosted runner post-exploitation, [11:56.060 --> 11:58.040] is how you go from trivial RCE [11:58.040 --> 11:59.980] to complete supply chain attack. [11:59.980 --> 12:01.340] And when we started our research, [12:01.340 --> 12:02.240] we submitted some reports [12:02.240 --> 12:03.260] and we saw some reports [12:03.260 --> 12:05.360] where researchers would get code execution [12:05.360 --> 12:06.840] on self-hosted runners, [12:06.840 --> 12:07.760] and then they'd say, [12:07.760 --> 12:08.620] hey, and by the way, [12:08.620 --> 12:09.740] you can probably do all these [12:09.740 --> 12:11.940] theoretical post-exploitation stuff. [12:12.280 --> 12:14.820] And orgs just didn't care at all. [12:14.820 --> 12:15.780] They should care if you're [12:15.780 --> 12:17.040] executing code on the runners, [12:17.040 --> 12:18.760] but it's kind of what they're [12:18.760 --> 12:19.800] supposed to do anyway, [12:19.800 --> 12:20.960] and so they didn't realize [12:20.960 --> 12:22.600] the actual impact of these attacks [12:22.600 --> 12:24.600] unless you go and demonstrate it. [12:24.600 --> 12:26.360] So, that is what we did. [12:26.880 --> 12:28.480] All right, so to understand [12:28.480 --> 12:29.640] how we were able to achieve [12:29.640 --> 12:30.480] some of this impact, [12:30.480 --> 12:31.360] I want to make sure everyone [12:31.360 --> 12:33.440] understands the magical getup token. [12:33.440 --> 12:34.640] So, this is a token [12:34.640 --> 12:37.060] that is used by all getup actions workflows [12:37.060 --> 12:38.380] to authenticate to GitHub [12:38.380 --> 12:40.760] for API or Git operations, [12:40.760 --> 12:42.500] and it's an OAuth bearer token [12:42.500 --> 12:43.700] that has multiple scopes. [12:43.700 --> 12:44.440] Some of these scopes [12:44.440 --> 12:45.620] can be read or write, [12:45.620 --> 12:46.340] and they're configured [12:46.340 --> 12:48.600] at the repository organization level [12:48.600 --> 12:49.720] or specified within [12:49.720 --> 12:51.660] each specific workflow file. [12:52.160 --> 12:54.240] So, it's very important to know [12:54.240 --> 12:56.060] that these tokens are only valid [12:56.060 --> 12:57.680] for the duration of each job [12:57.680 --> 12:58.620] within a workflow. [12:58.620 --> 13:00.300] As soon as that job concludes, [13:00.300 --> 13:01.660] the token is no longer valid. [13:01.660 --> 13:03.280] So, to conduct some of the [13:03.280 --> 13:04.820] post-exploitation attacks here, [13:04.820 --> 13:06.620] we need to work around [13:06.620 --> 13:07.960] this limitation. [13:08.240 --> 13:10.240] So, let's see how PyTorch, [13:10.240 --> 13:12.500] at the time, used or privileged [13:12.500 --> 13:14.060] the getup token. [13:14.480 --> 13:15.800] Okay, so this getup token [13:15.800 --> 13:17.380] has all the right permissions. [13:17.440 --> 13:20.220] This means we can, [13:20.220 --> 13:21.520] we have a lot of options to play with [13:21.520 --> 13:23.240] for some of our post-exploitation, [13:23.240 --> 13:25.120] and also, this runner right here [13:25.120 --> 13:27.300] is the same one that we now have C2 on. [13:28.640 --> 13:30.440] So, when a workflow uses [13:30.440 --> 13:31.600] the actions checkout step [13:31.600 --> 13:32.480] or some other steps, [13:32.480 --> 13:34.380] the getup token is stored on [13:34.380 --> 13:36.180] the self-hosted runner's file system, [13:36.180 --> 13:37.880] which we have compromised. [13:37.880 --> 13:39.660] So, the problem is that getup tokens [13:39.660 --> 13:42.380] from fork PRs only have read permissions. [13:42.520 --> 13:45.160] So, if we tried to take the getup token [13:45.160 --> 13:47.280] from the fork PR we used [13:47.280 --> 13:48.560] to actually implant the runners, [13:48.560 --> 13:49.900] it's pretty much useless to us. [13:49.900 --> 13:52.020] So, the solution is we persist on the runner [13:52.020 --> 13:53.220] and then we capture a token [13:53.220 --> 13:55.000] from a future workflow. [13:55.280 --> 13:56.880] This is the setup we typically see. [13:56.880 --> 13:58.760] We have the workflow from our fork PR, [13:58.760 --> 14:00.220] no access to secrets, [14:00.220 --> 14:02.780] and a getup token with only read permissions. [14:03.500 --> 14:05.360] Then, we have a workflow [14:05.360 --> 14:07.020] from the base repository. [14:07.160 --> 14:09.680] This workflow does have access to secrets [14:09.680 --> 14:11.620] and the getup token has write permissions. [14:11.620 --> 14:13.560] Notice how they both execute [14:13.560 --> 14:15.400] on the same self-hosted runner. [14:15.400 --> 14:16.500] So, this is the reason that [14:16.500 --> 14:18.480] persistent, non-ephemeral, self-hosted [14:18.480 --> 14:19.580] runners are so bad, right? [14:19.580 --> 14:20.640] If the runner's ephemeral [14:20.640 --> 14:22.420] and we implant it, [14:22.420 --> 14:24.120] it doesn't give us much access [14:24.120 --> 14:26.060] beyond secrets on the file system [14:26.060 --> 14:26.960] or something like that. [14:26.960 --> 14:28.900] If it's persistent and long-lived, [14:28.900 --> 14:31.120] then it will execute future workflows. [14:31.120 --> 14:33.060] So, we implant the runner, [14:33.060 --> 14:34.700] then we wait for future workflows [14:34.700 --> 14:36.980] from the base repo to execute on the runner. [14:36.980 --> 14:38.980] This is why we need to install persistence [14:38.980 --> 14:41.080] rather than just showing code execution. [14:41.300 --> 14:42.980] And then we compromise the getup token [14:42.980 --> 14:46.080] and any getup secrets used by subsequent workflows. [14:46.460 --> 14:48.480] So, in the PyTorch attack, [14:48.480 --> 14:50.000] you can see here, this was our [14:50.000 --> 14:52.140] C2 repository, so we were executing [14:52.140 --> 14:53.680] code on their self-hosted runners [14:53.680 --> 14:55.600] and we waited for a future workflow [14:55.600 --> 14:57.220] to execute from the base repo [14:57.220 --> 14:59.840] and then we just print out the getconfig file [14:59.840 --> 15:00.800] at runtime. [15:00.800 --> 15:02.720] So, this base64 encoded token [15:02.720 --> 15:04.960] is that getup token that we were just talking about. [15:04.960 --> 15:06.780] So, we compromised that getup token. [15:06.780 --> 15:07.880] Again, we could only use it [15:07.880 --> 15:09.820] for the duration of the build, [15:09.820 --> 15:12.820] but some of these jobs lasted a long time, [15:12.820 --> 15:14.280] so we were able to use it for a while. [15:14.560 --> 15:15.980] Alright, one of the first things we did [15:15.980 --> 15:17.200] after obtaining the getup token, [15:17.200 --> 15:18.960] which had actions write access, [15:18.960 --> 15:21.460] is we used it to delete the workflow run logs [15:21.460 --> 15:23.320] because if we got caught, [15:23.320 --> 15:25.320] then we likely wouldn't be able to show impact [15:25.320 --> 15:27.420] in order for Meta's triage team to understand [15:27.420 --> 15:29.060] the severity of the submission. [15:30.100 --> 15:31.760] One of the most direct ways [15:31.760 --> 15:33.360] to demonstrate impact with a getup token [15:33.360 --> 15:35.540] is by modifying getup releases. [15:35.540 --> 15:37.420] So, getup releases is just one way [15:37.420 --> 15:39.520] for a user to download [15:39.700 --> 15:42.060] a release of an application from a repository. [15:42.220 --> 15:43.900] What typically will happen [15:43.900 --> 15:45.780] is you can upload getup releases, [15:45.780 --> 15:47.100] so PyTorch uploads releases [15:47.100 --> 15:48.680] to their getup releases page, [15:48.680 --> 15:50.160] and then if you want to download PyTorch, [15:50.160 --> 15:51.340] one of the ways you can do that [15:51.340 --> 15:52.640] is by going to getup releases [15:52.640 --> 15:54.620] and downloading it there. [15:54.620 --> 15:56.580] Depending on the permissions of the getup token, [15:56.580 --> 15:58.620] it can allow you to modify [15:58.620 --> 16:00.780] releases and release assets. [16:00.780 --> 16:02.520] So, you could potentially backdoor [16:02.740 --> 16:04.620] a release asset, upload it, [16:04.620 --> 16:06.480] and then everyone who downloads and uses [16:06.480 --> 16:08.940] that asset will be running your malicious code. [16:09.660 --> 16:11.780] We did not want to upload [16:11.780 --> 16:13.560] any backdoored assets. We're trying to [16:13.560 --> 16:15.680] identify supply chain attacks, not actually [16:15.680 --> 16:17.840] execute them. So, instead of tampering [16:17.840 --> 16:19.580] with assets, we just tampered with [16:19.580 --> 16:21.760] the release name. So we sent this curl request [16:21.760 --> 16:23.400] using the getup API, [16:23.400 --> 16:25.140] and it uses the compromised getup token [16:25.140 --> 16:27.440] just to add my name to the [16:27.440 --> 16:29.340] end of the release. So, after we sent [16:29.340 --> 16:31.320] that request, you can see the latest [16:31.320 --> 16:32.820] PyTorch release at the time [16:32.820 --> 16:35.480] was now signed by yours truly, and [16:35.480 --> 16:37.280] all we did here was just take a screenshot [16:37.280 --> 16:39.240] and then revert it right away. Obviously, we didn't [16:39.240 --> 16:41.200] want this being seen by a lot of people, [16:41.200 --> 16:43.180] but this was our POC to show that we could [16:43.180 --> 16:45.260] tamper with getup releases if we wanted to. [16:46.000 --> 16:47.260] A problem that we've encountered [16:47.260 --> 16:48.800] with getup release tampering is [16:49.260 --> 16:51.140] organizations have came back to us and legitimately [16:51.140 --> 16:53.260] said, well, no one really [16:53.260 --> 16:54.920] uses our getup releases. [16:55.320 --> 16:57.200] Obviously, that shouldn't be the [16:57.200 --> 16:59.220] case, but to demonstrate [16:59.220 --> 17:01.000] further impact, we wanted to look at [17:01.000 --> 17:03.080] getup secrets. Getup secrets [17:03.080 --> 17:05.160] are the crown jewels of [17:05.160 --> 17:07.060] any repo that uses getup actions. [17:07.060 --> 17:09.500] A lot of the times, they're overprivileged, [17:09.500 --> 17:10.920] and they can provide lateral movement [17:10.920 --> 17:12.920] opportunities beyond the getup [17:12.920 --> 17:15.100] repository. So, we [17:15.100 --> 17:16.940] were back to being Charlie from [17:16.940 --> 17:18.960] It's Always Sunny, and we were searching through [17:18.960 --> 17:21.140] all those PyTorch workflows again, [17:21.140 --> 17:22.940] trying to see where getup secrets were used, [17:22.940 --> 17:25.020] and see if we could compromise them. Here, [17:25.020 --> 17:26.980] you can see that they're using some personal access [17:26.980 --> 17:29.040] tokens, which are always super interesting. They're using [17:29.040 --> 17:30.960] AWS keys, and there were [17:31.060 --> 17:32.960] a bunch of other secrets used by the PyTorch [17:32.960 --> 17:34.980] repository. And before we go [17:34.980 --> 17:37.000] any further, I want to quickly recap how [17:37.000 --> 17:38.820] we got here. So, remembering [17:38.820 --> 17:41.160] back to the grammar police, we came, [17:41.160 --> 17:42.960] we fixed the typo, that typo [17:42.960 --> 17:45.340] got merged, that made us a [17:45.340 --> 17:46.980] contributor to the repository, which was using the [17:47.260 --> 17:48.880] default setting, so we could execute arbitrary [17:48.880 --> 17:50.900] workflows. We used that access [17:50.900 --> 17:52.840] to execute a workflow that implanted [17:52.840 --> 17:55.040] three of their self-hosted runners. Then [17:55.040 --> 17:56.860] we stole this getup token from [17:57.900 --> 17:59.060] a future workflow executing [17:59.060 --> 18:01.000] on that runner, and now we're going to [18:01.000 --> 18:02.760] try to use this getup token to exfiltrate [18:02.760 --> 18:03.900] getup secrets. [18:04.280 --> 18:06.700] One problem that we had to work around [18:06.700 --> 18:08.940] is that the workflows that had the [18:08.940 --> 18:10.500] getup secrets that we wanted to take [18:10.500 --> 18:12.780] didn't actually run on the self-hosted runners [18:12.780 --> 18:14.800] that we were now sitting on. So, the solution [18:14.800 --> 18:16.680] here was to use the getup token [18:16.680 --> 18:19.020] to conduct pipeline privilege escalation [18:19.020 --> 18:20.740] and get arbitrary [18:20.740 --> 18:22.780] code execution within those workflows so [18:22.780 --> 18:25.080] we could get those very nice secrets. [18:25.960 --> 18:27.060] Another problem [18:27.060 --> 18:28.860] is getup tokens aren't [18:28.860 --> 18:31.040] allowed to modify files in the .github [18:31.040 --> 18:32.780] slash workflows directory. [18:32.780 --> 18:34.820] That seems like a kind of random restriction by [18:34.820 --> 18:36.740] getup, but it's actually implemented a few years [18:36.740 --> 18:39.020] ago to prevent these exact [18:39.020 --> 18:40.940] attacks. So, they want to stop attackers [18:40.940 --> 18:42.800] from doing what we're trying to do right [18:42.800 --> 18:44.900] now, and so you can't just make a new branch, [18:44.900 --> 18:46.760] modify a workflow to exfiltrate secrets, and [18:46.760 --> 18:48.300] then you're done. [18:48.520 --> 18:50.360] The solution here is you need to find a workflow [18:50.360 --> 18:52.760] that uses the getup secrets you're interested [18:52.760 --> 18:54.580] in that executes code from [18:54.580 --> 18:56.880] outside of this .github slash workflows [18:56.880 --> 18:59.100] directory. So, this was our path here. [18:59.300 --> 19:00.640] If you look back at [19:00.640 --> 19:03.420] PyTorch's weekly.yaml workflow at the time, [19:03.420 --> 19:04.720] you can see it does two [19:04.720 --> 19:06.380] interesting things. [19:06.380 --> 19:08.300] One of them is that it calls this [19:08.300 --> 19:11.160] underscore update commit hash .yaml workflow. [19:11.160 --> 19:12.980] The other is that it uses these [19:12.980 --> 19:15.320] update bot tokens and PyTorch [19:15.320 --> 19:17.180] bot tokens, which based on context, we were [19:17.180 --> 19:19.140] pretty sure were getup personal access [19:19.140 --> 19:21.180] tokens. So, let's look at update [19:21.180 --> 19:22.720] commit hash .yaml. [19:23.280 --> 19:25.280] This workflow is still in the restricted [19:25.280 --> 19:27.160] workflows directory, so we [19:27.160 --> 19:29.420] can't modify this workflow with the getup token, [19:30.120 --> 19:30.680] but [19:30.680 --> 19:32.980] it calls update commit [19:32.980 --> 19:35.320] hashes .py, which is in the .github [19:35.320 --> 19:37.160] slash scripts directory, so it's not in [19:37.160 --> 19:38.580] the restricted workflow directory. [19:38.580 --> 19:40.740] All right, so all we need to do now [19:40.740 --> 19:42.780] is use the getup token to make a [19:42.780 --> 19:45.000] new feature branch and [19:45.000 --> 19:46.800] modify that script. [19:46.800 --> 19:48.780] And we know that the workflow that calls it [19:48.780 --> 19:52.780] runs on a certain event, so we can take advantage of it. [19:52.780 --> 19:53.140] The [19:53.140 --> 19:54.820] modification that we introduced was quite simple. [19:54.820 --> 19:56.820] We saved off the tokens that it [19:56.820 --> 19:58.980] received via environment variables to files [19:58.980 --> 20:00.780] and then we used our public [20:00.780 --> 20:02.800] key to encrypt them and print them to the [20:02.800 --> 20:04.860] build logs. This would prevent any other [20:04.860 --> 20:06.600] attackers from getting those [20:06.600 --> 20:08.660] secrets while we were conducting our POC. [20:09.400 --> 20:10.540] Okay, so what did we actually [20:10.540 --> 20:12.560] do? We used the getup token to create [20:12.660 --> 20:14.560] a new branch. Then on the new branch [20:14.560 --> 20:16.440] we added our payload to update commit hashes [20:16.440 --> 20:18.540] .py script. Then we used [20:18.540 --> 20:20.300] the getup token to trigger our payload via [20:20.300 --> 20:22.640] workflow dispatch event. This is because [20:22.640 --> 20:24.660] the token had actions write privileges. [20:24.880 --> 20:26.420] And then we could retrieve the encrypted [20:26.420 --> 20:28.480] secrets from the build logs, cancel [20:28.480 --> 20:30.640] the workflow, delete the workflow logs, and actually [20:30.640 --> 20:31.960] decrypt the secrets. So [20:32.440 --> 20:34.780] at the time when we were doing this operation [20:34.780 --> 20:36.780] I was absolutely terrified that [20:36.780 --> 20:38.360] I was going to forget to take a screenshot. [20:38.360 --> 20:40.660] So instead of taking screenshots I just screen [20:40.660 --> 20:42.640] recorded the whole thing. So I have like an 8 hour [20:42.640 --> 20:44.740] screen recording of all this stuff from [20:44.740 --> 20:46.820] PyTorch. And I condensed some of it [20:46.820 --> 20:48.600] into a video on the next slide just showing [20:48.600 --> 20:50.540] the getup personal access token [20:50.540 --> 20:53.240] exfiltration. So we'll walk you all through that. [20:54.040 --> 20:54.480] Here [20:54.480 --> 20:56.260] we have our run on runner C2 [20:56.260 --> 20:58.560] and we're going to navigate to our command [20:58.560 --> 21:00.460] output and we're just going to get [21:00.460 --> 21:02.580] the base64 encoded getup [21:02.580 --> 21:04.620] token. This is from a future workflow [21:04.620 --> 21:06.420] that was executing on one of the compromised [21:06.420 --> 21:08.740] runners. So we're going to base64 [21:08.740 --> 21:10.480] decode that token and you can see [21:10.480 --> 21:12.520] it's just an authorization header within the getup [21:12.520 --> 21:14.560] token. Use the token to clone the [21:14.560 --> 21:16.700] repository and then we made a [21:16.700 --> 21:18.860] new branch in the PyTorch repository. [21:18.860 --> 21:20.980] So within our new branch [21:20.980 --> 21:23.000] we're going to modify that Python [21:23.000 --> 21:25.820] script that we identified as an injection point. [21:25.820 --> 21:27.460] Here with my [21:27.460 --> 21:28.980] really poor Vim skills I'm going to paste [21:28.980 --> 21:30.560] our new payload to exfiltrate those secrets [21:30.560 --> 21:32.540] and then once the payload [21:32.540 --> 21:34.540] is set we're going to actually commit [21:34.540 --> 21:36.680] this to the repository because the token [21:36.680 --> 21:38.640] has contents right. So we commit [21:38.640 --> 21:40.460] it to the repo. Now we're going to use a curl [21:40.460 --> 21:42.400] request just to trigger this [21:42.400 --> 21:44.560] workflow from our branch which has the [21:44.560 --> 21:46.520] injected code in it and then we're [21:46.520 --> 21:48.300] looking at the actual PyTorch repository [21:48.300 --> 21:49.880] now where we just triggered a workflow [21:50.520 --> 21:52.300] and we're going to see two [21:52.920 --> 21:54.480] base64 encoded encrypted [21:54.480 --> 21:56.300] blobs. So we're going to scroll down [21:56.300 --> 21:58.420] and we're going to get these blobs which is the [21:58.420 --> 22:00.400] output of our commands and then we're [22:00.400 --> 22:02.400] going to go to this [22:02.400 --> 22:04.740] other terminal and decrypt [22:04.740 --> 22:06.340] them. So first we're just going to base64 [22:06.340 --> 22:08.300] decode them and then we're going to save them to a file [22:08.300 --> 22:10.160] and we're going to use our private key [22:10.160 --> 22:12.580] locally to actually decrypt them and get the token. [22:12.580 --> 22:14.480] So once you see some [22:14.480 --> 22:16.580] output that starts with ghp [22:16.580 --> 22:18.280] underscore those are the personal [22:18.280 --> 22:20.220] access tokens and we're going to take them [22:20.220 --> 22:22.080] and run them through Gato [22:22.660 --> 22:24.420] which will do a bunch of automated [22:24.420 --> 22:26.220] enumeration using the GitHub APIs [22:26.220 --> 22:28.440] and then Gato will tell us [22:28.440 --> 22:30.360] who the owners are, what they have access [22:30.360 --> 22:32.180] to, and what the potential [22:32.180 --> 22:34.300] impact is. Because if they just had read [22:34.300 --> 22:36.300] access to the repository, you know, there's not [22:36.400 --> 22:38.300] a real risk here to PyTorch. If they [22:38.300 --> 22:40.180] have other, you know, more [22:40.180 --> 22:42.360] sensitive privileges then it could be bad. [22:42.360 --> 22:44.240] So here we're running them through Gato. You [22:44.240 --> 22:46.260] can see one of the users is the PyTorch update [22:46.260 --> 22:48.220] bot user. The other is the PyTorch bot [22:48.220 --> 22:50.360] user. And they're both PyTorch organization [22:50.360 --> 22:51.500] members. The tokens [22:51.940 --> 22:54.300] have repo scope. So we can use this [22:54.300 --> 22:56.020] now to interact with the PyTorch repository [22:56.020 --> 22:57.880] directly. These are long-lived credentials [22:57.880 --> 23:00.520] and they had access to 93 repos [23:00.520 --> 23:02.280] within the PyTorch organization. [23:02.300 --> 23:04.200] A lot of which were private and did not have [23:04.200 --> 23:06.160] branch protection. So you could have done whatever you [23:06.160 --> 23:08.020] wanted to them. And there's [23:08.400 --> 23:10.500] a lot of paths here to supply chain compromise. [23:11.160 --> 23:12.500] Alright, that was a lot, [23:12.500 --> 23:13.680] right? Okay, so [23:14.170 --> 23:16.260] what can we do? So we have those two [23:16.260 --> 23:18.280] tokens so we can use them by themselves [23:18.280 --> 23:20.540] to simply introduce code into the main branch. [23:20.540 --> 23:22.180] One creates a pull request and have [23:22.180 --> 23:23.960] the other one approve and merge it. Boom. [23:23.960 --> 23:26.140] Supply chain compromise. Another form [23:26.140 --> 23:27.800] would be to backdoor a dependency [23:27.800 --> 23:30.160] within the PyTorch organization that's used by [23:30.160 --> 23:32.040] the primary PyTorch repo. [23:32.040 --> 23:34.000] And that could be a more subtle way to [23:34.000 --> 23:36.840] obtain that same final impact. [23:36.860 --> 23:38.140] And finally, there's even [23:38.140 --> 23:40.280] more clever ways like smuggling [23:40.280 --> 23:41.860] malicious code into an in-progress [23:41.860 --> 23:44.000] feature branch as a developer is working on [23:44.000 --> 23:46.160] and then have that merged in. So really [23:46.160 --> 23:48.080] there's too many paths to count for [23:48.080 --> 23:50.080] how this could impact end users of [23:50.080 --> 23:51.020] PyTorch. [23:52.220 --> 23:54.280] If you want to see even more [23:54.280 --> 23:56.760] impact and you're not really into github, [23:56.760 --> 23:58.280] this section is for you. [23:58.280 --> 24:00.260] So, if you noticed a few slides ago [24:00.260 --> 24:02.240] when we were looking at their secrets, we saw that they also [24:02.240 --> 24:03.920] had AWS keys. [24:03.960 --> 24:06.120] We conducted a very similar attack [24:06.120 --> 24:08.180] to the one we just showed, right, where [24:08.180 --> 24:10.260] we do that kind of workflow hopping and injection [24:10.260 --> 24:11.940] and triggering with the github token. [24:11.940 --> 24:14.740] We repeated that process to grab their AWS keys. [24:14.740 --> 24:16.420] And the reason we wanted to do this was [24:16.420 --> 24:18.440] if you don't understand github, [24:18.440 --> 24:20.120] it can sometimes be hard to even [24:20.120 --> 24:22.100] see why code contributions [24:22.100 --> 24:24.520] to the main branch of a repository [24:24.520 --> 24:26.340] could be impactful. But, [24:26.340 --> 24:28.380] everyone understands AWS and AWS [24:28.380 --> 24:30.400] releases. So, we grabbed these keys [24:30.400 --> 24:32.480] then we used the AWS CLI to authenticate [24:32.480 --> 24:34.360] and we confirmed that we were the [24:34.360 --> 24:36.440] PyTorch bot user. So, we didn't [24:36.440 --> 24:38.440] want to poke around too much, but we did some basic [24:38.440 --> 24:40.260] AWS S3 LS commands [24:40.260 --> 24:42.420] and saw that this user had a lot of [24:42.420 --> 24:44.280] privileges. We confirmed through the [24:44.280 --> 24:46.160] workflow logs that they could actually write [24:46.160 --> 24:47.900] to these S3 buckets. [24:48.080 --> 24:50.060] And, one weird thing that we weren't [24:50.060 --> 24:52.040] really expecting to see was there were PyTorch [24:52.040 --> 24:54.060] releases in these S3 [24:54.060 --> 24:56.340] buckets. So, at the time, honestly [24:56.340 --> 24:58.080] I didn't think too much of it [24:58.080 --> 25:00.000] because I was kind of freaked out with the access we had [25:00.000 --> 25:02.280] and wanted to submit the report right away. [25:02.280 --> 25:03.720] I think, like we said, this was hour [25:03.720 --> 25:05.880] 8 or 9 at this point and [25:05.880 --> 25:08.020] I just wanted to get the report in. So, I didn't [25:08.020 --> 25:10.100] really pay attention to these releases. And then we were rehearsing [25:10.100 --> 25:12.060] like a week ago and we were talking [25:12.060 --> 25:13.980] and I was like, why were these [25:13.980 --> 25:16.080] releases in these S3 buckets? [25:16.080 --> 25:17.960] Like, what system was pulling releases from here? [25:17.960 --> 25:19.860] So, I went to the [25:19.860 --> 25:21.620] PyTorch website and [25:22.240 --> 25:24.260] just going to PyTorch.org [25:24.260 --> 25:25.920] or PyTorch.com, whatever it is, you [25:25.920 --> 25:28.020] can scroll down and you can see when they instruct [25:28.020 --> 25:29.980] users to install, download [25:29.980 --> 25:31.900] and install PyTorch, if you're using PIP or [25:31.900 --> 25:33.660] whatever, you're using this [25:33.660 --> 25:34.760] download. [25:36.180 --> 25:38.400] What is it? Download.pytorch.org [25:38.400 --> 25:39.780] URL. So, a lot of the releases [25:39.780 --> 25:41.880] were coming from this URL. So, we went to this [25:41.880 --> 25:44.300] URL in a [25:44.300 --> 25:46.160] new tab and we're just looking at [25:46.160 --> 25:48.480] the request and response headers [25:48.480 --> 25:50.120] and sure enough, [25:50.120 --> 25:52.280] in the headers, they confirmed that [25:52.280 --> 25:54.040] these were actually pulling releases from [25:54.040 --> 25:56.380] these S3 buckets and [25:56.380 --> 25:58.960] the layout of the [25:58.960 --> 26:00.160] release assets on [26:00.160 --> 26:02.120] that website were identical to the [26:02.120 --> 26:04.120] layout in the S3 buckets. So, [26:04.120 --> 26:06.220] basically, with those AWS keys, we could have [26:06.220 --> 26:08.060] uploaded our own PyTorch releases [26:08.060 --> 26:09.820] to these S3 buckets and then [26:09.820 --> 26:11.720] anyone who downloads [26:12.300 --> 26:13.780] PyTorch by following the [26:13.780 --> 26:15.720] instructions from the website is going to be [26:15.720 --> 26:17.760] downloading and potentially executing our [26:17.760 --> 26:19.460] malicious code. So, this is that kind of [26:19.460 --> 26:21.860] solar wind style supply chain attack for anyone [26:21.860 --> 26:23.840] that uses PyTorch in the future. [26:25.340 --> 26:26.300] Okay. [26:26.620 --> 26:27.820] That was a lot. We just [26:27.820 --> 26:29.940] did a lot. This is what it looks like [26:29.940 --> 26:31.700] put into a nice little red team diagram [26:31.700 --> 26:33.920] and if anyone got [26:33.920 --> 26:35.760] here late or fell asleep, we'll [26:35.760 --> 26:37.860] do a quick recap. So, we started by opening [26:38.080 --> 26:39.660] a typo fix PR in the PyTorch [26:39.660 --> 26:41.940] repository. That PR got [26:41.940 --> 26:43.980] merged and then we were a contributor [26:43.980 --> 26:45.860] so we submitted a malicious pull request [26:45.860 --> 26:47.760] that installed our runner-on-runner [26:47.760 --> 26:50.220] C2 on three different self-hosted [26:50.220 --> 26:51.300] GitHub runners. [26:51.660 --> 26:53.960] From one of these runners, we stole a GitHub [26:53.960 --> 26:55.960] token from a future build and [26:55.960 --> 26:57.860] we used that to do a bunch of stuff. First, we just [26:57.860 --> 26:59.880] modified that release by updating the release [26:59.880 --> 27:02.260] title with my name and reverting. [27:02.260 --> 27:03.860] Then, we created a feature [27:03.860 --> 27:05.420] branch in the PyTorch repository [27:05.420 --> 27:07.460] and we triggered additional [27:07.460 --> 27:09.020] workflows using that workflow [27:09.020 --> 27:11.500] dispatch event injecting through the scripts [27:11.500 --> 27:13.280] that were outside of the restricted workflows [27:13.280 --> 27:15.380] directory. Through this [27:15.380 --> 27:17.540] process, we stole some secrets. We stole [27:17.540 --> 27:19.220] the PyTorch bot AWS keys [27:19.220 --> 27:21.540] and then we stole two GitHub personal access [27:21.540 --> 27:23.920] tokens used by PyTorch bot users. [27:23.920 --> 27:25.380] There were a bunch more secrets in there but [27:25.380 --> 27:26.880] we didn't think there was [27:27.420 --> 27:30.100] any need for additional demonstration of impact. [27:30.380 --> 27:31.600] Using the AWS keys, [27:31.600 --> 27:33.460] we could upload new PyTorch [27:33.460 --> 27:35.480] releases to this S3 bucket. Obviously, we did [27:35.480 --> 27:37.620] not do that. Then, using the GitHub personal [27:37.620 --> 27:39.380] access tokens, we could have [27:39.380 --> 27:41.460] modified PyTorch dependencies. We could [27:41.460 --> 27:43.400] have used them in conjunction to commit and [27:43.400 --> 27:44.980] then approve merges to main [27:44.980 --> 27:47.040] and done a lot of other bad stuff. [27:47.720 --> 27:49.640] All of this goes to say, at the end of the day, [27:49.640 --> 27:51.380] there were a lot of supply chain [27:51.380 --> 27:53.260] compromised past year which would have affected [27:54.580 --> 27:55.380] most people [27:55.380 --> 27:57.340] using PyTorch both [27:57.340 --> 27:59.060] currently and in the future. [28:00.220 --> 28:01.560] You would think that this [28:01.560 --> 28:03.540] amount of demonstration of impact would [28:03.540 --> 28:05.640] be enough to convince PyTorch to [28:05.640 --> 28:07.700] immediately and urgently [28:07.700 --> 28:09.360] apply fixes and [28:09.360 --> 28:11.620] well, we'll let [28:11.620 --> 28:13.420] the disclosure timeline speak for itself. [28:13.420 --> 28:15.440] We submitted this issue [28:15.440 --> 28:17.500] in August 2023 to [28:17.500 --> 28:18.900] Metabug Bounty. [28:19.360 --> 28:21.560] A month later, [28:21.560 --> 28:23.820] Meta said there is no update to provide. [28:24.260 --> 28:25.440] Two months later, [28:25.440 --> 28:27.900] Meta said they consider the issue mitigated. [28:27.960 --> 28:29.300] I was suspicious [28:29.300 --> 28:30.620] so I went back in and [28:30.620 --> 28:32.600] just executed some [28:33.680 --> 28:35.080] shell commands on the runners. [28:35.080 --> 28:37.200] I didn't do the full attack, but anyone [28:37.200 --> 28:39.140] can still compromise their runners. Any contributor [28:39.140 --> 28:41.340] and based on the workflow logs and stuff, [28:41.340 --> 28:43.200] I don't think their configurations were still secure [28:43.200 --> 28:45.200] so we responded saying, hey, the issue [28:45.200 --> 28:47.420] is not fully mitigated. Here's some proof. [28:47.560 --> 28:48.040] Then [28:49.820 --> 28:51.360] another two months went [28:51.360 --> 28:53.120] by with really no word from Meta [28:53.120 --> 28:55.300] and we sent a strongly worded [28:55.300 --> 28:57.220] email expressing concerns [28:57.220 --> 28:59.020] on the remediation that has been [28:59.020 --> 29:01.240] implemented, which led to some back and forth. [29:01.240 --> 29:03.020] Then December 15th, [29:03.020 --> 29:04.420] Meta applied some other fixes [29:05.040 --> 29:06.660] which seemed to be sufficient [29:07.060 --> 29:09.200] and then they offered a call to discuss the remediation [29:09.200 --> 29:11.040] in depth. We actually ended up [29:11.040 --> 29:13.280] meeting with two of the PyTorch maintainers [29:13.280 --> 29:15.060] and they were very concerned about [29:15.060 --> 29:17.000] these issues. They were on top of it [29:17.000 --> 29:18.940] and they also expressed [29:18.940 --> 29:21.720] concern at the potential gaps in remediation. [29:21.800 --> 29:23.060] I'm not totally sure [29:23.060 --> 29:24.740] where the disconnect was, but [29:24.740 --> 29:26.360] it worried us that [29:26.360 --> 29:29.320] PyTorch was potentially vulnerable for this long. [29:31.100 --> 29:32.900] This attack took a lot of [29:32.900 --> 29:35.400] hands-on keyboard workflow modification, [29:35.400 --> 29:36.760] command and control, all that [29:36.760 --> 29:38.540] stuff, and so it kind of [29:38.540 --> 29:40.600] prompted us to say, hmm, [29:40.600 --> 29:43.220] is there an easier way to automate a lot of this? [29:43.800 --> 29:44.640] Alright, well, [29:44.640 --> 29:46.440] now there is. So with a tool that [29:46.440 --> 29:48.780] I've open sourced this week called GatoX, [29:48.780 --> 29:50.440] it actually automates that [29:50.440 --> 29:53.180] self-holster runner takeover process. [29:53.180 --> 29:55.420] So now, instead of all that work that you saw [29:55.420 --> 29:57.420] John have to do, which all you have to do [29:57.420 --> 29:58.780] is you fix a typo, [29:58.780 --> 30:01.620] and you become a contributor, then you run GatoX, [30:01.620 --> 30:03.360] and then one of two things happens. [30:03.500 --> 30:05.240] You either get a shell and you're [30:05.240 --> 30:07.100] on top of the world as hacker man, or [30:07.100 --> 30:09.140] you learn that approval is required and then [30:09.140 --> 30:11.680] you're sad because you didn't get to hack anything. [30:11.820 --> 30:13.240] So let's walk [30:13.240 --> 30:15.120] through a quick video demo of how GatoX [30:15.120 --> 30:17.220] works to automate this self-holstered runner [30:17.220 --> 30:19.220] takeover process. So first [30:19.220 --> 30:21.440] I use it to enumerate a runner. [30:21.440 --> 30:23.540] So now I'm going to go ahead and [30:23.540 --> 30:25.720] fix a typo in this test repository [30:25.720 --> 30:27.520] here. So I go ahead and [30:27.520 --> 30:29.440] fix a typo and make that [30:29.440 --> 30:31.580] commit. So after [30:31.580 --> 30:33.680] I make the commit, I'm going to go ahead [30:33.680 --> 30:35.440] and create a pull request. [30:35.440 --> 30:37.440] So I check that I fixed the typo and I make a quick [30:37.440 --> 30:39.520] typo fix PR and [30:39.520 --> 30:41.480] now that's merged in. So after [30:41.480 --> 30:43.460] that's merged in with my attacker account, [30:43.460 --> 30:45.420] I'm going to go ahead and delete the fork. [30:45.540 --> 30:47.340] So because GatoX will create a new fork [30:47.340 --> 30:49.760] to throw the payload at the repository. [30:49.760 --> 30:51.780] So I'm going to quickly go ahead [30:51.780 --> 30:53.260] and do the web flow to delete the fork [30:53.760 --> 30:55.780] and I hit confirm. Alright, [30:55.780 --> 30:57.600] now I'm going to run GatoX. So [30:57.600 --> 30:59.980] here I've just configured it to deploy a [30:59.980 --> 31:01.790] runner on runner on a Linux x86 [31:02.800 --> 31:03.840] 64-bit runner. [31:03.840 --> 31:06.240] So it's going to go ahead and create the payload [31:06.360 --> 31:08.340] within a gist and ask for confirmation [31:08.340 --> 31:10.400] because the next steps are overt. [31:10.400 --> 31:12.860] So I'm going to type confirm and hit enter. [31:12.860 --> 31:13.900] So as soon as [31:13.900 --> 31:16.100] I do that, it's going to create a draft pull [31:16.100 --> 31:17.700] request which is going to deploy that runner [31:17.700 --> 31:19.680] on runner payload onto that [31:19.680 --> 31:22.060] self hosted runner via fork PR. [31:22.120 --> 31:23.780] So it's going to take a second [31:23.780 --> 31:25.740] because it's now pulling for that runner to connect [31:25.740 --> 31:28.040] to GitHub and then check back into that repository. [31:28.100 --> 31:29.660] So as soon as it does that, it will drop [31:29.660 --> 31:31.340] into a nice and very convenient [31:31.340 --> 31:33.700] shell. Okay, now [31:33.700 --> 31:35.760] I'm just going to test this with uname-a [31:35.760 --> 31:37.860] and when I hit enter, what's happening [31:37.860 --> 31:39.860] under the hood is that GatoX [31:39.860 --> 31:41.640] is issuing a workflow dispatch event [31:41.640 --> 31:43.740] to that workflow in the C2 [31:43.740 --> 31:45.800] repository which is going to run code [31:45.800 --> 31:47.900] on that malicious [31:47.900 --> 31:50.200] self hosted runner. And you can see that output there. [31:50.960 --> 31:51.560] Alright, so [31:51.560 --> 31:53.720] now you know the techniques and now [31:53.720 --> 31:55.680] since I've open sourced it, you have a tool. [31:55.860 --> 31:57.240] And another thing I want to point out is that [31:58.420 --> 32:00.000] finding CICD misconfigurations [32:00.000 --> 32:01.820] in open source repositories can be [32:01.940 --> 32:03.700] a very thankless job because you [32:03.700 --> 32:05.900] submit a report, they fix a bug, and you don't even get [32:06.020 --> 32:07.680] a CVE. So there's not really a lot of motivation [32:07.680 --> 32:09.800] for people. So what I've done with GatoX [32:09.800 --> 32:11.760] is that on its wiki, I've [32:11.760 --> 32:13.960] created a little hall of fame. So if you use GatoX [32:13.960 --> 32:16.400] to find a pwn request, injection, [32:16.400 --> 32:17.980] or self hosted runner vulnerability in an [32:17.980 --> 32:20.240] open source project, and the maintainers [32:20.240 --> 32:22.040] fix it, then just make an issue and I'll add you [32:22.040 --> 32:24.200] your name to the wiki to get some credit. [32:24.200 --> 32:26.020] Just make sure it's actually fixed because we don't [32:26.020 --> 32:27.880] want the hall of fame to be the hall of odays. [32:27.880 --> 32:29.680] As much as some people might like that. [32:31.340 --> 32:32.100] Okay, so [32:32.100 --> 32:34.140] we showed all of the technical TTPs [32:34.140 --> 32:36.040] we used during our PyTorch attack [32:36.040 --> 32:37.840] but there are a bunch of other stuff [32:37.840 --> 32:39.960] we've used on other targets. And so [32:39.960 --> 32:41.980] we want to take these next [32:41.980 --> 32:43.960] few minutes to honor the die hard [32:43.960 --> 32:45.940] CICD nerds who are here to learn all [32:45.940 --> 32:48.040] the TTPs possible. So we're going to run through [32:48.040 --> 32:50.120] this pretty quickly but all the slides [32:50.120 --> 32:52.060] will be up there online so you can check it out after. [32:52.380 --> 32:54.020] Alright, so one thing you can [32:54.020 --> 32:55.760] do after getting persistence on a runner is [32:55.760 --> 32:57.900] solo run style build compromise. [32:58.020 --> 32:59.880] So, you get persistence [32:59.880 --> 33:02.360] and then you just have to modify [33:03.060 --> 33:03.940] scripts for the [33:03.940 --> 33:06.120] build or source code after it's checked out. [33:06.120 --> 33:07.980] And once you do that, the final [33:07.980 --> 33:09.880] build artifacts from that run [33:09.880 --> 33:11.740] are going to be poisoned but there's no [33:11.740 --> 33:13.940] it's not going to be linked back to the original source code [33:13.940 --> 33:15.500] so it's a very stealthy way to [33:15.500 --> 33:17.580] conduct a supply chain attack. [33:17.760 --> 33:19.960] And here's another way that you could take [33:19.960 --> 33:22.480] GitHub release asset tampering a little further. [33:22.540 --> 33:23.580] So, if you have that [33:23.580 --> 33:25.800] context write token, then all you have to do [33:25.800 --> 33:27.860] to tamper with releases on assets is [33:27.860 --> 33:30.000] use the API to delete the old asset [33:30.000 --> 33:31.660] and then upload a new one with a post request [33:31.660 --> 33:33.440] right on top of it. And [33:33.980 --> 33:35.900] the indicator of compromise here is [33:35.900 --> 33:37.880] just going to be the timestamp when [33:38.240 --> 33:39.820] a user is looking at it through the [33:39.820 --> 33:42.500] web interface so it's not very obvious. [33:42.500 --> 33:44.000] And if you want to see a tale of [33:44.200 --> 33:45.940] a bug bounty gone wrong and a program acting [33:45.940 --> 33:47.900] in some pretty bad faith, go check out my [33:47.900 --> 33:49.520] blog post on my report to the [33:49.520 --> 33:51.300] ASTAR network which is a tiny [33:51.900 --> 33:53.340] polkadot parachain. [33:59.940 --> 34:01.480] Alright, another technique [34:01.480 --> 34:03.280] you can add to your arsenal is something [34:03.280 --> 34:05.160] called a post checkout hook. [34:05.180 --> 34:07.200] So, what happens when [34:08.120 --> 34:09.380] a subsequent workflow that you need [34:09.380 --> 34:10.980] to get secrets from or token from [34:10.980 --> 34:12.960] runs only very [34:12.960 --> 34:14.880] infrequently? Well, you need something [34:14.880 --> 34:16.700] that can have these qualities. [34:16.700 --> 34:18.480] You need to be able to extend the build time [34:18.980 --> 34:21.020] you also don't want to break how the workflow [34:21.020 --> 34:23.000] works to inform someone that something is [34:23.000 --> 34:25.000] going wrong and you also want to get notified [34:25.000 --> 34:27.620] because you don't want to be pressing F5 for two weeks. [34:27.680 --> 34:29.200] Well, a quick solution [34:29.200 --> 34:31.020] here is to place a script like [34:31.020 --> 34:32.760] this into the git hooks directory [34:32.760 --> 34:34.840] of the repository in the original self hosted [34:34.840 --> 34:36.680] runner. This example here [34:36.680 --> 34:38.760] will just take that git config [34:38.760 --> 34:40.780] file, encode it and then send it off to your [34:40.780 --> 34:42.840] exfil URL and then sleep for 15 [34:42.840 --> 34:44.840] minutes. So, this is going to give you 15 minutes [34:44.840 --> 34:46.980] to take advantage of that github token to perform [34:46.980 --> 34:48.880] post exploitation actions. [34:49.180 --> 34:50.820] Alright, before we [34:50.820 --> 34:52.900] dive into other TTPs, it's important [34:52.900 --> 34:54.860] to remember how self hosted runner takeover [34:54.860 --> 34:56.680] falls within the landscape of [34:56.680 --> 34:59.060] broader github actions attack techniques. [34:59.060 --> 35:00.940] So, there's another type of attack [35:00.940 --> 35:02.180] called bone requests where [35:03.480 --> 35:04.760] you basically get [35:04.760 --> 35:06.700] execution within a privileged workflow. [35:06.700 --> 35:08.980] That's the same thing that happens with runner takeover. [35:09.020 --> 35:10.680] From there, there's different [35:10.680 --> 35:12.780] post exploitation techniques you can use. [35:12.780 --> 35:14.500] So, you can steal secrets, you could [35:14.500 --> 35:16.600] get the actions runtime token, which has some [35:16.600 --> 35:18.480] interesting attacks with cache poisoning [35:18.480 --> 35:20.700] as well as OIDC abuse, which [35:20.700 --> 35:22.160] I think the talk right after [35:22.580 --> 35:24.800] us in this track actually goes into a lot more detail [35:24.800 --> 35:26.560] there. So, kind of cool. [35:26.840 --> 35:28.640] And then, there's just too many different [35:28.640 --> 35:30.840] attacks to talk about. There's so many ways to achieve [35:31.260 --> 35:32.420] great impact. [35:33.300 --> 35:34.580] We talked about some of the permissions [35:34.580 --> 35:36.660] of the github token today, but there's a lot [35:36.660 --> 35:38.180] of other dangerous permissions out there. [35:38.180 --> 35:40.480] Some of them don't pose a risk, but others, like [35:40.480 --> 35:42.740] contents write and actions write, obviously pose [35:43.000 --> 35:44.260] a significant risk. [35:44.360 --> 35:46.780] Other permissions we have identified as dangerous [35:46.780 --> 35:48.480] and actually abused during our attacks are [35:48.480 --> 35:50.660] pages write, pull requests write, [35:50.660 --> 35:52.380] and packages write. And there's a lot of good documentation [35:52.380 --> 35:55.060] online if you want to learn more about what these actually do. [35:55.880 --> 35:56.560] If you have [35:56.560 --> 35:58.460] just actions write and contents write, you can create [35:58.460 --> 36:00.620] feature branches, modify files, [36:00.620 --> 36:02.660] execute in workflows, and then issue dispatches [36:02.660 --> 36:04.780] events to seal secrets. If that looks [36:04.780 --> 36:06.740] familiar, it's because that's exactly what we did during [36:06.740 --> 36:07.440] PyTorch. [36:08.000 --> 36:10.700] Alright, what if you have a workflow that [36:10.700 --> 36:12.700] looks like this? It runs on workflow dispatch, [36:12.700 --> 36:14.980] but then uses some of that input in a [36:14.980 --> 36:17.380] github script or run step. Well, [36:17.380 --> 36:19.740] this lets you do good old 90's style [36:19.740 --> 36:21.360] code injection. And I'm going to walk you through how [36:21.360 --> 36:23.840] this process works. And you only need a github token [36:23.840 --> 36:26.280] actions write to make this hop. [36:26.280 --> 36:28.040] So, here you can see [36:28.040 --> 36:29.780] that the input from the dispatch [36:29.780 --> 36:30.700] event has org and repository, and [36:30.700 --> 36:32.560] within that script step, repository [36:32.560 --> 36:35.300] is used by github context expression. [36:35.300 --> 36:36.860] So, that's going to be our injection [36:36.860 --> 36:38.620] point there. See that arrow? [36:38.760 --> 36:40.840] So, here's an example payload thrown [36:40.840 --> 36:42.660] with a simple request script in [36:42.660 --> 36:44.620] Python. The first thing here is to [36:44.620 --> 36:46.700] close out the script because we [36:46.700 --> 36:48.600] don't want a syntax error or have it to crash because [36:48.600 --> 36:50.740] we still need the code to finish in order for us [36:50.740 --> 36:52.500] to get our payload execution. [36:52.820 --> 36:54.700] The next thing, and this is where [36:54.700 --> 36:57.140] the actual payload is, is a [36:57.820 --> 36:58.340] JavaScript injection [36:58.340 --> 37:00.460] payload that essentially will pull [37:01.100 --> 37:02.340] code from a [37:03.840 --> 37:05.140] C2 URL [37:05.140 --> 37:06.720] and pipe it to bash. So, then [37:06.720 --> 37:09.220] you can just have arbitrary code there and [37:09.220 --> 37:10.760] get execution in that workflow, get the token, [37:10.760 --> 37:12.920] get the secrets, and then from there [37:12.920 --> 37:18.090] do more post exploitation. [37:18.090 --> 37:19.510] If you only have [37:19.510 --> 37:20.930] contents write, there's still a lot of bad stuff [37:20.930 --> 37:23.270] you can do. You can modify [37:23.270 --> 37:25.570] non-protected branches a lot of times, which [37:25.570 --> 37:27.790] actually could end up in releases. [37:27.790 --> 37:28.650] You can modify releases directly, like we [37:28.650 --> 37:30.830] did when we signed my name. You can modify [37:30.830 --> 37:32.790] tags, which a lot of times reusable actions [37:32.790 --> 37:34.750] are referenced by tags, so that could open [37:34.750 --> 37:36.770] up some fun possibilities. [37:36.770 --> 37:38.650] And then you can also issue repository dispatch [37:38.650 --> 37:40.490] events to execute workflows. [37:41.430 --> 37:42.790] Alright, here's a really [37:42.790 --> 37:44.190] unique way to take advantage of [37:44.190 --> 37:46.550] contents write. Alright, so [37:46.550 --> 37:48.690] one way is if you want to [37:48.690 --> 37:50.630] get execution on a workflow that only runs [37:50.630 --> 37:52.730] on the push trigger, you can add [37:52.730 --> 37:53.930] code to that [37:54.610 --> 37:56.910] feature branch that modifies [37:57.050 --> 37:58.670] a script that's called by that [37:58.670 --> 38:01.290] workflow. And the next time the developer will push changes, [38:01.290 --> 38:02.950] now you have arbitrary code [38:02.950 --> 38:04.750] execution within the context of that workflow [38:04.750 --> 38:07.550] and then you can jump further from there. [38:07.550 --> 38:08.630] Another way is instead of [38:08.630 --> 38:11.210] targeting the workflows, why not target the developer? [38:11.210 --> 38:13.070] So you could modify a unit test [38:13.070 --> 38:14.130] within a feature branch [38:14.750 --> 38:16.730] that a developer is working on [38:16.730 --> 38:19.130] and add an info stealer payload. [38:19.130 --> 38:20.750] So then when the workflow [38:20.750 --> 38:22.630] runs, the dev account's compromised and [38:22.630 --> 38:24.610] often in organizations, dev accounts [38:24.610 --> 38:26.330] compromise can be game over. [38:26.350 --> 38:28.050] Another way is if you have [38:28.410 --> 38:30.590] these two permissions for the token, you can get [38:30.590 --> 38:32.630] code modification in the protected [38:33.210 --> 38:34.550] default branch. So there's [38:34.550 --> 38:36.110] some preconditions here. The repository [38:36.110 --> 38:38.350] has to have the setting to allow get of actions [38:38.350 --> 38:40.690] to approve and merge pull requests. [38:40.730 --> 38:42.270] There can be at most one [38:42.270 --> 38:44.050] reviewer required for that [38:44.050 --> 38:45.870] pull request approval rule. [38:45.990 --> 38:48.330] And there cannot be any code [38:48.330 --> 38:50.190] owner protection rule sets enabled [38:50.190 --> 38:52.370] and enforced. When all of these are [38:52.370 --> 38:54.950] together, you can have an attack like this. [38:55.070 --> 38:57.510] Attacker gets the GitHub token, [38:57.510 --> 38:58.510] they use their account [38:58.510 --> 39:00.630] to create a fork pull request with malicious changes [39:00.630 --> 39:02.510] and then they approve that [39:02.510 --> 39:04.210] pull request with that capture token [39:04.210 --> 39:06.430] and merge that pull request. [39:06.430 --> 39:09.070] That leads to a good old supply chain compromise. [39:10.870 --> 39:12.430] Now, if you're on a runner, [39:12.430 --> 39:14.110] it's possible to steal the GitHub actions [39:14.110 --> 39:16.410] runtime token from a future workflow. [39:16.410 --> 39:18.410] This is where you'll have some attack paths [39:18.410 --> 39:20.370] for GitHub actions cache poisoning. [39:20.370 --> 39:22.290] I have a blog post on my website [39:22.290 --> 39:24.430] that goes into the details of that. [39:24.710 --> 39:26.770] And if there's an organization [39:26.770 --> 39:28.250] level runner group that shares [39:28.970 --> 39:30.630] that also private repositories [39:30.630 --> 39:32.290] are using, then there's paths to [39:32.290 --> 39:34.490] jump to private repositories and other runner groups [39:34.490 --> 39:36.330] and it just kind of blows those [39:36.330 --> 39:37.510] attack paths wide open. [39:38.550 --> 39:40.570] Okay, that's the end of some of the more advanced [39:40.570 --> 39:42.410] TTPs. If you're the type of [39:42.410 --> 39:44.390] person who likes big mind maps to [39:44.390 --> 39:46.310] tell you exactly what to do, I made [39:46.310 --> 39:48.430] one and I put it on my GitHub a few days [39:48.430 --> 39:50.450] ago, so you can go check that out. Obviously, this is [39:50.450 --> 39:52.350] not comprehensive, but if [39:52.350 --> 39:54.190] you're trying to get into GitHub actions exploitation [39:54.590 --> 39:56.410] and you have read or write access [39:56.410 --> 39:58.410] to a repo but don't really know what to look for [39:58.410 --> 40:00.470] or what to do next, check this out. It should [40:00.470 --> 40:01.950] be able to give you some good guidance. [40:03.110 --> 40:04.390] In our opinion, GitHub can do a few [40:04.390 --> 40:06.730] things better. They can increase warnings and awareness, [40:06.730 --> 40:08.570] so if you try to attach a selfless [40:08.570 --> 40:10.490] runner to a public repo, it'd be great [40:10.490 --> 40:12.650] if there were big red letters saying, be careful, [40:12.650 --> 40:14.550] this is dangerous. They can also improve their secure [40:15.030 --> 40:16.330] defaults, like we talked about with the [40:16.330 --> 40:18.250] workflow approval requirements, and then [40:18.250 --> 40:20.210] they could implement granular approval [40:20.210 --> 40:22.350] requirements so that maintainers [40:22.350 --> 40:23.990] don't need to select between [40:23.990 --> 40:26.230] three options, all of which have broad [40:26.230 --> 40:28.230] privileges and probably will hurt [40:28.230 --> 40:30.550] developer workflows one way or the other. [40:31.010 --> 40:32.270] If you're trying to defend [40:32.270 --> 40:34.110] your organization from these attacks, [40:34.110 --> 40:35.950] start with the easy stuff. Please [40:35.950 --> 40:37.970] change this radio button so that you require [40:37.970 --> 40:40.430] approval for all outside collaborators. [40:40.650 --> 40:42.430] We use the GitHub token extensively [40:42.430 --> 40:44.290] and almost all of our attacks set [40:44.290 --> 40:46.390] it to read-only. That will stop [40:46.510 --> 40:48.470] a lot of post-exploitation opportunities. [40:48.470 --> 40:50.250] And then use, enforce [40:50.250 --> 40:52.370] your devs to use fine-grained personal access tokens. [40:52.370 --> 40:54.410] We, like, we hate discovering [40:54.410 --> 40:56.310] fine-grained tokens on red team engagements [40:56.310 --> 40:58.270] because they only give you access [40:58.270 --> 41:00.330] to one repository. If we find a personal [41:00.330 --> 41:02.250] access token that's classic, we can do [41:02.350 --> 41:04.390] a lot of stuff. If it's fine-grained, [41:04.390 --> 41:06.010] sometimes that's the end of the road. [41:06.570 --> 41:08.370] Alright, there's also [41:08.370 --> 41:10.410] ways to secure yourself more by making [41:10.410 --> 41:12.770] sure that your selfless runners are ephemeral. [41:12.770 --> 41:14.510] So, GitHub maintains something called [41:14.990 --> 41:16.510] ActionsRunnerController, which allows you to [41:16.510 --> 41:18.290] automatically spin up and spin down [41:18.290 --> 41:20.330] self-hosted runners using Kubernetes. [41:20.610 --> 41:22.850] Also, a lot of cloud providers have auto-scaling [41:22.850 --> 41:24.210] groups that can be linked with [41:24.210 --> 41:26.330] self-hosted runners and have that [41:26.330 --> 41:28.630] also be done automatically. And finally, [41:28.630 --> 41:30.610] there's a lot of third parties that offer [41:30.610 --> 41:31.430] turnkey [41:32.330 --> 41:34.390] drop-in replacements for GitHub [41:34.390 --> 41:36.450] runners that are also ephemeral if you [41:36.450 --> 41:38.370] don't want to use just the GitHub-hosted [41:38.370 --> 41:40.430] runners. And one [41:40.430 --> 41:42.270] thing that's important to remember here is that [41:42.270 --> 41:44.430] ephemeral means the environment [41:44.430 --> 41:46.650] that the runner is in also has to be ephemeral. [41:46.650 --> 41:48.190] So, if there's an ephemeral runner, [41:48.190 --> 41:50.470] but it's using a non-ephemeral [41:50.470 --> 41:52.090] file share, then an attacker can simply [41:52.090 --> 41:54.510] jump to other workflows by [41:54.510 --> 41:56.550] saving certain files off. [41:56.550 --> 41:58.490] So, it's important to really consider the [41:58.490 --> 42:00.510] entirety of that environment [42:00.510 --> 42:03.030] when it comes to build agent security. [42:03.990 --> 42:04.530] Alright, so [42:04.530 --> 42:06.390] another way is by using GitHub's [42:06.390 --> 42:08.450] feature for runner group pinning. [42:08.450 --> 42:10.930] So, GitHub has a feature where if you have a [42:10.930 --> 42:12.890] runner group, you can actually pin it to [42:12.890 --> 42:14.790] a specific workflow, or even [42:14.790 --> 42:17.650] a specific SHA or reference of a workflow. [42:17.650 --> 42:18.750] So, with this, [42:18.950 --> 42:20.810] you have a lot of different options to [42:20.810 --> 42:22.850] restrict which workflows can even use the runner. [42:22.850 --> 42:25.410] And all of this has the ultimate effect of [42:25.410 --> 42:27.790] protecting your most privileged runners. [42:27.790 --> 42:29.250] We want to end our talk [42:29.250 --> 42:31.250] today by emphasizing that [42:31.250 --> 42:33.210] this talk and this research is not [42:33.210 --> 42:35.490] about PyTorch. So, we have [42:35.490 --> 42:36.490] some key takeaways here. If you've been zoning out, [42:36.490 --> 42:38.150] lock in for this last slide. [42:38.150 --> 42:40.310] What we did to PyTorch, we've [42:40.310 --> 42:42.430] been able to do to a lot of advanced [42:42.430 --> 42:44.410] mature organizations because of this [42:44.410 --> 42:46.850] lack of awareness around CICD agent security. [42:46.850 --> 42:47.970] So, I think we've submitted [42:48.330 --> 42:50.950] over 20 high and critical bug bounty submissions. [42:50.950 --> 42:52.170] Among them were critical vulnerabilities [42:52.170 --> 42:54.790] in GitHub Actions, Microsoft, PyTorch, [42:54.790 --> 42:56.670] TensorFlow, ASTAR, [42:57.210 --> 42:58.390] HydroGX, ByteDance, [42:58.390 --> 43:01.090] and a lot more that we're not allowed to talk about. [43:01.930 --> 43:02.570] Additionally, [43:02.570 --> 43:04.630] if you think that public CICD security [43:04.630 --> 43:06.450] is bad, internal CICD security [43:06.450 --> 43:08.650] is a nightmare. Almost [43:10.010 --> 43:10.450] not [43:10.450 --> 43:12.870] every Red Team engagement I've been on, but a [43:12.870 --> 43:14.930] lot of Red Team engagements were able to get access [43:15.050 --> 43:16.950] to a CICD platform and then [43:16.950 --> 43:19.030] escalate privileges and use it to reach objective. [43:19.030 --> 43:20.910] It's almost become the new ADCS [43:20.910 --> 43:24.170] for us where internally everyone's vulnerable [43:24.170 --> 43:25.690] and compromising these CICD [43:25.690 --> 43:28.750] platforms can give you extensive [43:28.750 --> 43:29.130] privileges. Finally, [43:29.130 --> 43:31.290] what we need everyone to do is go learn about [43:31.290 --> 43:32.710] these attacks to protect your org from compromise. [43:32.710 --> 43:34.570] The main issue we see is just this lack of [43:34.570 --> 43:36.710] awareness. So if devs, architects, [43:36.710 --> 43:38.990] execs, and everyone is learning about these attacks, [43:38.990 --> 43:40.710] they'll be able to implement controls that [43:40.710 --> 43:42.690] hopefully protect their organization from [43:42.690 --> 43:44.750] the next critical supply chain attack. [43:45.430 --> 43:46.830] Alright, the moral of the story here [43:46.830 --> 43:48.710] is learn about this stuff and don't let [43:48.710 --> 43:49.770] this be you. [43:52.590 --> 43:54.570] Alright, so we want to start off by [43:54.570 --> 43:56.790] thanking all of the bug bounty triage teams [43:56.790 --> 43:58.630] that handled some of the reports and [43:58.630 --> 44:00.790] handled them well and applied solid mitigations [44:00.790 --> 44:02.730] to their products. We'd like to thank [44:02.730 --> 44:04.870] everyone who showed out today. Thank you so much for watching [44:04.870 --> 44:06.710] us and helping us raise awareness and for everyone [44:06.710 --> 44:09.050] watching online. Thank you. [44:09.050 --> 44:10.650] We'd like to thank DEF CON for giving us [44:10.650 --> 44:12.810] this platform. We wanted to speak here for a long time [44:12.810 --> 44:14.150] so this has been really fun. [44:14.530 --> 44:16.610] Please, we don't have time for questions, but come find us [44:16.610 --> 44:18.710] after if you want to talk more. Thank you [44:18.710 --> 44:19.310] everybody!