On a Bayesian Approach to Malware Detection and Classification through n-gram Profiles

José A. Perusquía, Jim E. Griffin, Cristiano VillaarXiv 2020 · arXiv · OpenReview

Abstract

$n$-gram profiles are widely used to analyze long sequences for clustering or classification. While machine learning algorithms offer high predictive performance, they often fail to uncover hidden structures or provide full probabilistic representations. This paper introduces Beta-CoRM, a novel class of Bayesian generative models designed for $n$-gram profiles used as binary attributes. By incorporating a flexible feature selection mechanism and a slice sampling algorithm for efficient inference, the model demonstrates that feature selection can significantly improve classification accuracy while providing interpretable data representations.

1. Introduction

In fields such as cybersecurity and natural language processing, $n$-gram profiles—sequences of $n$ items such as bytes or words—serve as critical "fingerprints" for data identification. In malware analysis, specific byte sequences can distinguish between ransomware families or benign software. However, two primary challenges persist: the "curse of dimensionality," where datasets generate millions of unique $n$-grams, and the "interpretability gap," where high-performing discriminative models like XGBoost act as black boxes.

This research addresses these issues by proposing a Bayesian generative framework that handles high-dimensional binary features while automatically identifying the most discriminative attributes.

2. The Beta-CoRM Model

The core contribution is the Beta-CoRM (Beta Compound Random Measure) model. Unlike standard discriminative models, Beta-CoRM models the underlying generative process of the data.

2.1 Compound Random Measures (CoRM)

The model utilizes CoRMs to represent grouped data. By defining a global set of $n$-gram probabilities that are perturbed for specific groups (e.g., malware families), the model shares information across the entire dataset while simultaneously capturing the unique characteristics of each class.

2.2 Feature Selection via Spike-and-Slab Priors

To manage high dimensionality, the authors implement a generalized version of the model using a "spike-and-slab" prior. Each $n$-gram is assigned a score parameter ($a_i$). A small score acts as a "spike," effectively removing the feature from the model, while a larger score acts as a "slab," retaining the feature. This allows for automated pruning of noise. The authors found that an Objective Lomax prior provided the best balance, allowing the data to drive the feature selection process.

3. Computational Inference

Bayesian models often suffer from slow inference due to the nature of Markov Chain Monte Carlo (MCMC) simulations. To mitigate this, the authors derived a specialized slice sampling algorithm. By introducing latent variables, the algorithm stabilizes and accelerates posterior inference, making the Bayesian approach more viable for complex datasets.

4. Experimental Setup

The model was evaluated on two fronts:

  1. Synthetic Data: A controlled environment with 5 imbalanced groups and 300 binary features to validate the model's ability to recover known structures.
  2. Microsoft Malware Classification Challenge: A real-world dataset from Kaggle (2015) containing 842 malware samples across 9 families (e.g., Ramnit, Lollipop, Gatak). The researchers processed hexadecimal code into 4-gram profiles, resulting in a refined subset of 826 features for analysis.

5. Results and Discussion

The experiments highlighted a clear correlation between feature selection and predictive performance.

5.1 Classification Performance

On the Microsoft dataset, Beta-CoRM achieved an accuracy of 84-86%. While this was lower than XGBoost (~93%), it outperformed standard Decision Trees (~80%) and performed comparably to Multinomial Logistic Regression (~87%).

5.2 The Value of Interpretability

The primary advantage of Beta-CoRM lies in its output. Rather than a simple class label, the model generates "posterior predictive probabilities" for every $n$-gram across every family. This allows for the creation of probabilistic "fingerprints"—visual heatmaps that show exactly which features define a specific malware type. Furthermore, the model achieved peak performance using only 116 to 129 features, demonstrating significant efficiency through pruning.

6. Conclusion and Future Work

Beta-CoRM provides a robust probabilistic framework for $n$-gram analysis, bridging the gap between predictive accuracy and structural interpretability. While MCMC remains computationally more intensive than gradient-based methods, the insights gained into the generative structure of malware families are invaluable. Future research will focus on relaxing the independence assumption between $n$-grams and incorporating contextual information to further refine the model's discriminative power.

Summary updated

Abstract

n$-gram profiles have been successfully and widely used to analyse long sequences of potentially differing lengths for clustering or classification. Mainly, machine learning algorithms have been used for this purpose but, despite their predictive performance, these methods cannot discover hidden structures or provide a full probabilistic representation of the data. A novel class of Bayesian generative models designed for $n$-gram profiles used as binary attributes have been designed to address this. The flexibility of the proposed modelling allows to consider a straightforward approach to feature selection in the generative model. Furthermore, a slice sampling algorithm is derived for a fast inferential procedure, which is applied to synthetic and real data scenarios and shows that feature selection can improve classification accuracy.
BibTeX
@misc{perusquia2020bayesian,
  author = {José A. Perusquía and Jim E. Griffin and Cristiano Villa},
  title = {{On a Bayesian Approach to Malware Detection and Classification through n-gram Profiles}},
  year = {2020},
  eprint = {2011.11558},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2011.11558},
}
Figure