Wassimmaatoug/phishing-detection-threat-hunting

GitHub: Wassimmaatoug/phishing-detection-threat-hunting

一个结合机器学习分类、Docker 沙箱分析和 MISP 威胁情报的自动化钓鱼邮件检测与威胁狩猎平台。

Stars: 0 | Forks: 0

# 🛡️ 钓鱼检测与威胁狩猎 [![Python](https://img.shields.io/badge/Python-3.8+-blue?style=flat-square&logo=python)](https://python.org) [![Redis](https://img.shields.io/badge/Redis-Queue-red?style=flat-square&logo=redis)](https://redis.io) [![Docker](https://img.shields.io/badge/Docker-Sandbox-blue?style=flat-square&logo=docker)](https://docker.com) [![ELK Stack](https://img.shields.io/badge/ELK-Stack-005571?style=flat-square&logo=elastic)](https://elastic.co) [![MISP](https://img.shields.io/badge/MISP-Threat%20Intel-orange?style=flat-square)](https://misp-project.org) [![License](https://img.shields.io/badge/License-MIT-green?style=flat-square)](LICENSE) ## 📌 概述 钓鱼攻击是当今针对组织最普遍的网络威胁之一。本项目通过结合以下技术,自动化了从邮件获取到威胁狩猎的完整检测流程: - **机器学习** 用于 URL 和内容分类 - **沙箱分析** (Docker) 用于处理恶意附件 - **威胁情报** 通过 MISP 和 MITRE ATT&CK 实现 - **实时可视化** 通过 ELK Stack 实现 ## 🏗️ 架构 ``` IMAP Server ──► Redis Queue ──► Email Analysis Pipeline │ ┌───────────────┼───────────────┐ │ │ │ URL Analysis Attachment Header Analysis (ML Model) Analysis (SPF/DKIM/DMARC) (VirusTotal) (Docker + VirusTotal) │ │ │ └───────────────┼───────────────┘ │ Decision Engine │ ┌───────────────┼───────────────┐ │ │ │ Email Alert MISP Event ELK Stack (IOC Storage) (Dashboards) ``` ## ✨ 功能特性 | 模块 | 描述 | |--------|-------------| | 📥 **邮件获取** | 通过 IMAP + SSL 实时检索,使用 Redis 排队 | | 🔗 **URL 分析** | ML 分类(Random Forest — 97.57% 准确率)+ 黑名单/白名单缓存 | | 📎 **附件分析** | 哈希检查 → VirusTotal API(70+ 杀毒引擎)→ Docker 沙箱 | | 📨 **头部分析** | SPF、DKIM、DMARC 验证以检测欺骗 | | 🚨 **报警系统** | 自动邮件报警,包含完整的 IOC 详情和 MITRE ATT&CK 标签 | | 🧠 **威胁情报** | MISP 事件创建、IOC 关联、MITRE ATT&CK 映射 | | 📊 **可视化** | Kibana 仪表盘 — 地理地图、发件人分析、TTP 热力图 | ## 🤖 机器学习模型 在包含 **11,055 封邮件**(55.71% 正常邮件,44.29% 钓鱼邮件)的数据集上训练并评估了七种模型: | 模型 | 准确率 | |-------|----------| | 🥇 Random Forest | **97.57%** | | 🥈 XGBoost | 97.28% | | Decision Tree | 96.70% | | SVM | 95.00% | | Gradient Boosting | 95.11% | | KNN | 94.70% | | Logistic Regression | 93.00% | **使用的特征:** URL 结构(IP 地址、长度、SSL 状态、域名年龄、重定向次数...)、内容指标以及 30 多种行为信号。 **预处理:** 应用 SMOTE 平衡类别 → 训练集扩展至 16,200 个样本。使用 5 折交叉验证进行评估。 ## 🧰 技术栈 ### 后端与核心 - **Python 3.8+** — 主要语言 - **imaplib / redis-py** — 邮件获取和排队 - **scikit-learn, XGBoost, pandas, numpy** — ML 流程 - **dnspython, pyspf, dkimpy, pydmarc** — 头部认证 ### 基础设施 - **Redis** — 异步任务队列 - **Docker** — 用于附件执行的隔离沙箱 - **VirtualBox + Ubuntu 20.04** — 虚拟机环境 ### 威胁情报与监控 - **VirusTotal API** — 多引擎文件和 URL 扫描 - **MISP (pymisp)** — IOC 存储和威胁共享 - **MITRE ATT&CK** — TTP 标记 (T1566.001, T1566.002, T1036...) - **ELK Stack** (Elasticsearch + Logstash + Kibana) — 索引和仪表盘 ## 📊 测试结果(100 封邮件样本) ``` ✅ Phishing detection accuracy : 98% ⏱️ Average processing time : 4.75 sec/email 🔍 IOCs confirmed via MISP : 28 📤 Elasticsearch upload rate : 99% 📦 Redis cache hit rate (URL) : 80% ``` **检测到的钓鱼类型:** - 鱼叉式钓鱼链接:32 封邮件 - 品牌冒充:28 封邮件 - 鱼叉式钓鱼附件:18 封邮件 ## 🚀 入门指南 ### 前置条件 ``` # Python 3.8+ python --version # Docker docker --version # Redis redis-cli ping # should return PONG ``` ### 安装 ``` # 1. Clone the repository git clone https://github.com/YOUR_USERNAME/phishing-detection-threat-hunting.git cd phishing-detection-threat-hunting # 2. Install Python dependencies pip install -r requirements.txt # 3. Start Redis sudo systemctl start redis-server # 4. Configure environment variables cp .env.example .env # Edit .env with your credentials (IMAP, VirusTotal API key, MISP URL/key...) # 5. Run the pipeline python main.py ``` ### 环境变量 ``` # Email IMAP_HOST=your.mail.server IMAP_USER=your@email.com IMAP_PASS=your_password # VirusTotal VT_API_KEY=your_virustotal_api_key # MISP MISP_URL=https://your-misp-instance.com MISP_KEY=your_misp_auth_key # Elasticsearch ES_HOST=localhost ES_PORT=9200 ``` ### ELK Stack 设置 ``` # Start Elasticsearch sudo systemctl start elasticsearch # Start Kibana sudo systemctl start kibana # Access at http://localhost:5601 # Start Logstash sudo systemctl start logstash ``` ## 📁 项目结构 ``` phishing-detection-threat-hunting/ │ ├── src/ │ ├── ingestion/ │ │ └── imap_fetcher.py # IMAP email retrieval │ ├── analysis/ │ │ ├── url_analyzer.py # ML-based URL classification │ │ ├── attachment_analyzer.py # Docker sandbox + VirusTotal │ │ └── header_analyzer.py # SPF / DKIM / DMARC checks │ ├── intelligence/ │ │ ├── misp_client.py # MISP event creation │ │ └── mitre_tagger.py # ATT&CK TTP mapping │ ├── reporting/ │ │ ├── elk_publisher.py # Logstash/Elasticsearch indexer │ │ └── alert_sender.py # Email alert generator │ └── models/ │ ├── train.py # Model training script │ └── random_forest.joblib # Saved production model │ ├── notebooks/ │ └── model_evaluation.ipynb # ROC curves, confusion matrices │ ├── docker/ │ └── sandbox/ # Docker config for attachment sandbox │ ├── config/ │ └── logstash.conf # Logstash pipeline config │ ├── requirements.txt ├── .env.example └── README.md ``` ## 📈 Kibana 仪表盘 系统生成包含以下内容的交互式仪表盘: - 📊 **条形图** — 发件邮箱排名 - ☁️ **词云** — 最常被冒充的品牌(LinkedIn, Google, PayPal, Microsoft...) - 🗺️ **地理地图** — IP 源定位 - 🍩 **环形图** — 攻击来源国家 - 📋 **表格** — 可疑附件和 MITRE ATT&CK 标签 ## 🔬 方法论 本项目遵循 **micro.P3.express** 项目管理方法论,历时 4 个月: 1. **第 1 个月** — 技术发展水平研究(钓鱼工具、MITRE ATT&CK、威胁狩猎) 2. **第 2 个月** — ML 模型开发与训练 3. **第 3 个月** — 架构实现与测试 4. **第 4 个月** — 优化、报告撰写与演示 ## 👥 作者 | 姓名 | 角色 | |------|------| | **Wassim MAATOUG** | 开发者与研究员 | | **Sadok GHORBEL** | 开发者与研究员 | **学术导师:** M. Majdi Dammak **企业导师:** M. Mohamed Yassine Gadhgadhi **所属机构:** Faculté des Sciences de Sfax — Université de Sfax **实习公司:** Primatec Engineering, Sfax, Tunisia ## 📚 参考资料 - [MITRE ATT&CK Framework](https://attack.mitre.org/) - [VirusTotal API](https://docs.virustotal.com/) - [MISP Project](https://misp-project.org/) - [Phishing Statistics — The SSL Store](https://www.thesslstore.com/blog/phishing-statistics/) - [micro.P3.express Methodology](https://micro.p3.express/) ## 📄 许可证 本项目基于 MIT 许可证授权 — 详见 [LICENSE](LICENSE) 文件。
Built with ❤️ at Primatec Engineering — Sfax, Tunisia — 2024/2025
标签:Apex, Cloudflare, DAST, DNS枚举, Docker沙箱, ELK Stack, FTP漏洞扫描, IP 地址批量处理, MITRE ATT&CK, Python, Redis, URL分析, 域名收集, 威胁情报, 安全编排, 开发者工具, 恶意软件分析, 搜索引擎查询, 搜索语句(dork), 无后门, 机器学习, 结构化查询, 网络安全, 网络安全工具, 自动化安全, 请求拦截, 逆向工具, 邮件安全, 钓鱼检测, 附件分析, 隐私保护