Afkir-Mohamed/enterprise-soc-in-a-box
GitHub: Afkir-Mohamed/enterprise-soc-in-a-box
基于 AWS Free Tier 的无服务器 SIEM 方案,以约每月 0.5 美元的成本实现日志聚合、威胁检测、自动化事件响应和可视化。
Stars: 0 | Forks: 0
# 企业级 SOC-in-a-Box(AWS Free Tier + k3s 实验版)
基于 AWS Free Tier 服务构建的 Serverless SIEM,并在 k3s 家庭实验室中
自托管 Grafana。它将 CloudTrail 和 VPC Flow Logs 接入到
集中式的 S3 数据湖中,通过 Athena 运行检测查询,利用
Step Functions 自动化事件响应,并在 Grafana 中可视化所有内容——
所有这些成本仅为约 0.50 美元/月。
请参阅 [ARCHITECTURE.md](ARCHITECTURE.md) 了解完整的设计以及每项决策背后的
原因,[COSTS.md](COSTS.md) 了解运行成本明细,
以及 [docs/ARCHITECTURE-DECISIONS.md](docs/ARCHITECTURE-DECISIONS.md) 了解解释每个权衡的
8 个 ADR。
## 状态 — 所有阶段均已完成 ✅
- [x] **阶段 1 — 基础**:VPC、CloudTrail、VPC Flow Logs、S3 数据湖、
Glue database、remote state、CI/CD pipeline
- [x] **阶段 2 — 查询与仪表盘**:Glue Crawlers、11 个 Athena 威胁狩猎
查询(映射 MITRE ATT&CK)、运行在 k3s 上的 Grafana 包含 4 个实时仪表盘
- [x] **阶段 3 — 检测与响应**:3 个检测 Lambda(root 使用情况、大规模
IAM 更改、异常区域)、Step Functions EXPRESS 事件响应
playbook、EventBridge pipeline、SNS 警报
- [x] **阶段 4 — 实验模拟**:流量生成器 CronJob + k3s 上的威胁模拟器
— 3 个攻击场景已完成端到端验证
- [x] **阶段 5 — 文档**:8 个 ADR、演示脚本、拆除指南、
简历要点
## 架构
```
CloudTrail ──────────────────────────────→ S3 Data Lake
VPC Flow Logs (Parquet) ─────────────────→ (encrypted, partitioned,
lifecycle → Glacier 90d)
│
┌───────────────────┤
│ │
EventBridge (S3 PutObject) Athena
│ │
┌───────────────┼───────────────┐ └──→ Grafana (k3s)
↓ ↓ ↓
detect-root detect-mass-iam detect-network-recon
(Lambda) (Lambda) (Lambda)
└───────────────┼───────────────┘
↓
Step Functions EXPRESS
┌─────────────────────┐
│ Notify (SNS) │
│ Route by severity │
│ Contain (HIGH only) │
│ Document to S3 │
└─────────────────────┘
```
**成本:** ~$0.50/月(仅 VPC Flow Log 交付 — 其他所有均在 Free Tier 内)
**检测延迟:** <10 分钟(CloudTrail 交付窗口)
## 仓库结构
```
enterprise-soc-in-a-box/
├── bootstrap/ # one-time: Terraform remote-state bucket + DynamoDB lock
├── terraform/
│ ├── modules/
│ │ ├── s3-data-lake/ # encrypted S3 bucket + Glue database
│ │ ├── log-sources/ # VPC, CloudTrail, VPC Flow Logs
│ │ ├── athena-queries/ # Glue crawlers, Athena workgroup, results bucket
│ │ └── detection-rules/ # Lambdas, EventBridge, Step Functions, SNS
│ └── environments/dev/ # wires all modules together
├── lambdas/
│ ├── detect-root-activity/ # HIGH: any root API call
│ ├── detect-mass-iam/ # HIGH: 5+ IAM writes in one log file
│ └── detect-network-recon/ # MEDIUM: API calls outside allowed regions
├── step-functions/
│ └── incident-response.asl.json
├── queries/
│ ├── iam/detections.sql # root usage, no-MFA login, mass IAM, new access keys
│ ├── network/detections.sql # unusual regions, SG changes, CloudTrail tampering
│ └── account/detections.sql # brute force, S3 exposure, secrets access, daily rollup
├── simulators/
│ ├── traffic-generator/ # k3s CronJob: baseline AWS API activity every 30 min
│ ├── threat-simulator/ # k3s Job: mass IAM, unusual region, CloudTrail recon
│ └── setup.sh # one-time k8s namespace + secret + configmap setup
├── grafana/ # dashboard JSON + datasource config
├── docs/
│ ├── ARCHITECTURE-DECISIONS.md # 8 ADRs with full reasoning
│ ├── DEMO-SCRIPT.md # interview walkthrough guide
│ ├── RESUME-BULLETS.md # CV bullets, LinkedIn write-up, interview Q&A
│ ├── TEARDOWN.md # complete AWS teardown instructions
│ └── k3s-setup.md # k3s cluster prerequisites
├── .github/workflows/
│ └── terraform.yml # validate+plan on PR, apply on merge (OIDC auth)
├── ARCHITECTURE.md
├── COSTS.md
└── README.md
```
## 快速开始
### 前置条件
- 开启 Free Tier 的 AWS 账户
- Terraform >= 1.6
- 已配置的 AWS CLI
- kubectl + Helm(用于 Grafana/模拟器)
### 1. 初始化 remote state(仅限一次)
```
cd bootstrap
terraform init
terraform apply
```
请注意 outputs — 你需要在第 2 步中使用它们:
```
terraform output state_bucket_name
terraform output state_lock_table_name
```
### 2. 配置 backend
编辑 `terraform/environments/dev/backend.tf` 并将
`REPLACE_WITH_...` 占位符替换为第 1 步中的 outputs。
### 3. 配置变量
```
cd terraform/environments/dev
cp terraform.tfvars.example terraform.tfvars
# 编辑 terraform.tfvars:
# data_lake_bucket_name = "soc-in-a-box--dev"
# athena_results_bucket_name = "soc-in-a-box-athena--dev"
# alert_email = "you@example.com" # 可选
```
### 4. 部署所有内容
```
terraform init
terraform apply
```
在一次 apply 中部署所有 4 个 Terraform 模块:VPC + 日志源、S3 数据
湖、Athena workgroup + Glue crawlers、检测 Lambdas + Step Functions。
### 5. 注册 CloudTrail Athena 表
```
aws glue create-table \
--database-name soc_in_a_box \
--table-input file://docs/cloudtrail-table.json
```
然后添加今天的 partition:
```
aws athena start-query-execution \
--query-string "ALTER TABLE cloudtrail_logs ADD IF NOT EXISTS
PARTITION (year='$(date +%Y)', month='$(date +%m)', day='$(date +%d)')
LOCATION 's3:///cloudtrail/AWSLogs//CloudTrail/eu-central-1/$(date +%Y/%m/%d)/'" \
--query-execution-context Database=soc_in_a_box \
--work-group soc-in-a-box
```
### 6. 在 k3s 上部署 Grafana
```
helm repo add grafana https://grafana.github.io/helm-charts
helm repo update
kubectl create namespace monitoring
helm install grafana grafana/grafana \
--namespace monitoring \
--set adminPassword='YourPassword' \
--set service.type=NodePort \
--set service.nodePort=32000
# 安装 Athena plugin
kubectl exec -n monitoring deploy/grafana -- \
grafana-cli plugins install grafana-athena-datasource
kubectl rollout restart deployment grafana -n monitoring
```
打开 `http://:32000` 并将 Amazon Athena 添加为数据源。
### 7. 设置并运行模拟器
```
cd ~/enterprise-soc-in-a-box
bash simulators/setup.sh
# 运行 threat simulator 以测试完整 pipeline
kubectl apply -f simulators/threat-simulator/job.yaml -n soc-simulators
kubectl logs -f job/threat-simulator -n soc-simulators
```
等待 10-15 分钟,然后检查 CloudWatch Logs 中的 Lambda 执行情况。
## 检测覆盖范围 (MITRE ATT&CK)
| 检测项 | 严重程度 | MITRE | Lambda |
|---|---|---|---|
| Root 账户使用 | HIGH | T1078.004 | detect-root-activity |
| 大规模 IAM 更改 | HIGH | T1136.003, T1098 | detect-mass-iam |
| 异常区域 API 调用 | MEDIUM | T1535 | detect-network-recon |
| 未使用 MFA 的控制台登录 | MEDIUM | T1078 | Athena query |
| CloudTrail 篡改 | HIGH | T1562.008 | Athena query |
| S3 bucket 公开 | HIGH | T1530 | Athena query |
| 暴力破解 / AccessDenied 激增 | MEDIUM | T1110 | Athena query |
| 创建新的 access key | MEDIUM | T1098.001 | Athena query |
## 成本明细
| 服务 | 每月成本 |
|---|---|
| VPC Flow Logs → S3 | ~$0.50 |
| CloudTrail (1 trail) | $0 (Free Tier) |
| S3 存储空间 | $0 (Free Tier) |
| Lambda | $0 (Free Tier) |
| Athena | $0 (Free Tier) |
| Step Functions EXPRESS | $0 (Free Tier) |
| EventBridge | $0 (Free Tier) |
| Grafana (k3s) | $0 (自托管) |
| **总计** | **~$0.50/月** |
同等的托管技术栈(OpenSearch + GuardDuty + Security Hub +
Managed Grafana)每月至少需要花费 25-40 美元。
## 拆除
```
cd terraform/environments/dev && terraform destroy -auto-approve
```
完整说明请见 [docs/TEARDOWN.md](docs/TEARDOWN.md)。
标签:AWS, C语言, DPI, Grafana, 多线程, 子域名突变, 安全运营, 扫描框架, 自动化响应, 逆向工具