pantelovich/cloud-threat-detection-lab
GitHub: pantelovich/cloud-threat-detection-lab
基于 Terraform 的 AWS 云威胁检测与事件响应实验环境,通过模拟真实攻击场景演示 GuardDuty 检测、CloudWatch 告警和 Lambda 自动修复的完整安全响应流程。
Stars: 0 | Forks: 0
# 云威胁检测与事件响应实验室
[](https://aws.amazon.com/)
[](https://terraform.io/)
[](https://aws.amazon.com/guardduty/)
一个模拟真实 AWS 安全事件的动手实验室 —— 配置错误的 EC2 遭受攻击,GuardDuty 检测到威胁,CloudWatch 触发自动告警和可选的 Lambda 自动修复,所有基础设施均通过 Terraform 进行配置。
## 架构概述
```
flowchart TD
Attacker[Attacker] --> EC2[EC2 Instance
Intentionally Vulnerable] EC2 --> GD[GuardDuty
Threat Detection] GD --> CW[CloudWatch
Event Rules] CW --> SNS[SNS Topic
Email Alerts] SNS --> Email[Email Notification] CW --> Lambda[Lambda Function
Auto Remediation] Lambda --> EC2_Stop[Stop Instance] style Attacker fill:#ff6b6b style EC2 fill:#4ecdc4 style GD fill:#45b7d1 style CW fill:#96ceb4 style SNS fill:#ffeaa7 style Email fill:#dda0dd style Lambda fill:#98d8c8 style EC2_Stop fill:#f7dc6f ``` ### 组件 - **目标 EC2 实例**:故意配置错误,开放了 SSH 端口并使用弱凭证 - **GuardDuty 检测器**:监控可疑活动并生成发现结果 - **CloudWatch 事件规则**:捕获 GuardDuty 发现结果并触发响应 - **SNS 主题**:在检测到安全发现时发送电子邮件告警 - **Lambda 函数**(可选):在出现高严重性威胁时自动停止实例 ## 快速开始 ### 前置条件 - 已配置 CLI 的 AWS 账户 - 已安装 Terraform >= 1.5 - 用于 SNS 告警的已验证电子邮件地址 - 用于 EC2 访问的 SSH 密钥对 ### 1. 克隆并设置 ``` git clone https://github.com/pantelovich/cloud-threat-detection-lab.git cd cloud-threat-detection-lab ``` ### 2. 配置变量 ``` cd infra cp terraform.tfvars.example terraform.tfvars ``` 必需的变量: ``` aws_region = "us-east-1" ssh_public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC... your-public-key" alert_email = "your-email@example.com" enable_auto_remediation = false # Set to true for auto-stopping instances ``` ### 3. 部署基础设施 ``` # 使用 deployment script ../scripts/deploy.sh -i -a # 或者手动 terraform init terraform apply -auto-approve ``` ### 4. 确认电子邮件订阅 检查您的电子邮件并确认 SNS 订阅以接收告警。 ### 5. 测试设置 等待 5-10 分钟让 GuardDuty 初始化,然后运行: ``` terraform output instance_public_ip ../scripts/test_threats.sh
```
## 测试场景
### 端口扫描
```
./scripts/test_threats.sh -t portscan
```
### SSH 暴力破解
```
./scripts/test_threats.sh -t ssh-brute
```
### 综合攻击模拟
```
./scripts/test_threats.sh
```
## 预期结果
1. **GuardDuty 发现**(5-15 分钟):
- `Recon:EC2/PortProbeUnprotectedPort`
- `UnauthorizedAPICall:EC2/SSHBruteForce`
- `Recon:EC2/Portscan`
2. 通过 SNS 发送的**电子邮件告警**,包含发现 ID、类型、严重性和受影响的资源
3. **自动修复**(如果启用):高严重性发现会触发 Lambda,实例自动停止
## 项目结构
```
cloud-threat-detection-lab/
├── infra/
│ ├── main.tf
│ ├── variables.tf
│ ├── outputs.tf
│ ├── user_data.sh
│ ├── terraform.tfvars.example
│ ├── lambda/
│ │ └── index.py
│ ├── lambda_function.zip
│ └── package_lambda.sh
├── scripts/
│ ├── deploy.sh
│ └── test_threats.sh
└── README.md
```
## Terraform 变量
| Variable | Description | Default | Required |
|----------|-------------|---------|----------|
| `aws_region` | AWS 区域 | `us-east-1` | 否 |
| `instance_type` | EC2 实例类型 | `t3.micro` | 否 |
| `ssh_public_key` | 用于 EC2 访问的 SSH 公钥 | - | 是 |
| `alert_email` | 用于接收告警的电子邮件 | - | 是 |
| `enable_auto_remediation` | 启用 Lambda 自动修复 | `false` | 否 |
## 安全注意事项
- 请仅在隔离的 AWS 账户或实验室环境中部署
- 目标实例被故意设计为开放了 SSH 访问并使用弱凭证
- 测试后务必销毁基础设施 —— 切勿保持其运行状态
## 清理
```
cd infra && terraform destroy -auto-approve
```
## 后续步骤
- Security Hub 集成以实现集中化的发现管理
- Slack webhook 告警
- 使用隔离 VPC 替代停止实例的方案
- S3/Elasticsearch 日志存储与分析
## 许可证
MIT — 详情请参阅 [LICENSE](LICENSE)。
Intentionally Vulnerable] EC2 --> GD[GuardDuty
Threat Detection] GD --> CW[CloudWatch
Event Rules] CW --> SNS[SNS Topic
Email Alerts] SNS --> Email[Email Notification] CW --> Lambda[Lambda Function
Auto Remediation] Lambda --> EC2_Stop[Stop Instance] style Attacker fill:#ff6b6b style EC2 fill:#4ecdc4 style GD fill:#45b7d1 style CW fill:#96ceb4 style SNS fill:#ffeaa7 style Email fill:#dda0dd style Lambda fill:#98d8c8 style EC2_Stop fill:#f7dc6f ``` ### 组件 - **目标 EC2 实例**:故意配置错误,开放了 SSH 端口并使用弱凭证 - **GuardDuty 检测器**:监控可疑活动并生成发现结果 - **CloudWatch 事件规则**:捕获 GuardDuty 发现结果并触发响应 - **SNS 主题**:在检测到安全发现时发送电子邮件告警 - **Lambda 函数**(可选):在出现高严重性威胁时自动停止实例 ## 快速开始 ### 前置条件 - 已配置 CLI 的 AWS 账户 - 已安装 Terraform >= 1.5 - 用于 SNS 告警的已验证电子邮件地址 - 用于 EC2 访问的 SSH 密钥对 ### 1. 克隆并设置 ``` git clone https://github.com/pantelovich/cloud-threat-detection-lab.git cd cloud-threat-detection-lab ``` ### 2. 配置变量 ``` cd infra cp terraform.tfvars.example terraform.tfvars ``` 必需的变量: ``` aws_region = "us-east-1" ssh_public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC... your-public-key" alert_email = "your-email@example.com" enable_auto_remediation = false # Set to true for auto-stopping instances ``` ### 3. 部署基础设施 ``` # 使用 deployment script ../scripts/deploy.sh -i -a # 或者手动 terraform init terraform apply -auto-approve ``` ### 4. 确认电子邮件订阅 检查您的电子邮件并确认 SNS 订阅以接收告警。 ### 5. 测试设置 等待 5-10 分钟让 GuardDuty 初始化,然后运行: ``` terraform output instance_public_ip ../scripts/test_threats.sh
标签:AMSI绕过, AWS, CloudWatch, Cutter, DevSecOps, DPI, EC2, ECS, GuardDuty, IaC, IP 地址批量处理, Lambda, OPA, SNS, SSH攻击, Terraform, 上游代理, 云计算, 威胁检测, 子域名变形, 安全实验, 安全架构, 安全运营, 扫描框架, 攻击模拟, 网络信息收集, 自动化告警, 自动化补救, 蜜罐, 规则引擎, 证书利用, 逆向工具, 靶场, 驱动签名利用