Octoscan 是一个用于 GitHub Action 工作流的静态漏洞扫描器。
每条规则的易受攻击工作流位于 testdata,要试用这些规则:./octoscan scan testdata。
$ go mod tidy
$ go build
或使用 docker:
$ docker pull ghcr.io/synacktiv/octoscan:latest
Octoscan 可以针对本地 git 仓库运行,或者你可以使用 dl 操作下载所有工作流:
$ octoscan dl -h
Octoscan.
Usage:
octoscan dl [options] --org <org> [--repo <repo> --token <pat> --default-branch --max-branches <num> --path <path> --output-dir <dir> --include-archives]
Options:
-h, --help Show help
-d, --debug Debug output
--verbose Verbose output
--org <org> Organizations to target
--repo <repo> Repository to target
--token <pat> GHP to authenticate to GitHub
--default-branch Only download workflows from the default branch
--max-branches <num> Limit the number of branches to download
--path <path> GitHub file path to download [default: .github/workflows]
--output-dir <dir> Output dir where to download files [default: octoscan-output]
--include-archives Also download archived repositories
./octoscan dl --token ghp_<token> --org apache --repo incubator-answer
如果你不知道该运行什么,只需运行以下命令:
./octoscan scan path/to/repos/ --disable-rules shellcheck,local-action --filter-triggers external
它会减少误报,并给出最有趣的结果。
如果你使用 dl 命令下载了工作流,可能会得到重复的工作流,因为默认情况下 octoscan 会下载所有分支的所有工作流。要删除重复的工作流并加快分析速度,你可以在运行分析之前使用 fdupes 命令:
fdupes -n -r -N -d path/to/repo
$ octoscan scan -h
octoscan
Usage:
octoscan scan [options] --list-rules
octoscan scan [options] <target>
octoscan scan [options] <target> [--debug-rules --filter-triggers=<triggers> --filter-run --ignore=<pattern> ((--disable-rules | --enable-rules ) <rules>) --config-file <config>]
Options:
-h, --help
-v, --version
-d, --debug
--verbose
--format <format> Output format, json, sarif or custom template to format error messages in Go template syntax. See https://github.com/rhysd/actionlint/tree/main/docs/usage.md#format
--oneline Use one line per one error. Useful for reading error messages from programs
Args:
<target> Target File or directory to scan
--filter-triggers <triggers> Scan workflows with specific triggers (comma separated list: "push,pull_request_target" or pre-configured: external/allnopr)
--filter-run Search for expression injection only in run shell scripts.
--ignore <pattern> Regular expression matching to error messages you want to ignore.
--disable-rules <rules> Disable specific rules. Split on ","
--enable-rules <rules> Enable specific rules, this will disable all other rules. Split on ","
--debug-rules Enable debug rules.
--config-file <config> Config file.
Examples:
$ octoscan scan ci.yml --disable-rules shellcheck,local-action --filter-triggers external
此工具也可直接作为 GitHub action 使用,在 push/pull_request 事件触发时扫描你的仓库。更多信息请查看此仓库。
可通过以下命令查看完整的规则列表:
$ octoscan scan --list-rules
2024/08/07 16:50:48 [INFO] Available rules
- shellcheck
Checks for shell script sources in "run:" using shellcheck
- credentials
Checks for credentials in "services:" configuration
- dangerous-action
Check for dangerous actions.
- dangerous-checkout
Check for dangerous checkout.
- expression-injection
Check for expression injection.
- dangerous-write
Check for dangerous write operation on $GITHUB_OUTPUT or $GITHUB_ENV.
- local-action
Check for local actions.
- runner-label
Checks for GitHub-hosted and preset self-hosted runner labels in "runs-on:"
- unsecure-commands
Check 'ACTIONS_ALLOW_UNSECURE_COMMANDS' env variable.
- known-vulnerability
Check for known vulnerabilities.
- bot-check
Check for if statements that are based on a bot identity.
- dangerous-artefact
Check for workflow that upload artefacts containing sensitive files.
- overprovisioned-secrets
Check for dumps (toJSON(secrets)) and dynamic accesses (secrets[...]) of the secrets context.
- toctou
Check for checkouts of a mutable PR reference in workflows triggered after an approval (comment, dispatch, label).
- prompt-injection
Check for AI agents that process untrusted input, that anyone can trigger or that have dangerous tools.
- unsound-condition
Check for "if:" conditions that can be bypassed or that are always true.
- debug-external-trigger
Check for workflow that can be externally triggered.
- debug-artefacts
Check for workflow that upload artefacts.
- debug-js-exec
Check for workflow that execute system commands in JS scripts.
- debug-oidc-action
Check for OIDC actions.
- repo-jacking
Verify that external actions are pointing to a valid GitHub user or organization.
像 workflow_run 或 pull_request_target 这样的触发器会在特权上下文中运行,因为它们对机密信息具有读取权限,并且可能对目标仓库具有写入权限。对不受信任的代码执行显式检出,会导致攻击者的代码在此类上下文中被下载。

自 actions/checkout v7 起,该 action 在 pull_request_target 和 workflow_run 工作流中拒绝获取 fork PR 代码(该保护已向后移植到浮动主版本标签 v2 及更高版本,但不会移植到 SHA、次版本或补丁版本固定)。该规则会报告:
ref 或 repository 为 PR 头仓库的检出,并针对特权事件说明所固定的版本是否具有此保护;allow-unsafe-pr-checkout,即禁用该保护的输入:这是有意的选择退出,请仔细审查。通过脚本(git、gh pr checkout)和其他事件(issue_comment……)执行的检出不受该保护覆盖。
该规则会在使用危险 action 时向用户发出警告。它主要关注不受信任的工件。
使用工件在不同工作流之间传递数据是一种常见做法。我们经常在 workflow_run 触发器中遇到这种情况:触发工作流会准备一些数据,然后将其发送到被触发的工作流。鉴于此类工件数据的不受信任性质,务必谨慎对待并将其视为潜在威胁。该漏洞源于外部实体(例如恶意行为者)可以影响工件数据的内容。
