《计算机应用》唯一官方网站 ›› 2022, Vol. 42 ›› Issue (10): 3170-3176.DOI: 10.11772/j.issn.1001-9081.2021081548
• 计算机软件技术 • 上一篇
收稿日期:
2021-08-31
修回日期:
2021-11-20
接受日期:
2021-11-21
发布日期:
2022-01-07
出版日期:
2022-10-10
通讯作者:
程靖云
作者简介:
第一联系人:程靖云(1998—),男,重庆人,硕士研究生,主要研究方向:信息安全; 1508458583@qq.comJingyun CHENG, Buhong WANG, Peng LUO
Received:
2021-08-31
Revised:
2021-11-20
Accepted:
2021-11-21
Online:
2022-01-07
Published:
2022-10-10
Contact:
Jingyun CHENG
About author:
CHENG Jingyun, born in 1998, M. S. candidate. His research interests include information safety.摘要:
随着计算机软件规模和复杂度的不断增加,软件中存在的代码缺陷对公共安全形成了严重威胁。针对静态分析工具拓展性差,以及现有方法检测粒度粗、检测效果不够理想的问题,提出了一种基于程序切片和语义特征融合的代码缺陷静态检测方法。首先,对源代码中的关键点进行数据流和控制流分析,并采用基于过程间有限分布子集(IFDS)的切片方法,以获取由多行与代码缺陷相关的语句组成的代码片段;然后,通过词嵌入法获取代码片段语义相关的向量表示,从而在保证准确率的同时选择合适的代码片段长度;最后,利用文本卷积神经网络(TextCNN)和双向门控循环单元(BiGRU)分别提取代码片段中的局部关键特征和上下文序列特征,并将所提方法用于检测切片级别的代码缺陷。实验结果表明,所提方法能够有效检测不同类型的代码缺陷,并且检测效果显著优于静态分析工具Flawfinder;在细粒度的前提下,IFDS切片方法能进一步提高F1值和准确率,分别达到了89.64%和92.08%;与现有的基于程序切片的方法相比,在关键点为应用程序编程接口(API)或变量时,所提方法的F1值分别达到89.69%、89.74%,准确率分别达到92.15%、91.98%。可见在不显著增加时间复杂度的同时,所提方法具备更好的综合检测性能。
中图分类号:
程靖云, 王布宏, 罗鹏. 基于深度语义融合的代码缺陷静态检测方法[J]. 计算机应用, 2022, 42(10): 3170-3176.
Jingyun CHENG, Buhong WANG, Peng LUO. Static code defect detection method based on deep semantic fusion[J]. Journal of Computer Applications, 2022, 42(10): 3170-3176.
变量 | 后向 | 前向 |
---|---|---|
argc@main | {14} | {6,8,9,10,11,12, 17,19,20,21,22} |
argv@main | {14} | {9,19} |
buf@test | {6,8,14,17,20} | {8} |
str@test | {6,14,17,19,20} | {9} |
userstr@main | {14,17,19} | {19} |
表1 静态切片表
Tab. 1 Static slice table
变量 | 后向 | 前向 |
---|---|---|
argc@main | {14} | {6,8,9,10,11,12, 17,19,20,21,22} |
argv@main | {14} | {9,19} |
buf@test | {6,8,14,17,20} | {8} |
str@test | {6,14,17,19,20} | {9} |
userstr@main | {14,17,19} | {19} |
实际 | 预测 | |
---|---|---|
脆弱 | 非脆弱 | |
脆弱 | TP | FN |
非脆弱 | FP | TN |
表2 混淆矩阵
Tab. 2 Confusion matrix
实际 | 预测 | |
---|---|---|
脆弱 | 非脆弱 | |
脆弱 | TP | FN |
非脆弱 | FP | TN |
参数名 | 值 | 参数名 | 值 |
---|---|---|---|
滤波器数量(N) | 128 | 迭代轮次 | 20 |
卷积窗口大小(m) | 1、3、5 | 激活函数 | ReLU |
GRU神经元个数(u) | 50 | 卷积方式 | MaxPooling1D |
全连接层神经元个数 | 484 | 优化函数 | Adamax |
Dropout | 0.5 | 损失函数 | categorical_crossentrop |
Batch Size | 256 |
表3 实验参数
Tab. 3 Experimental parameters
参数名 | 值 | 参数名 | 值 |
---|---|---|---|
滤波器数量(N) | 128 | 迭代轮次 | 20 |
卷积窗口大小(m) | 1、3、5 | 激活函数 | ReLU |
GRU神经元个数(u) | 50 | 卷积方式 | MaxPooling1D |
全连接层神经元个数 | 484 | 优化函数 | Adamax |
Dropout | 0.5 | 损失函数 | categorical_crossentrop |
Batch Size | 256 |
缺陷类型 | F1 | Acc | Rec | Pre |
---|---|---|---|---|
缓冲区溢出 | 86.59 | 89.04 | 89.29 | 84.05 |
格式化字符串 | 89.86 | 91.88 | 91.21 | 88.55 |
内存管理 | 88.06 | 90.79 | 91.74 | 84.67 |
错误处理不当 | 89.95 | 93.57 | 93.14 | 86.98 |
命令执行 | 95.49 | 94.38 | 97.73 | 93.35 |
混合 | 96.13 | 96.59 | 97.69 | 94.62 |
表4 不同缺陷时本文方法的实验结果对比 (%)
Tab. 4 Experimental results comparison of the proposed method for different defects
缺陷类型 | F1 | Acc | Rec | Pre |
---|---|---|---|---|
缓冲区溢出 | 86.59 | 89.04 | 89.29 | 84.05 |
格式化字符串 | 89.86 | 91.88 | 91.21 | 88.55 |
内存管理 | 88.06 | 90.79 | 91.74 | 84.67 |
错误处理不当 | 89.95 | 93.57 | 93.14 | 86.98 |
命令执行 | 95.49 | 94.38 | 97.73 | 93.35 |
混合 | 96.13 | 96.59 | 97.69 | 94.62 |
切片类型 | 耗时/s | Token数 | 复用比/% | F1/% | Acc/% |
---|---|---|---|---|---|
IFDS_Bo | 757 | 378 | 72.88 | 89.64 | 91.94 |
IFDS_Bw | 634 | 233 | 80.03 | 89.51 | 92.08 |
IFDS_Fw | 671 | 351 | 93.91 | 43.67 | 65.40 |
SDG_Bo | 737 | 378 | 73.00 | 89.50 | 91.92 |
SDG_Bw | 652 | 233 | 80.19 | 89.36 | 92.01 |
SDG_Fw | 695 | 351 | 93.91 | 45.80 | 65.04 |
Weiser_Bw | 949 | 257 | 84.01 | 54.11 | 69.59 |
表5 不同切片方法的实验结果对比
Tab. 5 Experimental results comparison of different slicing methods
切片类型 | 耗时/s | Token数 | 复用比/% | F1/% | Acc/% |
---|---|---|---|---|---|
IFDS_Bo | 757 | 378 | 72.88 | 89.64 | 91.94 |
IFDS_Bw | 634 | 233 | 80.03 | 89.51 | 92.08 |
IFDS_Fw | 671 | 351 | 93.91 | 43.67 | 65.40 |
SDG_Bo | 737 | 378 | 73.00 | 89.50 | 91.92 |
SDG_Bw | 652 | 233 | 80.19 | 89.36 | 92.01 |
SDG_Fw | 695 | 351 | 93.91 | 45.80 | 65.04 |
Weiser_Bw | 949 | 257 | 84.01 | 54.11 | 69.59 |
检测方法 | 模型 | 关键点类别 | Token数 | 嵌入方法 | F1/% | Acc/% | 每批平均训练时间/ms | 每个平均检测时间/ms |
---|---|---|---|---|---|---|---|---|
基于规则 | Flawfinder[ | ― | ― | ― | 38.01 | 58.65 | ― | 0.126 |
基于深度 学习 | DCnnGRU[ | API | 363 | Skip-gram | 85.89 | 88.38 | 54.77 | 0.129 |
TextCNN+SVM[ | API | 363 | CBOW | 89.90 | 92.34 | 26.76+2 227.20 | 2.446 | |
BiGRU[ | API | 363 | FastText | 88.53 | 91.09 | 35.34 | 0.106 | |
本文模型 | API | 363 | Skip-gram | 89.69 | 92.15 | 62.11 | 0.167 | |
本文方法 | 本文模型 | 变量 | 378 | Skip-gram | 89.74 | 91.98 | 61.81 | 0.189 |
DCnnGRU | 变量 | 378 | Skip-gram | 87.68 | 89.31 | 55.68 | 0.139 | |
TextCNN+SVM | 变量 | 378 | Skip-gram | 89.35 | 92.17 | 27.06+2 059.67 | 2.509 | |
BiGRU | 变量 | 378 | Skip-gram | 88.79 | 91.16 | 35.87 | 0.117 |
表6 不同方法的实验结果对比
Tab. 6 Experimental results comparison of different methods
检测方法 | 模型 | 关键点类别 | Token数 | 嵌入方法 | F1/% | Acc/% | 每批平均训练时间/ms | 每个平均检测时间/ms |
---|---|---|---|---|---|---|---|---|
基于规则 | Flawfinder[ | ― | ― | ― | 38.01 | 58.65 | ― | 0.126 |
基于深度 学习 | DCnnGRU[ | API | 363 | Skip-gram | 85.89 | 88.38 | 54.77 | 0.129 |
TextCNN+SVM[ | API | 363 | CBOW | 89.90 | 92.34 | 26.76+2 227.20 | 2.446 | |
BiGRU[ | API | 363 | FastText | 88.53 | 91.09 | 35.34 | 0.106 | |
本文模型 | API | 363 | Skip-gram | 89.69 | 92.15 | 62.11 | 0.167 | |
本文方法 | 本文模型 | 变量 | 378 | Skip-gram | 89.74 | 91.98 | 61.81 | 0.189 |
DCnnGRU | 变量 | 378 | Skip-gram | 87.68 | 89.31 | 55.68 | 0.139 | |
TextCNN+SVM | 变量 | 378 | Skip-gram | 89.35 | 92.17 | 27.06+2 059.67 | 2.509 | |
BiGRU | 变量 | 378 | Skip-gram | 88.79 | 91.16 | 35.87 | 0.117 |
1 | ABU-DABASEH F, ALSHAMMARI E. Automated penetration testing: an overview[C]// Proceedings of the 4th International Conference on Natural Language Computing. Chennai, Tamil Nadu: AIRCC Publishing Corporation, 2018: 121-129. 10.5121/csit.2018.80610 |
2 | 李韵,黄辰林,王中锋,等. 基于机器学习的软件漏洞挖掘方法综述[J]. 软件学报, 2020, 31(7):2040-2061. |
LI Y, HUANG C L, WANG Z F, et al. Survey of software vulnerability mining methods based on machine learning[J]. Journal of Software, 2020, 31(7):2040-2061. | |
3 | SEMASABA A O A, ZHENG W, WU X X, et al. Literature survey of deep learning-based vulnerability analysis on source code[J]. IET Software, 2020, 14(6): 654-664. 10.1049/iet-sen.2020.0084 |
4 | Details CVE. Browse vulnerabilities by date[EB/OL]. [2021-07-24].. |
5 | YAMAGUCHI F. Pattern-based methods for vulnerability discovery[J]. it—Information Technology, 2017, 59(2): 101-106. 10.1515/itit-2016-0037 |
6 | 蒋考林,白玮,张磊,等. 基于多通道图像深度学习的恶意代码检测[J]. 计算机应用, 2021, 41(4):1142-1147. |
JIANG K L, BAI W, ZHANG L, et al. Malicious code detection based on multi-channel image deep learning[J]. Journal of Computer Applications, 2021, 41(4):1142-1147. | |
7 | KIM S, WOO S, LEE H, et al. VUDDY: a scalable approach for vulnerable code clone discovery[C]// Proceedings of the 2017 IEEE Symposium on Security and Privacy. Piscataway: IEEE, 2017:595-614. 10.1109/sp.2017.62 |
8 | GRIECO G, GRINBLAT G L, UZAL L, et al. Toward large-scale vulnerability discovery using machine learning[C]// Proceedings of the 6th ACM Conference on Data and Application Security and Privacy. New York: ACM, 2016: 85-96. 10.1145/2857705.2857720 |
9 | SCANDARIATO R, WALDEN J, HOVSEPYAN A, et al. Predicting vulnerable software components via text mining[J]. IEEE Transactions on Software Engineering, 2014, 40(10): 993-1006. 10.1109/tse.2014.2340398 |
10 | MIRSKY Y, DEMONTIS A, KOTAK J, et al. The threat of offensive AI to organizations[EB/OL]. (2021-06-30) [2021-07-26].. |
11 | RUSSELL R, KIM L, HAMILTON L, et al. Automated vulnerability detection in source code using deep representation learning[C]// Proceedings of the 2018 17th IEEE International Conference on Machine Learning and Applications. Piscataway: IEEE, 2018: 757-762. 10.1109/icmla.2018.00120 |
12 | ZHOU Y Q, LIU S Q, SIOW J, et al. Devign: effective vulnerability identification by learning comprehensive program semantics via graph neural networks[C/OL]// Proceedings of the 33rd Conference on Neural Information Processing Systems. [2021-07-27].. |
13 | 许健,陈平华,熊建斌. 融合滑动窗口和哈希函数的代码漏洞检测模型[J]. 计算机应用研究, 2021, 38(8):2394-2400. |
XU J, CHEN P H, XIONG J B. Code vulnerability detection model based on sliding window and hash function[J]. Application Research of Computers, 2021, 38(8):2394-2400. | |
14 | LI Z, ZOU D Q, XU S H, et al. VulDeePecker: a deep learning-based system for vulnerability detection[EB/OL]. (2018-01-05) [2021-07-27].. 10.14722/ndss.2018.23158 |
15 | 李元诚,崔亚奇,吕俊峰,等. 开源软件漏洞检测的混合深度学习方法[J]. 计算机工程与应用, 2019, 55(11):52-59. |
LI Y C, CUI Y Q, LYU J F, et al. Combined deep learning method for open source software vulnerability detection[J]. Computer Engineering and Applications, 2019, 55(11):52-59. | |
16 | 王晓萌,管志斌,辛伟,等. 基于深度卷积神经网络的源代码缺陷检测方法[J]. 清华大学学报(自然科学版), 2021, 61(11): 1267-1272. |
WANG X M, GUAN Z B, XIN W, et al. Source code defect detection using deep convolutional neural networks[J]. Journal of Tsinghua University (Science and Technology), 2021, 61(11): 1267-1272. | |
17 | LI X, WANG L, XIN Y, et al. Automated vulnerability detection in source code using minimum intermediate representation learning[J]. Applied Sciences, 2020, 10(5): No.1692. 10.3390/app10051692 |
18 | JEON S, KIM H K. AutoVAS: an automated vulnerability analysis system with a deep learning approach[J]. Computers and Security, 2021, 106: No.102308. 10.1016/j.cose.2021.102308 |
19 | CHANDRA A, SINGHAL A, BANSAL A. A study of program slicing techniques for software development approaches[C]// Proceedings of the 1st International Conference on Next Generation Computing Technologies. Piscataway: IEEE, 2015: 622-627. 10.1109/ngct.2015.7375196 |
20 | MIKOLOV T, CHEN K, CORRADO G, et al. Efficient estimation of word representations in vector space[EB/OL]. (2013-09-07) [2021-07-29].. 10.3126/jiee.v3i1.34327 |
21 | KIM Y. Convolutional neural networks for sentence classification[C]// Proceedings of the 2014 Conference on Empirical Methods in Natural Language Processing. Stroudsburg, PA: Association for Computational Linguistics, 2014:1746-1751. 10.3115/v1/d14-1181 |
22 | National Institute of Standards and Technology. Software assurance reference dataset[DS/OL]. [2021-08-02].. 10.1109/dasc.2007.4391957 |
23 | WHEELER D A. Flawfinder[EB/OL]. [2017-8-26].. |
[1] | 李敬虎, 邢前国, 郑向阳, 李琳, 王丽丽. 基于深度学习的无人机影像夜光藻赤潮提取方法[J]. 《计算机应用》唯一官方网站, 2022, 42(9): 2969-2974. |
[2] | 强赞霞, 鲍先富. 基于卷积长短期记忆的残差注意力去雨网络[J]. 《计算机应用》唯一官方网站, 2022, 42(9): 2858-2864. |
[3] | 魏佳璇, 杜世康, 于志轩, 张瑞生. 图像分类中的白盒对抗攻击技术综述[J]. 《计算机应用》唯一官方网站, 2022, 42(9): 2732-2741. |
[4] | 孟昱煜, 郭静. 信息熵改进主成分分析模型的链路预测算法[J]. 《计算机应用》唯一官方网站, 2022, 42(9): 2823-2829. |
[5] | 尹靖涵, 瞿绍军, 姚泽楷, 胡玄烨, 秦晓雨, 华璞靖. 基于YOLOv5的雾霾天气下交通标志识别模型[J]. 《计算机应用》唯一官方网站, 2022, 42(9): 2876-2884. |
[6] | 刘亚姣, 于海涛, 王江, 于利峰, 张春晖. 基于深度学习的型钢表面多形态微小缺陷检测算法[J]. 《计算机应用》唯一官方网站, 2022, 42(8): 2601-2608. |
[7] | 张显杰, 张之明. 基于卷积神经网络和Transformer的手写体英文文本识别[J]. 《计算机应用》唯一官方网站, 2022, 42(8): 2394-2400. |
[8] | 程南江, 余贞侠, 陈琳, 乔贺辙. 基于领域自适应的多源多标签行人属性识别[J]. 《计算机应用》唯一官方网站, 2022, 42(8): 2401-2406. |
[9] | 王一宁, 赵青杉, 秦品乐, 胡玉兰, 宗春梅. 基于轻量密集神经网络的医学图像超分辨率重建算法[J]. 《计算机应用》唯一官方网站, 2022, 42(8): 2586-2592. |
[10] | 刘万军, 王佳铭, 曲海成, 董利兵, 曹欣宇. 基于频谱空间域特征注意的音乐流派分类算法[J]. 《计算机应用》唯一官方网站, 2022, 42(7): 2072-2077. |
[11] | 韩亚茹, 闫连山, 姚涛. 基于元学习的深度哈希检索算法[J]. 《计算机应用》唯一官方网站, 2022, 42(7): 2015-2021. |
[12] | 杨瑞杰, 郑贵林. 基于InceptionV3和特征融合的人脸活体检测[J]. 《计算机应用》唯一官方网站, 2022, 42(7): 2037-2042. |
[13] | 秦庭威, 赵鹏程, 秦品乐, 曾建朝, 柴锐, 黄永琦. 基于残差注意力机制的点云配准算法[J]. 《计算机应用》唯一官方网站, 2022, 42(7): 2184-2191. |
[14] | 王震宇, 张雷, 高文彬, 权威铭. 基于渐进式神经网络架构搜索的人体运动识别[J]. 《计算机应用》唯一官方网站, 2022, 42(7): 2058-2064. |
[15] | 董宁, 程晓荣, 张铭泉. 基于物联网平台的动态权重损失函数入侵检测系统[J]. 《计算机应用》唯一官方网站, 2022, 42(7): 2118-2124. |
阅读次数 | ||||||
全文 |
|
|||||
摘要 |
|
|||||