subhaadeep/malware-analyzer

GitHub: subhaadeep/malware-analyzer

基于多技术栈的恶意软件检测与分析系统

Stars: 0 | Forks: 0

version python platform license status

# 🛡️ 恶意软件分析器 ### 多层恶意软件检测系统 *YARA 签名 · 启发式分析 · 熵检测 · ML 威胁评分 · 隔离 · Dashboard*
[🚀 快速开始](#-quick-start) · [📖 完整使用指南](USAGE.md) · [🏗️ 架构](#️-system-architecture) · [🖥️ Dashboard](#️-streamlit-dashboard) · [🤖 ML Pipeline](#-ml-pipeline) · [🛣️ 路线图](#️-roadmap)
## 📌 概述 **Malware Analyzer** 是一个开源的、基于 Python 构建的多层恶意软件检测引擎。它将基于规则的静态分析、行为启发式、统计混淆检测和机器学习结合到一个统一的 pipeline 中——为任何文件生成加权威胁评分和判定结果。
### 🔬 检测层一览 | 层级 | 引擎 | 检测内容 | |---|---|---| | 🧬 **YARA 扫描** | `yara-python` | 已知的恶意软件签名和模式 | | 🧠 **启发式分析** | 关键词引擎 | 可疑行为(cmd、powershell、shellcode 等) | | 📊 **熵分析** | Shannon 熵 | 混淆、打包或加密的 payload | | 🔍 **签名扫描** | 指标匹配 | 已知的恶意软件 API 调用和命令 | | ⚖️ **威胁评分** | 加权模型 | 0–100 的统一风险评分 | | 🤖 **ML 预测** | RandomForest | 置信度 % + 概率得分 | | 🚫 **隔离** | 文件隔离 | 将恶意软件移动到安全目录 | | 📄 **JSON 日志** | 结构化日志 | 审计跟踪 + ML 训练数据 | | 🖥️ **Dashboard** | Streamlit | 带有报告下载功能的实时 Web UI | ## 🚀 快速开始 ### 选项 A — Kali Linux / 任何托管的 Python(推荐) ``` git clone https://github.com/subhaadeep/malware-analyzer.git cd malware-analyzer # 一次性设置(创建 venv + 安装所有 packages) bash install.sh # 运行 CLI scanner bash run.sh scan --file samples/malware.txt # 启动 web dashboard bash run.sh dashboard ``` ### 选项 B — 手动(如果你自己管理 venv) ``` git clone https://github.com/subhaadeep/malware-analyzer.git cd malware-analyzer python3 -m venv venv source venv/bin/activate # Windows: venv\Scripts\activate pip install -r requirements.txt python main.py --file samples/malware.txt ``` ### 选项 C — Windows ``` git clone https://github.com/subhaadeep/malware-analyzer.git cd malware-analyzer install.bat ``` ## 📖 详细使用指南
### ➡️ **[查看完整使用指南 → USAGE.md](USAGE.md)**
| 主题 | 直接链接 | |---|---| | ⚙️ 安装(所有平台) | [USAGE.md → 安装](USAGE.md#1-installation) | | 🖥️ CLI 扫描器命令和标志 | [USAGE.md → CLI 扫描器](USAGE.md#2-cli-scanner) | | 🌐 Streamlit dashboard 指南 | [USAGE.md → Dashboard](USAGE.md#3-streamlit-dashboard) | | 🤖 ML 训练和预测 | [USAGE.md → ML Pipeline](USAGE.md#4-ml-pipeline) | | 📄 报告生成(HTML/PDF) | [USAGE.md → 报告生成器](USAGE.md#5-report-generator) | | 📜 读取扫描日志 | [USAGE.md → 日志查看器](USAGE.md#6-log-viewer) | | 🔧 编辑配置和阈值 | [USAGE.md → 配置](USAGE.md#7-configuration) | | 🧬 编写自定义 YARA 规则 | [USAGE.md → YARA 规则](USAGE.md#8-yara-rules) | | ❓ 了解判定结果和评分 | [USAGE.md → 了解结果](USAGE.md#9-understanding-results) | | 🔧 常见错误和修复 | [USAGE.md → 故障排除](USAGE.md#10-troubleshooting) | ## 📁 项目结构 ``` malware-analyzer/ │ ├── 📂 scanner/ # Core detection engines │ ├── yara_scanner.py │ YARA signature scanning │ ├── heuristic_scanner.py │ Behavioral keyword detection │ ├── entropy_analyzer.py │ Shannon entropy analysis │ ├── signature_scanner.py │ Known malware indicator matching │ ├── quarantine.py │ File isolation + SHA256 rename │ ├── threat_scorer.py │ Weighted scoring engine (0–100) │ └── osv_lookup.py │ OSV vulnerability advisory lookup │ ├── 📂 logging_system/ # Audit & reporting │ └── logger.py │ Daily JSON structured logs │ ├── 📂 ml_pipeline/ # Machine learning (Phase 2) │ ├── feature_extractor.py │ 10-feature vector extraction │ ├── train_model.py │ RandomForest / XGBoost trainer │ ├── predict.py │ Prediction + confidence score │ └── model/ │ Saved .pkl model files │ ├── 📂 dashboard/ # Web UI (Phase 3) │ └── app.py │ Streamlit 4-page dashboard │ ├── 📂 reports/ # Report generation │ ├── report_generator.py │ HTML report (printable as PDF) │ └── output/ │ Generated report files │ ├── 📂 config/ │ └── rules.yaml # All thresholds + weights (config-driven) │ ├── 📂 rules/ │ └── malware_rules.yar # YARA rule definitions (4 rules) │ ├── 📂 dataset/ │ ├── malware/ # Malicious training samples [label=1] │ ├── benign/ # Clean training samples [label=0] │ └── test/ # Held-out evaluation files │ ├── 📂 samples/ │ ├── malware.txt # Test malware sample │ └── benign.txt # Test clean sample │ ├── 📂 quarantine/ # Isolated malware (do NOT execute) ├── 📂 logs/ # Scan logs → YYYY-MM-DD.json │ ├── main.py # CLI entry point ├── run.sh # All-in-one venv runner (Linux/Kali) ├── install.sh # Auto installer (Linux/macOS/WSL) ├── install.bat # Auto installer (Windows) ├── USAGE.md # 📖 Complete usage & CLI guide ├── setup.py # Package setup └── requirements.txt # Python dependencies ``` ## 🏗️ 系统架构 ``` ┌─────────────────────────────────────────────────────┐ │ INPUT FILE │ └──────────────────────┬──────────────────────────────┘ │ ┌─────────────▼─────────────┐ │ YARA Scanner │ ← Signature rules (.yar) │ rules/malware_rules.yar │ └─────────────┬─────────────┘ │ ┌─────────────▼─────────────┐ │ Heuristic Scanner │ ← 20+ suspicious keywords │ config/rules.yaml │ └─────────────┬─────────────┘ │ ┌─────────────▼─────────────┐ │ Entropy Analyzer │ ← Shannon entropy (threshold: 6.0) └─────────────┬─────────────┘ │ ┌─────────────▼─────────────┐ │ Signature Scanner │ ← Known malware API indicators └─────────────┬─────────────┘ │ ┌─────────────▼─────────────┐ │ Threat Scorer │ ← Weighted score 0–100 │ YARA+40 | Heur+25 │ │ Entropy+20 | Sig+15 │ └─────────────┬─────────────┘ │ ┌────────▼────────┐ │ ML Predictor │ ← RandomForest (optional) │ Confidence % │ └────────┬────────┘ │ ┌─────────────▼─────────────┐ │ Final Verdict │ │ 🟢 SAFE / 🟡 SUSPICIOUS │ │ 🔴 MALICIOUS │ └──────┬────────────┬───────┘ │ │ ┌───────────▼──┐ ┌────▼──────────────┐ │ Quarantine │ │ JSON Logger │ │ (if MALICIOUS) │ logs/YYYY-MM-DD │ └──────────────┘ └───────────────────┘ ``` ## ⚖️ 威胁评分模型 评分引擎将所有层的结果汇总为一个单独的风险评分: | 检测层 | 评分贡献 | |---|:---:| | 🧬 YARA 匹配 | **+40** | | 🧠 启发式匹配 | **+25** | | 📊 高熵 | **+20** | | 🔍 签名匹配 | **+15** | | **最大值** | **100** | | 评分范围 | 判定 | 含义 | |:---:|---|---| | 0 – 30 | 🟢 **安全** | 未检测到重大威胁 | | 31 – 70 | 🟡 **可疑** | 潜在风险——需进一步调查 | | 71 – 100 | 🔴 **恶意** | 高可信度恶意软件——需隔离 | ## 🖥️ Streamlit Dashboard 一个包含 4 个页面的 Web UI,用于交互式扫描、日志浏览和报告生成。 ``` bash run.sh dashboard # 打开:http://localhost:8501 ``` | 页面 | 功能 | |---|---| | 🔍 **扫描文件** | 上传或基于路径的扫描、实时结果、判定横幅、评分条、下载 HTML 报告 | | 📊 **Dashboard** | 今日扫描统计、最近的历史记录表、Plotly 判定甜甜圈图 | | 📜 **扫描日志** | 浏览每日日志、按判定结果过滤、展开条目、下载单次扫描报告 | | ℹ️ **关于** | 项目描述、评分表、运行说明 | ## 🤖 ML Pipeline ### 训练模型 ``` # 首先将文件添加到 dataset # dataset/malware/ ← 恶意样本 (label = 1) # dataset/benign/ ← 干净样本 (label = 0) python ml_pipeline/train_model.py ``` ### 运行 ML 预测 ``` python ml_pipeline/predict.py --file samples/malware.txt ``` **输出:** ``` ================================================== FILE: samples/malware.txt PREDICTION: MALICIOUS CONFIDENCE: 91.00% RISK SCORE: 91/100 ================================================== ``` ## 🛣️ 路线图 ``` Phase 1 — Static Detection Engine ✅ COMPLETE ├── YARA signature scanning ✅ ├── Heuristic keyword analysis ✅ ├── Shannon entropy analysis ✅ ├── Signature indicator matching ✅ ├── Weighted threat scoring (0–100) ✅ ├── Quarantine system ✅ └── JSON structured logging ✅ Phase 2 — AI / ML Integration ✅ SCRIPTS READY ├── 10-feature vector extraction ✅ ├── RandomForest / XGBoost trainer ✅ ├── ML prediction + confidence score ✅ └── Real-world dataset collection ⏳ Pending Phase 3 — Advanced / UI ✅ COMPLETE ├── Streamlit 4-page dashboard ✅ ├── HTML / PDF report generator ✅ ├── OSV dependency vulnerability check ✅ └── Real-time file monitoring ⏳ Planned Phase 4 — Future Enhancements 📋 PLANNED ├── PE file analysis (Windows EXE) ├── API call monitoring (dynamic) ├── String frequency analysis ├── VirusTotal API integration └── Docker containerization ``` ## 🔧 配置 所有扫描器的行为均通过 `config/rules.yaml` 控制——无需硬编码: ``` scanner: entropy_threshold: 6.0 # Files above this → ELEVATED entropy_high_threshold: 7.5 # Files above this → HIGH threat_scoring: yara_match: 40 heuristic_match: 25 high_entropy: 20 signature_match: 15 thresholds: safe: 30 suspicious: 70 ``` ## 📦 依赖项 | 包 | 用途 | |---|---| | `yara-python` | YARA 规则引擎 | | `pyyaml` | YAML 配置解析 | | `scikit-learn` | RandomForest ML 模型 | | `xgboost` | XGBoost ML 模型 | | `numpy` / `pandas` | 特征处理 | | `streamlit` | Web dashboard | | `plotly` | 交互式图表 | | `colorama` | 彩色终端输出 | | `requests` | OSV API 查询 | | `joblib` | 模型序列化 | ## 📜 许可证 本项目基于 **MIT License** 授权——可免费使用、修改和分发。 ## 👤 作者
**Subhadeep Chowdhury** *网络安全爱好者 · 道德黑客与漏洞赏金学习者 · CSE 学生* *区块链 · Python · C · C++ · 技术探索者* [![GitHub](https://img.shields.io/badge/GitHub-subhaadeep-181717?style=flat-square&logo=github)](https://github.com/subhaadeep) *如果这个项目对你有帮助,请在 GitHub 上给它一个 ⭐!*
标签:Apex, DNS 反向解析, Python, YARA, 云安全监控, 云资产可视化, 安全工具, 恶意软件检测, 无后门, 机器学习, 静态分析