Venta02/MalViz-CNN

GitHub: Venta02/MalViz-CNN

MalViz-CNN 是一个利用深度学习进行恶意软件可视化分类的框架,集成对抗鲁棒性评估、可解释AI和LLM报告生成功能。

Stars: 0 | Forks: 0

MalViz-CNN Banner
[![Python](https://img.shields.io/badge/Python-3.9+-00ffd1?style=for-the-badge&logo=python&logoColor=white&labelColor=0a1929)](https://www.python.org/) [![PyTorch](https://img.shields.io/badge/PyTorch-2.0+-39ff88?style=for-the-badge&logo=pytorch&logoColor=white&labelColor=0a1929)](https://pytorch.org/) [![FastAPI](https://img.shields.io/badge/FastAPI-0.100+-00ffd1?style=for-the-badge&logo=fastapi&logoColor=white&labelColor=0a1929)](https://fastapi.tiangolo.com/) [![License](https://img.shields.io/badge/License-MIT-39ff88?style=for-the-badge&labelColor=0a1929)](LICENSE) [![Tests](https://img.shields.io/badge/tests-8%2F8%20passing-39ff88?style=for-the-badge&labelColor=0a1929)](tests/) **具备对抗鲁棒性、可解释AI和LLM驱动威胁报告能力的可视化恶意软件分类。** [功能特性](#features) • [系统架构](#architecture) • [效果演示](#demo) • [快速开始](#quick-start) • [项目结构](#project-structure)
## 概述 **MalViz-CNN** 将恶意软件二进制文件转换为图像,并利用深度学习进行分类。该框架在经典图像分类基础上集成了三项扩展能力: - **对抗鲁棒性评估** —— 测试模型在梯度攻击下的行为 - **可解释性** —— 可视化驱动恶意软件图像每个预测结果的关键区域 - **LLM集成** —— 根据分类输出生成自然语言威胁报告 代码库包含五种模型架构、命令行工具、REST API、交互式Web界面及完整的单元测试套件。 ## 功能特性
### 多架构支持 五种神经网络架构: - 自定义CNN基线模型 - ResNet-50(迁移学习) - EfficientNet-B0 - Vision Transformer - 集成投票模型 ### 对抗鲁棒性 针对常见攻击的评估: - FGSM单步攻击 - PGD迭代攻击 - 对抗性训练 - 随ε变化的鲁棒性曲线 ### 可解释AI 可视化决策透明度: - Grad-CAM热力图 - Top-K预测分析 - 家族归因分析 - 伪影一致性检查
### LLM集成 自然语言威胁报告: - Anthropic Claude / OpenAI GPT - 自动生成摘要 - 推荐应对措施 - 离线模板回退方案 ### 生产就绪 可直接部署的组件: - 带富文本输出的CLI - FastAPI REST服务器 - Docker容器化支持 - 完善的单元测试覆盖 ### Web界面 基于浏览器的演示界面: - 拖拽式文件上传 - 实时预测功能 - Top-K可视化 - 威胁报告查看器
## 系统架构
System Architecture
## 效果演示 ### Web界面 深色主题Web界面,支持拖拽上传文件、实时推理和动态结果可视化。 #### 登录页面
Web UI landing page

包含主标题和双栏工作区的完整登录页面

#### 工作流程
Input panel — Upload & model selection
Web UI input panel with model selector
File upload area with model architecture dropdown
Classification results — Top-K predictions
Web UI classification result with top-K bars
Predicted family, confidence score, and ranked alternatives
### REST API REST API在 `http://localhost:8000/docs` 自动生成OpenAPI文档。
Health check — GET /
API health check response
Service status, version, and active model
List families — GET /families
List of 25 malware families
All 25 malware families supported by the classifier
Classification — POST /classify
Classification API response
JSON response with predicted family and ranked top-K confidences
## 快速开始 ### 安装说明 ``` git clone https://github.com/Venta02/MalViz-CNN.git cd MalViz-CNN pip install -r requirements.txt ``` ### 命令行使用 ``` # 对二进制文件进行分类(使用随机初始化的权重快速演示) python -m src.cli detect --input sample.bin --model custom_cnn # 在 Malimg 上训练模型 python -m src.cli train --data-root data/malimg --model resnet50 # 评估对抗性鲁棒性 python -m src.cli adversarial-test --weights checkpoints/resnet50_best.pth --attack pgd ``` ### REST API ``` uvicorn api.main:app --reload ``` 访问 **http://localhost:8000/docs** 获取交互式Swagger文档。 ### Web界面 ``` # 在第二个终端中(保持 API 运行) cd web && python -m http.server 3000 ``` 访问 **http://localhost:3000** 并拖拽二进制文件进行分析。 ## 测试说明 框架包含覆盖关键组件的 **8个单元测试**: ``` $ python -m pytest tests/ -v tests/test_adversarial.py::TestFGSM::test_fgsm_perturbation_bounded PASSED tests/test_adversarial.py::TestFGSM::test_fgsm_changes_inputs PASSED tests/test_adversarial.py::TestPGD::test_pgd_perturbation_bounded PASSED tests/test_adversarial.py::TestPGD::test_pgd_stronger_than_fgsm PASSED tests/test_models.py::TestCustomCNN::test_forward_pass PASSED tests/test_models.py::TestCustomCNN::test_parameter_count PASSED tests/test_models.py::TestEnsemble::test_ensemble_forward PASSED tests/test_models.py::TestFactory::test_unknown_model_raises PASSED ========== 8 passed ========== ``` 测试涵盖模型输出形状、参数数量、对抗扰动边界、攻击强度排序、集成模型正确性和错误处理等方面。 ## 项目结构 ``` MalViz-CNN/ │ ├── README.md <- You are here ├── requirements.txt ├── Dockerfile │ ├── src/ <- Core implementation │ ├── data_loader.py <- Binary to image conversion │ ├── models.py <- 5 architectures + ensemble │ ├── train.py <- Training + adversarial training │ ├── adversarial.py <- FGSM + PGD attacks │ ├── explain.py <- Grad-CAM module │ ├── llm_reporter.py <- LLM threat reports │ ├── evaluate.py <- Comprehensive metrics │ └── cli.py <- Rich CLI interface │ ├── api/ <- FastAPI REST server │ └── main.py │ ├── web/ <- Interactive web UI │ └── index.html │ ├── notebooks/ <- Experiments │ └── 01_main_experiment.ipynb │ ├── tests/ <- Unit tests │ ├── docs/ <- Documentation & screenshots │ ├── methodology.md │ ├── research_notes.md │ └── screenshots/ │ ├── ui-landing.jpg │ ├── ui-input.jpg │ ├── ui-result.jpg │ ├── api-health.jpg │ ├── api-families.jpg │ └── api-classify.jpg │ └── assets/ <- Visual branding ├── banner.svg └── architecture.svg ``` ## 参考文献 本实现基于以下研究工作: - Nataraj et al. (2011) — *Malware Images: Visualization and Automatic Classification* - Vasan et al. (2020) — *IMCFN: Image-based malware classification using fine-tuned CNNs* - Goodfellow et al. (2015) — *Explaining and Harnessing Adversarial Examples* - Madry et al. (2018) — *Towards Deep Learning Models Resistant to Adversarial Attacks* - Selvaraju et al. (2017) — *Grad-CAM: Visual Explanations from Deep Networks* 详见 [`docs/research_notes.md`](docs/research_notes.md) 和 [`docs/methodology.md`](docs/methodology.md)。 ## 作者 **Embun Ventani** — embunventa02@gmail.com ## 许可证 基于 [MIT许可证](LICENSE) 发布。
标签:AI安全, AV绕过, Chat Copilot, DAST, FastAPI, PyTorch, REST API, TCP SYN 扫描, Web UI, 二进制分析, 云安全运维, 凭据扫描, 单元测试, 卷积神经网络, 可解释人工智能, 图像分类, 大型语言模型, 威胁报告生成, 对抗性攻击, 对抗鲁棒性, 恶意软件分析, 深度学习, 神经网络, 网络安全, 视觉Transformer, 计算机视觉, 请求拦截, 逆向工具, 隐私保护, 集成学习