start	end	text
1900	4800	All right. Hello, everyone.
4800	7620	All right, let's address the burning question in the room.
7620	11420	No, we did not get access to the source code for Grand Theft Auto VI,
11420	13880	nor do we know if the game will ever be released.
13880	16440	Maybe in the following presentation, but not today.
16860	21280	This is Grand Theft Actions abusing self-hosted GitHub runners at scale.
21840	23240	Hello, everybody.
23580	26780	Before we get started, we read online that as long as we have a disclaimer,
26780	29640	nobody's allowed to sue us, so here we go.
29640	32520	All vulnerabilities mentioned during this talk have been remediated.
32740	34980	The views and opinions expressed are solely our own,
34980	37080	and the content is not endorsed by,
37080	39020	nor does it represent the views of our employers.
40080	42140	All right. Whoa, there we go.
42320	44060	Adnan, I think we're good to go.
46900	50600	All right, if you're wondering about us, so my name is Adnan Khan.
50600	52900	For my day job, I work as a security engineer.
52900	56000	I'm also a security researcher and bug bounty hunter on the side,
56000	57920	and you can find some of my socials below.
57920	59800	My name is John Stawinski.
59800	61940	I'm a red team security engineer at Praetorian.
62120	65280	I also do CICD security research on the side.
65320	68640	In the last year, I've watched Avatar the Last Airbender three times,
68640	72520	the animated version, and in a past life, I was a collegiate wrestler.
73900	74900	All right.
74920	78280	All right, so we're going to be talking a lot about self-hosted runners today,
78280	80400	so I want to make sure everyone has a background understanding
80400	82040	of how GitHub runners work.
82040	84360	On one side, you have GitHub-hosted runners.
84360	87160	These are built by GitHub, updated frequently,
87160	90980	and as of writing, cover a wide variety of operating systems and architectures.
90980	95220	The key thing with GitHub-hosted runners is that they are ephemeral,
95220	98900	meaning they are torn down at the conclusion of each workflow job.
98900	101600	On the other hand, you have self-hosted runners.
101600	105320	These are managed and secured entirely by the end user,
105320	109080	and it's not surprising here that the path of least resistance
109080	111880	when configuring one of these self-hosted runners
111880	116500	is a non-ephemeral self-hosted runner that is actually the least secure.
116500	121180	Both GitHub-hosted and self-hosted runners work to service GitHub Actions workflows
121180	124060	that are triggered from repositories on GitHub.
124720	126460	So, why are we here today?
126460	130260	Well, all the organizations and projects that you see on the screen here
130260	135300	use or at one point use self-hosted runners on their public GitHub repositories.
135300	138040	Not only that, but they use them in an insecure manner,
138040	141180	and over the last 12 months, we were able to identify vulnerabilities
141180	144880	in these organizations and many more that we can't talk about.
144880	149340	Some of these cases could have led to widespread critical supply chain attacks.
150320	154800	You may be wondering if we just showed that last slide to flex our cool bones at DEF CON,
154800	159480	and I just want to go on record saying that, yeah, pretty much.
159660	162360	But it also raises a bigger question.
162360	166520	Why were we in a position to execute supply chain attacks on all of these companies?
166520	170840	And the reason behind that is that GitHub Actions provides this broad attack surface
170840	173520	that exposes these organizations to compromise,
173520	176380	especially when they use self-hosted runners.
177360	181440	All right, so how do we get started with our vulnerability research campaign?
181440	184540	Well, it all started all the way back in August of 2022
184540	187980	when I was working on a red team with my former employer.
187980	189600	I was fairly new to red teaming at the time,
189600	191900	and I tripped a canary and got us kicked out of the client network.
191900	193460	Maybe that's happened to some of y'all.
193720	196200	But while trying to get back in, we did some social engineering,
196200	199200	and I found that we could use a GitHub access token that we obtained
199200	202700	to execute a workflow and persist on a non-ephemeral self-hosted runner
202700	204240	inside that client's network.
204240	206520	And that got us back in, and we reached objective.
206600	210080	That led to a talk at ShmooCon called Phantom of the Pipeline
210080	211960	that was given in January of 2023,
211960	214780	and the release of the original Gato tool.
215520	220300	Around the time that Anand, Mason Davis, and Matt Chakassi were developing Gato,
220300	223300	I joined them on the red team, and Gato was my entry to CICD security.
223300	226720	So I started using Gato to identify GitHub Actions vulnerabilities
226720	228380	during red team engagements.
228380	231820	And then we started diving deeper into GitHub Actions abuse,
231820	233940	especially around post-exploitation.
234080	235240	And as we were doing our research,
235240	237800	we were trying to brainstorm ways to blow this up
237800	241300	and bring it from internal red team engagements to everybody.
241300	244220	And Anand had an idea that really took it to the next level.
244420	247520	So one of the little asterisks at the end of the ShmooCon presentation
247520	250460	was that if you fixed a typo on a public repository
250460	253000	that was using a non-ephemeral self-hosted runner,
253000	255620	you could just make a pull request and modify the workflow file
255620	256900	and get persistence.
256900	260140	I demonstrated that vulnerability against GitHub Actions
260140	261780	runner images repository,
261780	264560	which was accepted as a critical vulnerability.
265780	268360	After Anand hacked GitHub Actions runner images,
268360	270940	we started looking at all public repositories
270940	273300	and realized that these misconfigurations were everywhere.
273300	274820	So we decided to team up.
274820	277660	Our first joint operation was breaching Microsoft's perimeter
277660	280100	by getting code execution on a domain-joined machine
280100	281780	through Microsoft DeepSpeed.
281780	284940	And then we launched a series of attacks,
284940	287920	the next one of which we will cover today.
287920	289920	Alright, so at a high level,
289920	293340	there's three steps to discovering this vulnerability at scale.
293340	296060	The first step is to search for candidate repositories
296060	298260	that might be using a self-hosted runner.
298260	301140	To do this, we used a combination of GitHub CodeSearch
301140	304040	and Sourcegraph CodeSearch dorks.
304040	307060	Both have pros and cons, so we used both
307060	309820	and deduplicated the results to get a nice list
309820	312460	of candidate repositories for further analysis.
312660	316120	To do this, use the tool that's open source right now
316120	317440	called GatoX.
317440	320040	It uses automated workflow run log analysis
320040	321780	to determine if there's a non-ephemeral
321780	323440	self-hosted runner in use.
323440	326560	Once you have the results, you can plan your next step,
326560	328580	which is essentially, can you hack it
328580	330820	and can you hack it for some good impact?
331940	335160	Self-hosted runner takeover is a special case
335160	337840	of public Poison Pipeline execution.
337840	340120	So, Poison Pipeline execution at a high level
340120	342440	is anytime you can get your own code executed
342960	344940	by a GitHub Actions workflow,
344940	347180	you can conduct a Poison Pipeline attack.
347180	348620	In the case of self-hosted runner,
348620	350080	we'll use this to deploy persistence
350080	351980	on the self-hosted runner via a pull request
351980	354860	and that opens up a ton of lateral movement
354860	356340	and privilege escalation paths.
356340	358620	So, the first two aspects of this diagram
358620	359920	are pretty straightforward.
360040	363260	This last section, the GitHub Actions post-exploitation,
363260	365280	is where we focus most of our research.
366040	368820	Alright, so it's a tale as old as Unix time itself.
369160	372000	Misconfigurations are amplified by insecure defaults.
372140	375040	So, the default setting for a pull request approval
375040	376400	on the pull request trigger
376400	378420	is that it only requires approval
378420	380720	for first-time contributors.
380720	382200	So, if someone has a pull request,
382200	383420	no matter how trivial,
383420	384960	merged into the default branch,
384960	387600	they won't need approval for workload executions
387600	389380	on their pull requests.
389640	392740	This is that bad insecure default.
394440	397580	Today, we're going to walk through playing with fire,
397580	399840	which is what we've called our supply chain attack
399840	401600	on the PyTorch repository,
401600	404580	which began by compromising self-hosted runners.
404580	406960	This is one of our more complex and more...
407440	408740	more intricate attacks,
408740	409960	so we're going to use it as a case study
409960	412620	to teach technical TTPs of GitHub Actions
412620	415200	exploitation and post-exploitation as we go.
415700	417760	Alright, so, what is PyTorch?
417760	419260	I'm sure a lot of you already know what it is,
419260	420420	but it's a machine learning framer
420420	423020	originally developed by Meta that's been open-sourced,
423020	424700	and it's used by companies around the world
424700	427400	like Google, Lockheed Martin, OpenAI, and more.
427400	429280	If someone were to backdoor PyTorch,
429280	430980	this could allow compromising developers
430980	432960	and organizations in that very much
432960	435320	red-hot AIML space right now.
436040	438180	In all seriousness,
438500	440820	probably the hardest part of compromising PyTorch
440820	443460	was searching through their workflows.
443460	446180	They had something like over 90 workflows,
446180	447740	over 15 GitHub secrets,
447740	449320	and more than five self-hosted runners
449320	451080	on their public repository.
451240	453500	And I vividly remember sitting at my desk,
453500	455700	I had like three different notebooks out,
455700	457760	and I was manually, pen and paper,
457760	459240	mapping out the data flow
459240	460480	through all these workflows,
460600	462040	a lot of which were nested,
462040	463400	in preparing for this attack,
463400	465400	so that we could try to figure out the potential impact
465400	466880	before we actually started.
467800	469600	When we confirm that a repository
469600	471300	has a self-hosted runner,
471300	472980	we look at the workflow logs,
472980	474440	like Adnan talked about earlier.
474440	477020	So here's an example of the PyTorch repository,
477020	478400	and in this screenshot,
478400	479620	you can see in the workflow log,
479620	480980	it has the runner name,
480980	481840	the runner group name,
481840	482620	and the machine name.
482620	484780	So we see that this is a Jenkins runner,
484780	485680	it's a self-hosted runner
485680	487080	attached to their public repository
487520	489100	in the default group,
489100	490300	and this is one of the runners
490300	491760	that we ended up compromising.
492540	495500	Alright, remember that default approval requirement?
495500	497800	Well, for certain repositories that are very busy,
497800	499180	you can often determine that
499180	501140	just using contextual analysis.
501140	501820	And let me tell you,
501820	503540	PyTorch was very busy.
503540	505420	So what you look for is a pull request
505420	506880	submitted by a previous contributor
506880	508620	that's from a fork pull request.
508620	510400	You check that the workflow run
510400	512220	associated with it was not approved,
512220	515680	and that it ran on the pull request trigger.
515680	517080	When all these things come together,
517080	519360	it's very likely that the default approval requirements
519360	520300	are in place.
521780	523700	GitHub warns against attaching
523700	525580	self-hosted runners to public repositories
525580	526720	for obvious reasons,
526720	528780	but they don't make their documentation
528780	529760	and their warnings obvious,
529760	531080	and you kind of have to go out of your way.
531080	532640	So part of the reason we think that
532640	534900	so many repos publicly use self-hosted runners
534900	536040	is because they don't end up
536040	537420	seeing this documentation.
537800	538720	In this next slide,
538720	540240	we'll just walk through what it looks like
540240	541540	to register a self-hosted runner
541540	543440	and see what documentation
543440	545460	you come across as a developer.
546240	547960	So in my GitHub repository,
547960	549380	I'm going to actions panel,
549380	551140	I'm trying to register a self-hosted runner,
551140	552000	but first,
552000	553280	I'm going to look through their documentation,
553280	554400	because I'm a good developer.
554580	556000	And I click on these links,
556000	557520	I don't see anything security related,
557520	558760	so I click on this other link,
558760	560680	and we get to a lot of GitHub
560680	562560	self-hosted runner documentation.
562600	564820	We learn about auto-scaling,
564820	566200	usage limits,
566200	568180	I think it lists architecture stuff,
568180	569840	and then every API that the runner
569840	571640	is going to use in its lifetime.
571980	573040	And then,
573040	574360	way down here at the bottom,
574360	576480	it talks about self-hosted runner security.
576480	578420	And so, GitHub does clearly say
578420	580240	they don't recommend using
580240	582900	self-hosted GitHub runners on public repositories.
582900	584920	And they have other articles out there, too,
584920	587020	elaborating on this.
587020	589060	But the point we want to drive is
589060	590820	it's not obvious.
590820	591700	So chances are,
591700	593180	if you're just registering a self-hosted runner
593180	594420	to a public repo,
594420	596420	you're not going to come across this documentation.
597260	599520	Alright, the first step was to infiltrate
599520	600820	the contributor list.
600820	602640	This is what's important to take advantage
602640	604520	of those default approval settings.
605120	606880	To infiltrate the contributor list,
606880	608200	if you've been following our blogs at all,
608200	609840	we always call the grammar police.
609840	612180	So the grammar police is me and Adnan.
612180	613220	We show up,
613220	615040	and we run all their markdown files
615040	616240	through Grammarly.
616240	618120	Again, fixing a typo here
618120	619580	and finding a grammatical error
619580	620760	doesn't matter at all.
620760	622580	To become a contributor,
622580	624380	we also could make a legitimate,
624380	625660	substantial code contribution
625660	627260	to the PyTorch repository.
627520	629600	But, that's a lot of work.
629860	631400	So, what we do instead is
631400	634160	we notice resolve was in the past tense,
634160	635640	and it should have been in the present tense.
635640	638180	So, we fix that for them,
638180	639680	we did a pull request,
639680	640460	and a few days later,
640460	642200	it got merged by the maintainers.
642480	644520	And then we are now officially contributors,
644520	646060	which is not a security boundary.
646220	647400	And this is the same process
647400	649120	we did with all of our exploits.
649420	651580	All right, so this is where the hacking starts.
651580	653080	So, the step phase two
653080	654560	was to install command and control
654560	656820	on those non-ephemeral self-hosted runners
656820	658400	attached to PyTorch.
658400	659780	To do this, we leverage something
659780	661880	we like to call runner-on-runner.
661960	663060	In a nutshell, what that is,
663060	665120	is we install another self-hosted runner
665120	667000	on their self-hosted runner.
667000	669160	This has the benefit of sending all traffic
669160	671700	to the same domains and IP addresses
671700	674000	that the original self-hosted runner uses.
674000	676440	So, if there is any EDR or monitoring software
676440	677120	on that runner,
677120	678240	it's very likely that it will fly
678240	679440	right under the radar.
679680	681080	Oh yeah, so remember that default?
681080	682080	This is where those defaults
682080	683680	lead to an actual compromise.
683680	685140	To do this, we just modified
685620	686880	the workflow in our fork
686880	689520	and had it just install our C2.
690180	692100	The second runner is attached
692100	693460	to our private C2 repository,
693460	695740	so we can task it to execute commands.
695740	697340	It's essentially a web shell.
697800	699120	Using this web shell,
699120	701180	we're able to look around the file system
701180	703160	and learn about the host.
703160	704420	And all of this is in preparation
704420	706120	for phase three.
706840	709060	Phase three is the most important phase
709060	711540	of all of our CICD compromise.
711540	713880	So, the great secret heist,
714340	716060	self-hosted runner post-exploitation,
716060	718040	is how you go from trivial RCE
718040	719980	to complete supply chain attack.
719980	721340	And when we started our research,
721340	722240	we submitted some reports
722240	723260	and we saw some reports
723260	725360	where researchers would get code execution
725360	726840	on self-hosted runners,
726840	727760	and then they'd say,
727760	728620	hey, and by the way,
728620	729740	you can probably do all these
729740	731940	theoretical post-exploitation stuff.
732280	734820	And orgs just didn't care at all.
734820	735780	They should care if you're
735780	737040	executing code on the runners,
737040	738760	but it's kind of what they're
738760	739800	supposed to do anyway,
739800	740960	and so they didn't realize
740960	742600	the actual impact of these attacks
742600	744600	unless you go and demonstrate it.
744600	746360	So, that is what we did.
746880	748480	All right, so to understand
748480	749640	how we were able to achieve
749640	750480	some of this impact,
750480	751360	I want to make sure everyone
751360	753440	understands the magical getup token.
753440	754640	So, this is a token
754640	757060	that is used by all getup actions workflows
757060	758380	to authenticate to GitHub
758380	760760	for API or Git operations,
760760	762500	and it's an OAuth bearer token
762500	763700	that has multiple scopes.
763700	764440	Some of these scopes
764440	765620	can be read or write,
765620	766340	and they're configured
766340	768600	at the repository organization level
768600	769720	or specified within
769720	771660	each specific workflow file.
772160	774240	So, it's very important to know
774240	776060	that these tokens are only valid
776060	777680	for the duration of each job
777680	778620	within a workflow.
778620	780300	As soon as that job concludes,
780300	781660	the token is no longer valid.
781660	783280	So, to conduct some of the
783280	784820	post-exploitation attacks here,
784820	786620	we need to work around
786620	787960	this limitation.
788240	790240	So, let's see how PyTorch,
790240	792500	at the time, used or privileged
792500	794060	the getup token.
794480	795800	Okay, so this getup token
795800	797380	has all the right permissions.
797440	800220	This means we can,
800220	801520	we have a lot of options to play with
801520	803240	for some of our post-exploitation,
803240	805120	and also, this runner right here
805120	807300	is the same one that we now have C2 on.
808640	810440	So, when a workflow uses
810440	811600	the actions checkout step
811600	812480	or some other steps,
812480	814380	the getup token is stored on
814380	816180	the self-hosted runner's file system,
816180	817880	which we have compromised.
817880	819660	So, the problem is that getup tokens
819660	822380	from fork PRs only have read permissions.
822520	825160	So, if we tried to take the getup token
825160	827280	from the fork PR we used
827280	828560	to actually implant the runners,
828560	829900	it's pretty much useless to us.
829900	832020	So, the solution is we persist on the runner
832020	833220	and then we capture a token
833220	835000	from a future workflow.
835280	836880	This is the setup we typically see.
836880	838760	We have the workflow from our fork PR,
838760	840220	no access to secrets,
840220	842780	and a getup token with only read permissions.
843500	845360	Then, we have a workflow
845360	847020	from the base repository.
847160	849680	This workflow does have access to secrets
849680	851620	and the getup token has write permissions.
851620	853560	Notice how they both execute
853560	855400	on the same self-hosted runner.
855400	856500	So, this is the reason that
856500	858480	persistent, non-ephemeral, self-hosted
858480	859580	runners are so bad, right?
859580	860640	If the runner's ephemeral
860640	862420	and we implant it,
862420	864120	it doesn't give us much access
864120	866060	beyond secrets on the file system
866060	866960	or something like that.
866960	868900	If it's persistent and long-lived,
868900	871120	then it will execute future workflows.
871120	873060	So, we implant the runner,
873060	874700	then we wait for future workflows
874700	876980	from the base repo to execute on the runner.
876980	878980	This is why we need to install persistence
878980	881080	rather than just showing code execution.
881300	882980	And then we compromise the getup token
882980	886080	and any getup secrets used by subsequent workflows.
886460	888480	So, in the PyTorch attack,
888480	890000	you can see here, this was our
890000	892140	C2 repository, so we were executing
892140	893680	code on their self-hosted runners
893680	895600	and we waited for a future workflow
895600	897220	to execute from the base repo
897220	899840	and then we just print out the getconfig file
899840	900800	at runtime.
900800	902720	So, this base64 encoded token
902720	904960	is that getup token that we were just talking about.
904960	906780	So, we compromised that getup token.
906780	907880	Again, we could only use it
907880	909820	for the duration of the build,
909820	912820	but some of these jobs lasted a long time,
912820	914280	so we were able to use it for a while.
914560	915980	Alright, one of the first things we did
915980	917200	after obtaining the getup token,
917200	918960	which had actions write access,
918960	921460	is we used it to delete the workflow run logs
921460	923320	because if we got caught,
923320	925320	then we likely wouldn't be able to show impact
925320	927420	in order for Meta's triage team to understand
927420	929060	the severity of the submission.
930100	931760	One of the most direct ways
931760	933360	to demonstrate impact with a getup token
933360	935540	is by modifying getup releases.
935540	937420	So, getup releases is just one way
937420	939520	for a user to download
939700	942060	a release of an application from a repository.
942220	943900	What typically will happen
943900	945780	is you can upload getup releases,
945780	947100	so PyTorch uploads releases
947100	948680	to their getup releases page,
948680	950160	and then if you want to download PyTorch,
950160	951340	one of the ways you can do that
951340	952640	is by going to getup releases
952640	954620	and downloading it there.
954620	956580	Depending on the permissions of the getup token,
956580	958620	it can allow you to modify
958620	960780	releases and release assets.
960780	962520	So, you could potentially backdoor
962740	964620	a release asset, upload it,
964620	966480	and then everyone who downloads and uses
966480	968940	that asset will be running your malicious code.
969660	971780	We did not want to upload
971780	973560	any backdoored assets. We're trying to
973560	975680	identify supply chain attacks, not actually
975680	977840	execute them. So, instead of tampering
977840	979580	with assets, we just tampered with
979580	981760	the release name. So we sent this curl request
981760	983400	using the getup API,
983400	985140	and it uses the compromised getup token
985140	987440	just to add my name to the
987440	989340	end of the release. So, after we sent
989340	991320	that request, you can see the latest
991320	992820	PyTorch release at the time
992820	995480	was now signed by yours truly, and
995480	997280	all we did here was just take a screenshot
997280	999240	and then revert it right away. Obviously, we didn't
999240	1001200	want this being seen by a lot of people,
1001200	1003180	but this was our POC to show that we could
1003180	1005260	tamper with getup releases if we wanted to.
1006000	1007260	A problem that we've encountered
1007260	1008800	with getup release tampering is
1009260	1011140	organizations have came back to us and legitimately
1011140	1013260	said, well, no one really
1013260	1014920	uses our getup releases.
1015320	1017200	Obviously, that shouldn't be the
1017200	1019220	case, but to demonstrate
1019220	1021000	further impact, we wanted to look at
1021000	1023080	getup secrets. Getup secrets
1023080	1025160	are the crown jewels of
1025160	1027060	any repo that uses getup actions.
1027060	1029500	A lot of the times, they're overprivileged,
1029500	1030920	and they can provide lateral movement
1030920	1032920	opportunities beyond the getup
1032920	1035100	repository. So, we
1035100	1036940	were back to being Charlie from
1036940	1038960	It's Always Sunny, and we were searching through
1038960	1041140	all those PyTorch workflows again,
1041140	1042940	trying to see where getup secrets were used,
1042940	1045020	and see if we could compromise them. Here,
1045020	1046980	you can see that they're using some personal access
1046980	1049040	tokens, which are always super interesting. They're using
1049040	1050960	AWS keys, and there were
1051060	1052960	a bunch of other secrets used by the PyTorch
1052960	1054980	repository. And before we go
1054980	1057000	any further, I want to quickly recap how
1057000	1058820	we got here. So, remembering
1058820	1061160	back to the grammar police, we came,
1061160	1062960	we fixed the typo, that typo
1062960	1065340	got merged, that made us a
1065340	1066980	contributor to the repository, which was using the
1067260	1068880	default setting, so we could execute arbitrary
1068880	1070900	workflows. We used that access
1070900	1072840	to execute a workflow that implanted
1072840	1075040	three of their self-hosted runners. Then
1075040	1076860	we stole this getup token from
1077900	1079060	a future workflow executing
1079060	1081000	on that runner, and now we're going to
1081000	1082760	try to use this getup token to exfiltrate
1082760	1083900	getup secrets.
1084280	1086700	One problem that we had to work around
1086700	1088940	is that the workflows that had the
1088940	1090500	getup secrets that we wanted to take
1090500	1092780	didn't actually run on the self-hosted runners
1092780	1094800	that we were now sitting on. So, the solution
1094800	1096680	here was to use the getup token
1096680	1099020	to conduct pipeline privilege escalation
1099020	1100740	and get arbitrary
1100740	1102780	code execution within those workflows so
1102780	1105080	we could get those very nice secrets.
1105960	1107060	Another problem
1107060	1108860	is getup tokens aren't
1108860	1111040	allowed to modify files in the .github
1111040	1112780	slash workflows directory.
1112780	1114820	That seems like a kind of random restriction by
1114820	1116740	getup, but it's actually implemented a few years
1116740	1119020	ago to prevent these exact
1119020	1120940	attacks. So, they want to stop attackers
1120940	1122800	from doing what we're trying to do right
1122800	1124900	now, and so you can't just make a new branch,
1124900	1126760	modify a workflow to exfiltrate secrets, and
1126760	1128300	then you're done.
1128520	1130360	The solution here is you need to find a workflow
1130360	1132760	that uses the getup secrets you're interested
1132760	1134580	in that executes code from
1134580	1136880	outside of this .github slash workflows
1136880	1139100	directory. So, this was our path here.
1139300	1140640	If you look back at
1140640	1143420	PyTorch's weekly.yaml workflow at the time,
1143420	1144720	you can see it does two
1144720	1146380	interesting things.
1146380	1148300	One of them is that it calls this
1148300	1151160	underscore update commit hash .yaml workflow.
1151160	1152980	The other is that it uses these
1152980	1155320	update bot tokens and PyTorch
1155320	1157180	bot tokens, which based on context, we were
1157180	1159140	pretty sure were getup personal access
1159140	1161180	tokens. So, let's look at update
1161180	1162720	commit hash .yaml.
1163280	1165280	This workflow is still in the restricted
1165280	1167160	workflows directory, so we
1167160	1169420	can't modify this workflow with the getup token,
1170120	1170680	but
1170680	1172980	it calls update commit
1172980	1175320	hashes .py, which is in the .github
1175320	1177160	slash scripts directory, so it's not in
1177160	1178580	the restricted workflow directory.
1178580	1180740	All right, so all we need to do now
1180740	1182780	is use the getup token to make a
1182780	1185000	new feature branch and
1185000	1186800	modify that script.
1186800	1188780	And we know that the workflow that calls it
1188780	1192780	runs on a certain event, so we can take advantage of it.
1192780	1193140	The
1193140	1194820	modification that we introduced was quite simple.
1194820	1196820	We saved off the tokens that it
1196820	1198980	received via environment variables to files
1198980	1200780	and then we used our public
1200780	1202800	key to encrypt them and print them to the
1202800	1204860	build logs. This would prevent any other
1204860	1206600	attackers from getting those
1206600	1208660	secrets while we were conducting our POC.
1209400	1210540	Okay, so what did we actually
1210540	1212560	do? We used the getup token to create
1212660	1214560	a new branch. Then on the new branch
1214560	1216440	we added our payload to update commit hashes
1216440	1218540	.py script. Then we used
1218540	1220300	the getup token to trigger our payload via
1220300	1222640	workflow dispatch event. This is because
1222640	1224660	the token had actions write privileges.
1224880	1226420	And then we could retrieve the encrypted
1226420	1228480	secrets from the build logs, cancel
1228480	1230640	the workflow, delete the workflow logs, and actually
1230640	1231960	decrypt the secrets. So
1232440	1234780	at the time when we were doing this operation
1234780	1236780	I was absolutely terrified that
1236780	1238360	I was going to forget to take a screenshot.
1238360	1240660	So instead of taking screenshots I just screen
1240660	1242640	recorded the whole thing. So I have like an 8 hour
1242640	1244740	screen recording of all this stuff from
1244740	1246820	PyTorch. And I condensed some of it
1246820	1248600	into a video on the next slide just showing
1248600	1250540	the getup personal access token
1250540	1253240	exfiltration. So we'll walk you all through that.
1254040	1254480	Here
1254480	1256260	we have our run on runner C2
1256260	1258560	and we're going to navigate to our command
1258560	1260460	output and we're just going to get
1260460	1262580	the base64 encoded getup
1262580	1264620	token. This is from a future workflow
1264620	1266420	that was executing on one of the compromised
1266420	1268740	runners. So we're going to base64
1268740	1270480	decode that token and you can see
1270480	1272520	it's just an authorization header within the getup
1272520	1274560	token. Use the token to clone the
1274560	1276700	repository and then we made a
1276700	1278860	new branch in the PyTorch repository.
1278860	1280980	So within our new branch
1280980	1283000	we're going to modify that Python
1283000	1285820	script that we identified as an injection point.
1285820	1287460	Here with my
1287460	1288980	really poor Vim skills I'm going to paste
1288980	1290560	our new payload to exfiltrate those secrets
1290560	1292540	and then once the payload
1292540	1294540	is set we're going to actually commit
1294540	1296680	this to the repository because the token
1296680	1298640	has contents right. So we commit
1298640	1300460	it to the repo. Now we're going to use a curl
1300460	1302400	request just to trigger this
1302400	1304560	workflow from our branch which has the
1304560	1306520	injected code in it and then we're
1306520	1308300	looking at the actual PyTorch repository
1308300	1309880	now where we just triggered a workflow
1310520	1312300	and we're going to see two
1312920	1314480	base64 encoded encrypted
1314480	1316300	blobs. So we're going to scroll down
1316300	1318420	and we're going to get these blobs which is the
1318420	1320400	output of our commands and then we're
1320400	1322400	going to go to this
1322400	1324740	other terminal and decrypt
1324740	1326340	them. So first we're just going to base64
1326340	1328300	decode them and then we're going to save them to a file
1328300	1330160	and we're going to use our private key
1330160	1332580	locally to actually decrypt them and get the token.
1332580	1334480	So once you see some
1334480	1336580	output that starts with ghp
1336580	1338280	underscore those are the personal
1338280	1340220	access tokens and we're going to take them
1340220	1342080	and run them through Gato
1342660	1344420	which will do a bunch of automated
1344420	1346220	enumeration using the GitHub APIs
1346220	1348440	and then Gato will tell us
1348440	1350360	who the owners are, what they have access
1350360	1352180	to, and what the potential
1352180	1354300	impact is. Because if they just had read
1354300	1356300	access to the repository, you know, there's not
1356400	1358300	a real risk here to PyTorch. If they
1358300	1360180	have other, you know, more
1360180	1362360	sensitive privileges then it could be bad.
1362360	1364240	So here we're running them through Gato. You
1364240	1366260	can see one of the users is the PyTorch update
1366260	1368220	bot user. The other is the PyTorch bot
1368220	1370360	user. And they're both PyTorch organization
1370360	1371500	members. The tokens
1371940	1374300	have repo scope. So we can use this
1374300	1376020	now to interact with the PyTorch repository
1376020	1377880	directly. These are long-lived credentials
1377880	1380520	and they had access to 93 repos
1380520	1382280	within the PyTorch organization.
1382300	1384200	A lot of which were private and did not have
1384200	1386160	branch protection. So you could have done whatever you
1386160	1388020	wanted to them. And there's
1388400	1390500	a lot of paths here to supply chain compromise.
1391160	1392500	Alright, that was a lot,
1392500	1393680	right? Okay, so
1394170	1396260	what can we do? So we have those two
1396260	1398280	tokens so we can use them by themselves
1398280	1400540	to simply introduce code into the main branch.
1400540	1402180	One creates a pull request and have
1402180	1403960	the other one approve and merge it. Boom.
1403960	1406140	Supply chain compromise. Another form
1406140	1407800	would be to backdoor a dependency
1407800	1410160	within the PyTorch organization that's used by
1410160	1412040	the primary PyTorch repo.
1412040	1414000	And that could be a more subtle way to
1414000	1416840	obtain that same final impact.
1416860	1418140	And finally, there's even
1418140	1420280	more clever ways like smuggling
1420280	1421860	malicious code into an in-progress
1421860	1424000	feature branch as a developer is working on
1424000	1426160	and then have that merged in. So really
1426160	1428080	there's too many paths to count for
1428080	1430080	how this could impact end users of
1430080	1431020	PyTorch.
1432220	1434280	If you want to see even more
1434280	1436760	impact and you're not really into github,
1436760	1438280	this section is for you.
1438280	1440260	So, if you noticed a few slides ago
1440260	1442240	when we were looking at their secrets, we saw that they also
1442240	1443920	had AWS keys.
1443960	1446120	We conducted a very similar attack
1446120	1448180	to the one we just showed, right, where
1448180	1450260	we do that kind of workflow hopping and injection
1450260	1451940	and triggering with the github token.
1451940	1454740	We repeated that process to grab their AWS keys.
1454740	1456420	And the reason we wanted to do this was
1456420	1458440	if you don't understand github,
1458440	1460120	it can sometimes be hard to even
1460120	1462100	see why code contributions
1462100	1464520	to the main branch of a repository
1464520	1466340	could be impactful. But,
1466340	1468380	everyone understands AWS and AWS
1468380	1470400	releases. So, we grabbed these keys
1470400	1472480	then we used the AWS CLI to authenticate
1472480	1474360	and we confirmed that we were the
1474360	1476440	PyTorch bot user. So, we didn't
1476440	1478440	want to poke around too much, but we did some basic
1478440	1480260	AWS S3 LS commands
1480260	1482420	and saw that this user had a lot of
1482420	1484280	privileges. We confirmed through the
1484280	1486160	workflow logs that they could actually write
1486160	1487900	to these S3 buckets.
1488080	1490060	And, one weird thing that we weren't
1490060	1492040	really expecting to see was there were PyTorch
1492040	1494060	releases in these S3
1494060	1496340	buckets. So, at the time, honestly
1496340	1498080	I didn't think too much of it
1498080	1500000	because I was kind of freaked out with the access we had
1500000	1502280	and wanted to submit the report right away.
1502280	1503720	I think, like we said, this was hour
1503720	1505880	8 or 9 at this point and
1505880	1508020	I just wanted to get the report in. So, I didn't
1508020	1510100	really pay attention to these releases. And then we were rehearsing
1510100	1512060	like a week ago and we were talking
1512060	1513980	and I was like, why were these
1513980	1516080	releases in these S3 buckets?
1516080	1517960	Like, what system was pulling releases from here?
1517960	1519860	So, I went to the
1519860	1521620	PyTorch website and
1522240	1524260	just going to PyTorch.org
1524260	1525920	or PyTorch.com, whatever it is, you
1525920	1528020	can scroll down and you can see when they instruct
1528020	1529980	users to install, download
1529980	1531900	and install PyTorch, if you're using PIP or
1531900	1533660	whatever, you're using this
1533660	1534760	download.
1536180	1538400	What is it? Download.pytorch.org
1538400	1539780	URL. So, a lot of the releases
1539780	1541880	were coming from this URL. So, we went to this
1541880	1544300	URL in a
1544300	1546160	new tab and we're just looking at
1546160	1548480	the request and response headers
1548480	1550120	and sure enough,
1550120	1552280	in the headers, they confirmed that
1552280	1554040	these were actually pulling releases from
1554040	1556380	these S3 buckets and
1556380	1558960	the layout of the
1558960	1560160	release assets on
1560160	1562120	that website were identical to the
1562120	1564120	layout in the S3 buckets. So,
1564120	1566220	basically, with those AWS keys, we could have
1566220	1568060	uploaded our own PyTorch releases
1568060	1569820	to these S3 buckets and then
1569820	1571720	anyone who downloads
1572300	1573780	PyTorch by following the
1573780	1575720	instructions from the website is going to be
1575720	1577760	downloading and potentially executing our
1577760	1579460	malicious code. So, this is that kind of
1579460	1581860	solar wind style supply chain attack for anyone
1581860	1583840	that uses PyTorch in the future.
1585340	1586300	Okay.
1586620	1587820	That was a lot. We just
1587820	1589940	did a lot. This is what it looks like
1589940	1591700	put into a nice little red team diagram
1591700	1593920	and if anyone got
1593920	1595760	here late or fell asleep, we'll
1595760	1597860	do a quick recap. So, we started by opening
1598080	1599660	a typo fix PR in the PyTorch
1599660	1601940	repository. That PR got
1601940	1603980	merged and then we were a contributor
1603980	1605860	so we submitted a malicious pull request
1605860	1607760	that installed our runner-on-runner
1607760	1610220	C2 on three different self-hosted
1610220	1611300	GitHub runners.
1611660	1613960	From one of these runners, we stole a GitHub
1613960	1615960	token from a future build and
1615960	1617860	we used that to do a bunch of stuff. First, we just
1617860	1619880	modified that release by updating the release
1619880	1622260	title with my name and reverting.
1622260	1623860	Then, we created a feature
1623860	1625420	branch in the PyTorch repository
1625420	1627460	and we triggered additional
1627460	1629020	workflows using that workflow
1629020	1631500	dispatch event injecting through the scripts
1631500	1633280	that were outside of the restricted workflows
1633280	1635380	directory. Through this
1635380	1637540	process, we stole some secrets. We stole
1637540	1639220	the PyTorch bot AWS keys
1639220	1641540	and then we stole two GitHub personal access
1641540	1643920	tokens used by PyTorch bot users.
1643920	1645380	There were a bunch more secrets in there but
1645380	1646880	we didn't think there was
1647420	1650100	any need for additional demonstration of impact.
1650380	1651600	Using the AWS keys,
1651600	1653460	we could upload new PyTorch
1653460	1655480	releases to this S3 bucket. Obviously, we did
1655480	1657620	not do that. Then, using the GitHub personal
1657620	1659380	access tokens, we could have
1659380	1661460	modified PyTorch dependencies. We could
1661460	1663400	have used them in conjunction to commit and
1663400	1664980	then approve merges to main
1664980	1667040	and done a lot of other bad stuff.
1667720	1669640	All of this goes to say, at the end of the day,
1669640	1671380	there were a lot of supply chain
1671380	1673260	compromised past year which would have affected
1674580	1675380	most people
1675380	1677340	using PyTorch both
1677340	1679060	currently and in the future.
1680220	1681560	You would think that this
1681560	1683540	amount of demonstration of impact would
1683540	1685640	be enough to convince PyTorch to
1685640	1687700	immediately and urgently
1687700	1689360	apply fixes and
1689360	1691620	well, we'll let
1691620	1693420	the disclosure timeline speak for itself.
1693420	1695440	We submitted this issue
1695440	1697500	in August 2023 to
1697500	1698900	Metabug Bounty.
1699360	1701560	A month later,
1701560	1703820	Meta said there is no update to provide.
1704260	1705440	Two months later,
1705440	1707900	Meta said they consider the issue mitigated.
1707960	1709300	I was suspicious
1709300	1710620	so I went back in and
1710620	1712600	just executed some
1713680	1715080	shell commands on the runners.
1715080	1717200	I didn't do the full attack, but anyone
1717200	1719140	can still compromise their runners. Any contributor
1719140	1721340	and based on the workflow logs and stuff,
1721340	1723200	I don't think their configurations were still secure
1723200	1725200	so we responded saying, hey, the issue
1725200	1727420	is not fully mitigated. Here's some proof.
1727560	1728040	Then
1729820	1731360	another two months went
1731360	1733120	by with really no word from Meta
1733120	1735300	and we sent a strongly worded
1735300	1737220	email expressing concerns
1737220	1739020	on the remediation that has been
1739020	1741240	implemented, which led to some back and forth.
1741240	1743020	Then December 15th,
1743020	1744420	Meta applied some other fixes
1745040	1746660	which seemed to be sufficient
1747060	1749200	and then they offered a call to discuss the remediation
1749200	1751040	in depth. We actually ended up
1751040	1753280	meeting with two of the PyTorch maintainers
1753280	1755060	and they were very concerned about
1755060	1757000	these issues. They were on top of it
1757000	1758940	and they also expressed
1758940	1761720	concern at the potential gaps in remediation.
1761800	1763060	I'm not totally sure
1763060	1764740	where the disconnect was, but
1764740	1766360	it worried us that
1766360	1769320	PyTorch was potentially vulnerable for this long.
1771100	1772900	This attack took a lot of
1772900	1775400	hands-on keyboard workflow modification,
1775400	1776760	command and control, all that
1776760	1778540	stuff, and so it kind of
1778540	1780600	prompted us to say, hmm,
1780600	1783220	is there an easier way to automate a lot of this?
1783800	1784640	Alright, well,
1784640	1786440	now there is. So with a tool that
1786440	1788780	I've open sourced this week called GatoX,
1788780	1790440	it actually automates that
1790440	1793180	self-holster runner takeover process.
1793180	1795420	So now, instead of all that work that you saw
1795420	1797420	John have to do, which all you have to do
1797420	1798780	is you fix a typo,
1798780	1801620	and you become a contributor, then you run GatoX,
1801620	1803360	and then one of two things happens.
1803500	1805240	You either get a shell and you're
1805240	1807100	on top of the world as hacker man, or
1807100	1809140	you learn that approval is required and then
1809140	1811680	you're sad because you didn't get to hack anything.
1811820	1813240	So let's walk
1813240	1815120	through a quick video demo of how GatoX
1815120	1817220	works to automate this self-holstered runner
1817220	1819220	takeover process. So first
1819220	1821440	I use it to enumerate a runner.
1821440	1823540	So now I'm going to go ahead and
1823540	1825720	fix a typo in this test repository
1825720	1827520	here. So I go ahead and
1827520	1829440	fix a typo and make that
1829440	1831580	commit. So after
1831580	1833680	I make the commit, I'm going to go ahead
1833680	1835440	and create a pull request.
1835440	1837440	So I check that I fixed the typo and I make a quick
1837440	1839520	typo fix PR and
1839520	1841480	now that's merged in. So after
1841480	1843460	that's merged in with my attacker account,
1843460	1845420	I'm going to go ahead and delete the fork.
1845540	1847340	So because GatoX will create a new fork
1847340	1849760	to throw the payload at the repository.
1849760	1851780	So I'm going to quickly go ahead
1851780	1853260	and do the web flow to delete the fork
1853760	1855780	and I hit confirm. Alright,
1855780	1857600	now I'm going to run GatoX. So
1857600	1859980	here I've just configured it to deploy a
1859980	1861790	runner on runner on a Linux x86
1862800	1863840	64-bit runner.
1863840	1866240	So it's going to go ahead and create the payload
1866360	1868340	within a gist and ask for confirmation
1868340	1870400	because the next steps are overt.
1870400	1872860	So I'm going to type confirm and hit enter.
1872860	1873900	So as soon as
1873900	1876100	I do that, it's going to create a draft pull
1876100	1877700	request which is going to deploy that runner
1877700	1879680	on runner payload onto that
1879680	1882060	self hosted runner via fork PR.
1882120	1883780	So it's going to take a second
1883780	1885740	because it's now pulling for that runner to connect
1885740	1888040	to GitHub and then check back into that repository.
1888100	1889660	So as soon as it does that, it will drop
1889660	1891340	into a nice and very convenient
1891340	1893700	shell. Okay, now
1893700	1895760	I'm just going to test this with uname-a
1895760	1897860	and when I hit enter, what's happening
1897860	1899860	under the hood is that GatoX
1899860	1901640	is issuing a workflow dispatch event
1901640	1903740	to that workflow in the C2
1903740	1905800	repository which is going to run code
1905800	1907900	on that malicious
1907900	1910200	self hosted runner. And you can see that output there.
1910960	1911560	Alright, so
1911560	1913720	now you know the techniques and now
1913720	1915680	since I've open sourced it, you have a tool.
1915860	1917240	And another thing I want to point out is that
1918420	1920000	finding CICD misconfigurations
1920000	1921820	in open source repositories can be
1921940	1923700	a very thankless job because you
1923700	1925900	submit a report, they fix a bug, and you don't even get
1926020	1927680	a CVE. So there's not really a lot of motivation
1927680	1929800	for people. So what I've done with GatoX
1929800	1931760	is that on its wiki, I've
1931760	1933960	created a little hall of fame. So if you use GatoX
1933960	1936400	to find a pwn request, injection,
1936400	1937980	or self hosted runner vulnerability in an
1937980	1940240	open source project, and the maintainers
1940240	1942040	fix it, then just make an issue and I'll add you
1942040	1944200	your name to the wiki to get some credit.
1944200	1946020	Just make sure it's actually fixed because we don't
1946020	1947880	want the hall of fame to be the hall of odays.
1947880	1949680	As much as some people might like that.
1951340	1952100	Okay, so
1952100	1954140	we showed all of the technical TTPs
1954140	1956040	we used during our PyTorch attack
1956040	1957840	but there are a bunch of other stuff
1957840	1959960	we've used on other targets. And so
1959960	1961980	we want to take these next
1961980	1963960	few minutes to honor the die hard
1963960	1965940	CICD nerds who are here to learn all
1965940	1968040	the TTPs possible. So we're going to run through
1968040	1970120	this pretty quickly but all the slides
1970120	1972060	will be up there online so you can check it out after.
1972380	1974020	Alright, so one thing you can
1974020	1975760	do after getting persistence on a runner is
1975760	1977900	solo run style build compromise.
1978020	1979880	So, you get persistence
1979880	1982360	and then you just have to modify
1983060	1983940	scripts for the
1983940	1986120	build or source code after it's checked out.
1986120	1987980	And once you do that, the final
1987980	1989880	build artifacts from that run
1989880	1991740	are going to be poisoned but there's no
1991740	1993940	it's not going to be linked back to the original source code
1993940	1995500	so it's a very stealthy way to
1995500	1997580	conduct a supply chain attack.
1997760	1999960	And here's another way that you could take
1999960	2002480	GitHub release asset tampering a little further.
2002540	2003580	So, if you have that
2003580	2005800	context write token, then all you have to do
2005800	2007860	to tamper with releases on assets is
2007860	2010000	use the API to delete the old asset
2010000	2011660	and then upload a new one with a post request
2011660	2013440	right on top of it. And
2013980	2015900	the indicator of compromise here is
2015900	2017880	just going to be the timestamp when
2018240	2019820	a user is looking at it through the
2019820	2022500	web interface so it's not very obvious.
2022500	2024000	And if you want to see a tale of
2024200	2025940	a bug bounty gone wrong and a program acting
2025940	2027900	in some pretty bad faith, go check out my
2027900	2029520	blog post on my report to the
2029520	2031300	ASTAR network which is a tiny
2031900	2033340	polkadot parachain.
2039940	2041480	Alright, another technique
2041480	2043280	you can add to your arsenal is something
2043280	2045160	called a post checkout hook.
2045180	2047200	So, what happens when
2048120	2049380	a subsequent workflow that you need
2049380	2050980	to get secrets from or token from
2050980	2052960	runs only very
2052960	2054880	infrequently? Well, you need something
2054880	2056700	that can have these qualities.
2056700	2058480	You need to be able to extend the build time
2058980	2061020	you also don't want to break how the workflow
2061020	2063000	works to inform someone that something is
2063000	2065000	going wrong and you also want to get notified
2065000	2067620	because you don't want to be pressing F5 for two weeks.
2067680	2069200	Well, a quick solution
2069200	2071020	here is to place a script like
2071020	2072760	this into the git hooks directory
2072760	2074840	of the repository in the original self hosted
2074840	2076680	runner. This example here
2076680	2078760	will just take that git config
2078760	2080780	file, encode it and then send it off to your
2080780	2082840	exfil URL and then sleep for 15
2082840	2084840	minutes. So, this is going to give you 15 minutes
2084840	2086980	to take advantage of that github token to perform
2086980	2088880	post exploitation actions.
2089180	2090820	Alright, before we
2090820	2092900	dive into other TTPs, it's important
2092900	2094860	to remember how self hosted runner takeover
2094860	2096680	falls within the landscape of
2096680	2099060	broader github actions attack techniques.
2099060	2100940	So, there's another type of attack
2100940	2102180	called bone requests where
2103480	2104760	you basically get
2104760	2106700	execution within a privileged workflow.
2106700	2108980	That's the same thing that happens with runner takeover.
2109020	2110680	From there, there's different
2110680	2112780	post exploitation techniques you can use.
2112780	2114500	So, you can steal secrets, you could
2114500	2116600	get the actions runtime token, which has some
2116600	2118480	interesting attacks with cache poisoning
2118480	2120700	as well as OIDC abuse, which
2120700	2122160	I think the talk right after
2122580	2124800	us in this track actually goes into a lot more detail
2124800	2126560	there. So, kind of cool.
2126840	2128640	And then, there's just too many different
2128640	2130840	attacks to talk about. There's so many ways to achieve
2131260	2132420	great impact.
2133300	2134580	We talked about some of the permissions
2134580	2136660	of the github token today, but there's a lot
2136660	2138180	of other dangerous permissions out there.
2138180	2140480	Some of them don't pose a risk, but others, like
2140480	2142740	contents write and actions write, obviously pose
2143000	2144260	a significant risk.
2144360	2146780	Other permissions we have identified as dangerous
2146780	2148480	and actually abused during our attacks are
2148480	2150660	pages write, pull requests write,
2150660	2152380	and packages write. And there's a lot of good documentation
2152380	2155060	online if you want to learn more about what these actually do.
2155880	2156560	If you have
2156560	2158460	just actions write and contents write, you can create
2158460	2160620	feature branches, modify files,
2160620	2162660	execute in workflows, and then issue dispatches
2162660	2164780	events to seal secrets. If that looks
2164780	2166740	familiar, it's because that's exactly what we did during
2166740	2167440	PyTorch.
2168000	2170700	Alright, what if you have a workflow that
2170700	2172700	looks like this? It runs on workflow dispatch,
2172700	2174980	but then uses some of that input in a
2174980	2177380	github script or run step. Well,
2177380	2179740	this lets you do good old 90's style
2179740	2181360	code injection. And I'm going to walk you through how
2181360	2183840	this process works. And you only need a github token
2183840	2186280	actions write to make this hop.
2186280	2188040	So, here you can see
2188040	2189780	that the input from the dispatch
2189780	2190700	event has org and repository, and
2190700	2192560	within that script step, repository
2192560	2195300	is used by github context expression.
2195300	2196860	So, that's going to be our injection
2196860	2198620	point there. See that arrow?
2198760	2200840	So, here's an example payload thrown
2200840	2202660	with a simple request script in
2202660	2204620	Python. The first thing here is to
2204620	2206700	close out the script because we
2206700	2208600	don't want a syntax error or have it to crash because
2208600	2210740	we still need the code to finish in order for us
2210740	2212500	to get our payload execution.
2212820	2214700	The next thing, and this is where
2214700	2217140	the actual payload is, is a
2217820	2218340	JavaScript injection
2218340	2220460	payload that essentially will pull
2221100	2222340	code from a
2223840	2225140	C2 URL
2225140	2226720	and pipe it to bash. So, then
2226720	2229220	you can just have arbitrary code there and
2229220	2230760	get execution in that workflow, get the token,
2230760	2232920	get the secrets, and then from there
2232920	2238090	do more post exploitation.
2238090	2239510	If you only have
2239510	2240930	contents write, there's still a lot of bad stuff
2240930	2243270	you can do. You can modify
2243270	2245570	non-protected branches a lot of times, which
2245570	2247790	actually could end up in releases.
2247790	2248650	You can modify releases directly, like we
2248650	2250830	did when we signed my name. You can modify
2250830	2252790	tags, which a lot of times reusable actions
2252790	2254750	are referenced by tags, so that could open
2254750	2256770	up some fun possibilities.
2256770	2258650	And then you can also issue repository dispatch
2258650	2260490	events to execute workflows.
2261430	2262790	Alright, here's a really
2262790	2264190	unique way to take advantage of
2264190	2266550	contents write. Alright, so
2266550	2268690	one way is if you want to
2268690	2270630	get execution on a workflow that only runs
2270630	2272730	on the push trigger, you can add
2272730	2273930	code to that
2274610	2276910	feature branch that modifies
2277050	2278670	a script that's called by that
2278670	2281290	workflow. And the next time the developer will push changes,
2281290	2282950	now you have arbitrary code
2282950	2284750	execution within the context of that workflow
2284750	2287550	and then you can jump further from there.
2287550	2288630	Another way is instead of
2288630	2291210	targeting the workflows, why not target the developer?
2291210	2293070	So you could modify a unit test
2293070	2294130	within a feature branch
2294750	2296730	that a developer is working on
2296730	2299130	and add an info stealer payload.
2299130	2300750	So then when the workflow
2300750	2302630	runs, the dev account's compromised and
2302630	2304610	often in organizations, dev accounts
2304610	2306330	compromise can be game over.
2306350	2308050	Another way is if you have
2308410	2310590	these two permissions for the token, you can get
2310590	2312630	code modification in the protected
2313210	2314550	default branch. So there's
2314550	2316110	some preconditions here. The repository
2316110	2318350	has to have the setting to allow get of actions
2318350	2320690	to approve and merge pull requests.
2320730	2322270	There can be at most one
2322270	2324050	reviewer required for that
2324050	2325870	pull request approval rule.
2325990	2328330	And there cannot be any code
2328330	2330190	owner protection rule sets enabled
2330190	2332370	and enforced. When all of these are
2332370	2334950	together, you can have an attack like this.
2335070	2337510	Attacker gets the GitHub token,
2337510	2338510	they use their account
2338510	2340630	to create a fork pull request with malicious changes
2340630	2342510	and then they approve that
2342510	2344210	pull request with that capture token
2344210	2346430	and merge that pull request.
2346430	2349070	That leads to a good old supply chain compromise.
2350870	2352430	Now, if you're on a runner,
2352430	2354110	it's possible to steal the GitHub actions
2354110	2356410	runtime token from a future workflow.
2356410	2358410	This is where you'll have some attack paths
2358410	2360370	for GitHub actions cache poisoning.
2360370	2362290	I have a blog post on my website
2362290	2364430	that goes into the details of that.
2364710	2366770	And if there's an organization
2366770	2368250	level runner group that shares
2368970	2370630	that also private repositories
2370630	2372290	are using, then there's paths to
2372290	2374490	jump to private repositories and other runner groups
2374490	2376330	and it just kind of blows those
2376330	2377510	attack paths wide open.
2378550	2380570	Okay, that's the end of some of the more advanced
2380570	2382410	TTPs. If you're the type of
2382410	2384390	person who likes big mind maps to
2384390	2386310	tell you exactly what to do, I made
2386310	2388430	one and I put it on my GitHub a few days
2388430	2390450	ago, so you can go check that out. Obviously, this is
2390450	2392350	not comprehensive, but if
2392350	2394190	you're trying to get into GitHub actions exploitation
2394590	2396410	and you have read or write access
2396410	2398410	to a repo but don't really know what to look for
2398410	2400470	or what to do next, check this out. It should
2400470	2401950	be able to give you some good guidance.
2403110	2404390	In our opinion, GitHub can do a few
2404390	2406730	things better. They can increase warnings and awareness,
2406730	2408570	so if you try to attach a selfless
2408570	2410490	runner to a public repo, it'd be great
2410490	2412650	if there were big red letters saying, be careful,
2412650	2414550	this is dangerous. They can also improve their secure
2415030	2416330	defaults, like we talked about with the
2416330	2418250	workflow approval requirements, and then
2418250	2420210	they could implement granular approval
2420210	2422350	requirements so that maintainers
2422350	2423990	don't need to select between
2423990	2426230	three options, all of which have broad
2426230	2428230	privileges and probably will hurt
2428230	2430550	developer workflows one way or the other.
2431010	2432270	If you're trying to defend
2432270	2434110	your organization from these attacks,
2434110	2435950	start with the easy stuff. Please
2435950	2437970	change this radio button so that you require
2437970	2440430	approval for all outside collaborators.
2440650	2442430	We use the GitHub token extensively
2442430	2444290	and almost all of our attacks set
2444290	2446390	it to read-only. That will stop
2446510	2448470	a lot of post-exploitation opportunities.
2448470	2450250	And then use, enforce
2450250	2452370	your devs to use fine-grained personal access tokens.
2452370	2454410	We, like, we hate discovering
2454410	2456310	fine-grained tokens on red team engagements
2456310	2458270	because they only give you access
2458270	2460330	to one repository. If we find a personal
2460330	2462250	access token that's classic, we can do
2462350	2464390	a lot of stuff. If it's fine-grained,
2464390	2466010	sometimes that's the end of the road.
2466570	2468370	Alright, there's also
2468370	2470410	ways to secure yourself more by making
2470410	2472770	sure that your selfless runners are ephemeral.
2472770	2474510	So, GitHub maintains something called
2474990	2476510	ActionsRunnerController, which allows you to
2476510	2478290	automatically spin up and spin down
2478290	2480330	self-hosted runners using Kubernetes.
2480610	2482850	Also, a lot of cloud providers have auto-scaling
2482850	2484210	groups that can be linked with
2484210	2486330	self-hosted runners and have that
2486330	2488630	also be done automatically. And finally,
2488630	2490610	there's a lot of third parties that offer
2490610	2491430	turnkey
2492330	2494390	drop-in replacements for GitHub
2494390	2496450	runners that are also ephemeral if you
2496450	2498370	don't want to use just the GitHub-hosted
2498370	2500430	runners. And one
2500430	2502270	thing that's important to remember here is that
2502270	2504430	ephemeral means the environment
2504430	2506650	that the runner is in also has to be ephemeral.
2506650	2508190	So, if there's an ephemeral runner,
2508190	2510470	but it's using a non-ephemeral
2510470	2512090	file share, then an attacker can simply
2512090	2514510	jump to other workflows by
2514510	2516550	saving certain files off.
2516550	2518490	So, it's important to really consider the
2518490	2520510	entirety of that environment
2520510	2523030	when it comes to build agent security.
2523990	2524530	Alright, so
2524530	2526390	another way is by using GitHub's
2526390	2528450	feature for runner group pinning.
2528450	2530930	So, GitHub has a feature where if you have a
2530930	2532890	runner group, you can actually pin it to
2532890	2534790	a specific workflow, or even
2534790	2537650	a specific SHA or reference of a workflow.
2537650	2538750	So, with this,
2538950	2540810	you have a lot of different options to
2540810	2542850	restrict which workflows can even use the runner.
2542850	2545410	And all of this has the ultimate effect of
2545410	2547790	protecting your most privileged runners.
2547790	2549250	We want to end our talk
2549250	2551250	today by emphasizing that
2551250	2553210	this talk and this research is not
2553210	2555490	about PyTorch. So, we have
2555490	2556490	some key takeaways here. If you've been zoning out,
2556490	2558150	lock in for this last slide.
2558150	2560310	What we did to PyTorch, we've
2560310	2562430	been able to do to a lot of advanced
2562430	2564410	mature organizations because of this
2564410	2566850	lack of awareness around CICD agent security.
2566850	2567970	So, I think we've submitted
2568330	2570950	over 20 high and critical bug bounty submissions.
2570950	2572170	Among them were critical vulnerabilities
2572170	2574790	in GitHub Actions, Microsoft, PyTorch,
2574790	2576670	TensorFlow, ASTAR,
2577210	2578390	HydroGX, ByteDance,
2578390	2581090	and a lot more that we're not allowed to talk about.
2581930	2582570	Additionally,
2582570	2584630	if you think that public CICD security
2584630	2586450	is bad, internal CICD security
2586450	2588650	is a nightmare. Almost
2590010	2590450	not
2590450	2592870	every Red Team engagement I've been on, but a
2592870	2594930	lot of Red Team engagements were able to get access
2595050	2596950	to a CICD platform and then
2596950	2599030	escalate privileges and use it to reach objective.
2599030	2600910	It's almost become the new ADCS
2600910	2604170	for us where internally everyone's vulnerable
2604170	2605690	and compromising these CICD
2605690	2608750	platforms can give you extensive
2608750	2609130	privileges. Finally,
2609130	2611290	what we need everyone to do is go learn about
2611290	2612710	these attacks to protect your org from compromise.
2612710	2614570	The main issue we see is just this lack of
2614570	2616710	awareness. So if devs, architects,
2616710	2618990	execs, and everyone is learning about these attacks,
2618990	2620710	they'll be able to implement controls that
2620710	2622690	hopefully protect their organization from
2622690	2624750	the next critical supply chain attack.
2625430	2626830	Alright, the moral of the story here
2626830	2628710	is learn about this stuff and don't let
2628710	2629770	this be you.
2632590	2634570	Alright, so we want to start off by
2634570	2636790	thanking all of the bug bounty triage teams
2636790	2638630	that handled some of the reports and
2638630	2640790	handled them well and applied solid mitigations
2640790	2642730	to their products. We'd like to thank
2642730	2644870	everyone who showed out today. Thank you so much for watching
2644870	2646710	us and helping us raise awareness and for everyone
2646710	2649050	watching online. Thank you.
2649050	2650650	We'd like to thank DEF CON for giving us
2650650	2652810	this platform. We wanted to speak here for a long time
2652810	2654150	so this has been really fun.
2654530	2656610	Please, we don't have time for questions, but come find us
2656610	2658710	after if you want to talk more. Thank you
2658710	2659310	everybody!
