Detection method for identifying weakness in source code by utilizing machine learning

By using dynamic detection environment and machine learning models in source code detection, combined with user input code use cases generated by fuzzy testing tools, evaluating path coverage and resource occupancy, the problems of low weakness detection efficiency and high false alarm rate in source code in the existing technology are solved, and a more accurate vulnerability identification and a more efficient detection process are achieved.

CN119645848APending Publication Date: 2025-03-18GUANGZHOU RENHE SHICHUANG INFORMATION TECHNOLOGY CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202411711925.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-27
Publication Date
2025-03-18

AI Technical Summary

Technical Problem

In the source code, the existing technology has problems such as low code coverage, low detection process efficiency, high false alarm rate and confusing vulnerability repair strategies.

Method used

By configuring a dynamic source code detection environment, obtaining historical running data of historical source code, establishing a weakness detection machine learning model, predicting the types of execution paths of the source code segment to be detected, and combining the user input code use cases generated by the fuzzy testing tool, evaluating the path coverage and resource occupancy rate, and finally calculating the execution path anomaly rate and vulnerability repair difficulty coefficient.

Benefits of technology

It realizes more accurately identifying and classifying potential security vulnerabilities, improves detection efficiency, reduces false positive rates, and discovers potential security risk points in advance, helping development teams identify and fix problems in the early stage of software development.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119645848A_ABST
    Figure CN119645848A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of source code weak point detection, in particular to a detection method for recognizing weak points in source codes through machine learning, and the method specifically comprises the steps that a corresponding code detection environment is configured; establishing a weakness detection machine learning model, and predicting the execution path type of the code range through the weakness detection machine learning model; triggering an abnormal execution behavior of the source code, synchronously establishing a control flow graph, and analyzing a control flow transfer degree coefficient of each node in an injection process of a code case input by a user; quantifying the path coverage rate and the real-time resource occupancy rate of the application program in the injection process of the code case input by the user, and calculating the execution path exception rate of the source code segment to be detected; evaluating a vulnerability repair difficulty coefficient according to the execution path anomaly rate of the to-be-detected source code segment; according to the method, the problems of low code coverage rate of the dynamic source code, low detection process efficiency, high false alarm rate and disordered vulnerability repair strategies in the prior art are solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of source code weakness detection, in particular to a detection method for identifying weaknesses in source code by using machine learning. Background Art

[0002] In recent years, machine learning technology has shown great potential in the field of software security. Machine learning can learn patterns from large amounts of source code and security vulnerability data to improve the efficiency and accuracy of security vulnerability detection. Existing software security detection methods mainly include static code analysis and dynamic code analysis. Static analysis detects potential security vulnerabilities by analyzing source code or bytecode, but it is usually difficult to handle dynamically generated code and complex control flows. Dynamic analysis evaluates the security of programs by executing them, but there are problems with insufficient coverage and high resource consumption. Existing machine learning methods still have problems with low code coverage of dynamic source code, low detection process efficiency, high false positive rate, and confusing vulnerability repair strategies when dealing with security weakness detection in source code.

[0003] In the existing disclosed invention technologies, for example, the patent with publication number CN116627821A discloses a source code defect detection method and related devices, which obtains feature information of source code defects; vectorizes the feature information to obtain a corresponding feature vector; and inputs the feature vector into a pre-trained neural network model to obtain a defect detection result output by the neural network model.

[0004] The neural network model in the above patent will produce a high false alarm rate when there is a lack of sufficient labeled data or when faced with complex code logic, and has the problems described in the background technology. Summary of the invention

[0005] The technical problem to be solved by the present invention is to address the problems in the prior art such as low code coverage of dynamic source code, low detection process efficiency, high false alarm rate and confusing vulnerability repair strategy, and propose a detection method using machine learning to identify weaknesses in source code.

[0006] In order to achieve the above object, the present invention provides a technical solution for a detection method for identifying weaknesses in source code using machine learning, comprising the following steps:

[0007] S1: Configure the corresponding code detection environment according to the language characteristics of the source code segment to be detected;

[0008] S2: Obtain historical running data of historical source code, and establish a weakness detection machine learning model based on the historical running data, and predict the execution path type of each code range in the source code segment to be detected through the weakness detection machine learning model;

[0009] S3: Use the fuzz testing tool to randomly generate multiple user input code use cases, trigger abnormal execution behavior of the source code, synchronously build a control flow graph and analyze the control flow transfer degree coefficient of each node in the user input code use case during the injection process;

[0010] S4: quantify the path coverage and real-time resource occupancy of the application during the injection process of the user input code use case, and import the path coverage and real-time resource occupancy into the execution path anomaly judgment strategy to calculate the execution path anomaly rate of the source code segment to be detected;

[0011] S5: Evaluate the vulnerability repair difficulty coefficient according to the execution path exception rate of the source code segment to be detected, and arrange the vulnerability repair difficulty coefficients of each code range in order.

[0012] Specifically, S1 includes the following specific steps: first, configure the corresponding dynamic source code detection environment according to the language characteristics of the source code segment to be detected; then, determine the code range of the source code segment to be detected, set the dynamic source code detection environment variables, and synchronously install the required dependencies and libraries; finally, simulate the application usage behavior of real users.

[0013] Specifically, S2 includes the following specific steps:

[0014] S21: Obtain historical running data of historical source code, wherein the historical running data includes: historical execution path data, code feature data and execution environment data; the historical execution path data includes: code block execution order, number of conditional branches, and number of loop structure executions; the code feature data includes: function call relationship graph; the execution environment data includes: processor architecture, source code running container and network delay;

[0015] S22: establishing a weakness detection machine learning model according to the historical operation data, extracting the historical operation data of the historical source code, and combining the historical execution path data, code feature data and execution environment data of a single historical source code into a source code operation feature vector, to obtain a feature vector set of the historical source code;

[0016] S23: normalizing the feature vector set of the historical source code, wherein the normalization strategy is: Among them, g′ is the normalized data, g is the feature vector in the feature vector set of the historical source code, and g max is the characteristic maximum value, g min is the minimum value of the characteristic;

[0017] S24: dividing the feature vector set of the historical source code into a training set and a test set in a ratio of 8:2, inputting the training set into the weakness detection machine learning model for training, wherein the weakness detection machine learning model uses the matching degree between the historical source code in the training set and the historical source code in the test set as output and the actual matching degree as the matching target, thereby completing the training of the weakness detection machine learning model;

[0018] S25: Input each code range in the source code segment to be detected into the trained vulnerability detection machine learning model, and predict the execution path type of each code range in the source code segment to be detected through the vulnerability detection machine learning model.

[0019] Specifically, in S22, the vulnerability detection machine learning model is any one of a deep neural network model, a deep belief network model or a Bayesian network model.

[0020] Specifically, S3 includes the following specific steps:

[0021] S31: using a lexical analyzer and a syntax analyzer to process each code range in the source code segment to be detected, converting it into an abstract syntax tree, and at the same time dividing each code range in the source code segment to be detected into basic blocks, wherein the basic blocks are used to execute continuous instructions;

[0022] S32: combining basic blocks and control flow edges between the basic blocks, and constructing a control flow graph from the source code segment to be detected;

[0023] S33: randomly generate multiple user input code use cases through a fuzz testing tool, and identify function call nodes related to the user input code use cases;

[0024] S34: Analyze the control flow transfer degree coefficient of the function call node in the injection process of the user input code use case;

[0025] The specific calculation strategy of the control flow transfer degree coefficient Z is as follows:

[0026] Z = z1 + z2;

[0027] Among them, z1 is the execution path length evaluation coefficient, jd 1,n The number of nodes in the actual execution path of the nth code range during the injection process for the user-input code use case; 2,n The number of nodes in the execution path of each code range in the source code segment to be detected is predicted by the weakness detection machine learning model; R1 is the screening threshold for the number of abnormal nodes;

[0028] z2 is the execution path complexity evaluation coefficient, fz 1,nThe number of branches of the actual execution path of the nth code range during the injection process for the user-input code use case; fz 2,n The weakness detection machine learning model predicts the number of branches of the execution path of each code range in the source code segment to be detected; R2 is the screening threshold for the number of abnormal branches;

[0029] S35: extract the control flow transfer degree coefficient Z, set a transfer degree threshold, compare the control flow transfer degree coefficient Z with the set transfer degree threshold, filter the execution path whose control flow transfer degree coefficient Z is higher than the set transfer degree threshold and mark the control flow transfer as abnormal.

[0030] Specifically, S4 includes the following specific steps:

[0031] S41: Quantify the path coverage and real-time resource usage of the application during the injection process of the user input code use case;

[0032] The quantification strategy of the path coverage is: m n is the number of execution paths marked as control flow transfer exceptions in the execution path of the nth code range in the source code segment to be detected; M is the total number of execution paths of the code segment to be detected;

[0033] The quantification strategy of the real-time resource occupancy rate is: c n is the memory usage rate when the nth code range in the source code segment to be detected is executed; C is the total memory capacity of the processor;

[0034] S42: Importing the path coverage and real-time resource occupancy rate into the execution path anomaly judgment strategy to calculate the execution path anomaly rate of the source code segment to be detected; the execution path anomaly judgment strategy is specifically as follows:

[0035] fau n =α1×F n +α2×Y n ;

[0036] Among them, fau n is the execution path exception rate of the nth code range in the source code segment to be detected; α1 and α2 are the execution path exception impact ratios of the path coverage and real-time resource occupancy, respectively.

[0037] Specifically, in S5, the evaluation strategy for evaluating the vulnerability repair difficulty coefficient according to the execution path abnormality rate of the source code segment to be detected is as follows:

[0038]

[0039] Among them, nis the vulnerability repair difficulty coefficient of the nth code range in the source code segment to be detected;

[0040] l n is the number of code characters between the nth code range and the first code range in the source code segment to be detected; L is the total length of the source code segment to be detected.

[0041] A storage medium stores instructions. When a computer reads the instructions, the computer executes the above-mentioned detection method for identifying weaknesses in source code using machine learning.

[0042] An electronic device includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the above-mentioned detection method for identifying weaknesses in source code using machine learning is implemented.

[0043] Compared with the prior art, the technical effects of the present invention are as follows:

[0044] 1. The present invention not only considers the execution path and control flow of the source code, but also combines the user input code use cases generated by the fuzz testing tool, as well as multiple factors such as path coverage and real-time resource occupancy, to comprehensively evaluate the weaknesses in the source code, which helps to more accurately identify and classify potential security vulnerabilities.

[0045] 2. The present invention automatically predicts the types of execution paths of each code range in the source code segment to be detected through a machine learning model, and evaluates the difficulty coefficient of vulnerability repair, thereby realizing automated and intelligent source code security detection, which not only improves the detection efficiency, but also reduces the need for manual intervention, making security detection faster and more efficient.

[0046] 3. The present invention predicts the types of execution paths of each code range in the source code segment to be detected through a weakness detection machine learning model, and evaluates the difficulty coefficient of vulnerability repair. It can discover potential security risk points in advance, which helps the development team to identify and repair problems in the early stages of software development, thereby reducing the cost and risk of later repairs. BRIEF DESCRIPTION OF THE DRAWINGS

[0047] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative labor.

[0048] in:

[0049] Figure 1A schematic diagram of a flow chart of a detection method for identifying weaknesses in source code using machine learning according to the present invention;

[0050] Figure 2 A schematic diagram of a process of predicting the execution path of a code segment to be detected by a vulnerability detection machine learning model of the present invention. DETAILED DESCRIPTION

[0051] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the specific implementation methods of the present invention are described in detail below in conjunction with the accompanying drawings.

[0052] In the following description, many specific details are set forth to facilitate a full understanding of the present invention, but the present invention may also be implemented in other ways different from those described herein, and those skilled in the art may make similar generalizations without violating the connotation of the present invention. Therefore, the present invention is not limited to the specific embodiments disclosed below.

[0053] Embodiment 1:

[0054] like Figure 1 , 2 As shown, a detection method for identifying weaknesses in source code using machine learning in an embodiment of the present invention is as follows: Figure 1 As shown, the specific steps are as follows:

[0055] S1: Configure the corresponding code detection environment according to the language characteristics of the source code segment to be detected;

[0056] S1 includes the following specific steps: first, configure the corresponding dynamic source code detection environment according to the language characteristics of the source code segment to be detected; then, determine the code range of the source code segment to be detected, set the dynamic source code detection environment variables, and synchronously install the required dependencies and libraries; finally, simulate the application usage behavior of real users.

[0057] S2: Obtain historical running data of historical source code, and establish a weakness detection machine learning model based on the historical running data, and predict the execution path type of each code range in the source code segment to be detected through the weakness detection machine learning model;

[0058] S2 includes the following specific steps:

[0059] S21: Obtain historical running data of historical source code, wherein the historical running data includes: historical execution path data, code feature data and execution environment data; the historical execution path data includes: code block execution order, number of conditional branches, and number of loop structure executions; the code feature data includes: function call relationship graph; the execution environment data includes: processor architecture, source code running container and network delay;

[0060] S22: establishing a weakness detection machine learning model according to the historical operation data, extracting the historical operation data of the historical source code, and combining the historical execution path data, code feature data and execution environment data of a single historical source code into a source code operation feature vector, to obtain a feature vector set of the historical source code;

[0061] S23: normalizing the feature vector set of the historical source code, wherein the normalization strategy is: Among them, g′ is the normalized data, g is the feature vector in the feature vector set of the historical source code, and g max is the characteristic maximum value, g min is the minimum value of the characteristic;

[0062] S24: dividing the feature vector set of the historical source code into a training set and a test set in a ratio of 8:2, inputting the training set into the weakness detection machine learning model for training, wherein the weakness detection machine learning model uses the matching degree between the historical source code in the training set and the historical source code in the test set as output and the actual matching degree as the matching target, thereby completing the training of the weakness detection machine learning model;

[0063] S25: Input each code range in the source code segment to be detected into the trained vulnerability detection machine learning model, and predict the execution path type of each code range in the source code segment to be detected through the vulnerability detection machine learning model.

[0064] Exemplarily, in this embodiment, in S22, the weakness detection machine learning model is a deep neural network model.

[0065] S3: Use the fuzz testing tool to randomly generate multiple user input code use cases, trigger abnormal execution behavior of the source code, synchronously build a control flow graph and analyze the control flow transfer degree coefficient of each node in the user input code use case during the injection process;

[0066] S3 includes the following specific steps:

[0067] S31: using a lexical analyzer and a syntax analyzer to process each code range in the source code segment to be detected, converting it into an abstract syntax tree, and at the same time dividing each code range in the source code segment to be detected into basic blocks, wherein the basic blocks are used to execute continuous instructions;

[0068] Exemplarily, in this embodiment, the lexical analyzer is a lexer, and the syntax analyzer is a parser.

[0069] S32: combining basic blocks and control flow edges between the basic blocks, and constructing a control flow graph from the source code segment to be detected;

[0070] S33: randomly generate multiple user input code use cases through a fuzz testing tool, and identify function call nodes related to the user input code use cases;

[0071] S34: Analyze the control flow transfer degree coefficient of the function call node in the injection process of the user input code use case;

[0072] The specific calculation strategy of the control flow transfer degree coefficient Z is as follows:

[0073] Z = z1 + z2;

[0074] Among them, z1 is the execution path length evaluation coefficient, jd 1,n The number of nodes in the actual execution path of the nth code range during the injection process for the user-input code use case; 2,n The number of nodes in the execution path of each code range in the source code segment to be detected is predicted by the weakness detection machine learning model; R1 is the screening threshold for the number of abnormal nodes;

[0075] z2 is the execution path complexity evaluation coefficient, fz 1,n The number of branches of the actual execution path of the nth code range during the injection process for the user-input code use case; fz 2,n The weakness detection machine learning model predicts the number of branches of the execution path of each code range in the source code segment to be detected; R2 is the screening threshold for the number of abnormal branches;

[0076] S35: extract the control flow transfer degree coefficient Z, set a transfer degree threshold, compare the control flow transfer degree coefficient Z with the set transfer degree threshold, filter the execution path whose control flow transfer degree coefficient Z is higher than the set transfer degree threshold and mark the control flow transfer as abnormal.

[0077] S4: quantify the path coverage and real-time resource occupancy of the application during the injection process of the user input code use case, and import the path coverage and real-time resource occupancy into the execution path anomaly judgment strategy to calculate the execution path anomaly rate of the source code segment to be detected;

[0078] S4 includes the following specific steps:

[0079] S41: Quantify the path coverage and real-time resource usage of the application during the injection process of the user input code use case;

[0080] The quantification strategy of the path coverage is: m n is the number of execution paths marked as control flow transfer exceptions in the execution path of the nth code range in the source code segment to be detected; M is the total number of execution paths of the code segment to be detected;

[0081] The quantification strategy of the real-time resource occupancy rate is: c n is the memory usage rate when the nth code range in the source code segment to be detected is executed; C is the total memory capacity of the processor;

[0082] S42: Importing the path coverage and real-time resource occupancy rate into the execution path anomaly judgment strategy to calculate the execution path anomaly rate of the source code segment to be detected; the execution path anomaly judgment strategy is specifically as follows:

[0083] fau n =α1×F n +α2×Y n ;

[0084] Among them, fau n is the execution path exception rate of the nth code range in the source code segment to be detected; α1 and α2 are the execution path exception impact ratios of the path coverage and real-time resource occupancy, respectively.

[0085] S5: Evaluate the vulnerability repair difficulty coefficient according to the execution path exception rate of the source code segment to be detected, and arrange the vulnerability repair difficulty coefficients of each code range in order.

[0086] In S5, the evaluation strategy for evaluating the vulnerability repair difficulty coefficient according to the execution path abnormality rate of the source code segment to be detected is as follows:

[0087]

[0088] Among them, n is the vulnerability repair difficulty coefficient of the nth code range in the source code segment to be detected;

[0089] l n is the number of code characters between the nth code range and the first code range in the source code segment to be detected; L is the total length of the source code segment to be detected.

[0090] Embodiment 2:

[0091] This embodiment provides an electronic device, including: a processor and a memory, wherein the memory stores a computer program that can be called by the processor;

[0092] The processor executes the above-mentioned detection method for identifying weaknesses in source code using machine learning by calling a computer program stored in the memory.

[0093] The electronic device may have relatively large differences due to different configurations or performances, and may include one or more processors (Central Processing Units, CPU) and one or more memories, wherein the memory stores at least one computer program, and the computer program is loaded and executed by the processor to implement a detection method for identifying weaknesses in source code using machine learning provided by the above method embodiment. The electronic device may also include other components for implementing device functions, for example, the electronic device may also have components such as a wired or wireless network interface and an input / output interface to input and output data. This embodiment will not be described in detail here.

[0094] Embodiment three:

[0095] This embodiment provides a computer-readable storage medium having a rewritable computer program stored thereon;

[0096] When the computer program runs on a computer device, the computer device executes the above-mentioned detection method of using machine learning to identify weaknesses in source code.

[0097] For example, the computer readable storage medium can be a read-only memory (ROM), a random access memory (RAM), a compact disc (CD-ROM), a magnetic tape, a floppy disk, an optical data storage device, etc.

[0098] It should be understood that in the various embodiments of the present application, the size of the serial numbers of the above-mentioned processes does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.

[0099] It should be understood that determining B based on A does not mean determining B only based on A. B can also be determined based on A and / or other information.

[0100] The above embodiments can be implemented in whole or in part by software, hardware, firmware or any other combination. When implemented by software, the above embodiments can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions or computer programs. When a computer instruction or computer program is loaded or executed on a computer, a process or function according to an embodiment of the present invention is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. Computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, computer instructions can be transmitted from one website site, computer, server or data center to another website site, computer, server or data center through a wired network or / and a wireless network. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that contains one or more available media sets. The available medium can be a magnetic medium (for example, a floppy disk, a hard disk, a tape), an optical medium (for example, a DVD), or a semiconductor medium. The semiconductor medium can be a solid-state hard disk.

[0101] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed in the present invention can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.

[0102] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.

[0103] In the several embodiments provided by the present invention, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic, for example, the division of units is only one, and there may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0104] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0105] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.

[0106] In the description of this specification, the description with reference to the terms "one embodiment", "example", "specific example", etc. means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present invention. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described can be combined in any one or more embodiments or examples in a suitable manner.

[0107] In summary, compared with the prior art, the technical effects of the present invention are as follows:

[0108] 1. The present invention not only considers the execution path and control flow of the source code, but also combines the user input code use cases generated by the fuzz testing tool, as well as multiple factors such as path coverage and real-time resource occupancy, to comprehensively evaluate the weaknesses in the source code, which helps to more accurately identify and classify potential security vulnerabilities.

[0109] 2. The present invention automatically predicts the types of execution paths of each code range in the source code segment to be detected through a machine learning model, and evaluates the difficulty coefficient of vulnerability repair, thereby realizing automated and intelligent source code security detection, which not only improves the detection efficiency, but also reduces the need for manual intervention, making security detection faster and more efficient.

[0110] 3. The present invention predicts the types of execution paths of each code range in the source code segment to be detected through a weakness detection machine learning model, and evaluates the difficulty coefficient of vulnerability repair. It can discover potential security risk points in advance, which helps the development team to identify and repair problems in the early stages of software development, thereby reducing the cost and risk of later repairs.

[0111] The above shows and describes the basic principles and main features of the present invention and the advantages of the present invention. It should be understood by those skilled in the art that the present invention is not limited to the above embodiments. The above embodiments and descriptions are only for explaining the principles of the present invention. Without departing from the spirit and scope of the present invention, the present invention may have various changes and improvements, which fall within the scope of the present invention to be protected. The scope of protection of the present invention is defined by the attached claims and their equivalents.

Claims

1. A detection method for identifying weaknesses in source code using machine learning, characterized in that: The method comprises the following specific steps: S1: Configure the corresponding code detection environment according to the language characteristics of the source code segment to be detected; S2: Obtain historical running data of historical source code, and establish a weakness detection machine learning model based on the historical running data, and predict the execution path type of each code range in the source code segment to be detected through the weakness detection machine learning model; S3: Use the fuzz testing tool to randomly generate multiple user input code use cases, trigger abnormal execution behavior of the source code, synchronously build a control flow graph and analyze the control flow transfer degree coefficient of each node in the user input code use case during the injection process; S4: quantify the path coverage and real-time resource occupancy of the application during the injection process of the user input code use case, and import the path coverage and real-time resource occupancy into the execution path anomaly judgment strategy to calculate the execution path anomaly rate of the source code segment to be detected; S5: Evaluate the vulnerability repair difficulty coefficient according to the execution path exception rate of the source code segment to be detected, and arrange the vulnerability repair difficulty coefficients of each code range in order.

2. The detection method for identifying weaknesses in source code using machine learning according to claim 1, characterized in that: S1 includes the following specific steps: first, configure the corresponding dynamic source code detection environment according to the language characteristics of the source code segment to be detected; then, determine the code range of the source code segment to be detected, set the dynamic source code detection environment variables, and synchronously install the required dependencies and libraries; finally, simulate the application usage behavior of real users.

3. The detection method for identifying weaknesses in source code using machine learning according to claim 2, characterized in that: S2 includes the following specific steps: S21: Obtain historical running data of historical source code, wherein the historical running data includes: historical execution path data, code feature data and execution environment data; the historical execution path data includes: code block execution order, number of conditional branches, and number of loop structure executions; the code feature data includes: function call relationship graph; the execution environment data includes: processor architecture, source code running container and network delay; S22: establishing a weakness detection machine learning model according to the historical operation data, extracting the historical operation data of the historical source code, and combining the historical execution path data, code feature data and execution environment data of a single historical source code into a source code operation feature vector, to obtain a feature vector set of the historical source code; S23: normalizing the feature vector set of the historical source code, wherein the normalization strategy is: Among them, g′ is the normalized data, g is the feature vector in the feature vector set of the historical source code, and g max is the characteristic maximum value, g min is the minimum value of the feature; S24: dividing the feature vector set of the historical source code into a training set and a test set in a ratio of 8:2, inputting the training set into the weakness detection machine learning model for training, wherein the weakness detection machine learning model uses the matching degree between the historical source code in the training set and the historical source code in the test set as output and the actual matching degree as the matching target, thereby completing the training of the weakness detection machine learning model; S25: Input each code range in the source code segment to be detected into the trained vulnerability detection machine learning model, and predict the execution path type of each code range in the source code segment to be detected through the vulnerability detection machine learning model.

4. The detection method for identifying weaknesses in source code using machine learning according to claim 3, characterized in that: In S22, the vulnerability detection machine learning model is any one of a deep neural network model, a deep belief network model or a Bayesian network model.

5. The detection method for identifying weaknesses in source code using machine learning according to claim 4, characterized in that: S3 includes the following specific steps: S31: using a lexical analyzer and a syntax analyzer to process each code range in the source code segment to be detected, converting it into an abstract syntax tree, and at the same time dividing each code range in the source code segment to be detected into basic blocks, wherein the basic blocks are used to execute continuous instructions; S32: combining basic blocks and control flow edges between the basic blocks, and constructing a control flow graph from the source code segment to be detected; S33: randomly generate multiple user input code use cases through a fuzz testing tool, and identify function call nodes related to the user input code use cases; S34: Analyze the control flow transfer degree coefficient of the function call node in the injection process of the user input code use case; The specific calculation strategy of the control flow transfer degree coefficient Z is as follows: Z = z1 + z2; Among them, z1 is the execution path length evaluation coefficient, jd 1,n The number of nodes in the actual execution path of the nth code range during the injection process for the user-input code use case; 2,n The number of nodes in the execution path of each code range in the source code segment to be detected is predicted by the weakness detection machine learning model; R1 is the screening threshold for the number of abnormal nodes; z2 is the execution path complexity evaluation coefficient, fz 1,n The number of branches of the actual execution path of the nth code range during the injection process for the user-input code use case; fz 2,n The weakness detection machine learning model predicts the number of branches of the execution path of each code range in the source code segment to be detected; R2 is the screening threshold for the number of abnormal branches; S35: extract the control flow transfer degree coefficient Z, set a transfer degree threshold, compare the control flow transfer degree coefficient Z with the set transfer degree threshold, filter the execution path whose control flow transfer degree coefficient Z is higher than the set transfer degree threshold and mark the control flow transfer as abnormal.

6. The detection method for identifying weaknesses in source code using machine learning according to claim 5, characterized in that: S4 includes the following specific steps: S41: Quantify the path coverage and real-time resource usage of the application during the injection process of the user input code use case; The quantification strategy of the path coverage is: m n is the number of execution paths marked as control flow transfer exceptions in the execution path of the nth code range in the source code segment to be detected; M is the total number of execution paths of the code segment to be detected; The quantification strategy of the real-time resource occupancy rate is: c n is the memory usage rate when the nth code range in the source code segment to be detected is executed; C is the total memory capacity of the processor; S42: Importing the path coverage and real-time resource occupancy rate into the execution path anomaly judgment strategy to calculate the execution path anomaly rate of the source code segment to be detected; the execution path anomaly judgment strategy is specifically as follows: fau n =α1×F n +α2×Y n ; Among them, fau n is the execution path exception rate of the nth code range in the source code segment to be detected; α1 and α2 are the execution path exception impact ratios of the path coverage and real-time resource occupancy, respectively.

7. The detection method for identifying weaknesses in source code using machine learning according to claim 6, characterized in that: In S5, the evaluation strategy for evaluating the vulnerability repair difficulty coefficient according to the execution path abnormality rate of the source code segment to be detected is as follows: Among them, n is the vulnerability repair difficulty coefficient of the nth code range in the source code segment to be detected; l n is the number of code characters between the nth code range and the first code range in the source code segment to be detected; L is the total length of the source code segment to be detected.

8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the detection method for identifying weaknesses in source code using machine learning as described in any one of claims 1 to 7 is implemented.

9. An electronic device, characterized in that: include: A memory for storing instructions; A processor is used to execute the instruction so that the device performs operations to implement a detection method for identifying weaknesses in source code using machine learning as described in any one of claims 1 to 7.

Citation Information

Patent Citations

  • Source code defect detection method and related device

    CN116627821A