AuthaHub/ThreatDetection-IncidentResponse
GitHub: AuthaHub/ThreatDetection-IncidentResponse
基于 Terraform 构建的 AWS 安全运营中心自动化流水线,实现从威胁检测、自动隔离受损实例到取证留存的全链路秒级响应。
Stars: 1 | Forks: 0
# 自动化威胁检测与事件响应 Pipeline
[](https://aws.amazon.com)
[](https://terraform.io)
[](LICENSE)
## 业务背景
一个用于实时威胁检测和自动化事件响应的安全运营中心 (SOC) 自动化 pipeline。该项目用自动化的检测、隔离和取证保留 pipeline 取代了手动安全响应 —— 将平均响应时间 (MTTR) 从数小时缩短至数秒。
## 架构概览

| Service | Role |
|---|---|
| GuardDuty | 基于机器学习的威胁检测 |
| Macie | S3 中的自动化 PII 发现 |
| Security Hub | 集中化发现 (FSBP + CIS v1.4.0) |
| CloudTrail | 启用 KMS 的多区域审计日志 |
| AWS Config | 合规性漂移检测 |
| EventBridge | 事件驱动的自动化触发器 |
| Lambda | 隔离 EC2、快照 EBS、记录事件 |
| Step Functions | 多步修复编排 |
| DynamoDB | 安全事件审计踪迹 |
| Athena + Glue | 对 CloudTrail 日志进行 SQL 威胁搜寻 |
| SNS + CloudWatch | 告警和安全指标 |
| KMS | 所有静态数据的加密 |
## 事件响应工作流
```
GuardDuty Finding (Severity ≥ 7)
↓
EventBridge Rule
↓
Step Functions Workflow
↓
IsolateEC2 → SnapshotEBS → LogEvent → NotifySOC
```
## 应用的安全原则
- **最小权限 IAM** — 所有角色均限制在所需的最小权限范围内
- **处处加密** — 所有静态数据均使用 KMS 客户托管密钥
- **不可变审计踪迹** — 启用 DynamoDB 日志记录和 CloudTrail 日志文件验证
- **自动化响应** — 通过 Serverless 自动化将 MTTR 从数小时缩短至数秒
- **纵深防御** — GuardDuty + Macie + Security Hub + Config 分层检测
## 模拟的威胁场景
| Scenario | Method | Pipeline Response |
|---|---|---|
| EC2 加密货币挖矿 | GuardDuty 样本发现 (CryptoCurrency:EC2/BitcoinTool) | EventBridge 触发 → Step Functions → IsolateEC2 → SnapshotEBS → NotifySOC |
| 未授权 API 调用 | GuardDuty 样本发现 (UnauthorizedAccess:IAMUser) | CloudWatch 警报触发 → SNS 向安全团队发送警报 |
| 受损的 EC2 实例 | 使用模拟实例 ID 的 Step Functions 测试执行 | 执行完整工作流:隔离 → 快照 → 记录 → 通知 |
| S3 敏感数据泄露 | 扫描 CloudTrail 存储桶的 Macie 分类作业 | 每日自动扫描 PII/敏感数据 |
| CloudTrail 日志查询 | 针对 cloudtrail_logs 表的 Athena SQL 查询 | 返回 10 个真实事件,包括外部 IP 地址 |
## 安全控制映射
| Control | AWS Service | Purpose |
|---|---|---|
| NIST IR-4 | Step Functions | 自动化事件处理和响应 |
| NIST IR-5 | DynamoDB | 安全事件跟踪和审计踪迹 |
| NIST IR-6 | SNS | 事件报告和团队通知 |
| NIST AU-2 | CloudTrail | 跨所有区域的审计事件日志记录 |
| NIST AU-9 | KMS + S3 | 保护静态审计日志 |
| NIST SI-4 | GuardDuty | 系统监控和威胁检测 |
| NIST SI-7 | AWS Config | 软件和信息完整性检查 |
| NIST RA-5 | Macie | 漏洞和敏感数据扫描 |
| PCI DSS 10.x | CloudTrail + Athena | 审计日志记录和日志分析 |
| PCI DSS 11.4 | GuardDuty + Security Hub | 入侵检测和集中化发现 |
| PCI DSS 12.10 | Step Functions + Lambda | 自动化事件响应计划 |
| CIS v1.4.0 | Security Hub | 基准合规性监控 |
| CIS 3.x | CloudWatch Alarms | API 活动监控和告警 |
## 前置条件
- 已安装并配置 AWS CLI (`aws configure`)
- 已安装 Terraform >= 1.5.0
- 具有适当 IAM 权限的 AWS 账户
- 用于接收 SNS 安全警报的电子邮件地址
## 部署
### Step 1 — 克隆仓库
```
git clone https://github.com/AuthaHub/Project-03-ThreatDetection-IncidentResponse.git
cd Project-03-ThreatDetection-IncidentResponse
```
### Step 2 — 配置变量
复制示例文件并使用您的值进行编辑:
```
cp terraform.tfvars.example terraform.tfvars
```
编辑 `terraform.tfvars`:
```
aws_region = "us-east-1"
project_name = "p03-threat-detection"
environment = "dev"
alert_email = "your-email@example.com"
```
### Step 3 — 初始化 Terraform
```
terraform init
```
### Step 4 — 审查计划
```
terraform plan -var-file="terraform.tfvars"
```
### Step 5 — 部署
```
terraform apply -var-file="terraform.tfvars"
```
### 模块部署顺序
Terraform 自动按以下顺序处理依赖关系:
1. `kms` — 首先创建 KMS 密钥,所有其他模块均依赖于它
2. `s3` — 用于 CloudTrail 日志的 S3 存储桶
3. `cloudtrail` — 多区域跟踪
4. `guardduty` — 启用威胁检测
5. `macie` — 启用 PII 扫描
6. `security_hub` — 集中化发现
7. `sns` — 告警主题和电子邮件订阅
8. `cloudwatch` — 警报和日志组
9. `dynamodb` — 审计踪迹表
10. `lambda` — 事件响应函数
11. `eventbridge` — GuardDuty 发现触发器
12. `step_functions` — 修复工作流
13. `athena` — 日志分析工作组 和 Glue 目录
14. `config` — 合规性规则和记录器
## 验证
部署后,确认每个组件均正常工作:
- **GuardDuty** → Settings → Generate sample findings → check Findings page
- **Macie** → Summary page → confirm enabled and scanning
- **Security Hub** → Security standards → confirm FSBP and CIS v1.4.0 enabled
- **Step Functions** → Start execution with test payload → confirm workflow triggers
- **Athena** → Query editor → run SELECT against cloudtrail_logs table
- **CloudWatch** → Alarms → confirm root-usage and unauthorized-api alarms exist
- **SNS** → Confirm subscription email received and confirmed
## 清理
### Step 1 — 清空 S3 存储桶
```
# 空 CloudTrail 存储桶
aws s3 rm s3://$(terraform output -raw cloudtrail_bucket_name) --recursive
# 空 Athena 结果存储桶
aws s3 rm s3://$(terraform output -raw athena_results_bucket_name) --recursive
```
### Step 2 — 销毁所有资源
```
terraform destroy -var-file="terraform.tfvars"
```
### Step 3 — 验证清理
```
terraform state list
```
空响应确认所有资源已销毁。
## 成本分析
| Service | Estimated Cost |
|---|---|
| GuardDuty | 前 30 天免费,之后约 $4.50/月 |
| AWS Config | 每次规则评估约 $0.003 (约 $2-3/天) |
| Lambda | 本项目在免费额度内 |
| DynamoDB | 本项目在免费额度内 |
| SNS | 本项目在免费额度内 |
| Athena | 每次查询约 $0.005 (几美分) |
| KMS | 每个密钥 $1/月 |
| CloudTrail | 免费 (第一个跟踪),S3 存储约 $0.023/GB |
**预计总成本:** 若当天销毁,约 $0.50-$1.00/天
## 项目结构
```
Project-03-ThreatDetection-IncidentResponse/
├── modules/
│ ├── athena/ # Athena workgroup and Glue catalog for log analysis
│ ├── cloudtrail/ # Multi-region CloudTrail with log file validation
│ ├── cloudwatch/ # Log groups and alarms for security monitoring
│ ├── config/ # AWS Config rules for compliance drift detection
│ ├── dynamodb/ # Security event audit trail table
│ ├── eventbridge/ # Event-driven automation rules
│ ├── guardduty/ # GuardDuty detector configuration
│ ├── kms/ # Customer-managed encryption keys
│ ├── lambda/ # Incident response functions
│ ├── macie/ # Macie sensitive data discovery
│ ├── s3/ # S3 buckets with encryption and versioning
│ ├── security-hub/ # Security Hub with FSBP and CIS standards
│ ├── sns/ # SNS topics and email subscriptions
│ └── step-functions/ # Orchestration workflows
├── docs/
│ ├── architecture-decisions.md
│ ├── architecture-diagram.png
│ ├── build-log.md
│ └── cost-and-cleanup.md
├── screenshots/
├── main.tf # Root module configuration
├── variables.tf # Variable definitions
├── outputs.tf # Output values
├── versions.tf # Provider version constraints
├── terraform.tfvars.example # Example configuration file
├── .gitignore
└── README.md
```
## 附加文档
- [架构决策](docs/architecture-decisions.md) — 设计选择和技术原理
- [构建日志](docs/build-log.md) — 详细的实施时间表和挑战
- [成本与清理](docs/cost-and-cleanup.md) — 成本明细和清理程序
## 许可证
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## 致谢
作为展示 AWS 安全自动化和 Infrastructure as Code 最佳实践的作品集的一部分而构建。
标签:Amazon GuardDuty, Amazon Macie, AMSI绕过, Athena, AWS, CI/CD安全, CloudTrail, C语言, DevSecOps, DPI, EBS快照, EC2隔离, ECS, FTP漏洞扫描, GDRP, KMS加密, Lambda, Llama, MTTR, PE 加载器, ProjectDiscovery, Security Hub, Step Functions, Terraform, 上游代理, 取证, 威胁检测, 安全合规, 安全编排, 安全运营中心, 平均响应时间, 库, 应急响应, 异常检测, 恶意软件防护, 数据保护, 最小权限, 网络代理, 网络安全, 网络映射, 自动化响应, 速率限制, 隐私保护