jaypatel-Cyber/Cloud-IR-Threat-Hunting

GitHub: jaypatel-Cyber/Cloud-IR-Threat-Hunting

基于Python的AWS云威胁搜寻工具,通过统计异常检测与MITRE ATT&CK映射分析CloudTrail日志,识别配置错误与恶意行为。

Stars: 0 | Forks: 0

# 云事件响应与威胁搜寻 (AWS) | 字段 | 详情 | |------------|---------------------------------------------| | 角色侧重 | Cloud SOC 分析师 / 云 IR 专家 | | 难度 | ★★★★☆ 高级 | | 状态 | 完成 | | 技术栈 | Python 3, Pandas, AWS CloudTrail, LocalStack, Jupyter, Sigma | ## 架构 ``` ┌─────────────────────────────────────────────────────────────────────┐ │ Deliberately Vulnerable AWS Environment │ │ S3 (misconfigured) · IAM (over-privileged) · EC2 (open SG) │ └─────────────────────────────────────────┬───────────────────────────┘ │ CloudTrail API Logging ┌─────────────────────┼─────────────────────┐ │ │ │ ┌──────▼──────┐ ┌───────▼──────┐ ┌────────▼───────┐ │ Local JSON │ │ AWS S3 │ │ CloudWatch Logs│ │ (Dev/Lab) │ │ Bucket │ │ (Production) │ └──────┬──────┘ └───────┬──────┘ └────────┬───────┘ └─────────────────────┼─────────────────────┘ │ ┌───────────▼───────────┐ │ cloudtrail_ingestor │ │ Records → DataFrame │ └───────────┬───────────┘ │ ┌────────────────▼────────────────┐ │ anomaly_detector │ │ ┌──────────────────────────┐ │ │ │ Z-Score API Frequency │ │ │ │ IQR Error Rate Spike│ │ │ │ Baseline Rare API Calls │ │ │ │ Clock After-Hours Hunt │ │ │ │ Burst Resource Creation│ │ │ │ Triage Sensitive APIs │ │ │ └──────────────────────────┘ │ └────────────────┬────────────────┘ │ ┌────────────────▼────────────────┐ │ ip_profiler │ │ Timeline + MITRE ATT&CK Map │ │ T1530 · T1078.004 · T1496 │ └────────────────┬────────────────┘ │ ┌────────────────▼────────────────┐ │ hunt_orchestrator │ │ JSON Investigation Report │ └─────────────────────────────────┘ ``` ## 技术栈 | 组件 | 工具 | 角色 | |-----------------------|--------------------------|---------------------------------------------| | 云模拟 | LocalStack 3.4 | 本地 AWS (S3, IAM, EC2, CloudTrail, STS) | | 日志摄入 | cloudtrail_ingestor.py | 解析 CloudTrail JSON → Pandas DataFrame | | 统计分析 | Pandas + NumPy | Z-score, IQR, 频率异常检测 | | IP 分析 | ip_profiler.py | 构建攻击者时间线 + MITRE 映射 | | 搜寻编排 | hunt_orchestrator.py | 端到端流水线, JSON 报告输出 | | 交互式分析 | Jupyter Lab | 带可视化的分步 notebook | | 检测规则 | Sigma (YAML) | CloudTrail 原生 Sigma 规则 | | 云模拟 API | boto3 | S3/IAM/EC2 API 调用 (LocalStack endpoint) | | 攻击模拟 | generate_attack_logs.py | 合成 CloudTrail 日志生成 | ## 模拟的攻击场景 ### 1. S3 Bucket 配置错误 + 数据外泄 - 攻击者通过 `ListBuckets`, `GetBucketAcl` 枚举 buckets - 发现可公开访问的 bucket (`company-public-assets`) - 通过 `GetObject` 外泄 HR 导出数据、薪资数据、数据库凭证 - **MITRE:** T1530 — 来自云存储对象的数据 ### 2. IAM 角色劫持 + 持久化 - 使用被盗的开发者凭证枚举 `ListUsers`, `ListRoles` - 对 `ec2-admin-role` 执行 `AssumeRole` 以进行横向移动 - 创建新的 `AccessKey` 用于持久化后门访问 - **MITRE:** T1078.004 — 有效账户: 云账户 | T1098.001 — 额外的云凭证 ### 3. 挖矿 EC2 部署 - 在非标准区域 (`ap-southeast-1`) 启动 `p3.16xlarge` GPU 实例 - 创建宽松的安全组 (SSH 0.0.0.0/0) - **MITRE:** T1496 — 资源劫持 ### 4. 防御规避 - 尝试 `StopLogging` + `DeleteTrail` 以致盲 SOC - **MITRE:** T1562.008 — 禁用云日志 ## 设置 ### 选项 A — 本地文件 (无需 AWS) ``` # Clone and install dependencies cd Project_4_Cloud_IR_Threat_Hunting pip install -r requirements.txt # Run the full hunt pipeline against sample data cd hunting python hunt_orchestrator.py --input ../sample_data/cloudtrail_logs.json --profile-suspects # Open the interactive Jupyter notebook jupyter lab ../notebooks/cloud_threat_hunt.ipynb ``` ### 选项 B — LocalStack (完整 AWS 模拟) ``` # Start LocalStack + Jupyter docker-compose up -d # Generate and upload simulated attack logs cd attack_simulation python generate_attack_logs.py --output ../sample_data/cloudtrail_logs.json --upload-localstack # Run orchestrator against LocalStack S3 cd ../hunting AWS_ENDPOINT_URL=http://localhost:4566 \ python hunt_orchestrator.py --s3-bucket cloudtrail-logs --s3-prefix AWSLogs/ --profile-suspects ``` ### 选项 C — 真实 AWS CloudTrail ``` # Set real credentials cp ../.env.example ../.env # Edit .env with real AWS keys # Enable CloudTrail in your AWS account → deliver to S3 bucket # Run against real logs python hunt_orchestrator.py --s3-bucket YOUR-CLOUDTRAIL-BUCKET --s3-prefix AWSLogs/ --profile-suspects ``` ## 运行单个模块 ``` # Ingest only python hunting/cloudtrail_ingestor.py --input sample_data/cloudtrail_logs.json --output /tmp/flat.csv # Detect anomalies (all modules) python hunting/anomaly_detector.py --input /tmp/flat.csv # Run one specific module python hunting/anomaly_detector.py --input /tmp/flat.csv --module error_rate # Profile a specific suspect IP python hunting/ip_profiler.py --input /tmp/flat.csv --ip 185.220.101.47 # Full hunt + JSON output python hunting/hunt_orchestrator.py --input sample_data/cloudtrail_logs.json --json ``` ## MITRE ATT&CK 覆盖范围 | 战术 | 技术 ID | 技术名称 | 检测模块 | |----------------------|--------------|-----------------------------------------|--------------------------| | 发现 | T1580 | 云基础设施发现 | rare_api_calls | | 发现 | T1087.004 | 账户发现: 云账户 | sensitive_access | | 收集 | T1530 | 来自云存储对象的数据 | sensitive_access | | 权限提升 | T1078.004 | 有效账户: 云账户 | sensitive_access | | 持久化 | T1098.001 | 额外的云凭证 | creation_burst | | 影响 | T1496 | 资源劫持 (挖矿) | creation_burst | | 防御规避 | T1562.008 | 禁用云日志 | rare_api_calls | ## 检测逻辑摘要 | 模块 | 方法 | 信号 | 阈值 | |----------------------|----------------|-------------------------------------------------|------------------------| | api_frequency | Z-Score | 产生统计上异常调用量的 IP | z ≥ 2.5 | | error_rate | IQR Fence | AccessDenied 比率异常的 IP (侦察) | Q3 + 1.5×IQR | | rare_api_calls | 频率 | 低频调用 (StopLogging, DeleteTrail) | < 所有事件的 2% | | after_hours | 时间 | 非服务账户活动 00:00–07:00 UTC | 小时在 [0,7) 内 | | creation_burst | 计数 | ≥ 3 次资源创建调用 (RunInstances 等) | count ≥ 3 | | sensitive_access | 允许列表 | 对高风险 API 的调用, 无论频率如何 | 硬编码集合 | ## 展示的技能 | 技能 | 证据 | |--------------------------------|-------------------------------------------------------| | AWS CloudTrail 日志分析 | 解析嵌套的 CloudTrail JSON, 字段扁平化 | | 统计威胁搜寻 | 基于 API 调用模式的 Z-score + IQR 异常检测 | | 安全数据科学 | Pandas DataFrame 流水线, 时间序列分析 | | 云攻击模拟 | 覆盖 4 个场景的合成攻击日志生成 | | 云 MITRE ATT&CK | 4 个战术中的 7 个技术映射 | | Sigma 规则编写 | 3 条 CloudTrail 原生 Sigma 检测规则 | | Python 安全工具 | 4 个模块化 CLI 脚本, 使用 argparse + logging | | Jupyter Notebook 报告 | 带可视化的交互式调查 notebook| | AWS IAM & S3 安全 | 对配置错误攻击路径的理解 | | IR 报告生成 | 带时间线的自动化 JSON 调查报告 |
标签:AWS, Cloudflare, CloudTrail, CloudWatch, DPI, EC2, IaC, IAM, Jupyter, LocalStack, MITRE ATT&CK, Python, S3, 安全组, 异常检测, 数据科学, 无后门, 统计分析, 资源验证