MalConv+ β€” Build Your Own Antivirus (CSIS 582 Midterm)

A deep neural network that reads the raw bytes of a Windows executable (PE file: .exe / .dll) and classifies it as Malware or Benign, plus a browser app where you drag and drop a file to scan it. Based on MalConv (Raff et al., 2018, Malware Detection by Eating a Whole EXE).

⚠️ SAFETY NOTICE: Rebuilding the dataset downloads live Windows malware. Only build it on Linux (Google Colab, a Linux VM, or a lab machine), never on your everyday Windows computer. Never open, run, or double-click any sample. This repository contains no malware binaries, only code, hashes, labels, and model weights.

Repository layout

README.md               this file
requirements.txt        pinned dependencies
notebooks/
  part1_data_exploration.ipynb   data exploration, baseline model, dataset packaging
  part2_model.ipynb              MalConv + MalConv+ training, evaluation, predict()
dataset/
  manifest.csv          sha256, label, source, split, size_bytes (no binaries)
  build_dataset.py      rebuilds the dataset from the original source
  features.parquet      simple numeric features (byte histogram, entropy, size)
  README.md             dataset details, keep/drop decisions, limitations
model/
  model.pt              trained MalConv+ weights
  config.json           architecture settings, max_len, threshold
app/
  app.py                Gradio drag-and-drop antivirus app

Setup

Tested with Python 3.13 on Google Colab (Linux).

pip install huggingface_hub
python -c "from huggingface_hub import snapshot_download; snapshot_download('dqkirby/malconv-antivirus', local_dir='malconv-antivirus')"
cd malconv-antivirus
pip install -r requirements.txt

Alternatively, if Git LFS is installed: git lfs install, then git clone https://huggingface.co/dqkirby/malconv-antivirus. A plain git clone without Git LFS only downloads placeholder files for the model weights.

Rebuild the dataset (Linux only)

python dataset/build_dataset.py

Downloads a pinned commit of DikeDataset, verifies every file's SHA-256 against dataset/manifest.csv, and writes 9,932 files to data/<train|val|test>/<benign|malware>/<sha256>.bin. See dataset/README.md for details.

Run the app

python app/app.py            # local URL, e.g. http://127.0.0.1:7860
python app/app.py --share    # temporary public link (use this in Colab)

Drop a .exe or .dll onto the page. The app shows the verdict and the model's probability of malware. The file is only read, never executed. Empty and non-PE files get a clear error message. Works on CPU, no GPU needed.

Model

Architecture MalConv+: MalConv with a second gated-convolution scale (kernel/stride 32, plus the original 500), masked mean pooling alongside global max pooling, and dropout 0.5
Baseline Original MalConv: embedding 257β†’8, gated Conv1d (128 filters, kernel/stride 500), global max pool, FC 128 + ReLU, 1 output
Trainable parameters 1,157,897 (baseline MalConv: 1,042,953)
max_len 1,048,576 bytes (1 MB); longer files are truncated, shorter ones padded
Decision threshold 0.05, chosen on the validation set (see below)
Training Adam, lr 1e-3, batch 16, 6 epochs, pos_weight = 0.115 for class imbalance, Colab T4 GPU

Test-set results (1,465 files: 119 benign, 1,346 malware)

Model Threshold Accuracy Balanced acc. AUC Precision Recall F1 FP FN
LightGBM (byte histogram + entropy + size) 0.50 0.9945 0.9894 0.9996 0.9985 0.9955 0.9970 2 6
MalConv baseline 0.50 0.9918 0.9802 0.9991 0.9970 0.9941 0.9955 4 8
MalConv+ 0.50 0.9911 0.9875 0.9988 0.9985 0.9918 0.9952 2 11
MalConv+ (final) 0.05 0.9959 0.9901 0.9988 0.9985 0.9970 0.9978 2 4

Precision, recall, and F1 are for the malware class.

Threshold choice: a missed infection (false negative) is usually worse for an antivirus than a false alarm, so I lowered the threshold to catch more malware while allowing at most 2 false positives on the 119 benign validation files. 0.04 was slightly better on validation, but false positives start at 0.03, so I used 0.05 as a safety margin.

Limitations

  • DikeDataset is easy. 96.9% of validation malware has a near-identical twin in the training set, so malware scores are optimistic. All three models are essentially tied on AUC.
  • Shortcuts: byte entropy alone reaches AUC 0.974. The model treats compressed/random-looking files as suspicious. Example: a benign PyInstaller-packaged Python program (entropy β‰ˆ 7.8 of 8) was flagged as malware with 99.9% probability.
  • Small benign set: only 962 benign files (119 in test), so false-positive rates are noisy.

AI-assistant use

I used Claude (Anthropic) as a research and coding assistant throughout this project. It helped me plan the project, write and debug code (data loading, the PyTorch Dataset and models, the training loop, the build script, and the Gradio app), and draft explanations. I ran every experiment, made the data, model, and threshold decisions based on the results, and rewrote the notebook explanations in my own words. I can explain every part of the code.

References

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Papers for dqkirby/malconv-antivirus