Source code vulnerability detection method and device
By performing program slicing and false positive model analysis of static source code, false positive result report is generated, the problem of high false positive rate of static source code vulnerability detection is solved, the detection accuracy and efficiency are improved, and more valuable vulnerability detection is provided result.
Patent Information
- Application Number
- CN202211111594.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-13
- Publication Date
- 2024-11-08
- Estimated Expiration
- 2042-09-13
AI Technical Summary
The high false alarm rate of existing static source code vulnerability detection tools has caused developers to be inefficient when viewing scan reports, making it difficult to distinguish between real vulnerabilities and false alarms, and thus lose the reference value for static scan results.
By receiving vulnerability detection requests, the source code of the detection program is sliced according to the preset slicing criteria, the vulnerability program slice is filtered out, and the target false positive model is input to generate a false positive result report, and a vulnerability detection report is generated based on the scan analysis report. , including data on vulnerability and positive reports.
It reduces the false alarm rate of vulnerability detection, improves the accuracy and efficiency of vulnerability detection, reduces the patient consumption of developers during audits, and provides more valuable vulnerability detection reports.
Smart Images

Figure CN115510449B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of vulnerability detection technology, and in particular to a source code vulnerability detection method and device. Background Art
[0002] Code security testing is divided into binary code testing and source code security testing. Binary code-based testing has poor applicability and strict requirements. If the source code is directly manually reviewed, the efficiency is low and the test results vary greatly. Therefore, code auditing systems often use a combination of automated source code testing and manual auditing. SAST (static analysis security testing) has been developed along with the introduction of code security auditing technology and has become relatively mature. It has also become an automated testing method with a high market share in the industry.
[0003] SAST does not require the actual running of the program, but uses program analysis techniques such as taint analysis and data flow analysis to quickly and comprehensively analyze the source code of the program. Since static code detection tools must take into account both scanning efficiency and false positive rate, and some dynamic factors that affect the existence of vulnerabilities cannot be fixed in the rule base, its rule base has certain limitations, which will lead to false positives of vulnerabilities. When staff members review the scan reports generated by static vulnerability scanning tools, they face a large number of false positives in the reports, which makes it difficult to review, and they often lose patience and give up referring to static scanning vulnerability reports. Therefore, in order to enhance the reference significance of the test reports of static vulnerability testing tools, it is necessary to further reduce the false positive rate of the scanning results of static detection tools.
[0004] To address the above problems, no effective solution has been proposed yet. Summary of the invention
[0005] The embodiments of the present specification provide a source code vulnerability detection method and device to solve the problem of high false positive rate of vulnerability detection in the prior art.
[0006] The embodiment of this specification provides a source code vulnerability detection method, including:
[0007] Receive a vulnerability detection request; the vulnerability detection request carries the source code of the program to be detected and a scan analysis report; the scan analysis report is obtained by scanning the source code of the program to be detected using a static vulnerability detection tool; the scan analysis report includes a report vulnerability set;
[0008] Slicing the source code of the program to be detected according to a preset slicing criterion to obtain a plurality of program slices;
[0009] Based on the reported vulnerability set, filter out corresponding vulnerable program slices from the multiple program slices;
[0010] The vulnerable program slice and the vulnerability type corresponding to the vulnerable program slice are input into the target false alarm model, and a false alarm result report is output; a vulnerability detection report is generated based on the scanning analysis report and the false alarm result report; the vulnerability detection report includes false alarm vulnerability problem data and true alarm vulnerability problem data.
[0011] In one embodiment, the source code of the program to be detected is sliced according to a preset slicing criterion to obtain a plurality of program slices, including:
[0012] Performing code analysis on the source code of the program to be detected and constructing a corresponding program dependency graph;
[0013] Performing function call analysis on the program dependency graph to generate a cross-function program dependency graph;
[0014] Based on the program dependency graph, the cross-function program dependency graph and the preset slicing criterion, program slicing is performed on the source code of the program to be detected to obtain multiple program slices.
[0015] In one embodiment, the program dependency graph and the cross-function program dependency graph include a control flow graph and a data dependency graph;
[0016] Correspondingly, based on the program dependency graph, the cross-function program dependency graph and the preset slicing criteria, program slicing is performed on the source code of the program to be detected to obtain multiple program slices, including:
[0017] According to the preset slicing criteria, determining the vulnerability point to be sliced corresponding to the source code of the program to be detected;
[0018] Based on the control dependency relationship in the control flow graph and the data dependency relationship in the data dependency graph, determining a target suspected vulnerability path corresponding to the vulnerability point to be cut; the target suspected vulnerability path includes a dependency point corresponding to the vulnerability point to be cut;
[0019] Combine the vulnerability point to be cut with the target suspected vulnerability path to generate a suspected vulnerability path program slice.
[0020] In one embodiment, based on the control dependency relationship in the control flow graph and the data dependency relationship in the data dependency graph, determining the target suspected vulnerability path corresponding to the vulnerability point to be cut includes:
[0021] Analyze the source code of the program to be detected in the order of data dependency first and control dependency second for the vulnerability point to be cut, and generate a first suspicious vulnerability path;
[0022] Analyze the source code of the program to be detected in the order of control dependency first and data dependency second for the vulnerability point to be cut, and generate a second suspicious vulnerability path;
[0023] The first suspicious vulnerability path and the second suspicious vulnerability path are merged to obtain a target suspicious vulnerability path.
[0024] In one embodiment, the target false alarm model is obtained by the following steps:
[0025] Get batches of program source code;
[0026] Performing static scanning and program slicing on each program source code in the batch of program source codes to obtain a set of vulnerable program slices;
[0027] Based on the historical false alarm database, the vulnerability program slice set is analyzed to obtain a true alarm and false alarm data set; the historical false alarm database includes false alarm vulnerability problem data and true alarm vulnerability problem data;
[0028] Perform feature extraction on the set of vulnerable program slices to obtain a set of feature vectors; determine the label of each feature vector in the set of feature vectors using the true positive and false positive data set to obtain a set of labels corresponding to the set of feature vectors;
[0029] A support vector machine algorithm is used to perform machine learning on the feature vector set and the label set, and a target false alarm model is output.
[0030] In one embodiment, feature extraction is performed on the vulnerable program slice set to obtain a feature vector set, including:
[0031] Extracting an abstract syntax tree of a vulnerable program slice in the vulnerable program slice set to obtain a syntax feature vector;
[0032] Determine, based on the true positive and false positive data set, the vulnerability program slices belonging to the false positive type and the vulnerability program slices belonging to the true positive type in the vulnerability program slice set; extract the program dependency graph across functions for the vulnerability program slices belonging to the false positive type to obtain a semantic feature vector; extract the program dependency graph for the vulnerability program slices belonging to the true positive type to obtain a semantic feature vector;
[0033] Based on the grammatical feature vector and the semantic feature vector, a feature vector set corresponding to the vulnerable program slice set is generated.
[0034] In one embodiment, based on the historical false alarm database, the set of vulnerable program slices is analyzed to obtain a true alarm and false alarm data set, including:
[0035] Using the historical false alarm database, the vulnerable program slices in the vulnerable program slice set are matched to obtain a first true positive false alarm data set;
[0036] Performing data flow analysis on the vulnerable program slices in the vulnerable program slice set to obtain a second true positive and false positive data set;
[0037] The first true positive and false positive data set is merged with the second true positive and false positive data set to generate a true positive and false positive data set.
[0038] In one embodiment, the labels in the label set include: a false alarm type with a false alarm history, a positive alarm type with a false alarm history, and a positive alarm type without a false alarm history;
[0039] Accordingly, a support vector machine algorithm is used to perform machine learning on the feature vector set and the label set to output a target false alarm model, including:
[0040] A support vector machine algorithm is used to compare and learn the feature vectors corresponding to the false alarm type with a history of false alarms and the feature vectors corresponding to the positive alarm type with a history of false alarms; a support vector machine algorithm is used to compare and learn the feature vectors corresponding to the false alarm type with a history of false alarms and the feature vectors corresponding to the positive alarm type without a history of false alarms.
[0041] The embodiment of this specification also provides a source code vulnerability detection device, including:
[0042] A receiving module, configured to receive a vulnerability detection request; the vulnerability detection request carries a source code of a program to be detected and a scan analysis report; the scan analysis report is obtained by scanning the source code of the program to be detected using a static vulnerability detection tool; the scan analysis report includes a report vulnerability set;
[0043] A slicing module, used for slicing the source code of the program to be detected according to a preset slicing criterion to obtain a plurality of program slices;
[0044] A screening module, configured to screen out corresponding vulnerable program slices from the plurality of program slices based on the reported vulnerability set;
[0045] A detection module is used to input the vulnerable program slice and the vulnerability type corresponding to the vulnerable program slice into a target false alarm model, and output a false alarm result report; based on the scanning analysis report and the false alarm result report, a vulnerability detection report is generated; the vulnerability detection report includes false alarm vulnerability problem data and true alarm vulnerability problem data.
[0046] An embodiment of the present specification also provides a computer device, including a processor and a memory for storing processor executable instructions, wherein the processor implements the steps of the source code vulnerability detection method described in any of the above embodiments when executing the instructions.
[0047] The embodiments of this specification also provide a computer-readable storage medium on which computer instructions are stored. When the instructions are executed, the steps of the source code vulnerability detection method described in any of the above embodiments are implemented.
[0048] In an embodiment of the present specification, a source code vulnerability detection method is provided, which can receive a vulnerability detection request, wherein the vulnerability detection request carries a program source code to be detected and a scanning analysis report, wherein the scanning analysis report includes a report vulnerability set, and the program source code to be detected can be program sliced according to a preset slicing criterion to obtain multiple program slices, and based on the reported vulnerability set, corresponding vulnerability program slices are screened out from the multiple program slices, and the vulnerability program slices and the vulnerability types corresponding to the vulnerability program slices are input into a target false alarm model, and a false alarm result report is output, and then a vulnerability detection report can be generated based on the scanning analysis report and the false alarm result report, and the vulnerability detection report can include false alarm vulnerability problem data and true alarm vulnerability problem data. In the above scheme, after obtaining the source code of the program to be detected and the corresponding scanning analysis report including the reported vulnerability set, the source code of the program to be detected can be sliced, and the vulnerable program slices can be screened out from the program slices in combination with the reported vulnerability set, and the vulnerable program slices and the vulnerability types corresponding to the slices are input into the target false alarm model, and a false alarm result report is output. The false alarm result report can include the false alarm vulnerability program slices and their corresponding vulnerability data. After that, the false alarm result report can be combined with the scanning analysis report to obtain a vulnerability detection report containing false alarm vulnerability problem data and true alarm vulnerability problem data. In the above scheme, by performing false alarm analysis on the vulnerability problem data in the vulnerability set in the scanning analysis report through the trained target false alarm model, the false alarm vulnerability problem data and true alarm vulnerability problem data are determined, which can improve the accuracy and efficiency of vulnerability detection, thereby improving the efficiency of source code development. BRIEF DESCRIPTION OF THE DRAWINGS
[0049] The drawings described herein are used to provide a further understanding of this specification, constitute a part of this specification, and do not constitute a limitation of this specification. In the drawings:
[0050] Figure 1 A flow chart of a source code vulnerability detection method in an embodiment of this specification is shown;
[0051] Figure 2 The overall flow chart of the source code vulnerability detection method in an embodiment of this specification is shown;
[0052] Figure 3 A flowchart showing vulnerability data preparation of a target false alarm model of a source code vulnerability detection method in an embodiment of this specification is shown;
[0053] Figure 4 A flow chart showing the fusion of two paths in a source code vulnerability detection method in an embodiment of this specification is shown;
[0054] Figure 5 A flowchart showing the preparation of machine learning data in a source code vulnerability detection method in an embodiment of this specification is shown;
[0055] Figure 6 A schematic diagram of a source code vulnerability detection device in an embodiment of this specification is shown;
[0056] Figure 7 A schematic diagram of a computer device in an embodiment of the present specification is shown. DETAILED DESCRIPTION
[0057] The principles and spirit of this specification will be described below with reference to several exemplary embodiments. It should be understood that these embodiments are provided only to enable those skilled in the art to better understand and implement this specification, and are not intended to limit the scope of this specification in any way. On the contrary, these embodiments are provided to make this specification more thorough and complete, and to fully convey the scope of this disclosure to those skilled in the art.
[0058] Those skilled in the art will appreciate that the embodiments of this specification may be implemented as a system, device, method, or computer program product. Therefore, this specification may be implemented in the following forms: complete hardware, complete software (including firmware, resident software, microcode, etc.), or a combination of hardware and software.
[0059] The embodiments of this specification provide a method for detecting source code vulnerabilities. Figure 1 A flow chart of a source code vulnerability detection method in an embodiment of the present specification is shown. Although the present specification provides method operation steps or device structures as shown in the following embodiments or drawings, more or fewer operation steps or module units may be included in the method or device based on routine or no creative labor. In the steps or structures where there is no necessary causal relationship logically, the execution order of these steps or the module structure of the device is not limited to the execution order or module structure described in the embodiments of the present specification and shown in the drawings. When the method or module structure is applied to an actual device or terminal product, it can be connected according to the method or module structure shown in the embodiments or drawings for sequential execution or parallel execution (for example, a parallel processor or a multi-threaded processing environment, or even a distributed processing environment).
[0060] Specifically, Figure 1 As shown, a source code vulnerability detection method provided by an embodiment of this specification may include the following steps:
[0061] Step S101, receiving a vulnerability detection request; the vulnerability detection request carries the source code of the program to be detected and a scan analysis report; the scan analysis report is obtained by scanning the source code of the program to be detected using a static vulnerability detection tool; the scan analysis report includes a report vulnerability set.
[0062] The source code vulnerability detection method in this embodiment can be applied to a vulnerability detection server. The vulnerability detection server can receive a vulnerability detection request sent by a client. The vulnerability detection request can carry the source code of the program to be detected and the scanning analysis report of the static vulnerability detection tool.
[0063] The scanning and analysis report can be obtained by using any static detection tool to perform static scanning on the source code of the program to be detected. The static scanning here refers to static source code security scanning. Any static detection tool can be combined with its own vulnerability database and rule base to perform scanning and analysis on the source code of the program to be detected, thereby generating a scanning and analysis report. The scanning and analysis report can include a report vulnerability set. The report vulnerability set can include program fragments and their corresponding vulnerability information. Vulnerability information can include vulnerability name, outbreak line code and other vulnerability set information.
[0064] The server may be a single server, a server cluster, or a cloud server, etc., and the specific composition is not limited in this application. The client may be a desktop computer, a notebook, a mobile terminal, a PDA, etc., and the presentation of the client is not limited in this application.
[0065] Step S102, slicing the source code of the program to be detected according to a preset slicing criterion to obtain a plurality of program slices.
[0066] Step S103, based on the reported vulnerability set, filter out corresponding vulnerable program slices from the multiple program slices.
[0067] The vulnerability detection server can perform program slicing on the program code to be detected according to a preset slicing criterion. The slicing criterion can be preset. In one embodiment, the preset slicing criterion is a library / API function call, an array use, a pointer use, or an expression definition. In the slicing process, there is a function declaration, and the syntax structure of the code is retained when there is a branch control statement.
[0068] The vulnerability detection server can slice the source code of the program to be detected according to the preset slicing criteria to obtain multiple program slices, which show the code semantic information and grammatical structure. Therefore, program slicing not only retains the code semantic information but also shows the grammatical structure of the code, which will make the feature extraction more accurate later.
[0069] Afterwards, based on the vulnerability information in the reported vulnerability set, all program fragments associated with the vulnerability information in the vulnerability report set can be screened out from multiple program slices as program slices of the vulnerability. Specifically, based on the vulnerability outbreak line code information (including functions and variables) in the reported vulnerability set, the vulnerability program slice corresponding to the reported vulnerability set can be screened out from the multiple program slices.
[0070] Step S104, input the vulnerable program slice and the vulnerability type corresponding to the vulnerable program slice into the target false alarm model, and output a false alarm result report; generate a vulnerability detection report based on the scanning analysis report and the false alarm result report; the vulnerability detection report includes false alarm vulnerability problem data and true alarm vulnerability problem data.
[0071] After obtaining the vulnerability program slice corresponding to the source code of the program to be detected, the vulnerability program slice and the corresponding vulnerability type can be input into the target false alarm model to output a false alarm result report. Afterwards, a vulnerability detection report can be generated based on the scan analysis report and false alarm result report obtained by static scanning. The vulnerability detection report can include false alarm vulnerability problem data and true alarm vulnerability problem data. A true alarm means that the vulnerability problem detected by static scanning does exist. A false alarm means that the vulnerability problem detected by static scanning does not actually exist.
[0072] In the above embodiment, after obtaining the source code of the program to be detected and the corresponding scanning analysis report including the reported vulnerability set, the source code of the program to be detected can be program sliced, and the vulnerable program slices can be screened out from the program slices in combination with the reported vulnerability set, and the vulnerable program slices and the vulnerability types corresponding to the slices are input into the target false alarm model, and a false alarm result report is output. The false alarm result report can include the false alarm vulnerability program slices and their corresponding vulnerability data. After that, the false alarm result report can be combined with the scanning analysis report to obtain a vulnerability detection report containing false alarm vulnerability problem data and true alarm vulnerability problem data. In the above scheme, by performing false alarm analysis on the vulnerability problem data in the vulnerability set in the scanning analysis report through the trained target false alarm model, the false alarm vulnerability problem data and the true alarm vulnerability problem data are determined, which can improve the accuracy and efficiency of vulnerability detection, and thus improve the efficiency of source code development.
[0073] In some embodiments of the present specification, program slicing is performed on the source code of the program to be detected according to preset slicing criteria to obtain multiple program slices, including: performing code analysis on the source code of the program to be detected to construct a corresponding program dependency graph; performing function call analysis on the program dependency graph to generate a cross-function program dependency graph; and performing program slicing on the source code of the program to be detected based on the program dependency graph, the cross-function program dependency graph and the preset slicing criteria to obtain multiple program slices.
[0074] Specifically, in order to slice the source code of the program to be detected, the corresponding program dependency graph can be analyzed first. First, construct a program dependency graph (PDG), and then supplement and improve the information of its main function calling other sub-functions, generate a cross-function PDG, and break the function island of the slice. At the same time, each point of the cross-function PDG is marked with a digital serial number to facilitate the generation of subsequent slices. The preset slicing criteria are library / API function calls, array usage, pointer usage or expression definitions. There are function declarations during the slicing process, and the grammatical structure of the code is retained when there are branch control statements. Afterwards, based on the program dependency graph, the cross-function program dependency graph and the preset slicing criteria, the source code of the program to be detected is sliced to obtain multiple program slices, and the program slices show the semantic information and grammatical structure of the code. In the above manner, program slices of the source code of the program to be detected can be obtained.
[0075] In some embodiments of the present specification, the program dependency graph and the cross-function program dependency graph include a control flow graph and a data dependency graph; accordingly, based on the program dependency graph, the cross-function program dependency graph and the preset slicing criteria, the source code of the program to be detected is sliced to obtain multiple program slices, including: determining the vulnerability point to be cut corresponding to the source code of the program to be detected according to the preset slicing criteria; determining the target suspected vulnerability path corresponding to the vulnerability point to be cut based on the control dependency relationship in the control flow graph and the data dependency relationship in the data dependency graph; the target suspected vulnerability path includes the dependency point corresponding to the vulnerability point to be cut; combining the vulnerability point to be cut with the target suspected vulnerability path to generate a suspected vulnerability path program slice. In the above manner, a program slice with suspected vulnerability path characteristics can be generated.
[0076] In some embodiments of the present specification, based on the control dependencies in the control flow graph and the data dependencies in the data dependency graph, a target suspected vulnerability path corresponding to the vulnerability point to be cut is determined, including: analyzing the source code of the program to be detected in the order of data dependency first and control dependency for the vulnerability point to be cut, to generate a first suspected vulnerability path; analyzing the source code of the program to be detected in the order of control dependency first and data dependency for the vulnerability point to be cut, to generate a second suspected vulnerability path; merging the first suspected vulnerability path with the second suspected vulnerability path to obtain a target suspected vulnerability path.
[0077] Specifically, please refer to Figure 3 , showing a flow chart of vulnerability data preparation for the target false alarm model of the source code vulnerability detection method in an embodiment of the present specification. Since PDG includes a control flow graph (CFG) and a data dependency graph (DDG), the vulnerability points to be cut and their dependency points can be obtained in combination with the slicing criteria. The control dependencies in the control flow graph are mainly for three types of statements: conditional judgments, loops, and switches. The data dependencies in the data dependency graph focus on whether a certain variable in the program will be affected by other points, which is mainly divided into variable assignment and reading. Since control dependency and data dependency focus on different statements, the control dependency and data dependency paths related to the vulnerability points to be cut will be quite different, so two analysis methods with different analysis orders for control and data dependency are used to obtain paths 1 and 2 respectively, as shown in Figure 3 shown.
[0078] Path 1 is to analyze data dependency first and then control dependency. It analyzes the variable assignment and reading in the data dependency of the vulnerability point to be cut forward and backward, and adds the control dependency points to the results. This path analysis method enables the vulnerability point to be cut to have comprehensive data dependency points, while there is a possibility that some control dependency points are lost.
[0079] Path 2 is to analyze control dependency first and then data dependency. It analyzes the three statements in the control dependency statement forward and backward, and adds data dependency points to the results. This path analysis method enables the vulnerability points to be cut to have comprehensive control dependency points, while there is a possibility that some data dependency points are lost. Combining the vulnerability points to be cut with their final suspected vulnerability path, a suspected vulnerability path program slice can be generated.
[0080] In order to make the dependency points of the vulnerability points to be sliced in the final suspected vulnerability path program slicing comprehensive, it is not enough to only select the points where the control dependency and data dependency can verify each other, which will cause the loss of some dependency data. Therefore, this embodiment integrates and corrects the two path analysis methods to obtain the final suspected vulnerability path. Through the above program slicing method, it is possible to combine the scan report vulnerability set to cover as much relevant source code as possible required for vulnerability inspection, laying a solid data foundation for training the target false alarm model.
[0081] In some embodiments of the present specification, the target false alarm model is obtained by the following steps: obtaining a batch of program source codes; performing static scanning and program slicing on each program source code in the batch of program source codes to obtain a set of vulnerable program slices; analyzing the set of vulnerable program slices based on a historical false alarm database to obtain a true positive and false alarm data set; the historical false alarm database includes false positive vulnerability problem data and true positive vulnerability problem data; performing feature extraction on the set of vulnerable program slices to obtain a set of feature vectors; using the true positive and false alarm data set to determine the labels of each feature vector in the set of feature vectors to obtain a set of labels corresponding to the set of feature vectors; using a support vector machine algorithm to perform machine learning on the set of feature vectors and the set of labels to output a target false alarm model.
[0082] Specifically, the vulnerability detection server or the model training server can pre-build a target false alarm model. A batch of program source codes can be obtained. Each program source code in the batch of program source codes is statically scanned to generate a scan analysis report corresponding to each program source code; the scan analysis report corresponding to each program source code includes a report vulnerability set corresponding to each program source code. Each program source code in the batch of program source codes is program sliced according to a preset slicing criterion to obtain a plurality of program slices corresponding to each program source code. Based on the report vulnerability set corresponding to each program source code, the vulnerability program slice corresponding to each program source code is screened out from the plurality of program slices corresponding to each program source code to obtain a set of vulnerability program slices.
[0083] A historical false alarm database can be obtained. The historical false alarm database includes false alarm vulnerability problem data and true alarm vulnerability problem data. The true alarm false alarm data set is obtained by combining the historical false alarm database with the program slice data flow analysis results. The true alarm false alarm data set includes the vulnerable program slices in the vulnerable program slice set and whether they are true alarms or false alarms under the corresponding vulnerability problems. A true alarm means that the vulnerability does exist under the vulnerability type corresponding to the vulnerable program slice, and a false alarm means that the vulnerability does not exist under the vulnerability type corresponding to the vulnerable program slice. After obtaining the true alarm false alarm data set, the true alarm false alarm data set can be used to label the vulnerable program slices in the vulnerable program slice set to obtain the corresponding label set. Afterwards, the support vector machine algorithm can be used to perform machine learning on the feature vector set and the label set to output a target false alarm model. In the above manner, a target false alarm model can be obtained through machine learning.
[0084] In some embodiments of the present specification, feature extraction is performed on the vulnerable program slice set to obtain a feature vector set, including: extracting an abstract syntax tree of the vulnerable program slices in the vulnerable program slice set to obtain a grammatical feature vector; determining the vulnerable program slices of the false positive type and the vulnerable program slices of the true positive type in the vulnerable program slice set based on the true positive and false positive data sets; extracting a cross-function program dependency graph for the vulnerable program slices of the false positive type to obtain a semantic feature vector; extracting a program dependency graph for the vulnerable program slices of the true positive type to obtain a semantic feature vector; and generating a feature vector set corresponding to the vulnerable program slice set based on the grammatical feature vector and the semantic feature vector.
[0085] Specifically, by performing code analysis on the reported vulnerability set and its related vulnerability source code, an abstract syntax tree and a program dependency graph are extracted to obtain syntax features and semantic features. Combined with the names of the false alarm vulnerability problems in the false alarm database, the cross-function program dependency graph is extracted for the false alarm vulnerability problems under the vulnerability problem type. Compared with the program dependency graph without false alarm vulnerability problems, the cross-function program dependency graph with false alarm vulnerability problems supplements the relevant information of calling other functions in the function to generate a more accurate feature vector, and mines out certain code features of the false alarm vulnerability, thereby improving the ability of machine learning to identify false alarms. The grammatical and semantic feature vectors are extracted from the abstract syntax tree and the cross-function program dependency graph respectively, and the extraction of feature vectors can use relevant representation algorithms, such as graph2vec. Combine the grammatical and semantic feature vectors as the feature set of each vulnerability problem in the reported vulnerability set, and generate a feature vector set corresponding to the vulnerability program slice set. In the above manner, a more accurate feature vector can be generated, and certain code features of the false alarm vulnerability can be mined, thereby improving the ability of machine learning to identify false alarms.
[0086] In some embodiments of the present specification, the set of vulnerable program slices is analyzed based on a historical false alarm database to obtain a true positive and false alarm data set, including: using the historical false alarm database to match the vulnerable program slices in the set of vulnerable program slices to obtain a first true positive and false alarm data set; performing data flow analysis on the vulnerable program slices in the set of vulnerable program slices to obtain a second true positive and false alarm data set; and fusing the first true positive and false alarm data set with the second true positive and false alarm data set to generate a true positive and false alarm data set.
[0087] Specifically, the reported vulnerability set can be classified in combination with the historical false alarm database. The source of the false alarm database is the vulnerability report that has been manually modified in the past. The vulnerability classification is combined with the name of the false alarm vulnerability problem in the false alarm database (such as SQL injection, cross-site scripting, etc.), and the vulnerability problem type is secondary classified into whether there is a false alarm vulnerability problem under the corresponding vulnerability problem type. In combination with the historical false alarm database, the reported vulnerability set and its related source code are scanned to generate a first positive and false alarm data set. Based on the program dependency graph (the false alarm vulnerability problem is a program dependency graph across functions), the reported vulnerability set and its related vulnerability source code, data flow analysis is performed to generate a second positive and false alarm data set. Specifically, the security processing means of the code can be analyzed, including format filtering and content escape, format filtering includes a user-defined whitelist and filter function, and content escape includes the processing of a relatively mature rendering framework, thereby generating a second positive and false alarm data set. The first positive and false alarm data set is merged with the second positive and false alarm data set to generate a positive and false alarm data set. The second positive and false alarm data set can expand the false alarm data in the positive and false alarm data set. For a vulnerable program slice, if at least one of the first true positive false positive data set and the second true positive false positive data set is a false positive, the label of the vulnerable program slice in the final true positive false positive data set is a false positive. For a vulnerable program slice, if both the first true positive false positive data set and the second true positive false positive data set are true positive, the label of the vulnerable program slice in the final true positive false positive data set is a false positive. Through the above method, a cyclically iterative false positive database is adopted, and combined with its own format filtering and content escape, the timely expansion and update of false positive labels and the reduction of false positive rates are achieved, and the ability to automatically identify false positives is continuously improved.
[0088] In some embodiments of the present specification, the labels in the label set include: a false alarm type with a history of false alarms, a positive alarm type with a history of false alarms, and a positive alarm type without a history of false alarms; accordingly, a support vector machine algorithm is used to perform machine learning on the feature vector set and the label set, and a target false alarm model is output, including: using a support vector machine algorithm to compare and learn the feature vectors corresponding to the false alarm type with a history of false alarms and the feature vectors corresponding to the positive alarm type with a history of false alarms; using a support vector machine algorithm to compare and learn the feature vectors corresponding to the false alarm type with a history of false alarms and the feature vectors corresponding to the positive alarm type without a history of false alarms.
[0089] Considering that the classification feature extraction of the reported vulnerability set and its related source code is closely related to the accuracy of subsequent machine learning, in this embodiment, the false alarm vulnerability problems in the false alarm database are classified to obtain whether there are false alarm vulnerability problems under the corresponding vulnerability problem type, so that there are three types of data information under a certain vulnerability problem type in the subsequent machine learning (two categories of false alarm or true alarm vulnerabilities under historical false alarm records and one category of true alarm vulnerability problems without historical false alarm records). Therefore, this scheme divides the feature vectors of true alarms into two categories: one is the feature vectors of true alarms with false alarm records, and the other is the feature vectors of true alarms without false alarm records. During machine learning, the false alarm feature vectors with false alarm records are compared with the feature vectors of true alarms with false alarm records and the feature vectors of true alarms without false alarm records to obtain more comparison information, thereby improving the accuracy of machine learning.
[0090] In some embodiments of the present specification, after generating a vulnerability detection report based on the scanning analysis report and the false alarm result report, it may also include: updating a historical false alarm database based on the vulnerability detection report; the historical false alarm database includes false alarm vulnerability problem data and true alarm vulnerability problem data.
[0091] Specifically, after generating a vulnerability detection report, the historical false alarm database can be updated based on the vulnerability detection report. The historical false alarm database includes false alarm vulnerability problem data and true alarm vulnerability problem data. The false alarm database in this embodiment does not only rely on the initial historical database, but also adopts a cyclic iterative database, that is, a static and dynamic comprehensive false alarm data source, so as to achieve real-time update of the false alarm database data to improve the accuracy of feature extraction and the richness of false alarm labels.
[0092] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. For details, please refer to the description of the above-mentioned related processing related embodiments, and no further description is given here.
[0093] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0094] The above method is described below in conjunction with a specific embodiment. However, it should be noted that the specific embodiment is only for better illustrating the present specification and does not constitute an improper limitation on the present specification.
[0095] This specification discloses a vulnerability detection method for reducing the error rate of source code detection, so as to help developers reduce time costs and improve software robustness or provide a concise and effectively modifiable report to the code audit client. Figure 2 , shows the overall flow chart of the vulnerability detection method in this specific embodiment. The specific process can be as follows Figure 2 As shown, the vulnerability detection method in this embodiment includes the following steps.
[0096] Step 1: Generate a scan analysis report.
[0097] Scan and analyze the program source code through any static source code vulnerability detection tool to generate a scan analysis report.
[0098] Step 2: Generate a structured dataset
[0099] Step 1: Determine the slicing criteria. The slicing criteria adopted in this embodiment are four types of vulnerability syntax features (library / API function calls, array usage, pointer usage or expression definition, function declarations during slicing, and retaining the syntax structure of the code during branch control statements.
[0100] Step 2: Construct a program dependency graph (PDG).
[0101] Step 3: Supplement and improve the information of the main function calling other sub-functions in the PDG, generate a cross-function PDG, and break the function island of the slice. At the same time, digital serial numbers are marked on each point of the cross-function PDG to facilitate the subsequent generation of slices.
[0102] Step 4: Combine the slicing criteria to obtain the vulnerability points to be sliced and their dependency points. Control dependency mainly targets three statements: conditional judgment, loop, and switch. Data dependency focuses on whether a variable in the program will be affected by other points, which is mainly divided into variable assignment and reading. Since control dependency and data dependency focus on different statements, the paths of control dependency and data dependency related to the vulnerability points to be sliced will be quite different, so two analysis methods with different analysis orders for control and data dependency are used to obtain paths 1 and 2 respectively.
[0103] Path 1 is to analyze data dependency first and then control dependency: perform forward and backward analysis on the variable assignment and reading in the data dependency of the vulnerability point to be cut, and add the control dependency points to the results. This path analysis method enables the vulnerability point to be cut to have comprehensive data dependency points, while there is a possibility that some control dependency points are lost.
[0104] Path 2 is to analyze control dependency first and then data dependency: perform forward and backward analysis on the three statements in the control dependency statement, and add data dependency points to the results. This path analysis method enables the vulnerability points to be cut to have comprehensive control dependency points, while there is a possibility that some data dependency points are lost.
[0105] Step 6: In order to comprehensively define the dependency points of the vulnerability points to be sliced in the final suspected vulnerability path program slice, it is not sufficient to only select points where control dependency and data dependency can verify each other. Therefore, this embodiment integrates and corrects the two path analysis methods to obtain the final suspected vulnerability path.
[0106] Step 7: Combining the vulnerability point to be cut with its final suspected vulnerability path, a suspected vulnerability path program slice can be generated.
[0107] Step 8: Combine the vulnerability set reported by static scanning and select all suspicious path slices of the vulnerability to form the vulnerability slice set to be tested.
[0108] This embodiment performs fusion correction on the two paths to generate the final path, so that the control dependency and data dependency points related to the vulnerability point to be cut are comprehensive. Fusion correction is to process the differences of the points in the two paths that have a dependency relationship with the vulnerability point to be cut accordingly. The data dependency points and control dependency points at the same position can be directly merged into one point; the data points and control dependency points at different positions are all stored in the final path.
[0109] Assume that there are A1 and A2 data dependency points and control dependency points in path 1, and B1 and B2 data dependency points and control dependency points in path 2.
[0110] Please refer to Figure 4, shows a flow chart of two paths merging in a source code vulnerability detection method in an embodiment of this specification. Figure 4 As shown, fusion correction may include the following steps.
[0111] Step 1: Point D in path 1 that has data dependency on the vulnerability point to be cut 1i and control dependency point C 2m , i∈A1, m∈A2; Point C in path 1 that has control dependency with the vulnerability point to be cut 1j and data dependency point D 2n , j∈B1, n∈B2.
[0112] Step 2: Determine D 1i With D 2n Are the positions the same? If yes, go to step 3; otherwise, go to step 4; judge C 1j With C 2m If the positions of are the same, go to step 3, otherwise go to step 4. Since each point of the PDG across the function has been marked with a digital serial number, D 1i With D 2n , C 1j With C 2m They all correspond to the serial numbers of the points across the PDG function, so judgment can be made based on them. If the serial numbers of the points across the PDG function are consistent, it means that the positions are the same.
[0113] Step 3: D 1i With D 2n Merge into one point and record it as S k ; C 1j With C 2m Merge into one point and record it as S o .
[0114] Step 4: Unmerged D 1i Marked as S p ; Unmerged C 1j Marked as S q Since the data dependency point of path 1 is comprehensive, the data dependency point in path 2 is part of path 1, so the unmerged data dependency point is D 1i . C 1j Same reason.
[0115] Step 5: Determine S k With S o If the positions are the same, go to step 6, otherwise go to step 7. Since the cross-function PDG combines data dependency and control dependency into one, there is a point with two characteristics, so the combined S k With S o It is also necessary to judge the position and then merge. The judgment method of whether the position is the same or not is the same as the second step.
[0116] Step 6: S in the same position k With S o Merge a point and record it as S r .
[0117] Step 7: Unmerged S k With S o S s1 With S s2 .
[0118] Step 8: From the S in step 4 p With S q , S in the sixth step r and step 7 S s1 With S s2 Together they constitute all the dependency points of the vulnerability to be cut.
[0119] Step 9: Construct the final suspected vulnerability path based on the vulnerability point to be cut and all its dependent points.
[0120] Step 3: Train the false positive identification model.
[0121] Please refer to Figure 5 , which shows a flow chart of machine learning data preparation in a source code vulnerability detection method in an embodiment of this specification, such as Figure 5 As shown, the following steps are included.
[0122] Step 1: Classify the reported vulnerability set in combination with the historical false alarm database. Combined with the names of false alarm vulnerabilities in the false alarm database (such as SQL injection, cross-site scripting, etc.), classify them under the vulnerability problem type into vulnerabilities with or without false alarms under the corresponding vulnerability problem type.
[0123] Step 2: Extract the abstract syntax tree AST and program dependency graph PDG of the vulnerability source code related to the reported vulnerability set to obtain grammatical and semantic features.
[0124] Combined with the names of false positive vulnerability problems in the false positive database, the cross-function program dependency graph PDG is extracted for the false positive vulnerability problems under the vulnerability problem type. Compared with the program dependency graph PDG without false positive vulnerability problems, the cross-function program dependency graph PDG with false positive vulnerability problems supplements the relevant information of calling other functions in the function to generate a more accurate feature vector, and mines out certain code features of false positive vulnerabilities, thereby improving the ability of machine learning to identify false positives.
[0125] Step 3: Extract grammatical and semantic feature vectors from the abstract syntax tree AST and the cross-function program dependency graph PDG respectively. Relevant representation algorithms, such as graph2vec, can be used to extract feature vectors.
[0126] Step 4: Combine the grammatical feature vector and the semantic feature vector as the feature set of each vulnerability problem in the reported vulnerability set.
[0127] Step 5: Combine the historical false alarm database to match the source code related to the reported vulnerability set to generate the first positive alarm and false alarm data set.
[0128] Step 6: Combined with the program dependency graph PDG (false positive vulnerability issues are cross-function PDG), perform data flow analysis on the vulnerability source code related to the reported vulnerability set, and analyze the security processing methods of the code, including format filtering and content escape, to generate the second positive and false positive data set.
[0129] Step 7: Combine steps 5 and 6 to generate a dataset of positive and false positives.
[0130] Step 8: Obtain the corresponding false positive labels through the false positive dataset.
[0131] Step 9: Vulnerability false positive labeling automatically identifies and marks the vulnerability issues in the reported vulnerability set.
[0132] Step 10: Input the feature set of vulnerability issues that have been marked with false positive labels in the reported vulnerability set together with the feature set of unlabeled vulnerability issues into machine learning for classification learning.
[0133] This embodiment uses a support vector machine (SVM) algorithm for machine learning. SVM classifiers exist in the learning toolbox of related mathematical software, such as Matlab.
[0134] The basic principle of SVM algorithm classification is to first search for a hyperplane in the input feature space. The characteristic of this hyperplane is that it can optimally divide the label data according to the maximum boundary condition. i , the label value is b i ∈{-1,1}, then SVM is responsible for solving a hyperplane S, which is a strict convex optimization problem, as shown in formula (1). A robust classification method is used to classify the regularization term ||s|| 2 Weighted, when predicting label a i T When the sign of sr is positive, i is 0, and when the sign is negative, it increases linearly, so the goal of having a unique solution can be achieved.
[0135]
[0136] After machine learning is completed, a false alarm model can be generated. However, since the training of the machine learning model is very time-consuming, the false alarm model generated this time can be stored for application in the next false alarm vulnerability scan.
[0137] The false alarm database of this embodiment does not only rely on the original historical database, but adopts a cyclic iterative database, that is, a static and dynamic comprehensive false alarm data source, so as to achieve real-time updating of the false alarm database data to improve the accuracy of feature extraction and the richness of false alarm labels.
[0138] Step 4: Identify false positive vulnerabilities and output reports
[0139] The vulnerability slice set to be tested obtained in step 2 is input into the false alarm model trained in step 3 for detection to obtain a false alarm result report. Based on the scanning analysis report and the false alarm result report, a vulnerability detection report is generated.
[0140] The preset slicing criteria of this embodiment are library / API function calls, array usage, pointer usage or expression definition. In the slicing process, there are function declarations and branch control statements to preserve the grammatical structure of the code. Therefore, code slicing not only preserves the code semantic information but also displays the grammatical structure of the code, so the structured data set is more complete and accurate.
[0141] This embodiment combines two suspicious vulnerability path methods to construct code slices, and at the same time combines the vulnerability information in the scan report vulnerability set to filter out as much relevant source code as possible required for vulnerability false alarm verification, laying a solid data foundation for vulnerability false alarm identification.
[0142] This embodiment adopts a new classification feature extraction and false alarm label generation method. The label set is a false alarm type with a false alarm history record, a positive alarm type with a false alarm history record, and a positive alarm type without a false alarm history record, which improves the accuracy of machine learning in distinguishing true and false vulnerabilities. For the generation of false alarm labels, the traditional generation method is only based on the historical false alarm database, and does not combine its own characteristics, so the false alarm labels are not rich. This solution adopts a cyclically iterative false alarm database, which realizes the timely expansion and update of false alarm labels, and continuously improves the accuracy of automatic identification of false alarms.
[0143] In the feature vector extraction stage, this embodiment generates an abstract syntax tree and a program dependency graph (a program dependency graph across functions) for program slices, respectively, and extracts the semantic features and grammatical feature vectors of the code, thereby generating a more accurate feature vector set.
[0144] This embodiment adds detection of security processing in the code, such as format filtering and content escape processing. By detecting the security processing method in the code, some false positive vulnerabilities are screened out, thereby improving the accuracy of automatic correction and identification.
[0145] Based on the same inventive concept, a source code vulnerability detection device is also provided in the embodiments of this specification, as described in the following embodiments. Since the principle of solving the problem by the source code vulnerability detection device is similar to that of the source code vulnerability detection method, the implementation of the source code vulnerability detection device can refer to the implementation of the source code vulnerability detection method, and the repeated parts will not be repeated. As used below, the term "unit" or "module" can be a combination of software and / or hardware that implements a predetermined function. Although the device described in the following embodiments is preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceived. Figure 6 is a structural block diagram of a source code vulnerability detection device according to an embodiment of the present specification, such as Figure 6 As shown, it includes: a receiving module 601, a slicing module 602, a screening module 603 and a detection module 604, and the structure is described below.
[0146] The receiving module 601 is used to receive a vulnerability detection request; the vulnerability detection request carries the source code of the program to be detected and a scan analysis report; the scan analysis report is obtained by scanning the source code of the program to be detected using a static vulnerability detection tool; the scan analysis report includes a report vulnerability set.
[0147] The slicing module 602 is used to slice the source code of the program to be detected according to a preset slicing criterion to obtain multiple program slices.
[0148] The screening module 603 is used to screen out corresponding vulnerable program slices from the multiple program slices based on the reported vulnerability set.
[0149] The detection module 604 is used to input the vulnerable program slice and the vulnerability type corresponding to the vulnerable program slice into the target false alarm model, and output a false alarm result report; generate a vulnerability detection report based on the scanning analysis report and the false alarm result report; the vulnerability detection report includes false alarm vulnerability problem data and true alarm vulnerability problem data.
[0150] In some embodiments of the present specification, the slicing module is specifically used to: perform code analysis on the source code of the program to be detected to construct a corresponding program dependency graph; perform function call analysis on the program dependency graph to generate a cross-function program dependency graph; perform program slicing on the source code of the program to be detected based on the program dependency graph, the cross-function program dependency graph and the preset slicing criteria to obtain multiple program slices.
[0151] In some embodiments of the present specification, the program dependency graph and the cross-function program dependency graph include a control flow graph and a data dependency graph; accordingly, based on the program dependency graph, the cross-function program dependency graph and the preset slicing criteria, the source code of the program to be detected is sliced to obtain multiple program slices, including: determining the vulnerability point to be cut corresponding to the source code of the program to be detected according to the preset slicing criteria; determining the target suspected vulnerability path corresponding to the vulnerability point to be cut based on the control dependency relationship in the control flow graph and the data dependency relationship in the data dependency graph; the target suspected vulnerability path includes the dependency point corresponding to the vulnerability point to be cut; and generating a suspicious vulnerability path program slice by combining the vulnerability point to be cut and the target suspected vulnerability path.
[0152] In some embodiments of the present specification, based on the control dependencies in the control flow graph and the data dependencies in the data dependency graph, a target suspected vulnerability path corresponding to the vulnerability point to be cut is determined, including: analyzing the source code of the program to be detected in the order of data dependency first and control dependency later for the vulnerability point to be cut, to generate a first suspected vulnerability path; analyzing the source code of the program to be detected in the order of control dependency first and data dependency later for the vulnerability point to be cut, to generate a second suspected vulnerability path; merging the first suspected vulnerability path with the second suspected vulnerability path to obtain a target suspected vulnerability path.
[0153] In some embodiments of the present specification, the target false alarm model is obtained by the following steps: obtaining a batch of program source codes; performing static scanning and program slicing on each program source code in the batch of program source codes to obtain a set of vulnerable program slices; analyzing the set of vulnerable program slices based on a historical false alarm database to obtain a true positive and false alarm data set; the historical false alarm database includes false positive vulnerability problem data and true positive vulnerability problem data; performing feature extraction on the set of vulnerable program slices to obtain a set of feature vectors; using the true positive and false alarm data set to determine the labels of each feature vector in the set of feature vectors to obtain a set of labels corresponding to the set of feature vectors; using a support vector machine algorithm to perform machine learning on the set of feature vectors and the set of labels to output a target false alarm model.
[0154] In some embodiments of the present specification, feature extraction is performed on the vulnerable program slice set to obtain a feature vector set, including: extracting an abstract syntax tree of the vulnerable program slices in the vulnerable program slice set to obtain a grammatical feature vector; determining the vulnerable program slices of the false positive type and the vulnerable program slices of the true positive type in the vulnerable program slice set based on the true positive and false positive data sets; extracting a cross-function program dependency graph for the vulnerable program slices of the false positive type to obtain a semantic feature vector; extracting a program dependency graph for the vulnerable program slices of the true positive type to obtain a semantic feature vector; and generating a feature vector set corresponding to the vulnerable program slice set based on the grammatical feature vector and the semantic feature vector.
[0155] In some embodiments of the present specification, the set of vulnerable program slices is analyzed based on a historical false alarm database to obtain a true positive and false alarm data set, including: using the historical false alarm database to match the vulnerable program slices in the set of vulnerable program slices to obtain a first true positive and false alarm data set; performing data flow analysis on the vulnerable program slices in the set of vulnerable program slices to obtain a second true positive and false alarm data set; and fusing the first true positive and false alarm data set with the second true positive and false alarm data set to generate a true positive and false alarm data set.
[0156] In some embodiments of the present specification, the labels in the label set include: a false alarm type with a history of false alarms, a positive alarm type with a history of false alarms, and a positive alarm type without a history of false alarms; accordingly, a support vector machine algorithm is used to perform machine learning on the feature vector set and the label set, and a target false alarm model is output, including: using a support vector machine algorithm to compare and learn the feature vectors corresponding to the false alarm type with a history of false alarms and the feature vectors corresponding to the positive alarm type with a history of false alarms; using a support vector machine algorithm to compare and learn the feature vectors corresponding to the false alarm type with a history of false alarms and the feature vectors corresponding to the positive alarm type without a history of false alarms.
[0157] In some embodiments of the present specification, the device may further include: an update module, used to update a historical false alarm database based on the vulnerability detection report; the historical false alarm database includes false alarm vulnerability problem data and true alarm vulnerability problem data.
[0158] From the above description, it can be seen that the embodiments of this specification achieve the following technical effects: after obtaining the source code of the program to be detected and the corresponding scanning analysis report including the reported vulnerability set, the source code of the program to be detected can be sliced, and the vulnerable program slices can be screened out from the program slices in combination with the reported vulnerability set, and the vulnerable program slices and the vulnerability types corresponding to the slices are input into the target false alarm model, and a false alarm result report is output. The false alarm result report can include the false alarm vulnerability program slices and their corresponding vulnerability data. After that, the false alarm result report can be combined with the scanning analysis report to obtain a vulnerability detection report containing false alarm vulnerability problem data and true alarm vulnerability problem data. In the above scheme, by performing false alarm analysis on the vulnerability problem data in the vulnerability set in the scanning analysis report through the trained target false alarm model, the false alarm vulnerability problem data and the true alarm vulnerability problem data are determined, which can improve the accuracy and efficiency of vulnerability detection, thereby improving the efficiency of source code development.
[0159] This specification also provides a computer device, which can be found in Figure 7 The computer device structure diagram of the source code vulnerability detection method provided by the embodiment of this specification is shown, and the computer device may specifically include an input device 71, a processor 72, and a memory 73. Among them, the memory 73 is used to store processor executable instructions. When the processor 72 executes the instructions, the steps of the source code vulnerability detection method described in any of the above embodiments are implemented.
[0160] In this embodiment, the input device may specifically be one of the main devices for information exchange between the user and the computer system. The input device may include a keyboard, a mouse, a camera, a scanner, a light pen, a handwriting input board, a voice input device, etc.; the input device is used to input the original data and the program for processing these numbers into the computer. The input device can also obtain and receive data transmitted from other modules, units, and devices. The processor can be implemented in any appropriate manner. For example, the processor can take the form of a computer-readable medium, a logic gate, a switch, an application-specific integrated circuit (Application Specific Integrated Circuit, ASIC), a programmable logic controller, and an embedded microcontroller, etc., such as a microprocessor or a processor and a computer-readable program code (such as software or firmware) that can be executed by the (micro) processor. The memory may specifically be a memory device used to store information in modern information technology. The memory may include multiple levels. In a digital system, anything that can store binary data can be a memory; in an integrated circuit, a circuit with a storage function without a physical form is also called a memory, such as a RAM, a FIFO, etc.; in a system, a storage device with a physical form is also called a memory, such as a memory stick, a TF card, etc.
[0161] In this embodiment, the functions and effects specifically realized by the computer device can be explained in comparison with other embodiments and will not be described in detail here.
[0162] The present specification also provides a computer storage medium based on the source code vulnerability detection method, wherein the computer storage medium stores computer program instructions, and when the computer program instructions are executed, the steps of the source code vulnerability detection method described in any of the above embodiments are implemented.
[0163] In this embodiment, the storage medium includes, but is not limited to, a random access memory (RAM), a read-only memory (ROM), a cache, a hard disk (HDD) or a memory card. The memory may be used to store computer program instructions. The network communication unit may be an interface for network connection communication set in accordance with the standard specified by the communication protocol.
[0164] In this embodiment, the functions and effects specifically implemented by the program instructions stored in the computer storage medium can be explained in comparison with other embodiments and will not be repeated here.
[0165] Obviously, those skilled in the art should understand that the modules or steps of the above-mentioned embodiments of this specification can be implemented by a general computing device, they can be concentrated on a single computing device, or distributed on a network composed of multiple computing devices, and optionally, they can be implemented by a program code executable by a computing device, so that they can be stored in a storage device and executed by the computing device, and in some cases, the steps shown or described can be executed in a different order from that here, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. In this way, the embodiments of this specification are not limited to any specific combination of hardware and software.
[0166] It should be understood that the above description is for illustration and not for limitation. Many embodiments and many applications beyond the examples provided will be apparent to those skilled in the art upon reading the above description. Therefore, the scope of this specification should not be determined with reference to the above description, but should be determined with reference to the preceding claims and the full scope of equivalents to which these claims belong.
[0167] The above description is only the preferred embodiment of this specification and is not intended to limit this specification. For those skilled in the art, the embodiments of this specification may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of this specification shall be included in the protection scope of this specification.
Claims
1. A source code vulnerability detection method, characterized in that: include: Receive vulnerability detection requests; The vulnerability detection request carries the source code of the program to be detected and a scanning analysis report; The scanning analysis report is obtained by scanning the source code of the program to be detected using a static vulnerability detection tool; The scanning analysis report includes a report vulnerability set; Slicing the source code of the program to be detected according to a preset slicing criterion to obtain a plurality of program slices; Based on the reported vulnerability set, filter out corresponding vulnerable program slices from the multiple program slices; Input the vulnerable program slice and the vulnerability type corresponding to the vulnerable program slice into the target false alarm model, and output a false alarm result report; Generate a vulnerability detection report based on the scanning analysis report and the false alarm result report; the vulnerability detection report includes false alarm vulnerability problem data and true alarm vulnerability problem data; The target false alarm model is obtained by the following steps: Get batches of program source code; Performing static scanning and program slicing on each program source code in the batch of program source codes to obtain a set of vulnerable program slices; Based on the historical false alarm database, the vulnerability program slice set is analyzed to obtain a true alarm and false alarm data set; the historical false alarm database includes false alarm vulnerability problem data and true alarm vulnerability problem data; Perform feature extraction on the set of vulnerable program slices to obtain a set of feature vectors; determine the label of each feature vector in the set of feature vectors using the true positive and false positive data set to obtain a set of labels corresponding to the set of feature vectors; Performing machine learning on the feature vector set and the label set using a support vector machine algorithm to output a target false alarm model; Using a support vector machine algorithm to perform machine learning on the feature vector set and the label set, and outputting a target false alarm model, including: The support vector machine algorithm is used to compare and learn the feature vectors corresponding to the false alarm type with a history of false alarms and the feature vectors corresponding to the positive alarm type with a history of false alarms; the support vector machine algorithm is used to compare and learn the feature vectors corresponding to the false alarm type with a history of false alarms and the feature vectors corresponding to the positive alarm type without a history of false alarms.
2. The source code vulnerability detection method according to claim 1, characterized in that: The source code of the program to be detected is sliced according to a preset slicing criterion to obtain a plurality of program slices, including: Performing code analysis on the source code of the program to be detected and constructing a corresponding program dependency graph; Performing function call analysis on the program dependency graph to generate a cross-function program dependency graph; Based on the program dependency graph, the cross-function program dependency graph and the preset slicing criterion, program slicing is performed on the source code of the program to be detected to obtain multiple program slices.
3. The source code vulnerability detection method according to claim 2, characterized in that: The program dependency graph and the cross-function program dependency graph include a control flow graph and a data dependency graph; Correspondingly, based on the program dependency graph, the cross-function program dependency graph and the preset slicing criteria, program slicing is performed on the source code of the program to be detected to obtain multiple program slices, including: According to the preset slicing criteria, determining the vulnerability point to be sliced corresponding to the source code of the program to be detected; Based on the control dependency relationship in the control flow graph and the data dependency relationship in the data dependency graph, determining a target suspected vulnerability path corresponding to the vulnerability point to be cut; the target suspected vulnerability path includes a dependency point corresponding to the vulnerability point to be cut; Combine the vulnerability point to be cut with the target suspected vulnerability path to generate a suspected vulnerability path program slice.
4. The source code vulnerability detection method according to claim 3, characterized in that: Determining a target suspected vulnerability path corresponding to the vulnerability point to be cut based on the control dependency relationship in the control flow graph and the data dependency relationship in the data dependency graph includes: Analyze the source code of the program to be detected in the order of data dependency first and control dependency second for the vulnerability point to be cut, and generate a first suspicious vulnerability path; Analyze the source code of the program to be detected in the order of control dependency first and data dependency second for the vulnerability point to be cut, and generate a second suspicious vulnerability path; The first suspicious vulnerability path and the second suspicious vulnerability path are merged to obtain a target suspicious vulnerability path.
5. The source code vulnerability detection method according to claim 1, characterized in that: Perform feature extraction on the vulnerable program slice set to obtain a feature vector set, including: Extracting an abstract syntax tree of a vulnerable program slice in the vulnerable program slice set to obtain a syntax feature vector; Determine, based on the true positive and false positive data set, the vulnerability program slices belonging to the false positive type and the vulnerability program slices belonging to the true positive type in the vulnerability program slice set; extract the program dependency graph across functions for the vulnerability program slices belonging to the false positive type to obtain a semantic feature vector; extract the program dependency graph for the vulnerability program slices belonging to the true positive type to obtain a semantic feature vector; Based on the grammatical feature vector and the semantic feature vector, a feature vector set corresponding to the vulnerable program slice set is generated.
6. The source code vulnerability detection method according to claim 1, characterized in that: Based on the historical false positive database, the vulnerability program slice set is analyzed to obtain a true positive and false positive data set, including: Using the historical false alarm database, the vulnerable program slices in the vulnerable program slice set are matched to obtain a first true positive false alarm data set; Performing data flow analysis on the vulnerable program slices in the vulnerable program slice set to obtain a second true positive and false positive data set; The first true positive and false positive data set is merged with the second true positive and false positive data set to generate a true positive and false positive data set.
7. A source code vulnerability detection device, characterized in that: include: A receiving module, used for receiving a vulnerability detection request; The vulnerability detection request carries the source code of the program to be detected and a scanning analysis report; The scanning analysis report is obtained by scanning the source code of the program to be detected using a static vulnerability detection tool; The scanning analysis report includes a report vulnerability set; A slicing module, used for slicing the source code of the program to be detected according to a preset slicing criterion to obtain a plurality of program slices; A screening module, configured to screen out corresponding vulnerable program slices from the plurality of program slices based on the reported vulnerability set; A detection module, used for inputting the vulnerable program slice and the vulnerability type corresponding to the vulnerable program slice into a target false alarm model, and outputting a false alarm result report; Generate a vulnerability detection report based on the scanning analysis report and the false alarm result report; the vulnerability detection report includes false alarm vulnerability problem data and true alarm vulnerability problem data; The target false alarm model is obtained by the following method: obtaining a batch of program source codes; performing static scanning and program slicing on each program source code in the batch of program source codes to obtain a set of vulnerable program slices; analyzing the set of vulnerable program slices based on a historical false alarm database to obtain a set of true positive and false alarm data; the historical false alarm database includes false positive vulnerability problem data and true positive vulnerability problem data; performing feature extraction on the set of vulnerable program slices to obtain a set of feature vectors; using the true positive and false alarm data set to determine the labels of each feature vector in the set of feature vectors to obtain a set of labels corresponding to the set of feature vectors; using a support vector machine algorithm to perform machine learning on the set of feature vectors and the set of labels to output a target false alarm model; wherein, using a support vector machine algorithm to perform machine learning on the set of feature vectors and the set of labels to output a target false alarm model includes: using a support vector machine algorithm to compare and learn the feature vectors corresponding to the false alarm type with a false alarm history with the feature vectors corresponding to the true alarm type with a false alarm history; using a support vector machine algorithm to compare and learn the feature vectors corresponding to the false alarm type with a false alarm history with the feature vectors corresponding to the true alarm type without a false alarm history.
8. A computer-readable storage medium having computer instructions stored thereon, characterized in that: When the instructions are executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
Citation Information
Patent Citations
Fine-grained vulnerability detection method based on depth features
CN109657473A
Source code security analysis method based on historical optimization feature intelligent learning
CN112148602A
Code vulnerability intelligent detection method based on man-machine cooperation
CN113742205A
Multi-type vulnerability detection method based on BGRU and CNN fusion model
CN114861194A
Dynamic image and image marker tracking
US10089752B1
