pantelovich/cloud-incident-response-lab

GitHub: pantelovich/cloud-incident-response-lab

基于 Terraform 和 Lambda 构建的 AWS 自动化事件响应实验环境,用于演示 GuardDuty 检测到威胁后自动停止 EC2 实例并发送告警的完整流程。

Stars: 0 | Forks: 0

![CI](https://static.pigsec.cn/wp-content/uploads/repos/2026/05/beee696af5103012.svg) ![LICENSE](https://img.shields.io/github/license/pantelovich/cloud-incident-response-lab?style=for-the-badge) ![MADE WITH TERRAFORM](https://img.shields.io/badge/MADE%20WITH-TERRAFORM-5C4EE5?style=for-the-badge&logo=terraform) ![AWS](https://img.shields.io/badge/AWS-orange?style=for-the-badge&logo=amazonaws) ![CLOUD](https://img.shields.io/badge/CLOUD-blue?style=for-the-badge&logo=icloud) ![TERRAFORM](https://img.shields.io/badge/TERRAFORM-844FBA?style=for-the-badge&logo=terraform) ![LAMBDA](https://img.shields.io/badge/LAMBDA-FF9900?style=for-the-badge&logo=awslambda) ![SECURITY](https://img.shields.io/badge/SECURITY-gray?style=for-the-badge&logo=datadog) ![AUTOMATION](https://img.shields.io/badge/AUTOMATION-2E8B57?style=for-the-badge&logo=githubactions) # 云事件响应自动化实验环境 一个动手实践实验环境,演示如何自动响应由 GuardDuty 检测到的 AWS 安全事件。当检测到高危威胁时,Lambda 函数会自动隔离或停止受影响的 EC2 实例,并发送详细的 SNS 警报。 ## 架构概述 ``` flowchart TD Attacker --> EC2[(Compromised EC2)] EC2 --> GD[GuardDuty Finding] GD --> CW[CloudWatch Event Rule] CW --> Lambda[Lambda Function] Lambda --> SNS[SNS Alert Email] Lambda --> EC2Action[Stop Instance] ``` ### 组件 | 组件 | 用途 | |-----------|---------| | GuardDuty | 实时检测威胁 | | CloudWatch Events | 在发现新事件时触发自动化 | | Lambda Function | 通过停止实例执行修复操作 | | SNS | 发送警报通知 | | Terraform | 以代码形式部署和配置所有内容 | ## 部署 ### 前提条件 - 已配置 AWS CLI - Terraform >= 1.5 - Python 3.9+ - 用于 SNS 警报的已验证电子邮件地址 ### 快速开始 ``` git clone https://github.com/pantelovich/cloud-incident-response-lab.git cd cloud-incident-response-lab # 复制并修改变量 cp infra/terraform.tfvars.example infra/terraform.tfvars # 使用您的邮箱和偏好设置编辑 terraform.tfvars # 部署基础设施 make init make zip make apply ``` ### 手动步骤 ``` # 替代方案:手动部署 cd infra terraform init terraform plan terraform apply ``` ### 变量 复制示例文件并进行自定义: ``` cp infra/terraform.tfvars.example infra/terraform.tfvars ``` 使用您的配置编辑 `terraform.tfvars`: ``` aws_region = "us-east-1" alert_email = "your-email@example.com" # 可选:创建测试 VPC 和实例用于演示 create_test_vpc = true create_test_instance = true ``` ## 成本 本实验环境在可能的情况下使用了符合 AWS 免费套餐条件的服务: - **GuardDuty**:30 天免费试用,之后为每百万事件 $1.00 - **Lambda**:每月 100 万次免费请求,400,000 GB-秒的计算时间 - **SNS**:每月 100 万次免费通知 - **CloudWatch Events**:每月 100 万次免费事件 - **EC2 t3.micro**:12 个月内每月 750 小时免费 轻度测试的预计每月成本:**$0-5**(主要是 GuardDuty 事件) ## 本地测试 使用示例事件在本地测试 Lambda 函数: 1. **AWS 控制台测试**: - 前往 AWS 控制台中的 Lambda 函数 - 使用 `tests/sample-guardduty-event.json` 创建测试事件 - 运行测试并验证日志 2. **SAM Local**(可选): sam local invoke -e tests/sample-guardduty-event.json ## 测试 ### 手动测试 1. 使用测试实例进行部署: terraform apply -var="create_test_instance=true" -var="create_test_vpc=true" 2. 获取测试实例的公网 IP: terraform output test_instance_public_ip 3. 从另一台机器模拟攻击: nmap -p 22 4. 等待 5-10 分钟让 GuardDuty 检测到该活动 5. 检查结果: - Lambda 执行的 CloudWatch Logs - SNS 电子邮件警报 - EC2 实例应已被停止 ### 自动化测试 ``` # 运行多次端口扫描以触发 GuardDuty for i in {1..10}; do nmap -p 22 sleep 30 done ``` ## 图库 | SNS 警报邮件 | CloudWatch 日志 | 架构概述 | |------------------|-----------------|------------------------| | ![显示事件通知的 SNS 警报邮件](https://static.pigsec.cn/wp-content/uploads/repos/2026/05/f88c9bbdc2103013.png) | ![显示 Lambda 执行细节的 CloudWatch 日志](https://static.pigsec.cn/wp-content/uploads/repos/2026/05/5746dbaebd103014.png) | ![显示数据流的架构图](https://static.pigsec.cn/wp-content/uploads/repos/2026/05/f1b69a63e7103016.png) | ## 未来改进 - 为受影响的实例添加自动标记 - 向 Slack 或 Security Hub 发送警报 - 添加隔离 VPC 隔离功能,而不是仅仅停止实例 - 根据威胁严重程度实施不同的修复措施 - 添加用于审计跟踪的 CloudTrail 日志记录 - 创建自定义 GuardDuty 威胁列表 ## 清理 移除所有资源以避免产生费用: ``` # 使用 Makefile make destroy # 或手动 cd infra terraform destroy -auto-approve ``` **重要提示**:完成测试后请务必清理资源,以避免产生意外费用。 ## 许可证 MIT 许可证 - 详情请参阅 LICENSE 文件。
标签:AMSI绕过, AWS, CloudWatch, DPI, EC2, EC2, ECS, GuardDuty, IaC, IaC, Lambda, PB级数据处理, Python, SecOps, SNS, Terraform, 云安全架构, 告警通知, 威胁检测, 安全实验室, 安全运维, 实例隔离, 无后门, 无线安全, 网络安全, 自动化响应, 自动化运维, 逆向工具, 速率限制, 隐私保护