nekros1xx/ghascan

GitHub: nekros1xx/ghascan

检测GitHub Actions工作流中的表达式注入、GITHUB_ENV注入和AI提示注入漏洞的自动化工具

Stars: 10 | Forks: 3

# 🔒 GHA 漏洞扫描器 [![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/) [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT) **检测 GitHub 工作流中的表达式注入、GITHUB_ENV 注入和 AI 提示注入漏洞。** 作者:[Sergio Cabrera](https://www.linkedin.com/in/sergio-cabrera-878766239/) ## ⚡ 安装 ``` pip install --force-reinstall git+https://github.com/nekros1xx/ghascan.git ``` 就是这样。现在设置您的令牌并开始扫描: ``` export GITHUB_TOKEN="ghp_your_token_here" ghascan --query 1 ``` ## 🎯 检测内容 | 类别 | 示例 | 严重程度 | |----------|---------|----------| | **表达式注入** | `run:` 块中的 `${{ github.event.issue.title }}` | CRITICAL/HIGH | | **GITHUB_ENV 注入** | 攻击者输入写入 `$GITHUB_ENV` | MEDIUM/HIGH | | **间接注入** | `run:` 块中使用的污染步骤输出 | MEDIUM | | **AI 提示注入** | 攻击者输入 → AI 操作 → `run:` 块中的输出 | AI_INJECTION | | **未固定版本的操作** | 第三方操作通过 tag 而非 SHA 引用 | Info | ### 误报消除 7+ 条消除规则最大程度减少干扰:注释代码、禁用的作业/步骤、触发器不可达、安全上下文(`env:`、`with:`)、精确匹配门控、布尔表达式、引用 heredoc、每个作业的密钥作用域限制 ## 📖 使用方法 ### 基于查询的扫描 ``` ghascan --query 6 # Issue body in run blocks ghascan --all --min-stars 1000 # All 43 patterns, big repos only ghascan --custom '"my_pattern" path:.github/workflows' ``` ### 组织扫描 ``` ghascan --org Microsoft --min-stars 100 ghascan --org google --org-max-repos 200 --html report.html ``` ### 离线分析 ``` ghascan --offline scan_data.json -v --verdict CRITICAL HIGH ``` ### 输出格式 ``` ghascan --query 1 -o results.json # JSON ghascan --query 1 --html report.html # Interactive HTML ghascan --query 1 --pdf report.pdf # PDF ``` Markdown 会与 JSON 自动一起生成。 ### 有用的参数 ``` --verdict CRITICAL HIGH # Filter by severity --min-stars 500 # Skip small repos --limit 20 # Cap candidates (testing) --clone # Git clone for deeper analysis -v # Verbose output ``` ## 🔍 43 条查询模式
点击展开 | # | 模式 | 目标 | |---|---------|--------| | 1-3 | PR 标题/正文/head_ref 在 `run:` 中 | `pull_request_target` | | 4 | 评论正文在 `run:` 中 | `issue_comment` | | 5-6 | Issue 标题/正文在 `run:` 中 | `issues` | | 7-8 | 讨论标题/正文在 `run:` 中 | `discussion` | | 9-10 | 审查正文/评论在 `run:` 中 | `pull_request_review` | | 11-16 | 父对象上的 `toJSON()` | 多种 | | 17-22 | `contains()`/`startsWith()` 包装 | 多种 | | 23-24 | 带攻击者输入的 `format()` | 多种 | | 25-29 | 较少见字段(标签、仓库描述) | 多种 | | 30 | `run:` 中的 `toJSON(steps)` | 多种 | | 31-35 | `github-script` + 攻击者输入 | 多种 | | 36-38 | `GITHUB_ENV` 注入 | 多种 | | 39-41 | 通过步骤输出的间接注入 | 多种 | | 42-43 | `workflow_dispatch` 输入 | `workflow_dispatch` |
## 🏗️ 严重程度级别 | 级别 | 含义 | |-------|---------| | **CRITICAL** | 完全控制 + 开放触发器 + 自定义密钥 + 无认证 | | **HIGH** | 完全控制 + 开放触发器 + 仅 GITHUB_TOKEN | | **MEDIUM** | 存在认证检查、受限触发器或仅 dispatch | | **LOW** | 受限控制(head_ref)、内部触发器或只读权限 | | **AI_INJECTION** | AI 操作输出(被污染)用于可执行上下文 | | **FALSE_POSITIVE** | 所有表达式被分析规则消除 | ## 🛡️ 负责任的披露 此工具用于**防御性安全研究**。如果您发现漏洞,请通过仓库的 Security 选项卡负责任地报告它们。不要利用它们。 ## 📄 许可证 MIT — 请参阅 [LICENSE](LICENSE)。 ## 👤 作者 **Sergio Cabrera** — [LinkedIn](https://www.linkedin.com/in/sergio-cabrera-878766239/) · [GitHub](https://github.com/nekros1xx)
标签:AI安全, Chat Copilot, CI/CD安全, CISA项目, DevSecOps, GitHub Actions, GITHUB_ENV注入, Llama, Python, SAST, 上游代理, 云安全监控, 密码管理, 工作流安全, 无后门, 盲注攻击, 结构化查询, 网络安全审计, 自动化安全, 自动笔记, 表达式注入, 逆向工具, 静态分析