Journal of Information Security Reserach ›› 2024, Vol. 10 ›› Issue (4): 294-.

Previous Articles     Next Articles

Research on Source Code Vulnerability Detection Based on BERT Model

Luo Leqi, Zhang Yanshuo, Wang Zhiqiang, Wen Jin, and Xue Peiyang#br#   

  1. (Beijing Electronic Science and Technology Institute, Beijing 100070)

  • Online:2024-04-20 Published:2024-04-21

基于BERT模型的源代码漏洞检测技术研究

罗乐琦张艳硕王志强文津薛培阳


  

  1. (北京电子科技学院北京100070)
  • 通讯作者: 王志强 博士,副教授,硕士生导师.主要研究方向为人工智能安全、漏洞发现、恶意软件检测. wangzq@besti.edu.cn
  • 作者简介:罗乐琦 硕士研究生.主要研究方向为漏洞挖掘、网络攻防. 20211909@mail.besti.edu.cn 张艳硕 博士,副教授,硕士生导师,CCF高级会员.主要研究方向为密码理论及其应用. zhang_yanshuo@163.com 王志强 博士,副教授,硕士生导师.主要研究方向为人工智能安全、漏洞发现、恶意软件检测. wangzq@besti.edu.cn 文津 硕士研究生.主要研究方向为人工智能安全、动作识别. 1065253065@qq.com 薛培阳 硕士研究生.主要研究方向为网络空间安全和信息安全. 20212905@mail.besti.edu.cn

Abstract: Techniques such as code metrics, machine learning, and deep learning are commonly employed in source code vulnerability detection. However, these techniques have problems, such as their inability to retain the syntactic and semantic information of the source code and the requirement of extensive expert knowledge to define vulnerability features. To cope with the problems of existing techniques, this paper proposed a source code vulnerability detection model based on BERT(bidirectional encoder representations from transformers) model. The model splits the source code to be detected into multiple small samples, converted each small sample into the form of approximate natural language, realized the automatic extraction of vulnerability features in the source code through the BERT model, and then trained a vulnerability classifier with good performance to realize the detection of multiple types of vulnerabilities in Python language. The model achieved an average detection accuracy of 99.2%, precision of 97.2%, recall of 96.2%, and an F1 score of 96.7% across various vulnerability types. This represents a performance improvement of 2% to 14% over existing vulnerability detection methods. The experimental results showed that the model was a general, lightweight and scalable vulnerability detection method.

Key words: vulnerability detection, deep learning, Python language, BERT model, natural language processing

摘要: 源代码漏洞检测常使用代码指标、机器学习和深度学习等技术.但是这些技术存在无法保留源代码中的句法和语义信息、需要大量专家知识对漏洞特征进行定义等问题.为应对现有技术存在的问题,提出基于BERT(bidirectional encoder representations from transformers)模型的源代码漏洞检测模型.该模型将需要检测的源代码分割为多个小样本,将每个小样本转换成近似自然语言的形式,通过BERT模型实现源代码中漏洞特征的自动提取,然后训练具有良好性能的漏洞分类器,实现Python语言多种类型漏洞的检测.该模型在不同类型的漏洞中实现了平均99.2%的准确率、97.2%的精确率、96.2%的召回率和96.7%的F1分数的检测水平,对比现有的漏洞检测方法有2%~14%的性能提升.实验结果表明,该模型是一种通用的、轻量级的、可扩展的漏洞检测方法.

关键词: 漏洞检测, 深度学习, Python语言, BERT模型, 自然语言处理

CLC Number: