tryhackmeacct-netizen/Advanced-Threat-Intelligence-Platform-Dynamic-Policy-Enforcer

GitHub: tryhackmeacct-netizen/Advanced-Threat-Intelligence-Platform-Dynamic-Policy-Enforcer

一个自动从OSINT源获取威胁指标、评分并动态执行防火墙阻断的安全运营平台。

Stars: 1 | Forks: 0

# 高级威胁情报平台与动态策略执行器 一个生产就绪的威胁情报自动化平台,可从OSINT源获取恶意IOC数据,进行标准化和去重处理,分配风险评分,存储至MongoDB,通过iptables自动执行防火墙阻断,并生成适用于SOC合规的SIEM审计日志。 ## 🎯 项目概述 该平台自动化了整个威胁情报生命周期: - **获取** 来自VirusTotal、AlienVault OTX和AbuseIPDB的恶意IOC - **标准化** 指标格式并去重记录 - **评分** 基于源信誉对威胁进行评分(60-95分范围) - **存储** 通过适当模式管理存入MongoDB - **执行** 对高风险指标自动设置防火墙规则 - **日志** 记录所有安全事件以便SIEM集成和合规 ## 🔄 安全流程 ``` OSINT Feeds (VirusTotal, AlienVault, AbuseIPDB) ↓ IOC Normalization & Validation ↓ Deduplication Check (MongoDB) ↓ Risk Scoring Engine ↓ MongoDB Storage ↓ Risk Threshold Evaluation (≥80) ↓ Dynamic Firewall Enforcement (iptables) ↓ SIEM-Ready Security Logging ``` ## 📁 项目结构 ``` Advanced-Threat-Intelligence-Platform-Dynamic-Policy-Enforcer/ ├── main.py # Production entry point with CLI ├── requirements.txt # Python dependencies ├── README.md # This file ├── REVIEW.md # Comprehensive review guide (350+ lines) ├── DAY12_IMPROVEMENTS.md # Day 13 - Enhancements │ ├── core/ # Core threat processing modules │ ├── __init__.py │ ├── pipeline.py # Main processing pipeline │ ├── database.py # MongoDB integration │ ├── cleaner.py # IOC cleaning and validation │ ├── deduplicator.py # Duplicate detection │ ├── normalizer.py # Record normalization │ ├── risk_scoring.py # Risk calculation engine │ ├── config.py # Configuration management │ ├── logger.py # Application logging │ └── security_logger.py # SIEM-ready security logging │ ├── feeds/ # OSINT threat intelligence feeds │ ├── __init__.py │ ├── virustotal.py # VirusTotal API integration │ ├── alienvault.py # AlienVault OTX API integration │ └── abuseipdb.py # AbuseIPDB API integration │ ├── policy_enforcer/ # Firewall policy enforcement │ ├── __init__.py │ └── firewall_manager.py # Linux iptables integration │ ├── data_ingestion/ # Data ingestion scripts │ ├── __init__.py │ └── virustotal.py # Standalone ingestion example │ ├── normalization/ # Legacy normalization modules │ ├── __init__.py │ ├── cleaner.py │ ├── deduplicator.py │ └── risk_scoring.py │ ├── logs/ # Runtime logs │ ├── ingestion.log # Application logs │ └── security_events.log # SIEM-ready security events │ ├── screenshots/ # Proof artifacts └── docs/ # Additional documentation ``` ## ✨ 核心功能 - ✅ **多源OSINT集成** - VirusTotal、AlienVault OTX、AbuseIPDB - ✅ **IOC标准化** - 支持IP地址、域名和文件哈希 - ✅ **智能去重** - 基于MongoDB的重复检测 - ✅ **动态风险评分** - 60-95分范围,基于源类型 - ✅ **MongoDB持久化** - 包含时间戳和元数据的适当模式 - ✅ **自动防火墙执行** - 针对高风险IP的iptables规则 - ✅ **SIEM就绪日志** - 适用于ELK/Kibana的结构化安全事件 - ✅ **CLI界面** - 专业的argparse命令行工具 - ✅ **错误处理** - 全面的异常处理和日志记录 - ✅ **演示模式** - 无需API密钥即可安全测试 ## 🚀 快速开始 ### 安装说明 ``` # Clone the repository git clone https://github.com/tryhackmeacct-netizen/Advanced-Threat-Intelligence-Platform-Dynamic-Policy-Enforcer.git cd Advanced-Threat-Intelligence-Platform-Dynamic-Policy-Enforcer # Create virtual environment python3 -m venv .venv source .venv/bin/activate # Install dependencies pip install -r requirements.txt # Ensure MongoDB is running sudo systemctl start mongod ``` ### 基本用法 ``` # Run in demo mode (no API keys needed) python3 main.py --mode demo --indicators 203.0.113.10 198.51.100.20 # Run in live mode (requires API keys in .env) python3 main.py --mode live --indicators 8.8.8.8 1.1.1.1 # Show help python3 main.py --help ``` ## 📊 OSINT源 ### 支持的威胁情报源 | 源 | API | 风险评分 | 详情 | |------|-----|-----------|---------| | **VirusTotal** | 商业 | 90 | 恶意软件检测,70+反病毒引擎 | | **AlienVault OTX** | 免费 | 85 | Pulse数据,社区威胁情报 | | **AbuseIPDB** | 免费/专业 | 80 | IP信誉,滥用评分 | | **DemoFeed** | 演示 | 95 | 无需API密钥的安全测试 | # 最新增强功能(2026年6月) 在项目根目录创建 `.env` 文件: ``` # .env file MONGO_URI=mongodb://localhost:27017/ DB_NAME=threat_intelligence COLLECTION_NAME=ioc_data # OSINT Feed API Keys VIRUSTOTAL_API_KEY=your_virustotal_api_key ALIENVAULT_API_KEY=your_alienvault_api_key ABUSEIPDB_API_KEY=your_abuseipdb_api_key # Feed Configuration DEFAULT_FEED_INDICATORS=203.0.113.10,198.51.100.20,192.0.2.20 ENABLE_DEMO_FALLBACK=1 ``` ## 💯 风险评分 风险评分基于威胁源类型分配: ``` DemoFeed → 95 (Highest - Test Data) VirusTotal → 90 (Commercial Intelligence) AlienVault → 85 (Community Threat Data) AbuseIPDB → 80 (IP Reputation) URLHaus → 88 (URL Phishing/Malware) Default → 60 (Unknown Source) ``` **防火墙执行阈值:** ≥ 80(自动阻断所有评分80及以上的指标) ## 🔧 高级命令 ### 检查MongoDB数据库 ``` # Count total IOCs python3 << 'EOF' from pymongo import MongoClient client = MongoClient("mongodb://localhost:27017/") collection = client["threat_intelligence"]["ioc_data"] print(f"Total IOCs: {collection.count_documents({})}") EOF # View MongoDB with mongosh mongosh use threat_intelligence db.ioc_data.find().pretty() db.ioc_data.countDocuments() ``` ### 检查防火墙规则 ``` # List all DROP rules for malicious IPs sudo iptables -L INPUT -n | grep DROP # View all firewall rules sudo iptables -S # View rule count sudo iptables -L INPUT -n | grep -c DROP # Clear all custom rules (if needed) sudo iptables -F INPUT ``` ### 检查安全日志 ``` # View SIEM-ready security events tail -20 logs/security_events.log # View application logs tail -20 logs/ingestion.log # Count security events by type grep "EVENT=" logs/security_events.log | cut -d'=' -f2 | cut -d'|' -f1 | sort | uniq -c # Monitor in real-time tail -f logs/security_events.log ``` ### 检查MongoDB服务状态 ``` sudo systemctl status mongod mongosh --version ``` ## 📋 预期输出 ### 演示模式成功运行 ``` 2026-05-27 07:09:29,628 | INFO | tip_ingestion | Starting Threat Intelligence Platform [MODE=DEMO, INDICATORS=3] 2026-05-27 07:09:29,641 | INFO | tip_ingestion | Stored IOC 203.0.113.99 from DemoFeed ✓ 203.0.113.99 (ip) - Risk: 95 - Source: DemoFeed ✓ 198.51.100.99 (ip) - Risk: 95 - Source: DemoFeed ✓ 192.0.2.99 (ip) - Risk: 95 - Source: DemoFeed [SUCCESS] Processed 3 IOCs ``` ### MongoDB文档模式 ``` { "indicator": "203.0.113.99", "type": "ip", "source": "DemoFeed", "risk_score": 95, "status": "malicious", "timestamp": "2026-05-27T07:09:29.641000", "details": {} } ``` ### 防火墙规则示例 ``` $ sudo iptables -L INPUT -n | grep 203.0.113.99 DROP all -- 203.0.113.99 0.0.0.0/0 ``` ### 安全事件日志格式 ``` 2026-05-27 11:09:29 | EVENT=MALICIOUS_IP_DETECTED | IP=203.0.113.99 | SOURCE=DemoFeed | RISK=95 | ACTION=DETECTED 2026-05-27 11:09:29 | EVENT=FIREWALL_BLOCK | IP=203.0.113.99 | SOURCE=DemoFeed | RISK=95 | ACTION=BLOCKED ``` ## 📚 文档 如需完整的项目评审指南,包含所有命令、每周分解和测试清单,请参阅 **[REVIEW.md](REVIEW.md)** 评审指南中的关键部分: - ✅ 每周实现细节 - ✅ 所有评审和演示命令及预期输出 - ✅ 架构图和数据流 - ✅ 技术栈和主要功能 - ✅ 面试测试清单 - ✅ 项目演示要点 - ✅ 下一步增强步骤 ## 🏗️ 架构与设计 ### 管道阶段 1. **获取** - 从配置的OSINT源或演示数据获取IOC 2. **标准化** - 统一格式,推断类型(IP/域名/哈希) 3. **去重** - 查询MongoDB检测现有指标 4. **风险评分** - 基于源类型分配风险评分(60-95) 5. **存储** - 将标准化IOC及其元数据插入MongoDB 6. **防火墙** - 评估风险评分;如果≥80,添加iptables DROP规则 7. **日志** - 将所有事件记录到应用日志和安全日志 ### 数据库模式 **集合:** `threat_intelligence` 数据库中的 `ioc_data` ``` { "_id": ObjectId, "indicator": String, // IP, domain, or hash "type": String, // "ip", "domain", or "hash" "source": String, // Feed source (VirusTotal, AlienVault, etc.) "risk_score": Integer, // 60-95 scale "status": String, // "malicious" "timestamp": String, // ISO 8601 format "details": Object // Feed-specific metadata } ``` ### 安全事件日志 **文件:** `logs/security_events.log`(SIEM兼容) **格式:** `时间戳 | 事件=类型 | IP=指标 | 源=源 | 风险=评分 | 动作=状态` **事件类型:** - `MALICIOUS_IP_DETECTED` - 发现新的恶意指标 - `FIREWALL_BLOCK` - iptables规则成功创建 - `FIREWALL_BLOCK_FAILED` - iptables规则创建失败(无sudo权限) ## 🛠️ 使用技术 | 组件 | 技术 | |-----------|-----------| | **语言** | Python 3.8+ | | **数据库** | MongoDB 4.0+ with PyMongo | | **防火墙** | Linux iptables | | **日志** | Python logging模块 | | **配置** | python-dotenv | | **OSINT API** | VirusTotal, AlienVault OTX, AbuseIPDB | | **版本控制** | Git | ## 📊 项目统计 | 指标 | 值 | |--------|-------| | Python文件 | 15+ | | 模块 | 5 | | 核心函数 | 30+ | | OSINT源 | 3 | | 安全事件类型 | 2+ 种 | | 代码行数 | 500+ | | 风险等级 | 5-6 类 | ## 📝 注意事项 - **演示模式** - 使用 `--mode demo` 无需API密钥测试 - **实时模式** - 需要 `.env` 文件配置API密钥 - **去重** - 同一IOC运行两次会显示 "Duplicate IOC skipped" - **防火墙** - 需要 `sudo` 权限;若无权限则记录 `BLOCK_FAILED` - **日志** - 所有事件同时记录到控制台和文件以便审计追踪 ## 🚦 故障排除 ### MongoDB连接失败 ``` # Start MongoDB service sudo systemctl start mongod # Verify connection mongosh --eval "db.adminCommand('ping')" ``` ### 防火墙规则未创建 ``` # Check if you have sudo privileges sudo iptables -L INPUT -n # Look for errors in logs grep "BLOCK_FAILED" logs/security_events.log ``` ### API密钥问题 ``` # Verify .env file exists cat .env # Test feed connectivity python3 main.py --mode live --indicators 8.8.8.8 ``` ## 🚀 2026年6月更新 ### 新增功能 * ✅ 实时VirusTotal API集成 * ✅ MongoDB IOC存储和去重 * ✅ Elasticsearch SIEM转发 * ✅ 动态防火墙策略执行 * ✅ 改进的IOC处理日志 ### 成功测试 * IOC检测: `91.219.236.222` * VirusTotal恶意评分检测 * MongoDB存储和重复检查 * Elasticsearch SIEM摄取 * 安全事件日志记录 ### 示例命令 ``` python3 main.py --mode live --indicators 91.219.236.222 ``` ### 示例结果 ``` Stored IOC 91.219.236.222 from VirusTotal IOC forwarded to SIEM Risk Score: 100 ``` ## ✅ 测试清单 - [ ] MongoDB运行并连接 - ] 成功运行演示模式 - [ ] 检查数据库中IOC数量 - [ ] 验证SIEM就绪的安全日志 - [ ] 确认已创建防火墙规则 - [ ] 使用重复指标测试去重 - [ ] 检查应用日志中的错误 - [ ] 验证存储文档的模式 ## 📄 作者与许可 **开发者:** Sanket Pawar ## 🔗 快速链接 - GitHub仓库: https://github.com/tryhackmeacct-netizen/Advanced-Threat-Intelligence-Platform-Dynamic-Policy-Enforcer - 项目文档: [docs/](docs/)
标签:ESC4, FTP漏洞扫描, IOC, iptables, MongoDB, OSINT, Python, 动态防火墙, 合规, 威胁情报, 安全编排, 安全运营, 审计日志, 开发者工具, 恶意指标, 扫描框架, 无后门, 自动化响应, 逆向工具, 风险评分