marcuspaula-cloudsec/cloud-threat-hunting-platform

GitHub: marcuspaula-cloudsec/cloud-threat-hunting-platform

这是一个利用 Terraform 自动化构建的无服务器平台,通过 Athena 和 Security Hub 等 AWS 原生服务实现集中式的云端威胁狩猎与安全日志分析。

Stars: 0 | Forks: 0

# 云端威胁狩猎平台 利用 AWS 原生服务进行集中式威胁检测与狩猎。通过 Athena 分析 CloudTrail 日志,WAF 保护边缘,Macie 扫描敏感数据暴露,Security Hub 聚合发现结果——所有操作均通过 Terraform 自动化完成。 ## 架构 ``` ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │CloudTrail│ │ VPC Flow │ │ WAF │ │ Macie │ │ Logs │ │ Logs │ │ Logs │ │ Findings │ └────┬─────┘ └────┬─────┘ └────┬─────┘ └────┬─────┘ │ │ │ │ └──────────────┼──────────────┘ │ ▼ │ ┌───────────────┐ │ │ S3 (Central │ │ │ Log Bucket) │ │ └───────┬───────┘ │ ▼ ▼ ┌───────────────┐ ┌─────────────────┐ │ Athena │ │ Security Hub │ │ (SQL Query) │ │ (Aggregation) │ └───────┬───────┘ └────────┬────────┘ │ │ └────────────┬───────────────┘ ▼ ┌──────────────┐ │ Dashboard │ │ + Alerts │ └──────────────┘ ``` ## 威胁狩猎查询 ### 检测未授权的 API 调用 ``` SELECT eventTime, eventName, sourceIPAddress, userIdentity.arn, errorCode FROM cloudtrail_logs WHERE errorCode IN ('AccessDenied', 'UnauthorizedAccess') AND eventTime > current_timestamp - interval '24' hour ORDER BY eventTime DESC LIMIT 100; ``` ### 检测未启用 MFA 的控制台登录 ``` SELECT eventTime, userIdentity.userName, sourceIPAddress, responseElements FROM cloudtrail_logs WHERE eventName = 'ConsoleLogin' AND additionalEventData LIKE '%MFAUsed%No%' ORDER BY eventTime DESC; ``` ### 检测来自异常 IP 的 IAM 密钥使用 ``` SELECT sourceIPAddress, userIdentity.accessKeyId, COUNT(*) as call_count FROM cloudtrail_logs WHERE eventTime > current_timestamp - interval '7' day GROUP BY sourceIPAddress, userIdentity.accessKeyId HAVING COUNT(*) > 100 ORDER BY call_count DESC; ``` ## 结构 ``` . ├── README.md ├── architecture.png ├── terraform/ │ ├── main.tf │ ├── security-hub.tf # Enable + configure Security Hub │ ├── macie.tf # Macie classification jobs │ ├── waf.tf # WAF WebACL + rule groups │ ├── athena.tf # Workgroup + named queries │ ├── s3-log-bucket.tf # Centralized log storage │ └── variables.tf ├── athena-queries/ │ ├── unauthorized-api-calls.sql │ ├── console-login-no-mfa.sql │ ├── unusual-ip-access.sql │ ├── s3-public-access-changes.sql │ ├── iam-policy-changes.sql │ └── root-account-usage.sql ├── waf-rules/ │ ├── rate-limiting.json │ ├── geo-restriction.json │ ├── sql-injection-block.json │ └── known-bad-ips.json └── docs/ ├── hunting-playbook.md # Step-by-step investigation guide └── waf-tuning.md # False positive handling ``` ## 关键设计决策 ### 为什么选择 Athena 而非 Splunk/ELK Athena 直接查询 S3 —— 无需数据摄取管道,无需管理集群,按查询付费。针对 CloudTrail 日志的威胁狩猎,这是规模化场景下最具成本效益的方案。 ### 为什么选择 Security Hub 作为聚合器 为 GuardDuty、Macie、Config、IAM Access Analyzer 和 Firewall Manager 提供单一管理视图。CIS 基准和 AWS 基础安全最佳实践自动运行。 ### 为什么在边缘部署 WAF 在攻击模式(SQLi、XSS、机器人流量)到达应用层之前进行拦截。速率限制在边界处防御 DDoS 和暴力破解。 ## 部署 ``` cd terraform/ terraform init terraform plan -out=tfplan terraform apply tfplan ``` ## 参考资料 - [使用 Athena 进行 AWS 威胁狩猎](https://docs.aws.amazon.com/athena/latest/ug/cloudtrail-logs.html) - [Security Hub 标准](https://docs.aws.amazon.com/securityhub/latest/userguide/securityhub-standards.html) - [AWS WAF 规则组](https://docs.aws.amazon.com/waf/latest/developerguide/waf-rule-groups.html) - [MITRE ATT&CK 云矩阵](https://attack.mitre.org/matrices/enterprise/cloud/) *基于 Terraform + Athena SQL 构建 | 无服务器威胁狩猎*
标签:Amazon Athena, Amazon Macie, Amazon WAF, AWS, AWS Security Hub, CloudTrail, DPI, EC2, ECS, IaC, S3, Terraform, VPC Flow Logs, 人工智能安全, 合规性, 多线程, 安全运营, 扫描框架, 数据泄露防护, 网络探测