Skip to main content
Back

FARM Fights Malware Classifier Decay With 10-Shot Family Detection

FARM combines a triplet autoencoder with DBSCAN clustering and few-shot prototypes to keep Windows malware classifiers accurate as new families emerge.

Pro

  • FARM handles concept drift in Windows PE malware classification via triplet embeddings, DBSCAN clustering, and few-shot prototypes.
  • Boosts F1 by 5.6% under covariate drift and hits 0.85 F1 on unseen families with only 10 labeled samples.
  • Full retraining after buffering 100+ new samples lifts F1 to 0.94, a 10.6% relative gain.
  • Beats CADE baseline (0.77 F1) on label drift with better precision/recall balance.
  • Evaluated on BenchMFC, 223,000 timestamped samples spanning 526 malware families.
  • Code and scripts available at github.com/numanhg/farm.

Malware classifiers age fast. A model that hits 99% accuracy at deployment can drop to 76% within six months as attackers ship new variants, and evaluating on future data rather than random splits can cut performance by up to 50%. A new framework called FARM (Few-shot Adaptive Recognition of Malware) tackles this decay head-on for Windows Portable Executable (PE) malware, combining metric learning, density clustering, and prototype-based few-shot updates into a single pipeline.

Why static classifiers rot in production

The malware world drifts in two distinct ways, and both break classifiers trained on a fixed snapshot. Label drift describes the emergence of entirely new, previously unknown malware families, introducing novel patterns that detection models have never encountered. Covariate drift refers to evolving behaviors and properties of existing malware families, where malware authors alter characteristics to evade detection while preserving the overall malware class identity.

The naive fix, checking the softmax score, does not work. Softmax-based classification layers tend to remain high and overconfident even for previously unseen samples. Add in a daily detection volume of Windows PE malware exceeding 300,000 samples, unreliable vendor labels, and the cost of manual annotation, and you end up with a system that quietly makes worse decisions every week.

The FARM pipeline

FARM starts from EMBER features, a standard static representation of PE files covering byte histograms, header fields, section metadata, and imported libraries. Those 2,381-dimensional vectors are trimmed to 1,830 after a quantile transform and variance thresholding, then pushed through a symmetric autoencoder that squeezes them down to a 32-dimensional embedding.

FARM pipeline architecture showing triplet encoder, DBSCAN clustering, buffer, and prototype generation

The training objective is what makes the space useful. FARM uses a triplet loss, which takes an anchor sample, a positive from the same family, and a negative from a different family, and pushes the anchor closer to the positive than to the negative by at least a margin. A parallel reconstruction loss (weighted at half the triplet loss) keeps the embeddings informative enough to rebuild the input. The result is a latent space where distance is a meaningful proxy for family membership.

Instead of picking a fixed number of clusters per family, FARM runs DBSCAN, a density-based clustering algorithm that decides cluster count from the data. A single malware family may exhibit multiple dense subclusters in the latent space due to internal behavioral diversity, and DBSCAN captures those substructures while flagging sparse points as noise. Each cluster gets a centroid and an acceptance threshold equal to the maximum distance from any inlier to that centroid. If a new sample lands outside every threshold, it is treated as drift rather than being force-fit into a known class.

Adapting without full retraining

Drifted samples flow into a buffer. Once at least 10 accumulate and DBSCAN finds a coherent cluster among them, FARM computes the mean embedding of that cluster and adds it as a prototype, borrowing the idea from prototypical networks. New queries are then classified by nearest-prototype in Euclidean distance. This gives immediate coverage of an emerging family with roughly 10 labeled examples, no gradient updates required.

When the buffer for a novel family grows past 100 samples, FARM triggers a full retrain of the triplet autoencoder on the original data plus the new samples, rebuilding centroids and thresholds. The prototype is retired and replaced by a proper centroid. It is a two-speed strategy: prototypes handle the next hour, retraining handles the next month.

What the numbers show

The team evaluated on BenchMFC, a benchmark of over 223,000 timestamped Windows PE samples spanning 526 families collected between 2012 and 2022. They use a controlled 16-family subset split into known, evolved, and unseen groups, 500 samples each.

t-SNE visualization of latent embeddings for vobfus and related malware families under three ablation configurations

Key results:

  • Covariate drift: Adaptation lifts F1 by an average of 5.6%, with upatre gaining +19.4% and fareit +11.6%.
  • Label drift detection: 84% of samples from entirely unseen families are correctly flagged as drift.
  • Few-shot adaptation on unseen families: Average F1 of 0.85 across eight novel families using only 10 labeled samples each.
  • After full retraining: Average F1 climbs to 0.94, a 10.6% relative improvement over the few-shot stage.
  • Against baselines: FARM's F1 of 0.83 on label drift beats CADE (0.77) and a percentile-thresholded ablation (0.79), with a better precision/recall balance.

Few-shot accuracy also scales cleanly with support size. In an 8-way task the model reaches 64.9% at 1-shot, 74.5% at 5-shot, and 76.8% at 10-shot, with diminishing returns beyond that. That empirically justifies the choice of 10 as the buffer threshold.

Where it stumbles

The most instructive failure is the vobfus family, which FARM only flagged as drift 20% of the time. Vobfus acts as a dropper for fareit and zbot, both in the training set, so its embeddings sit right on top of those known families. Ablations that remove fareit or zbot from training show vobfus gradually pulling apart into its own cluster, confirming that the encoder is doing its job but that behaviorally overlapping malware defeats distance-based novelty detection.

Other limitations worth flagging:

  • DBSCAN's epsilon and minPts are set with an elbow heuristic and a dimensionality rule; more adaptive selection could help in noisy regions.
  • Triplets are sampled randomly. There is no hard positive or hard negative mining, which likely leaves accuracy on the table in ambiguous clusters.
  • The evaluation is drift-response, not full continual learning. There is no replay strategy or explicit forgetting measurement across long task sequences.
  • Only unpacked binaries are considered. Packed malware, which introduces obfuscation-driven drift, is left to future work.

When to reach for it

FARM is a fit if you are running a static PE classifier over an EMBER-style feature pipeline and are watching accuracy erode as new families appear. The design assumes you can afford to buffer suspected drift and get a small number of labels (around 10) before committing to a prototype, and that you have compute budget for occasional full retrains once a family is confirmed. It is not a continual-learning replacement, and it will struggle when novel families share strong structural features with something already in your training set.

The source code is available on GitHub, along with the scripts used to reproduce the BenchMFC experiments.