CoolFace
Apppublic

ampls/Malware-Classifier

sourceHugging Faceupdated 5mo agoView on Hugging Face
0likes
App README

Malware Binary Classifier

Static PE File Analysis using a Multi-Layer Perceptron

Student: Amine Garaali | Deep Learning Project | 2026


What this does

This 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.

It 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.


The approach

Instead 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.

The 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.

This is a feature-based deep learning approach. The EMBER library 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.


Dataset — EMBER 2018

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.

  • 1,000,000 labeled Windows PE file samples
  • 800,000 training samples (400k malware, 400k benign)
  • 200,000 test samples (100k malware, 100k benign)
  • Each file is represented as a 2381-dimensional feature vector
  • No raw binaries — only pre-extracted numerical features (safe to use academically)

The 2381 features come from 8 groups:

Feature groupDimensionsWhat it captures
Imports1280Which Windows API functions the file uses
Byte histogram256Distribution of raw byte values across the file
Byte-entropy histogram256Local entropy — detects packed/encrypted regions
Section info255PE section names, sizes, entropy, permissions
String features104Embedded URLs, registry paths, file paths
Header info62PE header fields, timestamps, subsystem flags
General info10File size, presence of debug/TLS sections
Exports128Functions the file exposes to other programs

The 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.


Model Architecture

Input: 2381-dimensional feature vector (one per PE file)
         │
         ▼
┌─────────────────────────────────────────┐
│  Hidden Layer 1                         │
│  Linear(2381 → 512)                     │
│  BatchNorm → ReLU → Dropout(0.3)        │
└─────────────────────────────────────────┘
         │
         ▼
┌─────────────────────────────────────────┐
│  Hidden Layer 2                         │
│  Linear(512 → 256)                      │
│  BatchNorm → ReLU → Dropout(0.3)        │
└─────────────────────────────────────────┘
         │
         ▼
┌─────────────────────────────────────────┐
│  Hidden Layer 3                         │
│  Linear(256 → 128)                      │
│  ReLU                                   │
└─────────────────────────────────────────┘
         │
         ▼
┌─────────────────────────────────────────┐
│  Output Layer                           │
│  Linear(128 → 1) → Sigmoid             │
│  outputs probability in [0, 1]          │
└─────────────────────────────────────────┘
         │
         ▼
Output > 0.5  →  MALWARE
Output ≤ 0.5  →  BENIGN

Why this architecture:

  • 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.
  • 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.
  • 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.
  • 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.
  • Sigmoid output: Maps the final score to a probability in [0, 1], interpretable as "probability this file is malware."

Total trainable parameters: ~1.5 million


Training Details

SettingValue
FrameworkPyTorch
Loss functionBinary Cross-Entropy
OptimizerAdam (lr=0.001, weight_decay=1e-5)
SchedulerReduceLROnPlateau (factor=0.5, patience=2)
Batch size1024
Epochs10
HardwareNVIDIA RTX 3060 8GB
PreprocessingStandardScaler normalization

Results

Evaluated on 200,000 held-out test samples:

MetricScore
Accuracy95%
Precision (malware)0.96
Recall (malware)0.94
F1 Score0.95
ROC-AUC0.9878

The 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.

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.


How to use the demo

  1. 1.Upload any .exe or .dll file
  2. 2.Click Classify
  3. 3.The app extracts 2381 EMBER features from the file, normalizes them, and runs them through the MLP
  4. 4.You get a verdict (MALWARE / BENIGN) and a confidence probability

Test it yourself:

  • Upload notepad.exe from C:\Windows\System32\ → should be ~0% malware probability
  • Upload any cracked or suspicious executable → should score significantly above 50%

Limitations

  • The model was trained on PE files from 2018 and earlier. Very recent malware that uses novel evasion techniques may score lower than expected.
  • The model classifies files as malware or benign — it does not identify the malware family. See the companion CNN model for family classification.
  • This is a research/educational model, not a production security tool. Do not rely on it as your only line of defense.
  • High-entropy legitimate files (e.g. compressed installers) may occasionally score higher than expected.

References

  • Anderson, H.S. & Roth, P. (2018). EMBER: An Open Dataset for Training Static PE Malware Machine Learning Models. arXiv:1804.04637
  • Lad, S. & Adamuthe, A. (2022). Improved Deep Learning Model for Static PE Files Malware Detection and Classification. IJCNIS.
  • Raff, E. et al. (2017). Malware Detection by Eating a Whole EXE. arXiv:1710.09435