3

Github Action 的 context 功能容易被攻击者利用实施脚本注入攻击

 2 years ago
source link: https://mozillazg.com/2021/12/security-script-injection-attack-via-github-action-context.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Github Action 的 context 功能容易被攻击者利用实施脚本注入攻击

2021-12-12

Github Action 提供了一个叫 context 的功能,通过 context 可以在 workflow 中应用当前仓库、当前 job 等等 上下文 metadata 信息,其中通过 github context 可以获取当前 workflow 的运行信息,比如分支名称、issue/PR 标题, commit id, issue/PR message 等等。

github context 获取到的很多信息其实是第三方控制的信息, 比如贡献者通过 PR 触发 CI 时,github context 中的很多信息就是贡献者提交 PR 的那个贡献者所控制的分支的相关信息。

基于 github context 的这个特点,攻击者可以通过 PR 流程来实施脚本注入攻击。 比如,攻击者可以通过构造一个 shell 语句作为一个分支的名称,然后提交 PR 以触发 CI, 如果 CI 中 github action workflow 有直接在 shell 命令中使用分支名的逻辑话, 就会触发执行攻击者构造的 shell 语句的操作,攻击者就成功实施了脚本注入攻击。

下面演示一个在 github action 中会存在脚本注入攻击问题的 workflow 语法的例子:

- name: test
  run: |
    echo 'show branch name: '
    echo "${{ github.ref_name }}"

上面这个 run 指令中,通过 echo 输出了执行当前 workflow 的分支名称,看起来没啥问题。 但是,但我创建一个名为 $(ls$IFS$(echo$IFS'UkVBRE1FLm1kCg=='|base64$IFS'-d')) 的分支 然后在这个分支下触发 workflow 的时候, 结果就会跟预期的不一样了:

image


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK