๐ Introduction
Github actions์์ ์ฌ์ฉ์๊ฐ ์์ฑํ๋ workflow, ๊ฐ๋ฐ์๊ฐ ์ ๊ณตํ๋ custom actions์์ ์ฌ์ฉ์ ์ ๋ ฅ ๊ฐ์ ๋ํด ์ ํํ๊ฒ ๊ฒ์ฆํ๊ณ ์ฌ์ฉํ์ง ์์ผ๋ฉด Command Injection์ ๊ฐ๋ฅ์ฑ์ด ์กด์ฌํ๊ฒ ๋ฉ๋๋ค. ์ผ๋ฐ์ ์ผ๋ก Github action injection, Github action script injection ๋ฑ์ผ๋ก ๋ถ๋ฆฝ๋๋ค.
Example code
|
|
์์ ๊ฐ์ด github.event.pull_request.title
๋ก Pull Request์ Title์ Workflow์์ ์ง์ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ ์๋์ ๊ฐ์ ์ ๋ชฉ์ผ๋ก ๊ณต๊ฒฉ์ด ๊ฐ๋ฅํฉ๋๋ค.
Workflow ์ฝ๋์์ ๋ณ์ ๊ฐ์ด ๊ทธ๋๋ก ์ฝ์
๋๊ธฐ ๋๋ฌธ์ ์๋์ ๊ฐ์ ์ฝ๋๋ก ์นํ๋ฉ๋๋ค. ๊ทธ๋ฌ๋ฉด curl
์ด string ๋ด๋ถ์ ์๋๊ฒ ์๋๊ธฐ ๋๋ฌธ์ ๋ช
๋ น์ผ๋ก ์คํ๋ฉ๋๋ค.
|
|
Actions > Workflow ์ ๋ค์ด๊ฐ์ ๋ก๊ทธ๋ฅผ ๋ณด๋ฉด curl ๋ช
๋ น์ด ์คํ๋ ๊ฒ์ ๋ณผ ์ ์์ต๋๋ค.
๊ทธ๋ฆฌ๊ณ ์ค์ ๋ก OAST ์๋น์ค๋ก DNS Query์ HTTP Request๋ก ๋์ฐฉํ ๊ฒ์ ๋ณผ ์ ์์ฃ .
์์ ๋ํ ์ค์ ๋ฐ์ดํฐ๋ ์๋ ๋งํฌ์์ ํ์ธํ์ค ์ ์์ต๋๋ค.
Risk
Public github
Public Githubd์์ github์ runner๊ฐ ์ฌ์ฉ๋๊ธฐ ๋๋ฌธ์ ์ค์ ๋ก ์ฝ๋ ๋์์ github ์ชฝ ์๋ฒ์์ ์ผ์ด๋๊ฒ ๋ฉ๋๋ค. ๋ค๋ง workflow ๋์์ ์ํด secret ๋ฑ ๋ runner์ ๋ด๋ ค์ค๊ธฐ ๋๋ฌธ์ ๊ณต๊ฒฉ์๊ฐ ๋จ์ํ ๋ช ๋ น ์คํ์ ํตํด github์ ๋ฌธ์ ๋ฅผ ๋ฐ์์ํค๊ธฐ ๋ณด๋จ ํ ํฐ ํ์ทจ๋ ์ค์์ ๋ณด๋ฅผ ํ์ทจํ๋๋ฐ ํฌ์ปค์ค๊ฐ ๋์ต๋๋ค.
Enterprise github
Enterprise github์์๋ runner๊ฐ enterprise ์ฌ์ฉ์์ผ ๊ฐ๋ฅ์ฑ์ด ๋๊ธฐ ๋๋ฌธ์ ์๋ฒ ํ์ทจ์ ๊ด๋ จ๋ ์ด์, ๊ทธ๋ฆฌ๊ณ workflow ๋์ ์ checkout ๋ฑ์ ํตํด ์ฝ๋๋ฅผ ๋ด๋ ค๋ฐ๋ ๊ฒฝ์ฐ๊ฐ ๋์๋ฐ, ์ด๋ฐ ํํ๋ก ์ฌ์ฉ๋ ๊ฒฝ์ฐ ๋ด๋ถ ์ฝ๋ ํ์ทจ ๋ฑ์ ์ด์๊ฐ ์กด์ฌํฉ๋๋ค. ์ ๋ขฐํ ์ ์๋ ์ฝ๋๋ฅผ ์คํํ ์ ์๊ธฐ ๋๋ฌธ์ ์ ์ฒดํฌ๋์ด์ผ ํฉ๋๋ค.
Self-hosted runner
Public, Enterprise ๋ชจ๋ Self-hosted runner ์ฌ์ฉ์ด ๊ฐ๋ฅํฉ๋๋ค. ์ด ๋ ๋น์ฐํ Runner๋ฅผ ์ด์ํ๋ ์ฌ์ฉ์์ ์๋ฒ๋ฅผ ๋์์ผ๋ก ๊ณต๊ฒฉ์ด ์ผ์ด๋ ์ ์๊ธฐ ๋๋ฌธ์ ํด๋น ๊ด์ ์์ ๋ฆฌ์คํฌ๊ฐ ๋์ต๋๋ค.
๐ก Offensive techniques
Detect
Workflow
์ฌ์ฉ์๊ฐ workflow ๊ตฌ์ฑ ์ ์ธ๋ถ์์ ์
๋ ฅ ๊ฐ์ ๋ฐ์ run
์ผ๋ก ์ฒ๋ฆฌํ๋ ๊ฒฝ์ฐ ์ทจ์ฝํฉ๋๋ค.
|
|
Custom Actions
Action ๋ด๋ถ์์ shell exec ํ๋ ๊ตฌ๊ฐ ์ค ์ธ๋ถ๋ก ๋ถํฐ ์ ๋ ฅ ๊ฐ์ ๋ฐ์ ๋ฐ์ํ๋ ๊ตฌ๊ฐ์ ์ ์ฌ์ ์ผ๋ก ๋ชจ๋ ์ทจ์ฝํฉ๋๋ค. ์ผ๋ฐ์ ์ธ RCE ์ทจ์ฝ์ ์ ์ฝ๋ ํจํด๊ณผ ์ ์ฌํฉ๋๋ค.
|
|
๐ก Defensive techniques
In workflow
Change to actions’s input
Workflow์์ ๊ฐ๊ธ์ ์ด๋ฉด ์ธ๋ถ์์ ์ ๋ ฅ ๊ฐ์ ๋ฐ์ง ์๋ ๊ฒ์ด ์ข์ต๋๋ค. ๊ฐ๋ฅํ๋ค๋ฉด Action์ ๋ง๋ค์ด์ ํด๋น Action์ Input์ผ๋ก ์ ๋ฌ์์ผ ์ด๋ฅผ run์์ ๊บผ๋ด ์ฌ ์ฌ์ฉํ๊ฑฐ๋ ์ฝ๋๋จ์์ ์ฒ๋ฆฌํ๋ ๊ฒ์ด ์ข์ต๋๋ค.
|
|
Change to env
์์ ์ ์ฌํ ๋ฐฉ๋ฒ์ผ๋ก run์ ์ง์ ๊ฐ์ ๋ฃ์ง ์๊ณ env๋ฅผ ๊ฑฐ์ณ์ ์ฒ๋ฆฌํ๋ ๋ฐฉ๋ฒ๋ ์์ต๋๋ค. ์ด๋ฌํ ๊ฒฝ์ฐ run์ผ๋ก ์ธํ ์ ์คํฌ๋ฆฝํธ ์์ฑ์ ๊ด์ฌํ์ง ์๊ธฐ ๋๋ฌธ์ injection์ ์ํํ ์ ์์ต๋๋ค.
|
|
In Action
Action ๋ด๋ถ์์ ์ฌ์ฉ์ ์ ๋ ฅ ๊ฐ์ ์ฒ๋ฆฌํ๋ ๊ณผ์ ์์ shell execute ๋ฑ์ ๋์์ด ์๋ ๊ฒฝ์ฐ ์ฌ์ฉ์ ์ ๋ ฅ ๊ฐ์ ๊ฒ์ฆํ ํ ์ฒ๋ฆฌํ๋ ๊ฒ์ด ์ข์ต๋๋ค.
|
|
๐น Tools
๐ References
- https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#understanding-the-risk-of-script-injections
- https://github.com/hahwul/github-aciton-injection-test/pull/1
- https://github.com/hahwul/github-aciton-injection-test/runs/6537735592?check_suite_focus=true
- https://github.com/hahwul/github-aciton-injection-test/blob/9a7ec16a7cff8132ac080a16a41c521b7a42f880/.github/workflows/blank.yml