ANVIL: Anomaly-based Vulnerability Identification without Labelled Training Data

Fuente: arXiv
Saved in:
Bibliographic Details
Main Authors: Wang, Weizhou, Liu, Eric, Guo, Xiangyu, Hu, Xiao, Grishchenko, Ilya, Lie, David
Format: Preprint
Published: 2024
Subjects:
Online Access:
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866913869097598976
author Wang, Weizhou
Liu, Eric
Guo, Xiangyu
Hu, Xiao
Grishchenko, Ilya
Lie, David
author_facet Wang, Weizhou
Liu, Eric
Guo, Xiangyu
Hu, Xiao
Grishchenko, Ilya
Lie, David
contents Supervised-learning-based vulnerability detectors often fall short due to limited labelled training data. In contrast, Large Language Models (LLMs) like GPT-4 are trained on vast unlabelled code corpora, yet perform only marginally better than coin flips when directly prompted to detect vulnerabilities. In this paper, we reframe vulnerability detection as anomaly detection, based on the premise that vulnerable code is rare and thus anomalous relative to patterns learned by LLMs. We introduce ANVIL, which performs a masked code reconstruction task: the LLM reconstructs a masked line of code, and deviations from the original are scored as anomalies. We propose a hybrid anomaly score that combines exact match, cross-entropy loss, prediction confidence, and structural complexity. We evaluate our approach across multiple LLM families, scoring methods, and context sizes, and against vulnerabilities after the LLM's training cut-off. On the PrimeVul dataset, ANVIL outperforms state-of-the-art supervised detectors-LineVul, LineVD, and LLMAO-achieving up to 2x higher Top-3 accuracy, 75% better Normalized MFR, and a significant improvement on ROC-AUC. Finally, by integrating ANVIL with fuzzers, we uncover two previously unknown vulnerabilities, demonstrating the practical utility of anomaly-guided detection.
format Preprint
id arxiv_https___arxiv_org_abs_2408_16028
institution arXiv
publishDate 2024
record_format arxiv
spellingShingle ANVIL: Anomaly-based Vulnerability Identification without Labelled Training Data
Wang, Weizhou
Liu, Eric
Guo, Xiangyu
Hu, Xiao
Grishchenko, Ilya
Lie, David
Cryptography and Security
Machine Learning
Software Engineering
Supervised-learning-based vulnerability detectors often fall short due to limited labelled training data. In contrast, Large Language Models (LLMs) like GPT-4 are trained on vast unlabelled code corpora, yet perform only marginally better than coin flips when directly prompted to detect vulnerabilities. In this paper, we reframe vulnerability detection as anomaly detection, based on the premise that vulnerable code is rare and thus anomalous relative to patterns learned by LLMs. We introduce ANVIL, which performs a masked code reconstruction task: the LLM reconstructs a masked line of code, and deviations from the original are scored as anomalies. We propose a hybrid anomaly score that combines exact match, cross-entropy loss, prediction confidence, and structural complexity. We evaluate our approach across multiple LLM families, scoring methods, and context sizes, and against vulnerabilities after the LLM's training cut-off. On the PrimeVul dataset, ANVIL outperforms state-of-the-art supervised detectors-LineVul, LineVD, and LLMAO-achieving up to 2x higher Top-3 accuracy, 75% better Normalized MFR, and a significant improvement on ROC-AUC. Finally, by integrating ANVIL with fuzzers, we uncover two previously unknown vulnerabilities, demonstrating the practical utility of anomaly-guided detection.
title ANVIL: Anomaly-based Vulnerability Identification without Labelled Training Data
topic Cryptography and Security
Machine Learning
Software Engineering
url https://arxiv.org/abs/2408.16028