CEBin: A Cost-Effective Framework for Large-Scale Binary Code Similarity Detection

Hao Wang, Zeyu Gao, Chao Zhang, Mingyang Sun, Yuchen Zhou, Han Qiu, Xi Xiao · DOI

Abstract

Binary Code Similarity Detection (BCSD) is critical for identifying vulnerabilities in large software ecosystems. However, existing methods struggle to balance the speed of embedding-based models with the accuracy of comparison-based models. We present CEBin, a hierarchical framework that combines these approaches. By utilizing a novel Reusable Embedding Cache Mechanism (RECM) to train with massive negative samples, CEBin achieves state-of-the-art accuracy and a 4x improvement in vulnerability detection recall while maintaining high scalability.

1. Introduction

Binary Code Similarity Detection (BCSD) determines if two compiled functions are semantically equivalent, even when compiled for different architectures or with varying optimization levels. This task is foundational for security applications like 1-day vulnerability discovery.

Current deep learning approaches generally fall into two categories:

  • Embedding-based models: These map code to vectors for fast search via Approximate Nearest Neighbor (ANN) techniques, but often lack the precision to distinguish subtle semantic differences.
  • Comparison-based models: These analyze pairs of functions side-by-side for high accuracy but are computationally prohibitive for large-scale searches.
Comparison of embedding-based (left) and comparison-based (right) similarity detection models.

CEBin addresses this challenge by implementing a hierarchical inference pipeline that leverages the strengths of both paradigms.

2. Methodology

CEBin introduces a multi-stage framework designed for high-precision, large-scale retrieval.

The CEBin framework overview, spanning pre-training, fine-tuning of dual models, and hierarchical inference.

2.1 Hierarchical Inference

To maintain efficiency, CEBin employs a two-step process:

  1. Top-K Retrieval: An embedding model quickly identifies the most likely candidates (e.g., K=50) from a massive pool.
  2. Final Selection: A comparison model performs fine-grained pairwise analysis on only these candidates to produce the final result.

2.2 Reusable Embedding Cache Mechanism (RECM)

Effective training requires exposure to a vast number of "negative samples" (dissimilar code). Standard training is often bottlenecked by GPU memory. CEBin’s RECM caches previously computed embeddings, allowing the model to be trained against thousands of negative samples (up to 8,192 per step) without the overhead of re-calculating gradients for every sample in a batch.

2.3 Normalization and Pre-training

CEBin uses BinaryNinja’s Intermediate Language (IL) to represent code, which helps the model ignore architecture-specific noise. The model is pre-trained on a Transformer-based architecture to learn robust semantic features that generalize across compilers and CPU architectures.

3. Evaluation

The framework was evaluated on standard datasets (BinaryCorp, Cisco, Trex) and a new large-scale vulnerability benchmark consisting of 187 CVEs across a search pool of 27 million functions.

3.1 Key Results

  • Accuracy: CEBin achieved 84.5% Recall@1 on the BinaryCorp dataset, compared to 57.1% for the previous state-of-the-art (jTrans).
  • Vulnerability Detection: In 1-day vulnerability search tasks, CEBin achieved an average recall of 85.46%, representing a 4.07x improvement over the best existing baseline.
  • Efficiency: CEBin can identify a similar function from a pool of 4 million candidates in approximately 3.1 seconds.
  • Generalization: Models trained on x86 data generalized effectively to ARM and MIPS, outperforming models specifically trained on those architectures.

4. Conclusion

CEBin demonstrates that a hierarchical approach, combined with efficient training mechanisms like RECM, can significantly advance the state-of-the-art in large-scale binary code similarity detection. While future work is needed to address fine-grained "patched" function detection, CEBin provides a scalable and highly accurate solution for real-world security auditing.

Summary updated

BibTeX
@inproceedings{wang2024cebin,
  author = {Hao Wang and Zeyu Gao and Chao Zhang and Mingyang Sun and Yuchen Zhou and Han Qiu and Xi Xiao},
  title = {{CEBin: A Cost-Effective Framework for Large-Scale Binary Code Similarity Detection}},
  booktitle = {ISSTA},
  year = {2024},
  doi = {10.1145/3650212.3652117},
}
Figure