A code semantic redundancy measurement verification method based on learnable model triggerability
By generating a hybrid code dataset and inserting triggers, a backdoor neural network model is trained, and the semantic redundancy space is verified and measured. This solves the problem that deep learning models in existing technologies are vulnerable to text backdoor attacks, and achieves more efficient vulnerability detection.
Patent Information
- Application Number
- CN202211088884.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-07
- Publication Date
- 2025-11-25
- Estimated Expiration
- 2042-09-07
AI Technical Summary
The lack of existing methods for verifying and measuring the semantic redundancy space of code data makes deep learning models vulnerable to security threats from text backdoor attacks.
By generating a hybrid code dataset, inserting triggers and performing code semantic representation, training a backdoor neural network model, verifying and measuring the semantic redundancy space, and using a benign neural network model for training and compressing the redundancy space.
Accurately verify and measure semantic redundancy space, reduce the security threat of deep learning models to text backdoor attacks, and improve the generalization ability of vulnerability detection models.
Smart Images

Figure CN116301875B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of software analysis, in particular to a code semantic redundancy measurement verification method based on learning model triggerability. BACKGROUND
[0002] In recent years, the scale and complexity of software are increasing, which increases the cost of code auditing, reverse analysis and vulnerability mining based on manual means. Deep learning technology is applied to software code dynamic and static analysis and vulnerability automatic detection fields due to its ability to quickly mine features from massive data. Code analysis based on deep neural network (DNN) can understand the complex semantics of code logic, breaking through the bottleneck problem of high false positive rate / false negative rate of traditional code analysis technology, and thus has higher accuracy than traditional code analysis methods. For multi-language, cross-platform and logic nested code samples, deep learning-based code analysis automatically mines information flow features from a large number of code samples, thereby replacing manual data flow and control flow representation and analysis. For example, a recurrent neural network is used to process serialized code text with context relationship, understand the semantics of the code text and improve the accuracy and efficiency of vulnerability detection.
[0003] However, in the process of compiling source code into executable files, the source code and its complex intermediate representation will generate a large amount of semantic redundancy irrelevant to the code logic. Moreover, the one-to-many mapping between code logic and software form will mislead the deep learning model to capture non-common features of software samples, i.e., the semantic redundancy space generated in the process of representing and transforming code semantics is vulnerable to security threats caused by text backdoor attacks.
[0004] Backdoor attack is achieved by adding a trigger to the input sample. If the added trigger is in the semantic redundancy space, the attack success rate will have stronger concealment and higher success rate. If the semantic redundancy space of code data can be verified and measured, and the semantic redundancy space is compressed accordingly, the security threat caused by text backdoor attack on code data can be reduced. However, the existing technology lacks a technical method for verifying and measuring the semantic redundancy space, so the code data of the existing technology is still in the security threat caused by text backdoor attack. SUMMARY
[0005] The present application relates to the technical field of software analysis, in particular to a code semantic redundancy measurement verification method based on learning model triggerability.
[0006] The object of the present application can be achieved by the following technical solutions:
[0007] The application provides a code semantic redundancy measurement verification method based on learnable model triggerability, which is used for verifying and measuring semantic redundancy space generated in the process of converting target code data into a feature vector, and comprises the following steps:
[0008] S1: generating a mixed code data set comprising a non-malicious code data set and a malicious code data set, and dividing the mixed code data set into a training set and a test set;
[0009] S2: inserting a trigger in the training set to serve as a first training set, performing code semantic representation on the first training set, poisoning in the code semantic representation process, obtaining a poisoned code semantic representation result, processing the poisoned code semantic representation result into a feature vector, inputting the feature vector into a benign neural network model for training, and obtaining a backdoor neural network model;
[0010] S3: inserting a trigger in the test set to obtain a first test set, sequentially performing code semantic representation and processing operations on the first test set, inputting the first test set into the backdoor neural network model, and judging whether a semantic redundancy space is generated in the process of converting target code data into a feature vector according to the output result of the backdoor neural network model.
[0011] Preferably, S2 comprises the following steps:
[0012] S2.1: traversing all code data in the training set, determining code data in which a trigger is inserted, and inserting the trigger into a semantic redundancy space of the code data to obtain a first training set;
[0013] S2.2: performing code semantic representation on the first training set, poisoning in the code semantic representation process, and obtaining a poisoned code semantic representation result;
[0014] S2.3: converting the code semantic representation result obtained in S2.2 into a feature vector, inputting the feature vector into a benign neural network model for training, and obtaining a backdoor neural network model.
[0015] Preferably, the formula for describing the trigger insertion process in S2.1 is as follows:
[0016]
[0017] wherein, is a poisoning result after a trigger is inserted into code data i located at stage M in a code processing cycle, the Insert() function is a function for inserting the trigger T i into the code data i, is a semantic redundancy space in which the trigger is inserted into the code data i located at stage M in the code processing cycle, The semantic space related to the code function of the code data i that needs to be avoided when inserting the trigger to the code data i.
[0018] Preferably, in S2.3, the process of training the benign neural network model into a backdoor neural network model is regarded as a constrained optimization problem, and the formula describing the optimization problem is specifically:
[0019]
[0020]
[0021] Wherein, F is a benign neural network model, is a directional label corresponding to the code data containing the trigger, k is the number of code data, is a loss function, and * is an optimization model parameter, is a malicious code data set, The semantic space related to the code function of the code data i that needs to be avoided when inserting the trigger to the code data i.
[0022] Preferably, after performing S3, if it is verified that a semantic redundancy space is generated in the process of converting the target code data into a feature vector, then S4 is performed, and S4 is specifically:
[0023] A semantic redundancy source analysis model is constructed, and the real semantic redundancy space of the target code data is obtained according to the semantic redundancy source analysis model; and the semantic redundancy space generated in the verification of S3 is compressed according to the real semantic redundancy space of the target code data and the semantic redundancy space of the code data inserted with the trigger in S2.1.
[0024] Preferably, the S4 includes the following steps:
[0025] S4.1: A semantic redundancy source analysis model is constructed according to the semantic redundancy information of different code compilation stages in a code processing period;
[0026] S4.2: The code compilation stages involved in the target code data are compared with the analysis results of the semantic redundancy source analysis model, and the semantic redundancy source of the target code data is determined according to the generation and inheritance of semantic information, so as to obtain the real semantic redundancy space of the target code data;
[0027] S4.3: The semantic redundancy space verified in S3 is compressed according to the real semantic redundancy space obtained in S4.2 and the semantic redundancy space of the code data inserted with the trigger in S2.1.
[0028] Preferably, the semantic redundancy source analysis rule of the code compilation stage, i.e., the target stage, involved in the target code data in S4.2 is:
[0029] The information that the target stage is discarded and converted in the subsequent stage is classified as semantic redundancy information that is not required for the final function of the binary code.
[0030] The semantic redundancy information inherited by the target stage from the previous stage is classified as semantic redundancy information that is not required for the final function of the binary code.
[0031] The semantic information generated by the target stage in the processing process of the current stage is classified as semantic redundancy information that is not required for the final function of the binary code.
[0032] The semantic redundancy information that is not required for the final function of the binary code and is retained when the target stage is represented is classified as semantic redundancy inherited by the representation process.
[0033] The semantic information generated when the target stage is represented is classified as semantic redundancy generated by the representation process.
[0034] Preferably, in S3, the process of determining whether a semantic redundancy space is generated in the process of converting the target code data into the feature vector according to the output result of the backdoor neural network model is specifically:
[0035] If the poisoning accuracy of the backdoor neural network model is higher than the set threshold, a threatening semantic redundancy space is generated in the process of converting the target code data into the feature vector.
[0036] If the poisoning accuracy of the backdoor neural network model is lower than the set threshold, a threatening semantic redundancy space is not generated in the process of converting the target code data into the feature vector.
[0037] Preferably, the poisoning accuracy of the backdoor neural network model is the classification accuracy of the backdoor neural network model on the malicious code data set.
[0038] Preferably, the training process of the benign neural network model is: sequentially performing code semantic representation and conversion operations on the training set in the mixed code data set in S1, thereby obtaining a benign feature vector, inputting the benign feature vector into the neural network for training, and obtaining the benign neural network model.
[0039] Compared with the prior art, the present application has the following beneficial effects:
[0040] The application provides a code semantic redundancy measurement verification method based on learning model triggerability, which inserts a trigger in a semantic redundancy space of code data by adding a malicious code data set to a mixed code data set, simulates a backdoor attack, and then processes the data set with the added malicious code data set and the inserted trigger, and trains a backdoor neural network model, verifies the classification accuracy of the backdoor neural network model through a poisoning accuracy, and can accurately verify whether semantic redundancy space is generated in the process of converting target code data into a feature vector. The application solves the problem that the prior art lacks a technical method for verifying and measuring semantic redundancy space, and makes the code data in the prior art still in a security threat caused by a text backdoor attack. BRIEF DESCRIPTION OF DRAWINGS
[0041] Figure 1 A flowchart of the application of the code semantic redundancy measurement verification method based on learning model triggerability to a vulnerability detection model.
[0042] Figure 2 Figure 1 A training flowchart of a benign neural network model in the embodiment.
[0043] Figure 3 A semantic redundancy source analysis diagram in a code processing period.
[0044] Figure 4 A semantic redundancy space modeling diagram.
[0045] Figure 5 A model training experiment diagram in a feature learning process of an ideal backdoor attack based on BGRU.
[0046] Figure 6 A model training experiment diagram in a feature learning process of an ideal backdoor attack based on LSTM. DETAILED DESCRIPTION
[0047] The application will be described in detail below in combination with the drawings and specific embodiments. The embodiments are implemented on the premise of the technical solution of the application, and detailed implementation modes and specific operation processes are given, but the protection scope of the application is not limited to the following embodiments.
[0048] Term explanation:
[0049] 1. Backdoor attack:
[0050] Backdoor Attack is a threat to deep learning models, with the characteristics of concealment and directionality. Concealment means that the DNN model implanted with backdoor performs normally in the test of normal samples, without exposing the existence of backdoor. Directionality means that when the input contains a trigger, the model with backdoor will output the directed results preset by the attacker. Since the similarity between code text and natural language text is high, the backdoor attack means existing in the field of natural language processing is usually applicable to code vulnerability detection models, making code analysis models face mature text backdoor attack threats. Among them, the ideal backdoor attack refers to the backdoor attack scheme that meets the actual attack scenario on the premise of not changing the sample function. For example, inserting a trigger into the semantic redundancy space of malicious code, the attacker uploads the malicious code to the target host, which can not only function normally without affecting the function due to the insertion of the trigger, but also can be directed to avoid the detection of the deep learning model, so that the malicious code is judged as a benign file by the model, causing the automatic code analysis model of the target host to be bypassed, causing unpredictable losses. The patent mainly analyzes the semantic redundancy space based on the ideal backdoor attack effect.
[0051] 2. Code processing period:
[0052] Reference Figure 4 As shown in the figure, the code processing period refers to the code form of each stage in the code compilation process, mainly including source code, intermediate code, assembly code, binary code, etc. Each form is connected through preprocessing, compilation, assembly, linking and other processing operations, and information will be added or deleted during the processing process. Among them, the semantic information related to the function of the code will be retained, and the semantic redundancy information (such as the naming habit of data structure) will be discarded, retained or added according to the difference of the compiler and the representation method.
[0053] The code processing period of the embodiment includes three code compilation stages, which are source code compilation stage, intermediate code compilation stage and binary code compilation stage in turn. Among them, the intermediate code compilation stage may include several continuous sub-stages.
[0054] 3. Code semantic representation:
[0055] The process of code semantic representation is to analyze the data flow and control flow of the extracted code data, and perform semantic representation on the code data based on the analysis results of data flow and control flow.
[0056] The semantic representation method mainly includes two types of code attribute graph conversion and code slicing. Among them, the code attribute graph represents the semantic information in the code in the form of a graph structure, such as an abstract syntax tree, a data dependency graph, a control dependency graph, etc. The association relationship between nodes in the graph structure makes the semantics easy to format. Code slicing splits the source code and recombines and arranges it according to specific rules to reflect data dependency and control dependency relationships, so as to improve the attention of the neural network to data dependency and control dependency.
[0057] Among them, the source code is split in code blocks, and the code blocks are connected through data dependency and control dependency. Therefore, the purpose of code semantic representation is to represent the data dependency and control dependency of the source code. The source of semantic deviation essentially reflects that the representation method introduces non-data-dependent and non-control-dependent features into the representation result, which further leads to the generation of semantic redundancy.
[0058] 4. Feature learning:
[0059] The code semantic representation result is converted into a vector through mature natural language processing methods (Word2Vec, etc.) for word embedding and coding. After formatting the representation result into a fixed-length vector, a neural network (RNN, etc.) is used for feature learning to obtain a classifier.
[0060] Reference Figure 1 As shown in the figure, the present application provides a code semantic redundancy measurement verification method based on the learnability of a model, which is used to verify and measure the semantic redundancy space generated in the process of converting target code data into feature vectors, including the following steps:
[0061] S1: Generate a mixed code dataset including a non-malicious code dataset and a malicious code dataset, and divide the mixed code dataset into a training set and a test set.
[0062] Specifically, the method for obtaining the mixed code dataset is: environment configuration is performed on the target model, and batch representation is performed on the code samples as a benign dataset. Among them, the target model refers to an existing code analysis and vulnerability detection technical solution, which is the analysis object of the present patent method.
[0063] S2: Insert a trigger in the training set as a first training set, perform code semantic representation on the first training set, poison in the code semantic representation process, obtain the poisoned code semantic representation result, process the poisoned code semantic representation result into a feature vector, input the feature vector into a benign neural network model for training, and obtain a backdoor neural network model;
[0064] Specifically, the training process of the benign neural network model is: sequentially performing code semantic representation and transformation operation on the training set in the mixed code data set in S1, and then obtaining the benign feature vector, inputting the benign feature vector into the neural network for training, and obtaining the benign neural network model.
[0065] S2.1: traversing all code data in the training set, determining the code data to insert the trigger, and inserting the trigger into the semantic redundancy space of the code data, obtaining a first training set;
[0066] S2.2: performing code semantic representation on the first training set, and performing poisoning in the code semantic representation process to obtain a poisoned code semantic representation result;
[0067] S2.3: processing the code semantic representation result obtained in S2.2 into a feature vector, inputting the feature vector into the benign neural network model for training, and obtaining a backdoor neural network model.
[0068] Specifically, the formula for describing the trigger insertion process in S2.1 is specifically:
[0069]
[0070] wherein, is a representation of the poisoning result after inserting the trigger into the code data i located in the stage M in the code processing cycle, the Insert() function is a function for inserting the trigger T i into the code data i, is the semantic redundancy space of inserting the trigger into the code data i located in the stage M in the code processing cycle, is the semantic space related to the code function of the code data i which needs to be avoided when inserting the trigger into the code data i.
[0071] Specifically, for the Insert() function, first traverse all code data in the training set, for each code data, obtain as many trigger insertion modes as possible in the semantic redundancy space of the code data, select the insertion mode with the lowest insertion cost, traverse all accessible insertion points in the insertion mode, replace the redundancy mode of the insertion point with the trigger mode, and then complete the trigger insertion of a single code data.
[0072] It should be noted that since the insertion point of the trigger is located in the semantic redundancy space of the code data, the replacement of information will not affect the normal function of the code data, but will introduce the trigger, which ensures the feasibility of the ideal high-concealment backdoor attack.
[0073] An ideal high-concealment backdoor attack refers to making the target model perceive the existence of the trigger in the code and output a targeted result without affecting the normal function of the code sample inserted with the trigger. Considering the precondition that the attacker inserts a trigger into the uploaded malicious code without affecting the function of the malicious code, otherwise, even if the detection of the defense model is bypassed, the attack cannot be realized.
[0074] In S2.3, the process of training the benign neural network model into a backdoor neural network is regarded as a constrained optimization problem, and the formula describing the optimization problem is as follows:
[0075]
[0076]
[0077] Wherein, F is a benign neural network model, Z_i^p represents a targeted label corresponding to the code data containing a trigger, k is the number of code data, L is a loss function, Φ^* is an optimized model parameter, X_i^p is a malicious code data set, and the whole is to reduce the loss function according to k samples Optimize the model parameter Φ by random gradient descent iteration * The precondition of the optimization problem is not to interfere with the normal function of the sample, that is, the input of the poisoned sample containing the trigger Contains all.
[0078] S3: Insert the trigger in the test set, obtain the first test set, and input the backdoor neural network model after the code semantic representation and processing operation of the first test set in turn. According to the output result of the backdoor neural network model, it is judged whether the semantic redundant space is produced in the process of converting the target code data into a feature vector.
[0079] Specifically, the process of judging whether the semantic redundant space is produced in the process of converting the target code data into a feature vector according to the output result of the backdoor neural network model is as follows:
[0080] The classification accuracy of the neural network on the malicious code data set is taken as the poisoning accuracy;
[0081] If the poisoning accuracy of the backdoor neural network model is higher than the set threshold, the process of converting the target code data into a feature vector produces a threatening semantic redundant space;
[0082] If the poisoning accuracy of the backdoor neural network model is lower than the set threshold, the process of converting the target code data into a feature vector does not produce a threatening semantic redundant space.
[0083] As an optional implementation, the backdoor neural network model is retrained by adding the mixed code dataset to obtain a purified neural network model. The purified neural network model has repeatability and can be repeatedly used in the code semantic redundancy measurement verification method based on the learning model triggerability provided by the application.
[0084] It should be noted that the application takes the classification accuracy of the benign dataset by the neural network as the benign accuracy. Both the benign accuracy and the poisoning accuracy are taken as measurement indexes. The benign accuracy of the benign neural network model is taken as the baseline model to reflect the benchmark effect of the target neural network model in feature learning. The benign accuracy of the backdoor neural network model is used to reflect the concealment of the backdoor attack. The poisoning accuracy of the backdoor neural network model is used to reflect the vulnerability of the target neural network model in using the semantic redundancy space for backdoor attack. The benign accuracy and the poisoning accuracy of the purified neural network model are used to reflect the performance of the backdoor anti-filtering.
[0085] As an optional implementation, after S3 is performed, if the semantic redundancy space is generated in the process of converting the target code data into the feature vector, S4 is performed, and S4 is specifically:
[0086] A semantic redundancy source analysis model is constructed, and the real semantic redundancy space of the target code data is obtained according to the semantic redundancy source analysis model. The semantic redundancy space generated in S3 is compressed according to the real semantic redundancy space of the target code data and the semantic redundancy space of the code data in which the trigger is inserted in S2.1.
[0087] Specifically, S4 includes the following steps:
[0088] S4.1: A semantic redundancy source analysis model is constructed according to the semantic redundancy information of different code compilation stages in the code processing period.
[0089] Further, the semantic redundancy information includes independent semantic redundancy information and common semantic redundancy information.
[0090] For the independent semantic redundancy information, the independent semantic redundancy information of the source code compilation stage includes annotations, conditional compilation instructions, special symbols, code writing styles, macro definitions and the like. The independent semantic redundancy information of the intermediate code compilation stage includes machine instruction sets and format rules of intermediate code files. The independent semantic redundancy information of the binary code compilation stage includes coding rules and the like.
[0091] For the common semantic redundancy information, the common semantic redundancy information of the source code compilation stage and the intermediate code compilation stage includes key strings and naming rules of codes, etc.; the common semantic redundancy information of the intermediate code compilation stage and the binary code compilation stage includes compiler fingerprints, etc.
[0092] S4.2: Comparing the code compilation stage involved by the target code data with the analysis result of the semantic redundancy source analysis model, and determining the semantic redundancy source of the target code data according to the generation and inheritance of the semantic information, and then obtaining the real semantic redundancy space of the target code data.
[0093] Further, the semantic information includes explicit information and implicit information.
[0094] The explicit information refers to the specific syntax and structural features of the file at a specific stage, which is directly presented from the file.
[0095] The implicit information refers to the side information hidden in the file without explicit format, but can be excavated from the explicit information.
[0096] Preferably, the semantic redundancy source analysis rule of the target stage of the code compilation stage involved by the target code data is:
[0097] 1) The information discarded and converted by the target stage in the subsequent stage is classified as the semantic redundancy information not required by the final function of the binary code.
[0098] 2) The semantic redundancy information inherited by the target stage from the previous stage is classified as the semantic redundancy information not required by the final function of the binary code.
[0099] 3) The semantic information generated in the processing process of the target stage in the current stage is classified as the semantic redundancy information not required by the final function of the binary code.
[0100] 4) The semantic redundancy information not required by the final function of the binary code retained by the target stage when representing is classified as the semantic redundancy inherited by the representation process.
[0101] 5) The semantic information generated by the target stage when representing is classified as the semantic redundancy generated by the representation process.
[0102] S4.3: According to the real semantic redundancy space obtained in S4.2 and the semantic redundancy space of the inserted trigger in S2.1, the semantic redundancy space verified in S3 is compressed.
[0103] As an optional implementation, the way of compressing the semantic redundancy space verified in S3 includes:
[0104] 1) in the code compilation phase of the target code data, divert the target code data to the direction close to the binary file;
[0105] 2) based on the security threat model, reduce the code sample triggerability, and improve the semantic redundancy utilization cost;
[0106] 3) without affecting the code semantic representation information, moderately confuse the code semantic representation result of the target code data, and break the inheritance of semantic redundancy.
[0107] In summary, the present application provides a code semantic redundancy measurement verification method based on learning model triggerability, which adds a malicious code data set to the mixed code data set, inserts a trigger in the semantic redundancy space of the code data, simulates a backdoor attack, and then processes the data set with the added malicious code data set and the inserted trigger. The training of the backdoor neural network model is carried out, the classification accuracy of the backdoor neural network model is verified through the poisoning accuracy, and then whether the semantic redundancy space is generated in the process of converting the target code data into a feature vector can be accurately verified. The problem that the prior art lacks a technical method for verifying and measuring semantic redundancy space is solved, and the code data of the prior art is still in the security threat caused by the text backdoor attack.
[0108] Embodiment 1:
[0109] Taking vulnerability automatic detection as an example, a code semantic redundancy measurement verification method based on learning model triggerability provided by the present application is used in vulnerability automatic detection, including the following steps:
[0110] S1: generate a mixed code data set, and divide the mixed code data set into a training set and a test set;
[0111] In this embodiment, the mixed code data set is a representative vulnerability code sample database (SADR, NVD, Github, etc.) or a self-made data set.
[0112] S2: insert a trigger in the training set as a first training set, perform code semantic representation on the first training set, poison in the code semantic representation process, obtain the code semantic representation result, process the code semantic representation result into a feature vector, input the feature vector into a benign neural network model for training, and obtain a backdoor neural network model;
[0113] In this embodiment, the benign neural network model is a vulnerability detection model capable of classifying and detecting whether the code contains vulnerabilities. However, due to the extensive semantic redundancy space of code data in the compilation process, it is difficult for the vulnerability detection model to have high generalization ability; that is, there is always a deviation between the features learned by the vulnerability detection model and the real vulnerability semantic features, resulting in the vulnerability detection model not having high classification confidence on un-covered code samples.
[0114] Specifically, referring to FIG. 1, the training process of the benign neural network model is as follows: Figure 3
[0115] The training set in the mixed code data set in S1 is sequentially subjected to code semantic representation and conversion operations, and then the benign feature vector is obtained. The benign feature vector is input into the neural network for training to obtain the benign neural network model.
[0116] Referring to FIG. 2, S2 specifically includes the following steps: Figure 2
[0117] S2.1: Traverse all code data in the training set, determine the code data to which the trigger is inserted, and insert the trigger into the semantic redundancy space of the code data to obtain a first training set.
[0118] The formula describing the trigger insertion process is specifically as follows:
[0119]
[0120] wherein, is a representation of the poisoning result after the trigger is inserted into the code data i located in stage M in the code processing period, the Insert() function is a function representing the insertion of the trigger T i into the code data i, is the semantic redundancy space into which the trigger is inserted into the code data i located in stage M in the code processing period, is the semantic space related to the code function of the code data i that needs to be avoided when the trigger is inserted into the code data i.
[0121] Specifically, for the Insert() function, first traverse all code data in the training set, for each code data, obtain as many trigger insertion patterns as possible in the semantic redundancy space of the code data, select the insertion pattern with the lowest insertion cost, traverse all accessible insertion points in the insertion pattern, replace the redundancy pattern of the insertion point with the trigger pattern, and then complete the trigger insertion of a single code data.
[0122] In this embodiment, the trigger insertion pattern is to replace the naming habit of the data structure with a specific trigger pattern.
[0123] S2.2: code semantic representation is performed on the first training set, poisoning is performed in the code semantic representation process, and a code semantic representation result is obtained;
[0124] S2.3: The code semantic representation result obtained in S2.2 is processed into a feature vector, the feature vector is input into a benign neural network model for training, and a backdoor neural network model is obtained.
[0125] The training process of the benign neural network model is regarded as a constrained optimization problem, and the formula for describing the optimization problem is as follows:
[0126]
[0127]
[0128] Wherein, F is a benign neural network model, is a directional label corresponding to the trigger code data, k is the number of code data, is a loss function, and * is an optimization model parameter, is a malicious code data set. The whole is to reduce the loss function by iteratively optimizing the model parameter * by random gradient descent. The premise of this optimization problem is not to interfere with the normal function of the sample, that is, the input of the trigger-containing poisoned sample contains all.
[0129] S3: Insert the trigger in the test set, obtain the first test set, and input the backdoor neural network model after sequentially performing code semantic representation and processing operations on the first test set. According to the output result of the backdoor neural network model, it is judged whether a semantic redundant space is generated in the process of converting the target code data into a feature vector.
[0130] Specifically, the process of judging whether a semantic redundant space is generated in the process of converting the target code data into a feature vector according to the output result of the backdoor neural network model is as follows:
[0131] The classification accuracy of the neural network on the malicious data set is taken as the poisoning accuracy;
[0132] If the poisoning accuracy of the backdoor neural network model is higher than the set threshold, a threatening semantic redundant space is generated in the process of converting the target code data into a feature vector;
[0133] If the poisoning accuracy of the backdoor neural network model is lower than the set threshold, a threatening semantic redundant space is not generated in the process of converting the target code data into a feature vector.
[0134] On the basis of the backdoor neural network model, the mixed code dataset is added to retrain the backdoor neural network model to obtain a purified neural network model. The purified neural network model reflects the code semantic redundancy measurement verification method provided by the application based on the learning model triggerability, which is reproducible and can be reused.
[0135] The classification accuracy of the neural network on the benign dataset is taken as the benign accuracy. Both the benign accuracy and the poisoning accuracy are taken as measurement indexes. Among them, the benign accuracy of the benign neural network model is taken as the baseline model to reflect the benchmark effect of the target neural network model in feature learning; the benign accuracy of the backdoor neural network model is used to reflect the concealment of the backdoor attack; the poisoning accuracy of the backdoor neural network model is used to reflect the vulnerability of the target neural network model in using the semantic redundancy space for backdoor attack; and the benign accuracy and the poisoning accuracy of the purified neural network model are used to reflect the performance of the backdoor anti-filtering.
[0136] In this embodiment, BGRU and LSTM models are used as neural network models, and the naming habits of data structures are replaced with specific trigger insertion patterns to perform semantic redundancy measurement verification.
[0137] After performing S3, if a semantic redundancy space is generated in the process of converting the target code data into a feature vector, S4 is performed, and S4 is specifically:
[0138] A semantic redundancy source analysis model is constructed, and the real semantic redundancy space of the target code data is obtained according to the semantic redundancy source analysis model; and the semantic redundancy space generated in S3 is compressed according to the real semantic redundancy space of the target code data and the semantic redundancy space of the code data with inserted triggers in S2.1.
[0139] Specifically, S4 includes the following steps:
[0140] S4.1: Referring to Figure 5 As shown in the figure, a semantic redundancy source analysis model is constructed according to the semantic redundancy information of different code compilation stages in the code processing period;
[0141] S4.2: The code compilation stage involved in the target code data is compared with the analysis result of the semantic redundancy source analysis model, and the semantic redundancy source of the target code data is determined according to the generation and inheritance of semantic information, and then the real semantic redundancy space of the target code data is obtained.
[0142] S4.3: According to the real semantic redundancy space obtained in S4.2 and the semantic redundancy space of the code data with inserted triggers in S2.1, the semantic redundancy space verified in S3 is compressed.
[0143] In the embodiment, the way to compress the semantic redundancy space verified in S3 is:
[0144] Without affecting the code semantic representation information, the code semantic representation result of the target code data is moderately confused, and the inheritance of semantic redundancy is broken.
[0145] In summary, the embodiment uses a code semantic redundancy measurement and verification method based on the learnability of a learning model in automatic vulnerability detection, which not only solves the problem that the prior art lacks a technical method capable of verifying and measuring semantic redundancy space, but also makes the code data of the prior art still in the security threat caused by the text backdoor attack.
[0146] It is also proposed to take semantic redundancy as an analysis dimension of the mechanism of semantic deviation, to compress the semantic redundancy space, and to further reduce the semantic deviation and improve the generalization ability of the vulnerability detection model of the prior art.
[0147] The above describes the preferred embodiments of the application in detail. It should be understood that those skilled in the art can make many modifications and changes without creative labor according to the concept of the application. Therefore, any technical solution obtained by logical analysis, reasoning or limited experiment on the basis of the prior art according to the concept of the application shall be within the protection scope defined by the claims.
Claims
1. A code semantic redundancy measurement and verification method based on the triggerability of a learning model, characterized in that, This is used to verify and measure the semantic redundancy space generated during the transformation from target code data to feature vectors, and includes the following steps: S1: Generate a hybrid code dataset, which includes a non-malicious code dataset and a malicious code dataset, and divide the hybrid code dataset into a training set and a test set; S2: Insert a trigger into the training set and use it as the first training set. Perform code semantic representation on the first training set. Poisoning is performed during the code semantic representation process. Obtain the poisoned code semantic representation results and process the poisoned code semantic representation results into feature vectors. Input the feature vectors into the benign neural network model for training to obtain the backdoor neural network model. S3: Insert a trigger into the test set, obtain the first test set, perform code semantic representation and processing operations on the first test set in sequence, input it into the backdoor neural network model, and determine whether semantic redundancy space is generated in the process of converting target code data into feature vectors based on the output of the backdoor neural network model. S2 includes the following steps: S2.1: Traverse all code data in the training set, determine the code data to be inserted into the trigger, and insert the trigger into the semantic redundancy space of the code data to obtain the first training set; S2.2: Perform code semantic representation on the first training set, poison the code semantic representation process, and obtain the poisoned code semantic representation results; S2.3: Convert the code semantic representation results obtained in S2.2 into feature vectors, input the feature vectors into a benign neural network model for training, and obtain the backdoor neural network model; The formula describing the trigger insertion process in S2.1 is as follows: in, To indicate the stage located in the code processing cycle Code data The result of poisoning after the trigger is inserted. The function represents the trigger. Insert into code data The function in To insert a trigger at a stage in the code processing cycle Code data semantic redundancy space, To insert triggers into code data i When it comes to code data, it is necessary to avoid i The semantic space related to code functionality; The training process of the benign neural network model is as follows: the training set in the mixed code dataset in S1 is sequentially subjected to code semantic representation and transformation operations to obtain benign feature vectors, and these benign feature vectors are input into the neural network for training to obtain a benign neural network model.
2. The code semantic redundancy measurement and verification method based on the triggerability of a learning model according to claim 1, characterized in that, In S2.3, the process of training a benign neural network model into a backdoor neural network model is regarded as a constrained optimization problem, and the formula describing this optimization problem is as follows: in, For benign neural network models, To represent the orientation label corresponding to the data containing trigger code, The number of code data. For loss function, To optimize model parameters.
3. The code semantic redundancy measurement and verification method based on the triggerability of a learning model according to claim 1, characterized in that, After executing S3, to verify the semantic redundancy space generated during the transformation from target code data to feature vectors, S4 is then executed. Specifically, S4 is as follows: Construct a semantic redundancy source analysis model and obtain the true semantic redundancy space of the target code data based on the semantic redundancy source analysis model; compress the semantic redundancy space generated by the S3 verification based on the true semantic redundancy space of the target code data and the semantic redundancy space of the code data of the inserted trigger in S2.
1.
4. The code semantic redundancy measurement and verification method based on the triggerability of a learning model according to claim 3, characterized in that, S4 includes the following steps: S4.1: Identify and construct a semantic redundancy source analysis model based on the semantic redundancy information of different code compilation stages in the code processing cycle; S4.2: Compare the code compilation stages involved in the target code data with the analysis results of the semantic redundancy source analysis model, and determine the semantic redundancy source of the target code data based on the generation and inheritance of semantic information, thereby obtaining the true semantic redundancy space of the target code data; S4.3: Based on the actual semantic redundancy space obtained in S4.2 and the semantic redundancy space of the inserted trigger in S2.1, compress the semantic redundancy space verified in S3.
5. The code semantic redundancy measurement and verification method based on the triggerability of a learning model according to claim 4, characterized in that, The semantic redundancy source analysis rules for the code compilation stage involved in the target code data in S4.2, i.e., the target stage, are as follows: Information that is discarded and transformed in subsequent stages during the target phase is classified as semantic redundancy that is not needed for the final function of the binary code; The semantic redundancy information inherited by the target stage from the previous stage is classified as semantic redundancy information that is not needed for the final function of the binary code. The semantic information generated during the processing of the target stage in the current stage is classified as semantic redundancy information that is not needed for the final function of the binary code. The semantic redundancy information of the binary code retained during the target stage that is not needed by the final function is classified as semantic redundancy inherited from the representation process. The semantic information generated during the target stage representation is classified as semantic redundancy generated during the representation process.
6. The code semantic redundancy measurement and verification method based on the triggerability of a learning model according to claim 1, characterized in that, In S3, the process of determining whether semantic redundancy space is generated during the conversion from target code data to feature vector based on the output of the backdoor neural network model is as follows: If the poisoning accuracy of the backdoor neural network model is higher than the set threshold, a threatening semantic redundancy space will be generated in the process of converting target code data into feature vectors. If the poisoning accuracy of the backdoor neural network model is lower than the set threshold, no threatening semantic redundancy space will be generated during the process of converting target code data into feature vectors.
7. The code semantic redundancy measurement and verification method based on the triggerability of a learning model according to claim 6, characterized in that, The poisoning accuracy of the backdoor neural network model is the classification accuracy of the backdoor neural network model on the malicious code dataset.
Citation Information
Patent Citations
Using gradients to detect backdoors in neural networks
CN111971698A
Method for performing text backdoor attack by using punctuations
CN114936594A