自动化 AWS 安全评估 CLI,包含 30 个模块,涵盖 IAM 权限提升、S3 暴露、计算、网络、日志记录和错误配置检查,可生成 Markdown 审计报告。
面向授权审计、渗透测试和红队演练的自动化 AWS 云安全评估框架。
AWS Pentest Tool 审计 AWS 环境中的身份风险、公开暴露、密钥泄露、弱信任关系、日志记录缺口以及云服务配置错误。它运行多模块评估流水线,并生成带时间戳的 Markdown 报告,其中包含严重性计数、证据、概念验证命令和修复指导。
该 CLI 专为实际演练工作而设计:
boto3 进行多区域 AWS 枚举reports/ 中生成执行风格的 Markdown 报告需要授权。仅对您拥有或已获得明确书面许可进行测试的 AWS 账户运行此工具。
git clone https://github.com/capture0x/aws-pentest.git
cd aws-pentest
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
python3 aws_agent.py configure
python3 aws_agent.py audit --mode recon
运行更全面的评估:
python3 aws_agent.py audit --mode all --regions us-east-1,eu-west-1 --output reports
运行针对性服务扫描:
python3 aws_agent.py scan-sts
python3 aws_agent.py scan-apigw --regions us-east-1,us-west-2
python3 aws_agent.py scan-dns --region us-east-1
| 模式 | 范围 | 推荐用途 |
|---|---|---|
recon | 核心身份、存储、计算、无服务器、网络、日志和治理检查 | 快速初步评估 |
loot | recon 加上更深入的网络、RDS、KMS、密钥、ECR、EBS 和 CloudTrail 检查 | 敏感数据和暴露审查 |
all | 完整的可用扫描路径 | 完整参与或最终验证 |
示例:
python3 aws_agent.py audit --mode all --profile security-audit --regions us-east-1,eu-west-1
| 命令 | 用途 |
|---|---|
configure | 将 AWS 凭证保存到本地 .env 文件,权限为 0600 |
audit | 运行完整的编排评估并生成 Markdown 报告 |
exploit-iam | 显示 IAM 权限提升发现结果和概念验证命令 |
exploit-s3 | 显示每个存储桶的 S3 暴露情况和利用提示 |
backdoor-create | 创建持久性 IAM 管理员用户;具有破坏性,需确认后执行 |
| 命令 | 模块 | 主要检查项 |
|---|---|---|
scan-sts | STS 跨账户 | 高风险信任策略、薄弱的 ExternalId 配置、OIDC 提供程序、角色链 |
scan-apigw | API Gateway | 缺少身份验证、薄弱的资源策略、WAF 缺口、JWT/CORS 问题 |
scan-cognito | Cognito | 未认证的身份池、薄弱的 MFA 配置、应用客户端暴露 |
scan-dynamodb | DynamoDB | 加密、PITR、流、资源策略 |
scan-sqs-sns | SQS / SNS | 公开策略、HTTP 订阅、缺少服务器端加密 |
scan-cfn | CloudFormation | 机密输出、堆栈角色权限风险、漂移 |
scan-dns | Route53 | 子域接管候选、DNSSEC、NS 委派风险 |
scan-codebuild | CodeBuild / CodePipeline | 明文机密、特权模式、构件加密 |
scan-waf | AWS WAF | 默认操作、缺少托管规则、速率限制、日志记录 |
scan-scp | AWS Organizations SCP | 护栏覆盖范围、缺少关键拒绝策略、组织成员资格 |
scan-sfn | Step Functions / EventBridge | 公开事件总线、跨账户目标、状态机日志记录和机密 |
python3 aws_agent.py audit --mode recon
python3 aws_agent.py audit --mode all --regions us-east-1,eu-west-1 --output /tmp/audit
python3 aws_agent.py audit --mode recon --auto-backdoor --verbose
python3 aws_agent.py exploit-iam --identity user/pentest-user
python3 aws_agent.py exploit-iam --auto-assume-role
python3 aws_agent.py exploit-s3 --bucket example-bucket
python3 aws_agent.py backdoor-create --dry-run
python3 aws_agent.py backdoor-create --user-name authorized-test-admin
| # | 领域 | 模块文件 | 关键检查项 |
|---|---|---|---|
| 00 | 账户上下文 | account.py | 调用者身份、账户别名、密码策略 |
| 01 | IAM 权限提升 | iam.py | 通配符、PassRole、AssumeRole、CreateAccessKey、危险操作 |
| 02 | S3 访问控制 | s3.py、s3_website.py | 公开存储桶、网站暴露、公开写入、劫持风险 |
| 03 | 计算资源清单 | compute.py | EC2 与 Lambda 清单、user-data 中的密钥指标 |
| 04 | 网络安全组 | network_sg.py | 暴露于互联网的管理端口、IPv4/IPv6 暴露 |
| 05 | 日志配置态势 | logging.py | CloudTrail、GuardDuty、Config、VPC Flow Logs |
| 06 | RDS / KMS / Secrets | rds.py、rds_enum.py、kms_secrets.py | 公开 RDS、快照、KMS 密钥、Secrets Manager、SSM 参数 |
| 07 | Lambda 分析 | lambda_analysis.py | 函数 URL、环境变量密钥、公开调用、执行角色风险 |
| 08 | EKS 分析 | eks_analysis.py | 公开 API 端点、审计日志、控制平面暴露 |
| 09 | CloudTrail 数据外泄 | cloudtrail_exfil.py | 公开日志存储桶、跨账户访问、未加密日志 |
| 10 | EBS 快照 | ebs_snapshots.py | 公开/共享快照、加密态势 |
| 11 | S3 子域名 | s3_subdomain.py | 存储桶接管与悬空 CNAME 检查 |
| 12 | S3 Git 制品 | s3_git_detector.py | S3 中暴露的 .git 对象 |
| 13 | ECR 容器 | ecr_analysis.py | 公开仓库、镜像扫描、可变标签 |
| 14 | IAM 后门 | iam_backdoor.py | 受 dry-run 保护的持久化验证 |
| 15 | IMDS 枚举 | imds_enum.py | IMDSv1/v2、角色凭证、user-data 密钥 |
| 16 | SSM 托管 EC2 | ssm_ec2.py | 托管实例、Run Command 路径 |
| 17 | S3 版本历史 | s3_versions.py | 已删除对象恢复、可疑历史版本 |
| 18 | Amazon MQ | mq_enum.py | Broker 暴露、用户、版本指标 |
| 19 | STS 跨账户 | sts_cross_account.py | 信任策略弱点、OIDC 条件、角色链 |
| 20 | API Gateway | api_gateway.py | 认证绕过、WAF 缺口、资源策略、CORS |
| 21 | Cognito | cognito.py | 身份池、未认证访问、MFA 策略 |
| 22 | DynamoDB | dynamodb.py | 加密、流、PITR、访问策略 |
| 23 | SQS / SNS | sqs_sns.py | 公开队列/主题策略、端点泄露、SSE |
| 24 | CloudFormation | cloudformation.py | 密钥输出、堆栈角色权限、漂移 |
| 25 | Route53 / DNS | route53.py | 接管候选、DNSSEC、NS 委派 |
| 26 | CodeBuild / Pipeline | codebuild_pipeline.py | 明文环境变量密钥、buildspec 密钥、特权构建 |
| 27 | WAF 分析 | waf_analysis.py | 默认允许、缺少托管规则、速率限制、日志记录 |
| 28 | SCP 审计 | scp_audit.py | AWS Organizations 防护栏覆盖情况 |
| 29 | Step Functions / EventBridge | stepfunctions_eventbridge.py | 公开总线、跨账户目标、日志缺口、硬编码密钥 |
每次 audit 运行都会生成一份带时间戳的 Markdown 报告:
reports/aws_audit_report_YYYYMMDD_HHMMSS.md
报告包含:
报告顶层章节:
1. Account Information
2. IAM Identity & Access
3. STS Cross-Account Trust Analysis
4. S3 Storage
5. Compute - EC2
6. Network Exposure & Security Groups
7. Lambda Function Analysis
8. EKS Cluster Analysis
9. ECR Container Analysis
10. Instance Metadata (IMDS) & Credential Exposure
11. SSM-Managed EC2
12. RDS Databases & Snapshots
13. KMS / Secrets Manager / SSM Parameters
14. EBS Snapshot Exposure
15. CloudTrail Exfiltration Risks
16. Logging & Detection Posture
17. Amazon MQ / ActiveMQ
18. API Gateway Security
19. Cognito / Identity Pool Analysis
20. DynamoDB Security
21. SQS / SNS Security
22. CloudFormation Security
23. Route53 / DNS Security
24. CodeBuild / CodePipeline Secret Exposure
25. AWS WAF Rule Analysis
26. Service Control Policy Audit
27. Step Functions / EventBridge Exposure
28. Consolidated Recommendations
29. Auto-Backdoor Capability Assessment
╭────────────────────────────────────────────╮
│ AWS Cloud Security Audit │
│ Profile: default/env Region: us-east-1 │
╰────────────────────────────────────────────╯
Audit complete ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 33/33 0:02:14
Assessment Overview
Metric Value
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Overall Risk CRITICAL
Finding Totals 4 critical / 9 high
AWS Account 123456789012
Execution Scope mode=all / region=us-east-1
Modules 33/33 completed, 0 skipped/error
Report Directory reports
Audit Summary