Transform malware binaries into images, then let neural networks see what humans can't.
MalVision converts malware executables into grayscale images and uses Convolutional Neural Networks to classify them into malware families. This technique leverages the visual patterns that emerge when binary data is rendered as pixels – patterns that are surprisingly distinctive for different malware variants.
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Malware Binary │ ──► │ Grayscale Image │ ──► │ CNN Classifier │
│ (bytes) │ │ (visualization)│ │ (25 families) │
└─────────────────┘ └─────────────────┘ └─────────────────┘
- Transfer Learning - ResNet18 & EfficientNet-B0 pretrained on ImageNet
- Custom CNN - Simple architecture for educational purposes
- Data Augmentation - Rotation, flipping, color jitter for robust training
- Rich Visualization - Training curves, confusion matrices, per-class analysis
- GPU Accelerated - CUDA support for fast training
- Model Checkpointing - Save best models with full training state
We use Conda for environment management and uv for fast package installation.
# Clone the repository
git clone https://github.com/Y4NN777/MalVision.git
cd MalVision
# 1. Create Conda environment
conda create -n malvision python=3.10 -y
conda activate malvision
# 2. Install uv (fast installer)
pip install uv
# 3. Install dependencies from pyproject.toml
uv pip install -r pyproject.tomlDownload the MalImg Dataset from Kaggle:
# Using helper script
python scripts/fetch_dataset.py
# OR manually download/unzip 'malimg-dataset.zip' to 'malware_data/' folder# Start Jupyter
jupyter notebook malware_detection.ipynbThe notebook guides you through:
- Dataset exploration
- Data preparation with augmentation
- Model training (ResNet18)
- Evaluation with confusion matrix
- Single image prediction
- Model export
MalVision/
├── malware_detection.ipynb # Main notebook (run this!)
├── pyproject.toml # Dependencies & Config
├── utils/
│ ├── __init__.py # Package exports
│ └── helpers.py # Dataset, models, visualization
├── scripts/
│ └── fetch_dataset.py # Dataset helper
├── malware_data/ # Dataset folder (create this!)
├── .gitignore
├── LICENSE
└── README.md
| Model | Parameters | Best For |
|---|---|---|
| SimpleCNN | ~2M | Learning & experimentation |
| ResNet18 | ~11M | Balance of speed & accuracy |
| EfficientNet-B0 | ~5M | Best accuracy |
Input (3, 224, 224)
│
├── Conv2d(3→32) + BN + ReLU + MaxPool → (32, 112, 112)
├── Conv2d(32→64) + BN + ReLU + MaxPool → (64, 56, 56)
├── Conv2d(64→128) + BN + ReLU + MaxPool → (128, 28, 28)
├── Conv2d(128→256) + BN + ReLU + MaxPool → (256, 14, 14)
│
├── Flatten → (256 × 14 × 14 = 50,176)
├── Dropout(0.5) + Linear(50176→512) + ReLU
└── Dropout(0.5) + Linear(512→25)
Output: 25 classes (malware families)
MalImg Dataset - 9,339 malware samples across 25 families
| Family | Samples | Family | Samples | |
|---|---|---|---|---|
| Adialer.C | 122 | Lolyda.AA1 | 213 | |
| Agent.FYI | 116 | Lolyda.AA2 | 184 | |
| Allaple.A | 2,949 | Lolyda.AA3 | 123 | |
| Allaple.L | 1,591 | Lolyda.AT | 159 | |
| Alueron.gen!J | 198 | Malex.gen!J | 136 | |
| Autorun.K | 106 | Obfuscator.AD | 142 | |
| C2LOP.gen!g | 200 | Rbot!gen | 158 | |
| C2LOP.P | 146 | Skintrim.N | 80 | |
| Dialplatform.B | 177 | Swizzor.gen!E | 128 | |
| Dontovo.A | 162 | Swizzor.gen!I | 132 | |
| Fakerean | 381 | VB.AT | 408 | |
| Instantaccess | 431 | Wintrim.BX | 97 | |
| Yuner.A | 800 |
Expected performance with default configuration:
| Metric | Value |
|---|---|
| Test Accuracy | ~97% |
| Training Time | ~15 min (GPU) |
| Best Epoch | ~12-15 |
Training artifacts are saved locally:
training_curves.png: Visual training historyconfusion_matrix.png: Per-class performanceclassification_report.txt: F1-scores and precision/recall
📂 Download Trained Models
Models are too large for Git. Download checkpoints from: ☁️ Google Drive Link
Place downloaded .pth files in the models/ directory:
best_model.pth: Highest validation accuracymalware_model_complete.pth: Full checkpoint with training history
| Parameter | Default | Description |
|---|---|---|
epochs |
20 | Training epochs |
batch_size |
32 | Samples per batch |
learning_rate |
0.001 | Initial LR |
weight_decay |
1e-4 | L2 regularization |
train_split |
0.70 | Training data ratio |
val_split |
0.15 | Validation data ratio |
patience |
5 | Early stopping patience |
- PyTorch - Deep learning framework
- torchvision - Pretrained models & transforms
- NumPy & Pandas - Data manipulation
- Matplotlib & Seaborn - Visualization
- scikit-learn - Metrics & analysis
- PIL - Image processing
- tqdm - Progress bars
This project was developed as part of a Deep Learning course, demonstrating:
- Image Classification - End-to-end CNN pipeline
- Transfer Learning - Leveraging pretrained models
- Data Augmentation - Preventing overfitting
- Model Evaluation - Comprehensive metrics analysis
- Visualization - Interpreting model behavior
- MalImg Dataset - Malware visualization dataset
- PyTorch - Deep learning framework
- Original research: "Malware Images: Visualization and Automatic Classification" by Nataraj et al.