securekamal/cspm-guardian
GitHub: securekamal/cspm-guardian
基于 Python 的 AWS 云安全态势扫描器,可检测配置错误并映射多项合规框架。
Stars: 0 | Forks: 0
# ☁️ CSPM Guardian




## 概述
CSPM Guardian 持续审计您的 AWS 环境以发现安全配置错误,并将每项发现映射到 **CIS AWS Foundations Benchmark**、**SOC 2**、**PCI DSS**、**HIPAA** 和 **NIST SP 800-53** 合规控制项。它会分配一个安全态势等级(A–F)和风险评分,以确定修复的优先级。
## 覆盖范围
| 服务 | 检查项 |
|---|---|
| **IAM** | Root 密钥暴露、缺少 MFA、旧访问密钥、用户拥有 AdministratorAccess、弱密码策略 |
| **S3** | 公有访问阻止设置、默认加密、版本控制、访问日志 |
| **EC2/SGs** | 安全组对 0.0.0.0/0 开放 (SSH, RDP, 数据库, 缓存) |
| **RDS** | 公有可访问性、存储加密、备份保留 |
| **CloudTrail** | Trail 存在性、多区域、日志验证、CloudWatch 集成 |
| **GuardDuty** | 按区域启用、检测器暂停 |
| **KMS** | *(即将推出)* 密钥轮换强制执行 |
| **Lambda** | *(即将推出)* 环境变量机密、公有函数 URL |
| **VPC** | *(即将推出)* Flow logs、默认 VPC 使用情况 |
## 安装
```
git clone https://github.com/securekamal/cspm-guardian.git
cd cspm-guardian
pip install -r requirements.txt
# 配置 AWS 凭证
aws configure
# 或
export AWS_PROFILE=myprofile
```
## 使用方法
```
# 完整扫描(所有检查)
python cspm_guardian.py --all-regions
# 仅特定检查
python cspm_guardian.py --checks iam s3 cloudtrail
# 使用特定 AWS Profile 和 Region
python cspm_guardian.py --profile prod-readonly --region us-west-2
# 仅 JSON 输出
python cspm_guardian.py --format json --output results/aws_scan_$(date +%Y%m%d)
```
## 所需 IAM 权限
```
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"iam:Get*", "iam:List*",
"s3:GetBucket*", "s3:ListAllMyBuckets",
"ec2:DescribeSecurityGroups", "ec2:DescribeInstances",
"rds:DescribeDBInstances",
"cloudtrail:DescribeTrails", "cloudtrail:GetTrailStatus",
"guardduty:ListDetectors", "guardduty:GetDetector",
"sts:GetCallerIdentity"
],
"Resource": "*"
}
]
}
```
附加到具有只读访问权限的专用 `CSPMGuardianRole`。**切勿使用 AdministratorAccess。**
## 输出示例
```
[+] Connected: Account 123456789012 (arn:aws:iam::123456789012:user/security-scanner)
[*] Running IAM checks...
[*] Running S3 checks...
[*] Running CLOUDTRAIL checks...
[*] Running SECURITYGROUPS checks...
[*] Running GUARDDUTY checks...
[*] Running RDS checks...
============================================================
[+] Posture Grade: D
[+] Risk Score: 47
[+] Findings: CRITICAL=3 HIGH=5 MEDIUM=4 LOW=2
[+] Resources checked: 34
[+] Checks performed: 61
[+] JSON report: cspm_report.json
[+] HTML report: cspm_report.html
```
## 态势评级
| 等级 | 标准 |
|---|---|
| **A** | 无严重/高危发现 |
| **B** | 无严重,≤1 个高危 |
| **C** | 无严重,2–5 个高危 |
| **D** | 1+ 个严重 或 >5 个高危 |
| **F** | 5+ 个严重 或 (严重 + 大量高危) |
## 合规映射
每项发现至少映射到一个框架控制项:
- **CIS AWS Foundations Benchmark v1.3.0**
- **SOC 2 Type II** (CC6.x, CC7.x, A1.x)
- **PCI DSS v3.2.1** (要求 1, 3, 8, 10)
- **HIPAA Security Rule** (§164.312)
- **NIST SP 800-53** (AC, AU, IA, SI 系列)
## CI/CD 集成
```
# .github/workflows/cspm.yml
- name: CSPM Scan
run: |
pip install boto3
python cspm_guardian.py --format json --output cspm_results
- name: Fail on Critical Findings
run: |
python -c "
import json
r = json.load(open('cspm_results.json'))
crits = r['summary']['by_severity']['CRITICAL']
if crits > 0:
print(f'❌ {crits} CRITICAL findings found!')
exit(1)
print('✅ No critical findings')
"
```
## 作者
**securekamal** — 产品安全工程师 | 云安全
- [GitHub](https://github.com/securekamal)
## 许可证
MIT
标签:ATTACK-Python-Client, CIS Benchmark, CSPM, DevSecOps, EC2 安全, GCP 安全, HIPAA, IAM 安全, LNA, NIST, PCI DSS, Python, S3 存储安全, SOC 2, TinkerPop, 上游代理, 云安全态势管理, 云配置审计, 前端应用, 合规报告, 安全合规, 无后门, 漏洞利用检测, 等保, 网络代理, 逆向工具, 错误配置扫描, 风险评分