ampls/Malware-Classifier
0
1---2title: Malware Binary Classifier3emoji: ๐ก๏ธ4colorFrom: red5colorTo: gray6sdk: docker7app_port: 78608pinned: false9---10 11# Malware Binary Classifier12### Static PE File Analysis using a Multi-Layer Perceptron13 14**Student:** Amine Garaali | **Deep Learning Project** | **2026**15 16---17 18## What this does19 20This model takes any Windows executable file (`.exe` or `.dll`) and classifies it as either **malware** or **benign**. Upload a file, get a probability score and a verdict in seconds โ without ever executing the file.21 22It was built as part of a deep learning course project to demonstrate a complete end-to-end ML pipeline applied to a real cybersecurity problem.23 24---25 26## The approach27 28Instead of executing suspicious files (which would be dangerous), this model performs **static analysis** โ it reads the structure of the PE file without running it and extracts measurable properties that differ between malware and legitimate software.29 30The key insight is that malware tends to leave structural fingerprints: it imports suspicious Windows API functions, has unusual byte distributions from packing or encryption, and has anomalous section layouts. A neural network can learn to detect these patterns automatically by training on hundreds of thousands of labeled examples.31 32This is a **feature-based deep learning** approach. The [EMBER library](https://github.com/elastic/ember) handles feature extraction, producing a 2381-dimensional numerical vector from each file. The MLP then learns a classification boundary in that high-dimensional feature space.33 34---35 36## Dataset โ EMBER 201837 38**EMBER** (Endgame Malware BEnchmark for Research) was released by Elastic in 2018 and has become one of the standard benchmarks in academic malware detection research.39 40- **1,000,000** labeled Windows PE file samples41- **800,000** training samples (400k malware, 400k benign)42- **200,000** test samples (100k malware, 100k benign)43- Each file is represented as a **2381-dimensional feature vector**44- No raw binaries โ only pre-extracted numerical features (safe to use academically)45 46The 2381 features come from 8 groups:47 48| Feature group | Dimensions | What it captures |49|---|---|---|50| Imports | 1280 | Which Windows API functions the file uses |51| Byte histogram | 256 | Distribution of raw byte values across the file |52| Byte-entropy histogram | 256 | Local entropy โ detects packed/encrypted regions |53| Section info | 255 | PE section names, sizes, entropy, permissions |54| String features | 104 | Embedded URLs, registry paths, file paths |55| Header info | 62 | PE header fields, timestamps, subsystem flags |56| General info | 10 | File size, presence of debug/TLS sections |57| Exports | 128 | Functions the file exposes to other programs |58 59The **imports group** (1280 dims) is the most powerful signal. Combinations like `VirtualAllocEx` + `WriteProcessMemory` + `CreateRemoteThread` are almost exclusively used by malware performing process injection, and the model learns these patterns automatically.60 61---62 63## Model Architecture64 65```66Input: 2381-dimensional feature vector (one per PE file)67 โ68 โผ69โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ70โ Hidden Layer 1 โ71โ Linear(2381 โ 512) โ72โ BatchNorm โ ReLU โ Dropout(0.3) โ73โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ74 โ75 โผ76โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ77โ Hidden Layer 2 โ78โ Linear(512 โ 256) โ79โ BatchNorm โ ReLU โ Dropout(0.3) โ80โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ81 โ82 โผ83โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ84โ Hidden Layer 3 โ85โ Linear(256 โ 128) โ86โ ReLU โ87โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ88 โ89 โผ90โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ91โ Output Layer โ92โ Linear(128 โ 1) โ Sigmoid โ93โ outputs probability in [0, 1] โ94โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ95 โ96 โผ97Output > 0.5 โ MALWARE98Output โค 0.5 โ BENIGN99```100 101**Why this architecture:**102 103- **Funnel shape (2381 โ 512 โ 256 โ 128 โ 1):** Each layer compresses the representation, forcing the network to discard noise and retain only the most discriminative patterns. Early layers learn raw feature correlations, later layers combine those into higher-level malware indicators.104 105- **BatchNorm:** Normalizes activations within each batch, stabilizing training and allowing higher learning rates. Without it, training on 800k samples with high-dimensional input is much less stable.106 107- **ReLU activations:** Introduce non-linearity between layers. Without activation functions, stacking linear layers is mathematically equivalent to a single linear transformation โ the network could only learn linear decision boundaries, which are far too simple for this problem.108 109- **Dropout(0.3):** During training, randomly zeroes 30% of neuron outputs each forward pass. Forces the network to learn redundant representations and prevents overfitting on the training set.110 111- **Sigmoid output:** Maps the final score to a probability in [0, 1], interpretable as "probability this file is malware."112 113**Total trainable parameters:** ~1.5 million114 115---116 117## Training Details118 119| Setting | Value |120|---|---|121| Framework | PyTorch |122| Loss function | Binary Cross-Entropy |123| Optimizer | Adam (lr=0.001, weight_decay=1e-5) |124| Scheduler | ReduceLROnPlateau (factor=0.5, patience=2) |125| Batch size | 1024 |126| Epochs | 10 |127| Hardware | NVIDIA RTX 3060 8GB |128| Preprocessing | StandardScaler normalization |129 130---131 132## Results133 134Evaluated on 200,000 held-out test samples:135 136| Metric | Score |137|---|---|138| Accuracy | **95%** |139| Precision (malware) | 0.96 |140| Recall (malware) | 0.94 |141| F1 Score | 0.95 |142| **ROC-AUC** | **0.9878** |143 144The ROC-AUC of 0.9878 means the model can almost perfectly separate malware from benign files across all possible decision thresholds. For reference, the EMBER paper's own LightGBM baseline achieves ~0.999 AUC โ our MLP gets close using a significantly simpler training setup.145 146**On the threshold:** The default threshold is 0.5. Lowering it (e.g. to 0.3) increases recall โ catching more malware โ at the cost of more false positives. In a high-security environment you would lower the threshold. In a consumer product where false alarms are costly, you would raise it.147 148---149 150## How to use the demo151 1521. Upload any `.exe` or `.dll` file1532. Click **Classify**1543. The app extracts 2381 EMBER features from the file, normalizes them, and runs them through the MLP1554. You get a verdict (MALWARE / BENIGN) and a confidence probability156 157**Test it yourself:**158- Upload `notepad.exe` from `C:\Windows\System32\` โ should be ~0% malware probability159- Upload any cracked or suspicious executable โ should score significantly above 50%160 161---162 163## Limitations164 165- The model was trained on PE files from 2018 and earlier. Very recent malware that uses novel evasion techniques may score lower than expected.166- The model classifies files as malware or benign โ it does not identify the malware family. See the companion CNN model for family classification.167- This is a research/educational model, not a production security tool. Do not rely on it as your only line of defense.168- High-entropy legitimate files (e.g. compressed installers) may occasionally score higher than expected.169 170---171 172## References173 174- Anderson, H.S. & Roth, P. (2018). *EMBER: An Open Dataset for Training Static PE Malware Machine Learning Models.* arXiv:1804.04637175- Lad, S. & Adamuthe, A. (2022). *Improved Deep Learning Model for Static PE Files Malware Detection and Classification.* IJCNIS.176- Raff, E. et al. (2017). *Malware Detection by Eating a Whole EXE.* arXiv:1710.09435177 