NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Stack-based Buffer Overflow Detection using Recurrent Neural Networks

William Arild Dahl, Laszlo Erdodi, Fabio Massimo ZennaroarXiv 2020

Abstract

Stack-based buffer overflows remain a critical security threat, often exploited in compiled binaries where source code is unavailable. This paper investigates the application of Recurrent Neural Networks (RNNs), specifically Long Short-Term Memory (LSTM) networks, to detect these vulnerabilities directly within assembly code. By treating assembly instructions as a sequential language, the proposed model achieves up to 99% accuracy in identifying subtle, context-dependent flaws. This approach demonstrates the potential for automated security auditing of proprietary or legacy software without requiring original source code.

Introduction

Stack-based buffer overflows are among the most persistent and dangerous software vulnerabilities. They occur when a program writes more data to a fixed-length block of memory (a buffer) than it can hold, overwriting adjacent memory on the call stack. This can lead to arbitrary code execution, as seen in major exploits like the WannaCry ransomware. While many tools exist to detect these vulnerabilities in high-level source code, security professionals often face the challenge of auditing compiled binaries where the source is inaccessible. This research explores whether machine learning can bridge this gap by analyzing assembly code directly.

The Challenge of Binary-Level Detection

Most automated vulnerability detection tools rely on high-level semantic information available in source code (e.g., C, C++, or Java). However, in scenarios involving malware analysis or third-party software auditing, only the compiled executable is available. Analyzing raw machine code is extremely complex due to its lack of structure. Assembly code serves as a "Goldilocks" representation: it is more concise and hardware-agnostic than binary, yet easily obtainable via decompilers like Ghidra or IDA Pro. The central question is whether neural networks can learn to recognize the patterns of vulnerability within this low-level "language."

Methodology

The researchers adopted a Natural Language Processing (NLP) framework, treating assembly instructions as tokens in a sequence.

Data Preprocessing

  1. Compilation: Synthetic C programs were generated with both safe and vulnerable implementations of standard library functions and compiled into 64-bit Intel assembly using GCC.
  2. Compression: Redundant compiler directives (e.g., .size, .ident) were removed to focus the model on core program logic.
  3. Tokenization: The assembly was split into atomic tokens such as opcodes (mov, push) and registers (rbp, rsp), while preserving structural elements like newlines.

Model Architecture

The tokenized sequences are processed through a multi-layer neural network designed to capture long-range dependencies in code logic.

The neural network architecture for assembly-based vulnerability detection.

The architecture consists of an N-D real embedding layer to convert tokens into dense vectors, followed by two 512-dimensional LSTM layers to process the sequential context. A temporal dropout layer (0.5) is used to prevent overfitting, leading into a fully connected layer with a Sigmoid activation for binary classification (vulnerable vs. benign).

Experimental Design and Datasets

Due to the scarcity of labeled real-world assembly data, the authors created three synthetic simulation sets focusing on eight risky C system calls (e.g., strcpy, fgets, memcpy):

  • Simulation 1: 4,000 small programs (3 functions each) with distinct differences between safe and unsafe code.
  • Simulation 2: 200 programs focused on the fgets function, testing the model's ability to distinguish between a vulnerable call and a safely patched version where only a buffer size check differs.
  • Simulation 3: 8,000 larger programs (20 functions each) to evaluate the model's scalability and performance on more complex code structures.

Results and Analysis

The model demonstrated exceptional performance across all simulations. In Simulation 1 and 2, it achieved a Correct Classification Rate (CCR) of nearly 1.0 (100% accuracy). Crucially, in Simulation 2, the network successfully differentiated between safe and unsafe code even when the differences were minimal, proving it learns the context of instructions rather than just flagging "dangerous" keywords.

In the most challenging scenario, Simulation 3, the two-layer LSTM achieved a 99.00% CCR with a low binary cross-entropy loss of 0.057.

Training progress for Simulation 3, showing the convergence of classification rate and loss over 20,000 steps.

As shown in the training progress, the model initially struggles but eventually converges rapidly to high accuracy. The authors noted that achieving this convergence required careful hyperparameter tuning, particularly a very low learning rate to prevent training instability.

Conclusion and Future Directions

This study confirms that assembly code possesses sufficient structural regularity to be analyzed using NLP-based deep learning. By successfully identifying vulnerabilities in compiled code, the researchers have provided a viable path for automated security auditing in the absence of source code.

Limitations: The current work relies on synthetic data, which lacks the convoluted logic and scale of real-world software. The model's sensitivity to learning rates also suggests potential instability on noisier, real-world datasets.

Future Work: Future research will focus on scaling the architecture to handle larger, more realistic programs and exploring Transformer-based models to better capture long-range dependencies. Additionally, the researchers aim to move beyond binary classification to pinpoint the exact location and type of vulnerability within the code.

Summary updated

BibTeX
@misc{dahl2020stack,
  author = {William Arild Dahl and Laszlo Erdodi and Fabio Massimo Zennaro},
  title = {{Stack-based Buffer Overflow Detection using Recurrent Neural Networks}},
  year = {2020},
  eprint = {2012.15116},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2012.15116},
}
Figure