Transformers for End-to-End InfoSec Tasks: A Feasibility Study

Mohammad Saidur Rahman, Ethan M. Rudd, Mohammad Saidur Rahman 0002, Philip Tully

Abstract

This study investigates the applicability of Transformer architectures to raw information security data, specifically URLs and Portable Executable (PE) files. By bypassing traditional manual feature engineering, the authors evaluate whether "end-to-end" learning can match specialized models. The findings reveal that standard NLP pre-training strategies are insufficient for security tasks. However, a novel Balanced Mixed Objective approach—combining classification with auxiliary next-character prediction—enables Transformers to achieve state-of-the-art performance on URL detection.

Introduction

In machine learning for information security (InfoSec), practitioners traditionally rely on expert-driven feature engineering. Extracting specific strings, header information, or byte histograms from malware samples is effective but requires constant maintenance by Subject Matter Experts (SMEs) to counter evolving threats. While Natural Language Processing (NLP) has successfully transitioned to "end-to-end" learning from raw data, InfoSec data presents unique challenges: it lacks the inherent structure of human language and often contains extremely long-range dependencies. This paper assesses the feasibility of using Transformers to bridge this gap, specifically examining the "pre-train then fine-tune" paradigm.

Methodology

The research evaluates Transformers across two distinct data formats:

URL Detection (Short Sequences)

The authors implemented a character-level Transformer utilizing a Balanced Mixed Objective. Unlike standard classification models, this architecture forces the model to simultaneously predict the next character in a URL while determining its maliciousness. An adaptive balancing scheme ensures that neither the classification loss nor the prediction loss dominates the gradients during training.

Figure 1: Comparison of Transformer training objectives, highlighting the (c) Classification with Auxiliary Loss approach.

PE File Analysis (Long Sequences)

To address the massive length of binary files, the study employs an Adaptive Attention Span Transformer. This mechanism allows the model to attend to varying context lengths across different layers, mitigating the quadratic memory overhead typically associated with Transformers and enabling the processing of longer byte sequences.

Datasets

The study utilized two primary datasets:

  • URL Dataset: A proprietary Mandiant dataset containing approximately 1 million labeled URLs (180k malicious) and an additional 20-million unlabeled URL corpus for pre-training.
  • PE Dataset: The industry-standard EMBER 2018 dataset. For comparison with raw-byte models, files were truncated to the first 4096 bytes, covering the typical PE header.

Key Insights

A critical finding was that the standard NLP "pre-train and fine-tune" strategy failed for URLs. Pre-training on 20 million unlabeled URLs actually hindered performance, suggesting that the "grammar" of a URL does not correlate with its maliciousness as directly as language structure correlates with sentiment.

However, using next-character prediction as an auxiliary loss during the main training phase provided a significant performance boost. This approach encourages the model to fuse sequential context with class information within its hidden states, effectively serving as the "secret sauce" for high-accuracy detection.

Results

The Mixed Objective Transformer demonstrated strong performance across tasks:

  • URL Detection: Achieved an AUC of 0.956, matching 1D-CNNs (0.959) and significantly outperforming Random Forests (0.925).
  • Malware Detection: On truncated EMBER data, the Byte Transformer reached an AUC of 0.971, comparable to MalConv (0.972) but slightly behind more complex architectures like MG-CNN (0.982).
Figure 6: ROC Curve comparing different training strategies for URL detection. The MixedObjective approach significantly outperforms standard fine-tuning.

Conclusion and Future Work

While Transformers can match specialized models without manual feature engineering, scalability remains a primary hurdle. The quadratic scaling of attention mechanisms makes them more compute-intensive than CNNs for large binary files. Future research should explore bi-directional models (e.g., BERT-style masking), sparse attention mechanisms (e.g., Longformer) to handle larger file segments, and the application of these techniques to other InfoSec telemetry like network logs.

Summary updated

Abstract

Training a machine learning (ML) model from raw information security (InfoSec) data involves utilizing distinct data types and input formats that require unique considerations compared to more conventional applications of ML like natural language processing (NLP) and computer vision (CV). In this paper, we assess the viability of transformer models in end-to-end InfoSec settings, in which no intermediate feature representations or processing steps occur outside the model. We implement transformer models for two distinct InfoSec data formats - specifically URLs and PE files - in a novel end-to-end approach, and explore a variety of architectural designs, training regimes, and experimental settings to determine the ingredients necessary for performant detection models. We show that in contrast to conventional transformers trained on more standard NLP-related tasks, our URL transformer model requires a different training approach to reach high performance levels. Specifically, we show that 1) pre-training on a massive corpus of unlabeled URL data for an auto-regressive task does not readily transfer to binary classification of malicious or benign URLs, but 2) that using an auxiliary auto-regressive loss improves performance when training from scratch. We introduce a method for mixed objective optimization, which dynamically balances contributions from both loss terms so that neither one of them dominates. We show that this method yields quantitative evaluation metrics comparable to that of several top-performing benchmark classifiers. Unlike URLs, binary executables contain longer and more distributed sequences of information-rich bytes. To accommodate such lengthy byte sequences, we introduce additional context length into the transformer by providing its self-attention layers with an adaptive span similar to Sukhbaatar et al. We demonstrate that this approach performs comparably to well-established malware detection models on benchmark PE file datasets, but also point out the need for further exploration into model improvements in scalability and compute efficiency.
BibTeX
@inproceedings{rahman2022transformers,
  author = {Mohammad Saidur Rahman and Ethan M. Rudd and Mohammad Saidur Rahman and Philip Tully},
  title = {{Transformers for End-to-End InfoSec Tasks: A Feasibility Study}},
  booktitle = {Worma@asiaccs},
  year = {2022},
  doi = {10.1145/3494110.3528242},
}
Figure