frangelbarrera/Cloud-Misconfig-Scanner

GitHub: frangelbarrera/Cloud-Misconfig-Scanner

一个基于 Python 的云存储安全配置扫描 CLI 工具,旨在自动化检测 AWS S3 存储桶的公开访问、加密缺失等错误配置风险。

Stars: 6 | Forks: 0

# 云错误配置扫描器 [![CI](https://static.pigsec.cn/wp-content/uploads/repos/cas/ad/ad5834178f7599af9fdda11629d49cae07f2997beec49821b2920eff5bfd50e7.svg)](https://github.com/frangelbarrera/Cloud-Misconfig-Scanner/actions/workflows/ci.yml) [![Python](https://img.shields.io/badge/Python-3.9+-blue.svg)](https://www.python.org/) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE) [![AWS](https://img.shields.io/badge/AWS-S3-orange.svg)](https://aws.amazon.com/s3/) [![Last Commit](https://img.shields.io/github/last-commit/frangelbarrera/Cloud-Misconfig-Scanner)](https://github.com/frangelbarrera/Cloud-Misconfig-Scanner) ## 功能 ### AWS S3(已实现) - 通过 boto3 进行**真实 API 扫描**(自动检测您的 AWS 凭据) - **账户级别的 Block Public Access (BPA)** 验证 - 每个存储桶的**存储桶级 BPA**(检查所有四个标志) - **服务端加密**检测 - **版本控制**状态检查 - **存储桶 ACL** 分析 — 将 `AllUsers` / `AllAuthenticatedUsers` 授权标记为 CRITICAL - **存储桶策略**分析 — 将 `Principal: "*"` Allow 语句标记为 CRITICAL - **服务器访问日志**验证 - **MFA Delete** 状态检查(启用版本控制时) - 当不存在 AWS 凭据时,**模拟模式**作为优雅降级方案 - **YAML 驱动的规则** — 所有发现的元数据都位于 `cms/checks/aws_s3_rules.yaml` 中,与 Azure/GCP 保持一致 ### Azure Blob(路线图) - 仅限模拟模式(计划集成真实 SDK) ### GCP Storage(路线图) - 仅限模拟模式(计划集成真实 SDK) ## 快速开始 ### 前置条件 - Python 3.9+ - 具有只读 S3 权限的 AWS 账户(用于真实扫描) - 已配置 AWS 凭据(`~/.aws/credentials` 或 `AWS_ACCESS_KEY_ID`/`AWS_SECRET_ACCESS_KEY` 环境变量) ### 安装 ``` git clone https://github.com/frangelbarrera/Cloud-Misconfig-Scanner.git cd Cloud-Misconfig-Scanner # 运行时依赖 pip install -r requirements.txt # 或者:editable install(也会注册 console script) pip install -e . ``` ### 使用方法 #### 真实 AWS S3 扫描(默认行为) ``` # 自动检测 credentials 并以 real mode 运行 python cms.py --provider aws # 使用特定 profile python cms.py --provider aws --profile my-profile # JSON 输出 python cms.py --provider aws --format json # HTML 报告输出到特定文件 python cms.py --provider aws --format html -o report.html # 仅显示 HIGH 和 CRITICAL findings python cms.py --provider aws --severity HIGH # 仅扫描特定 buckets python cms.py --provider aws --targets bucket-a,bucket-b ``` #### 模拟模式 模拟模式会针对一个模拟存储桶,对 `cms/checks/aws_s3_rules.yaml` 中的每条规则生成一个发现结果,因此您可以在没有云凭据的情况下测试 CLI/报告器。 ``` # 强制模拟模式(适用于 CI / sandbox 测试) python cms.py --provider aws --simulated ``` 如果完全没有检测到 AWS 凭据,扫描器将自动回退到模拟模式。 ### 退出码 | 代码 | 含义 | |------|------------------------------------| | 0 | 无发现(安全态势良好) | | 1 | 检测到发现 | | 2 | CLI 使用错误 | | 3 | 扫描器运行时错误 | ### 所需的 AWS IAM 权限 扫描器需要只读 S3 权限。请参阅 [`docs/iam/aws_least_privilege.json`](docs/iam/aws_least_privilege.json) 了解最小权限策略。 关键权限: - `s3:ListAllMyBuckets` - `s3:GetBucketPublicAccessBlock` - `s3:GetBucketEncryption` - `s3:GetBucketVersioning` - `s3:GetBucketAcl` - `s3:GetBucketPolicy` - `s3:GetBucketLogging` - `s3control:GetPublicAccessBlock` - `sts:GetCallerIdentity` ## 架构 ``` Cloud-Misconfig-Scanner/ ├── cms.py # Legacy CLI entry point (delegates to cms.cli) ├── cms/ │ ├── __init__.py │ ├── __main__.py # Allows `python -m cms` │ ├── cli.py # CLI implementation (argparse + exit codes) │ ├── core/ # Core engine │ │ ├── models.py # Resource, Finding, ScanResult dataclasses │ │ ├── rules.py # YAML rule loader + RuleRegistry │ │ ├── reporter.py # Text/JSON output + severity filtering │ │ └── html_reporter.py # HTML report (XSS-safe, CRITICAL supported) │ ├── providers/ # Cloud providers (all subclass ProviderScanner) │ │ ├── base.py # ProviderScanner ABC + shared helpers │ │ ├── aws_s3.py # AWS S3 scanner (real API + simulated fallback) │ │ ├── azure_blob.py # Azure Blob (simulated, roadmap) │ │ └── gcp_storage.py # GCP Storage (simulated, roadmap) │ └── checks/ # YAML rule definitions │ ├── aws_s3_rules.yaml │ ├── azure_blob_rules.yaml │ └── gcp_storage_rules.yaml ├── tests/ # pytest + moto test suite │ ├── conftest.py │ ├── test_rules.py │ ├── test_reporter.py │ ├── test_html_reporter.py │ ├── test_aws_s3_scanner.py │ └── test_cli.py ├── docs/ │ └── iam/ │ ├── aws_least_privilege.json │ ├── azure_least_privilege.md │ └── gcp_least_privilege.md ├── .github/workflows/ci.yml # GitHub Actions: pytest + ruff on push/PR ├── pyproject.toml # pip install -e . support + tool config ├── requirements.txt # Runtime deps └── requirements-dev.txt # Test/lint deps ``` ## 输出格式 ### 文本(默认) ``` Findings: - [CRITICAL] AWS-S3-PUBLIC-ACL | Bucket ACL allows public access -> aws:my-bucket - [HIGH] AWS-S3-ENCRYPTION | No default server-side encryption -> aws:another-bucket ``` ### JSON ``` [ { "rule_id": "AWS-S3-PUBLIC-ACL", "title": "Bucket ACL allows public access", "severity": "CRITICAL", "description": "...", "remediation": "...", "resource": { "provider": "aws", "service": "s3", "account": "123456789012", "region": "us-east-1", "name": "my-bucket", "meta": {} }, "evidence": { "public_grants": [{"grantee": "http://acs.amazonaws.com/groups/global/AllUsers", "permission": "READ"}] } } ] ``` ### HTML 包含严重性颜色标记(CRITICAL=红色,HIGH=粉色,MEDIUM=黄色,LOW=蓝色)的独立 HTML 报告。所有字段均经过 HTML 转义以防止 XSS。 ## 开发 ``` pip install -r requirements.txt pip install -r requirements-dev.txt pip install -e . # 运行带有 coverage 的测试(强制要求 >=80%) pytest -v # Lint ruff check cms tests ``` ## 路线图 - [x] AWS S3 真实 API 扫描 - [x] AWS S3 存储桶策略深度分析(Principal: "*" 检测) - [x] AWS S3 存储桶 ACL 分析(AllUsers / AllAuthenticatedUsers) - [x] AWS S3 访问日志验证 - [x] AWS S3 MFA Delete 验证 - [x] YAML 驱动的 AWS 规则(与 Azure/GCP 保持一致) - [x] 使用 moto + pytest 进行测试(核心覆盖率 >=80%) - [x] GitHub Actions CI(pytest + ruff) - [x] CLI 改进:--output、--severity、退出码 - [x] HTML 报告器:XSS 修复、CRITICAL 严重性 - [ ] AWS IAM 扫描(过于宽松的策略) - [ ] Azure Blob 真实 API 扫描 - [ ] GCP Storage 真实 API 扫描 - [ ] CIS Benchmark ID 映射 - [ ] CSV 输出格式 - [ ] 用于 GitHub 代码扫描的 SARIF 输出 - [ ] Slack webhook 通知 - [ ] Docker 容器支持 ## 安全 - **切勿**将 AWS 凭据提交到代码库 - 使用 `~/.aws/credentials` 或环境变量 - 扫描器仅需要**只读**权限 - 请参阅 [`docs/iam/aws_least_privilege.json`](docs/iam/aws_least_privilege.json) 了解最小权限策略 ## 许可证 MIT - 详见 [LICENSE](LICENSE)
标签:AWS, DPI, Python, S3, 无后门, 逆向工具