Carrtik/aws-security-auditor
GitHub: Carrtik/aws-security-auditor
一款自动化 AWS 云安全配置审计工具,通过扫描常见错误配置并映射到杀伤链框架,提升安全态势可见性。
Stars: 0 | Forks: 0
# AWS 安全态势审计器
一款命令行工具,可扫描您的 AWS 账户中的常见安全错误配置,并将每个发现映射到 **网络杀伤链** 框架。
```
$ aws-auditor
AWS Security Posture Audit Report
┌─────────────────────────────────────────────────────┐
│ Account ID: 123456789012 │
│ Identity ARN: arn:aws:iam::123456789012:user/audit │
│ Scan Time: 2025-05-16 11:59:05 UTC │
│ Duration: 55.3s │
└─────────────────────────────────────────────────────┘
CRITICAL (3) HIGH (4) MEDIUM (3) LOW (2) INFO (0)
Kill Chain Coverage
╭──────────────────────────┬───────┬───────────────────────╮
│ Kill Chain Phase │ Total │ Breakdown by Severity │
├──────────────────────────┼───────┼───────────────────────┤
│ Initial Access │ 5 │ 3 CRIT 2 HIGH │
│ Privilege Escalation │ 1 │ 1 CRIT │
│ Defense Evasion │ 3 │ 2 HIGH 1 LOW │
│ Credential Access │ 2 │ 1 MEDI 1 LOW │
│ Impact │ 1 │ 1 MEDI │
╰──────────────────────────┴───────┴───────────────────────╯
```
## 检查项
| 检查 ID | 服务 | 发现 | 严重性 | 杀伤链阶段 |
|----------|---------|---------|----------|-----------------|
| S3-001 | S3 | 未/部分设置公共访问屏蔽 | 严重 / 高危 | 初始访问 |
| S3-002 | S3 | 公共 ACL 授权 | 严重 | 初始访问 |
| S3-003 | S3 | 默认加密已禁用 | 中等 | 影响 |
| S3-004 | S3 | 版本控制已禁用 | 低危 | 影响 |
| S3-005 | S3 | 访问日志记录已禁用 | 低危 | 防御规避 |
| IAM-001 | IAM | 根账户未启用 MFA | 严重 | 初始访问 |
| IAM-002 | IAM | 根账户拥有活跃访问密钥 | 严重 | 凭证访问 |
| IAM-003 | IAM | 弱/缺失密码策略 | 高危 / 中等 | 凭证访问 |
| IAM-004 | IAM | 控制台用户未启用 MFA | 高危 | 初始访问 |
| IAM-005 | IAM | 访问密钥超过 90 天 | 中等 | 凭证访问 |
| IAM-006 | IAM | 客户策略:Action:\* Resource:\* | 严重 | 权限提升 |
| IAM-007 | IAM | 客户策略:服务通配符 | 高危 | 权限提升 |
| SG-001 | EC2 | 安全组允许所有入站流量 | 严重 | 初始访问 |
| SG-002 | EC2 | SSH/RDP/数据库端口对 0.0.0.0/0 开放 | 严重 / 高危 | 初始访问 |
| CT-001 | CloudTrail | 未配置跟踪 | 严重 | 防御规避 |
| CT-002 | CloudTrail | 跟踪日志记录已禁用 | 高危 | 防御规避 |
| CT-003 | CloudTrail | 日志文件验证已禁用 | 中等 | 防御规避 |
| CT-004 | CloudTrail | 未与 CloudWatch Logs 集成 | 低危 | 防御规避 |
| CT-005 | CloudTrail | 未配置 S3 存储桶 | 高危 | 防御规避 |
| CT-006 | CloudTrail | 无多区域跟踪 | 高危 | 防御规避 |
| RDS-001 | RDS | 实例可公开访问 | 严重 | 初始访问 |
| RDS-002 | RDS | 存储未加密 | 高危 | 影响 |
| RDS-003 | RDS | 自动备份已禁用 | 中等 | 影响 |
| RDS-004 | RDS | 删除保护已禁用 | 中等 | 影响 |
| RDS-005 | RDS | 非多可用区 | 低危 | 影响 |
| RDS-006 | RDS | 未启用 IAM 认证 | 低危 | 凭证访问 |
| RDS-007 | RDS | 手动快照未加密 | 中等 | 数据渗出 |
| RDS-008 | RDS | 快照公开共享 | 严重 | 数据渗出 |
## 安装
### 从源码安装
```
git clone https://github.com/your-org/aws-security-auditor
cd aws-security-auditor
# 安装依赖项
pip install -r requirements.txt
# 安装 CLI 工具
pip install -e .
```
### 要求
- Python 3.9+
- 具有被审计服务只读访问权限的 AWS 凭证
## 配置
凭证按标准 boto3 顺序解析:
1. `AWS_ACCESS_KEY_ID` + `AWS_SECRET_ACCESS_KEY` 环境变量
2. `~/.aws/credentials`(通过 `--profile` 指定命名配置文件)
3. IAM 实例角色 / ECS 任务角色 / Web Identity(适用于 EC2、ECS、Lambda)
### 最小 IAM 权限
```
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:ListAllMyBuckets",
"s3:GetBucketLocation",
"s3:GetBucketPublicAccessBlock",
"s3:GetBucketAcl",
"s3:GetBucketEncryption",
"s3:GetBucketVersioning",
"s3:GetBucketLogging",
"iam:GetAccountSummary",
"iam:GetAccountPasswordPolicy",
"iam:ListUsers",
"iam:GetLoginProfile",
"iam:ListMFADevices",
"iam:ListAccessKeys",
"iam:ListPolicies",
"iam:GetPolicyVersion",
"ec2:DescribeRegions",
"ec2:DescribeSecurityGroups",
"cloudtrail:DescribeTrails",
"cloudtrail:GetTrailStatus",
"rds:DescribeDBInstances",
"rds:DescribeDBSnapshots",
"rds:DescribeDBSnapshotAttributes",
"sts:GetCallerIdentity"
],
"Resource": "*"
}
]
}
```
## 使用
```
# 使用默认凭据扫描所有内容
aws-auditor
# 使用命名的 AWS 配置文件
aws-auditor --profile prod-readonly
# 仅扫描特定检查项
aws-auditor --checks s3 --checks iam
# 将 JSON 报告保存到文件
aws-auditor --output report.json
# 输出原始 JSON(适用于管道到 jq)
aws-auditor --json | jq '.summary'
aws-auditor --json | jq '.findings[] | select(.severity == "CRITICAL")'
# 仅在 CRITICAL 发现时使 CI 失败(不包括 HIGH)
aws-auditor --fail-on critical
# 特定区域,无颜色(适用于 CI 日志)
aws-auditor --region eu-west-1 --no-color
# 在 CI 中运行:保存报告 + 在 critical/high 时失败
aws-auditor --output report.json --fail-on high
```
### 退出码
| 代码 | 含义 |
|------|---------|
| 0 | 未发现等于或高于 `--fail-on` 指定严重性的发现 |
| 1 | 存在一个或多个等于或高于 `--fail-on` 指定严重性的发现 |
| 2 | 凭证或配置错误 |
### 所有选项
```
Options:
-p, --profile NAME AWS named profile
-r, --region REGION AWS region
-c, --checks CHECK Checks to run: s3, iam, sg, cloudtrail, rds (repeatable)
-o, --output FILE Write JSON report to FILE
--json Output raw JSON to stdout
--no-color Disable ANSI color
--fail-on LEVEL Exit 1 if findings >= level (critical/high/medium/low/none)
-h, --help Show this message and exit
```
## 示例输出
完整的 JSON 报告示例,请参见 [`example_output/example_report.json`](example_output/example_report.json)。
## CI/CD 集成
### GitHub Actions
```
- name: AWS Security Audit
run: |
pip install -r requirements.txt
pip install -e .
aws-auditor --output audit-report.json --fail-on high --no-color
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: us-east-1
- name: Upload audit report
uses: actions/upload-artifact@v4
if: always()
with:
name: aws-audit-report
path: audit-report.json
```
### GitLab CI
```
aws-audit:
script:
- pip install -r requirements.txt -e .
- aws-auditor --output gl-audit.json --fail-on high --no-color
artifacts:
when: always
paths: [gl-audit.json]
```
## 项目结构
```
aws-security-auditor/
├── aws_auditor/
│ ├── __init__.py
│ ├── auditor.py # Orchestrator: session, credential validation, check runner
│ ├── cli.py # Click CLI entry point
│ ├── models.py # Finding dataclass, Severity, KillChainPhase enums
│ ├── report.py # JSON report builder + Rich terminal renderer
│ └── checks/
│ ├── s3.py # S3 bucket checks
│ ├── iam.py # IAM users, policies, root account
│ ├── security_groups.py # EC2 security group checks (all regions)
│ ├── cloudtrail.py # CloudTrail trail checks
│ └── rds.py # RDS instance and snapshot checks
├── example_output/
│ └── example_report.json
├── requirements.txt
├── setup.py
└── README.md
```
## 许可证
MIT
标签:AWS安全, CloudTrail审计, CSPM, IAM安全, LNA, RDS安全, S3安全, TinkerPop, 云合规性, 图计算, 安全态势管理, 安全报告, 安全组检查, 文档结构分析, 网络杀伤链, 逆向工具, 配置错误检测