lmoreno0435/gcp-abuse-scanner

GitHub: lmoreno0435/gcp-abuse-scanner

一款面向 GCP 经销商的只读 CLI 扫描工具,用于检测可被利用于加密货币挖矿和 Gemini API 滥用的云资源配置错误。

Stars: 0 | Forks: 0

# gcp-abuse-scanner [![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](LICENSE) [![Python](https://img.shields.io/badge/python-3.11%2B-blue)](https://www.python.org/) [![CI](https://static.pigsec.cn/wp-content/uploads/repos/cas/39/39faa54be350a1dab8afd3b2fb8c1c83e4d9cff84abfef2374d19a18053687c4.svg)](https://github.com/lmoreno0435/gcp-abuse-scanner/actions) [![PyPI](https://img.shields.io/pypi/v/gcp-abuse-scanner.svg)](https://pypi.org/project/gcp-abuse-scanner/) [![Docker](https://img.shields.io/badge/docker-ghcr.io-blue)](https://ghcr.io/lmoreno0435/gcp-abuse-scanner) [![codecov](https://codecov.io/gh/lmoreno0435/gcp-abuse-scanner/branch/main/graph/badge.svg)](https://codecov.io/gh/lmoreno0435/gcp-abuse-scanner) `gcp-abuse-scanner` 是一款开源 CLI 工具,用于扫描 Google Cloud Platform 的组织和项目,查找可被利用于以下用途的**安全配置错误**: - 🪙 **加密货币挖矿** — 未经授权滥用计算资源 - 🤖 **Gemini API 滥用** — 未经授权或不受控地访问 Generative AI API 该工具是**只读的**且是**预防性的**:它从不修改资源、从不禁用 API,也从不撤销权限。它会生成一份**已区分优先级的修复报告**,让你清楚地知道需要修复什么以及修复的顺序。 ## 功能特性 - 🔍 **约 65+ 项安全检查**:涵盖 Compute、GKE、Cloud Run、IAM、网络、API 密钥、Vertex AI、Billing 和组织策略 - 🏢 **组织范围或按项目**扫描 - 🔐 **Service account 身份验证**(推荐使用 impersonation,也支持密钥文件) - 📊 **多种输出格式**:Console (rich)、JSON、Markdown、HTML、SARIF 2.1.0 - ⚡ **并发收集**:支持重试/退避机制 — 能够处理拥有数千个项目的大型组织 - 🎯 **已区分优先级的发现结果**:包含 CRITICAL / HIGH / MEDIUM / LOW 严重级别 - 🚫 **支持白名单**:可配置已知的例外情况 - 🔌 **插件架构** — 无需修改核心代码即可添加新的检查 ## 快速开始 ### 安装 ``` # 推荐:pipx(隔离环境) pipx install gcp-abuse-scanner # 或 pip pip install gcp-abuse-scanner # 或 Docker docker run --rm -v ~/.config/gcloud:/root/.config/gcloud \ ghcr.io/lmoreno0435/gcp-abuse-scanner:latest scan --org YOUR_ORG_ID ``` ### 身份验证 **推荐:Service Account Impersonation** ``` gcp-abuse-scanner scan --org 123456789012 \ --impersonate-service-account scanner-sa@your-project.iam.gserviceaccount.com ``` **替代方案:Service Account 密钥文件** ``` export GOOGLE_APPLICATION_CREDENTIALS=/path/to/sa-key.json gcp-abuse-scanner scan --org 123456789012 ``` ### 基本用法 ``` # 扫描整个组织 gcp-abuse-scanner scan --org 123456789012 # 扫描特定项目 gcp-abuse-scanner scan --project my-project-1 --project my-project-2 # 输出为 JSON gcp-abuse-scanner scan --org 123456789012 --format json --output report.json # 输出为 Markdown gcp-abuse-scanner scan --org 123456789012 --format markdown --output report.md # 输出为自包含 HTML 报告 gcp-abuse-scanner scan --org 123456789012 --format html --output report.html # 输出为 SARIF 2.1.0(GitHub Advanced Security, VS Code) gcp-abuse-scanner scan --org 123456789012 --format sarif --output results.sarif # 同时输出所有格式(自动命名文件) gcp-abuse-scanner scan --org 123456789012 --format all # 仅扫描 Gemini 滥用向量 gcp-abuse-scanner scan --org 123456789012 --vector gemini_abuse # 使用 inventory cache(1小时 TTL)加速重新运行 gcp-abuse-scanner scan --org 123456789012 --cache # 列出所有可用检查 gcp-abuse-scanner list-checks # Dry run(解析范围但不执行扫描) gcp-abuse-scanner scan --org 123456789012 --dry-run ``` ## 所需的 IAM 角色 运行此工具的 Service account 需要具备以下**只读**角色,并且必须在**组织级别**(用于全组织扫描)或项目级别进行分配: | 角色 | 用途 | |------|---------| | `roles/cloudasset.viewer` | 高效枚举所有资源和 IAM policy | | `roles/iam.securityReviewer` | 读取所有资源的 IAM policy | | `roles/compute.viewer` | 读取 Compute Engine 实例、防火墙规则和网络 | | `roles/container.viewer` | 读取 GKE 集群和节点池 | | `roles/run.viewer` | 读取 Cloud Run 服务和作业 | | `roles/serviceusage.serviceUsageViewer` | 确定每个项目启用了哪些 API | | `roles/serviceusage.apiKeysViewer` | 列出 API 密钥及其限制 | | `roles/aiplatform.viewer` | 读取 Vertex AI endpoint 和模型配置 | | `roles/billing.viewer` | 验证 Billing 账户和预算是否存在 | | `roles/recommender.viewer` | 读取 IAM recommender 洞察信息 | | `roles/orgpolicy.policyViewer` | 读取组织策略限制 | | `roles/monitoring.viewer` | *(可选)* 验证告警策略 | 有关逐步设置说明,请参阅 [docs/iam-setup.md](docs/iam-setup.md)。 ## 安全检查 ### 加密货币挖矿途径(约 40 项检查) | ID | 严重程度 | 描述 | |----|----------|-------------| | CM-001 | HIGH | 具有外部 IP 地址的 VM 实例 | | CM-004 | CRITICAL | 防火墙允许来自 0.0.0.0/0 的 SSH/RDP 访问 | | CM-009 | MEDIUM | 未启用 Shielded VM | | CM-020 | HIGH | 具有无限自动缩放的 GKE 节点池 | | CM-023 | HIGH | 具有公共 endpoint 且没有授权网络的 GKE 集群 | | CM-030 | HIGH | 具有公共 invoker (allUsers) 的 Cloud Run 服务 | | CM-040 | HIGH | 被广泛授予 compute admin 角色的 SA | | CM-041 | HIGH | 具有用户管理(导出)密钥的 Service account | | CM-043 | CRITICAL | IAM 绑定向 allUsers/allAuthenticatedUsers 授权 | | CM-044 | HIGH | 默认的 Compute SA 拥有 Editor/Owner 角色 | | ... | ... | 请参阅 [docs/checks/crypto_mining.md](docs/checks/crypto_mining.md) | ### Gemini API 滥用途径(约 25 项检查) | ID | 严重程度 | 描述 | |----|----------|-------------| | GEM-001 | CRITICAL | API 密钥没有 API 限制 | | GEM-002 | CRITICAL | API 密钥没有应用限制 | | GEM-003 | HIGH | API 密钥明确指向 Gemini API 但没有应用限制 | | GEM-020 | HIGH | Vertex AI 角色被授予给广泛的 principal(域/组) | | GEM-021 | CRITICAL | Vertex AI 角色被授予给 allUsers/allAuthenticatedUsers | | GEM-030 | HIGH | 没有 private endpoint 也能访问 Vertex AI endpoint | | GEM-040 | MEDIUM | Vertex AI 配额处于默认(高)值 | | GEM-051 | HIGH | 没有涵盖 Vertex AI/Gemini 支出的预算 | | ... | ... | 请参阅 [docs/checks/gemini_abuse.md](docs/checks/gemini_abuse.md) | ### 常规检查(约 6 项检查) | ID | 严重程度 | 描述 | |----|----------|-------------| | CMN-001 | HIGH | Billing 账户未配置预算 | | CMN-002 | MEDIUM | 预算存在但没有阈值警报规则 | | CMN-005 | MEDIUM | 缺少关键的组织策略限制 | | CMN-006 | MEDIUM | Cloud Audit Logs(数据访问)被禁用 | ## 报告格式 每个发现结果包含: - **严重程度**:CRITICAL / HIGH / MEDIUM / LOW - **优先级排名**:用于修复计划的全局排序 - **证据**:触发该发现的确切资源详情 - **影响**:攻击者可以利用此配置错误做什么 - **修复建议**:包含 `gcloud` 命令、Terraform 参考和工作量估算的分步修复指南 发现结果示例 (JSON): ``` { "check_id": "GEM-002", "title": "API key has no application restrictions", "severity": "CRITICAL", "priority_rank": 1, "resource": {"project_id": "my-project", "resource_id": "..."}, "remediation": { "summary": "Add HTTP referrer or IP restrictions to the key.", "effort": "LOW", "gcloud_commands": ["gcloud services api-keys update KEY_UID --allowed-referrers=..."] } } ``` ## 配置 创建一个 `config.yaml` 来自定义行为: ``` # 完整参考请参见 examples/config.example.yaml allowlist: - check_id: CM-001 project_id: my-legacy-project reason: "External IP required for on-prem VPN — reviewed 2024-01-15" ``` ## 许可证 Apache 2.0 — 请参阅 [LICENSE](LICENSE)。
标签:GCP, Python, 无后门, 请求拦截, 逆向工具