An improved ACGAN-based vehicle-mounted network intrusion detection method and detection system
By improving ACGAN and multi-label classification technology, the problem that existing vehicle network intrusion detection methods cannot detect unknown attacks and multiple attacks is solved. It realizes the detection of unknown attacks and multi-label classification, improves detection efficiency, and provides an integrated hardware and software detection solution.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-25
- Publication Date
- 2026-03-20
AI Technical Summary
Existing deep learning-based intrusion detection methods for vehicular networks cannot detect unknown attack types, and can only detect one attack when multiple attacks appear within a sliding window.
An improved Generative Adversarial Network (ACGAN) is adopted, which combines a generator G and a discriminator D. The generator learns the distribution of real CAN ID images and generates fake data. Multi-label classification technology and multiple sigmoid layers are used to replace the softmax layer to achieve multi-label classification of the adversarial network.
It enables the detection of unknown attack types, can detect multiple CAN bus attacks simultaneously, improves the accuracy and detection efficiency of multi-tag classification, and provides an integrated hardware and software solution for vehicle network intrusion detection.
Smart Images

Figure CN116707939B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application relates to the technical field of vehicle network intrusion detection, and in particular to a vehicle network intrusion detection method and system based on an improved ACGAN. BACKGROUND
[0002] With the development of automobile intelligence, network security problems of vehicles have attracted more and more attention. Vehicle network intrusion refers to the fact that hackers or malicious attackers invade the electronic control system of a vehicle through a network, so as to achieve the purpose of remotely controlling the vehicle, stealing vehicle information and attacking the privacy of passengers. Vehicle network intrusion can cause potential harm to driving safety and the privacy of vehicle owners, and has become one of the important obstacles to the development of automobile intelligence. As one of the most commonly used communication protocols in modern vehicles, the controller area network (CAN) has the advantages of high reliability, high flexibility, low cost and low latency, but the CAN protocol does not have a built-in security mechanism. Therefore, it is very important to detect attack packets on the CAN bus in real time and timely report the attack types so as to take emergency measures.
[0003] At present, the vehicle network intrusion detection method based on deep learning often has the following limitations: 1. Only known attack types can be detected, and unknown attack types cannot be detected; 2. When multiple attacks occur in a sliding window, only one attack can be detected. SUMMARY
[0004] In order to solve the problems existing in the prior art, the purpose of the present application is to provide a vehicle network intrusion detection method and system based on an improved ACGAN. The existing problems in the prior art are solved by using 1. a distribution outside detection technology based on a generative adversarial network; 2. an auxiliary classifier generative adversarial network (ACGAN); and 3. a multi-label classification technology.
[0005] The vehicle network intrusion detection method based on the improved ACGAN comprises the following steps:
[0006] Step 1: Collect CAN message data frames, and screen out standard data frames according to whether the values of RTR bits and IDE bits are both 0.
[0007] Step 2: Preprocess the collected standard data frame ID, batch-convert it into a CAN ID image suitable for inputting into a neural network model, and assign appropriate labels to the CAN ID images.
[0008] Step 3: Construct a generator G and a discriminator D, use the CAN ID image, and use the Adam optimization algorithm to train the generator G and the discriminator D.
[0009] Step 4: The discriminator D is deployed to a computer connected to the CAN bus using a USB-CAN device, and the collected CAN ID image is input into the discriminator D, and the discriminator D outputs the CAN message state in the CAN ID image range, including whether the CAN message is subjected to one or more known attacks and whether there is an unknown attack. The types of known attacks include but are not limited to DoS attacks, Fuzzy attacks and Spoofing attacks.
[0010] In step 1, the collection of CAN message data frames first needs to obtain all messages on the CAN bus by connecting the vehicle OBD port, and then filter out standard data frames according to the existence of RTR bit and IDE bit and the value of 0, and the ID part of these standard data frames will be used in the subsequent steps.
[0011] In the present application, step 2 includes:
[0012] Step 2.1: Extract the CAN ID part of the CAN message, represented by a three-digit hexadecimal number, and fill in the high bits with zeros if less than three digits.
[0013] Step 2.2: One-hot encoding of the three-digit hexadecimal number of CAN ID, each bit is encoded with 1 according to the rules of hexadecimal number, forming an encoding data with a length of 3*16=48; for example, 43f, after one-hot encoding, the positions corresponding to 4 in the first row, 3 in the second row and f in the third row are encoded as 1.
[0014] Step 2.3: Concatenate the three one-hot encoded data of the same CAN ID to form an encoding data with a length of 1*48=48; take 48 consecutive CAN IDs as a group, and group the one-hot encoded data into a 48*48 image.
[0015] Step 2.4: The known classification label set is {Normal, DoS, Fuzzy, Spoofing}, representing normal, DoS, fuzzy, and spoofing, respectively; the label of the image is the sum of the one-hot encoding of each classification label in the CAN message to which the CAN ID in the image belongs. For example, if the 48 CAN IDs in the image belong to CAN messages that only contain DoS attacks DoS Attack, the image label is [0, 1, 0, 0]; if the 48 CAN IDs in the image belong to CAN messages that contain Fuzzy Attack and Spoofing Attack, the image label is [0, 0, 1, 1].
[0016] In the present application, step 3 includes:
[0017] Step 3.1: Randomly initialize the parameters of the generator G and the discriminator D.
[0018] Step 3.2: Input a normally distributed noise vector z and a random image label gen_label into the generator G to obtain the image gen_img output by the generator G. The noise vector z needs to follow a simple, easily sampled distribution. Besides a normal distribution, a uniform distribution can also be chosen, which has almost no impact on subsequent results. However, it is not recommended that the noise vector z follow other more complex distributions, as this may cause the generator to experience gradient vanishing.
[0019] The label format of gen_label is as described in step 2.4. Each time, one label is randomly selected from 15 types: [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1], [1, 1, 0, 0], [1, 0, 1, 0], [1, 0, 0, 1], [0, 1, 0, 1], [0, 0, 1, 1], [1, 1, 1, 0], [1, 1, 0, 1], [1, 0, 1, 1], [0, 1, 1, 1], [1, 1, 1, 1]. This label is then input into the generator along with the noise vector z.
[0020] Step 3.3: Input gen_img into discriminator D. Discriminator D evaluates the input image, obtaining the probability (validity) that image gen_img is a real image and its predicted label (pred_label). The predicted label (pred_label) takes the form described in Step 2.4. It iterates through the output values of the four Sigmoid functions responsible for different classifications in discriminator D. When the output value is greater than or equal to the threshold T, the corresponding position of the predicted label (pred_label) is assigned a value of 1. The initial default value of the threshold T is 0.5. After training, a curve is plotted between the threshold and the sum of the F1 scores for each classification. The threshold is adjusted to optimize the sum of the F1 scores.
[0021] Step 3.4: Calculate the loss function L of generator G using the following formula. G :
[0022] L G =L C -L S
[0023] L C =E[log P(C=c|X real )]+E[log P(C=c|X fake )]
[0024] L S =E[log P(S=real|X real )]+E[log P(S=fake|X fake )]
[0025] wherein L C is the loss function of classification, L S is the loss function of true or false judgment, E represents mathematical expectation, and P(C|X) represents the probability of X belonging to the category C given the input sample X. P(S|X) represents the probability of the data source of X being S given the input sample X.
[0026]
[0027]
[0028] wherein N is the number of samples in a batch, l n is the loss function corresponding to the nth sample, and M is the number of elements in the classification label set4, is the loss function corresponding to the ith classification in the nth sample, w i is a hyperparameter for processing the sample imbalance problem between labels, is the predicted value of the discriminator D for the ith classification in the nth sample (the value range is [0, 1]), is the true value of the ith classification in the nth sample (0 or 1).
[0029]
[0030] l n =-w[y n *log x n +(1-y n )*log(1-x n )]
[0031] wherein N is the number of samples in a batch, l n is the loss function corresponding to the nth sample, w is a hyperparameter for processing the sample imbalance problem between labels, x n is the predicted value of the discriminator D for the data source of the nth sample (the value range is [0, 1]), y n is the true value of the data source of the nth sample (0 or 1).
[0032] Step 3.5: Update the parameters of the generator G with the Adam optimizer after back propagation. The learning rate of the Adam optimizer is set to 0.0002, the exponential decay rate of the first moment estimate is set to 0.5, and the exponential decay rate of the second moment estimate is set to 0.999. The Adam optimization first needs to calculate the gradient of the loss function L GThe partial derivatives of the parameters of the generator G are used to obtain the parameter gradients. Then, the momentum is calculated based on the weighted average of the current gradient and the previous gradients. The momentum is then used to calculate the adaptive learning rate so that different learning rates can be used for each parameter. Finally, the parameters of the generator G are updated using the adaptive learning rate and momentum.
[0033] Step 3.6: Input the real image and the image gen_img output by the generator G into the discriminator D in turn, and obtain the output real probability real_validity, real prediction label real_pred_label, fake probability fake_validity, and fake prediction label fake_pred_label respectively.
[0034] Step 3.7: Calculate the loss function L of discriminator D using the following formula. D :
[0035] L D =L C +L S
[0036] Among them, L C It is the loss function for classification, L S It is the loss function for judging whether something is true or false, and the specific expansion of both is as described in step 3.4.
[0037] Step 3.8: After backpropagation, update the parameters of the discriminator D using the Adam optimizer. The learning rate of the Adam optimizer is set to 0.0002, the exponential decay rate for the first-order moment estimation is set to 0.5, and the exponential decay rate for the second-order moment estimation is set to 0.999. Adam optimization first requires adjusting the parameters based on the loss function L of the discriminator D. D The partial derivatives of the parameters of the discriminator D are used to obtain the parameter gradients. Then, the momentum is calculated based on the weighted average of the current gradient and the previous gradients. The momentum is then used to calculate the adaptive learning rate so that different learning rates can be used for each parameter. Finally, the parameters of the discriminator D are updated using the adaptive learning rate and momentum.
[0038] Step 3.9: Train the generator G and discriminator D alternately, that is, repeat steps 3.2 to 3.8 to obtain a discriminator D with better performance.
[0039] In this invention, the neural network structure of the generator G is as follows:
[0040] The first layer is a linear layer with a 100-dimensional input vector and a 18432-dimensional output.
[0041] The second layer is a batch normalization layer, with both input and output being tensors of size 128*12*12.
[0042] The third layer is an upsample layer (Upsample), the scale factor is 2, the input is a 128*12*12 tensor, and the output is a 128*24*24 tensor.
[0043] The fourth layer is a convolution layer (Conv), the convolution kernel size is 3*3, the stride is 1, the surrounding padding is 1, and the input and output are both 128*24*24 tensors.
[0044] The fifth layer is a batch normalization layer (BN), and the input and output are both 128*24*24 tensors.
[0045] The sixth layer is a LeakyReLU layer, the negative slope is 0.2, and the input and output are both 128*24*24 tensors.
[0046] The seventh layer is an upsample layer (Upsample), the scale factor is 2, the input is a 128*24*24 tensor, and the output is a 128*48*48 tensor.
[0047] The eighth layer is a convolution layer (Conv), the convolution kernel size is 3*3, the stride is 1, the surrounding padding is 1, the input is a 128*48*48 tensor, and the output is a 64*48*48 tensor.
[0048] The ninth layer is a batch normalization layer (BN), and the input and output are both 64*48*48 tensors.
[0049] The tenth layer is a LeakyReLU layer, the negative slope is 0.2, and the input and output are both 64*48*48 tensors.
[0050] The eleventh layer is a convolution layer (Conv), the convolution kernel size is 3*3, the stride is 1, the surrounding padding is 1, the input is a 64*48*48 tensor, and the output is a 1*48*48 tensor.
[0051] The twelfth layer is a Tanh layer, and the input and output are both 1*48*48 tensors.
[0052] In the present application, the neural network structure of the discriminator D is as follows:
[0053] The first layer is a convolution layer (Conv), the convolution kernel size is 3*3, the stride is 2, the surrounding padding is 1, the input is a 1*48*48 tensor, and the output is a 16*24*24 tensor.
[0054] The second layer is a LeakyReLU layer, the negative slope is 0.2, and the input and output are both 16*24*24 tensors.
[0055] The third layer is a Dropout layer, which removes a portion of neurons from the neural network. The dropout probability is 0.25, and the input and output are both 16*24*24 tensors.
[0056] The fourth layer is a Convolutional layer (Conv) with a kernel size of 3*3, a stride of 2, and a padding of 1. The input is a 16*24*24 tensor, and the output is a 32*12*12 tensor.
[0057] The fifth layer is a LeakyReLU layer with a negative slope of 0.2. The input and output are both 32*12*12 tensors.
[0058] The sixth layer is a Dropout layer with a dropout probability of 0.25. The input and output are both 32*12*12 tensors.
[0059] The seventh layer is a Batch Normalization layer (BN) with an input and output of 32*12*12 tensors.
[0060] The eighth layer is a Convolutional layer (Conv) with a kernel size of 3*3, a stride of 2, and a padding of 1. The input is a 32*12*12 tensor, and the output is a 64*6*6 tensor.
[0061] The ninth layer is a LeakyReLU layer with a negative slope of 0.2. The input and output are both 64*6*6 tensors.
[0062] The tenth layer is a Dropout layer with a dropout probability of 0.25. The input and output are both 64*6*6 tensors.
[0063] The eleventh layer is a Batch Normalization layer (BN) with an input and output of 64*6*6 tensors.
[0064] The twelfth layer is a Convolutional layer (Conv) with a kernel size of 3*3, a stride of 2, and a padding of 1. The input is a 64*6*6 tensor, and the output is a 128*3*3 tensor.
[0065] The thirteenth layer is a LeakyReLU layer with a negative slope of 0.2. The input and output are both 128*3*3 tensors.
[0066] The fourteenth layer is a Dropout layer with a dropout probability of 0.25. The input and output are both 128*3*3 tensors.
[0067] The fifteenth layer is a Batch Normalization layer (BN) with an input and output of 128*3*3 tensors.
[0068] The sixteenth layer is composed of five linear layers, which are respectively responsible for judging true or false, judging whether containing Normal message, judging whether containing DoS message, judging whether containing Fuzzy message, judging whether containing Spoofing message, and the input vectors are all 1152 dimensions, and the output vectors are all 1 dimension.
[0069] The seventeenth layer is composed of five Sigmoid layers, and the input vectors and the output vectors are all 1 dimension.
[0070] In the discriminator D, multiple Sigmoid layers are used to replace the original Softmax layer, so that multiple CAN bus attacks can be detected at the same time, which is very effective for the case where more than one attack occurs in a range, and the detection result is more comprehensive.
[0071] The image output by the generator G is used to train the discriminator D, which can improve the accuracy of the discriminator D for multi-label classification to a certain extent.
[0072] The application also provides a system for implementing the above method, which comprises a CAN message collection module, a data preprocessing module, a generator module, a discriminator module and a result output module.
[0073] The CAN message collection module is composed of a USB-CAN device, which is used to collect original CAN message data from the CAN bus and transmit the CAN message data to the data preprocessing module through the USB interface.
[0074] The data preprocessing module is deployed on a personal computer, which is responsible for screening standard data frames, and converting the CAN ID of the standard data frames into a two-dimensional image as the input of the discriminator module.
[0075] The generator module accepts a noise vector subject to normal distribution and an image label as input, and outputs a fake CAN ID image similar to the image label type. After the training of the generator module is completed, it can generate a large number of fake CAN ID images similar to the image label type, and these fake images will be further used to train the discriminator module.
[0076] The discriminator module accepts a CAN ID image as input, and outputs whether the CAN ID image exists unknown attack and the multi-label classification result of the CAN ID image. After the training of the discriminator module is completed, it can judge whether the input CAN ID image exists unknown attack, and represent which types of CAN messages are contained in the input CAN ID image in the form of multi-label. Among them, whether there is unknown attack and multi-label classification result will be used as the input of the result output module.
[0077] The result output module accepts the output result of the discriminator module, and displays it to the user through the host computer interface, so that the user knows whether a CAN message on the CAN bus exists unknown attack and which type of CAN message.
[0078] The application further discloses application of the detection method or the detection system in vehicle-mounted network intrusion detection.
[0079] Compared with the prior art, the application has the following advantages:
[0080] (1) The application uses out-of-distribution detection technology based on a generative adversarial network, compared with the prior art which can only complete coarse-grained binary classification and multi-classification of known attacks, the application realizes detection of unknown attack types, and provides corresponding detection capability for new attack types that may appear in the future. The application uses a generator to learn the distribution of real CAN ID images and generate fake data similar to the real CAN ID images, and then uses real CAN ID images and fake CAN ID images to train a discriminator, so that the discriminator has the ability to distinguish real and fake images. Once the discriminator considers that the input image is fake, it indicates that the input image is out of the real image distribution, so as to identify unknown attack types.
[0081] (2) The application improves the ACGAN by using multi-label classification technology, compared with the prior art which can only give one classification result for a range of CAN messages, the application can detect multiple CAN bus attacks at the same time, which is very effective for the case where more than one attack occurs in a range, and is convenient for embedded engineers to quickly judge the attack type on the CAN bus and improve the problem solving efficiency. The improvement of the ACGAN is reflected in three aspects: in the activation function aspect, a plurality of Sigmoid layers are used instead of the original Softmax layer in the discriminator D, which can make the probability of each class be independently output; in the loss function aspect, in order to adapt to the change of the activation function, the sum of a plurality of binary cross-entropy loss functions is used instead of the original cross-entropy loss function in the discriminator D, and each Sigmoid layer output is independently optimized, which is more suitable for multi-label classification problems; in the classification label form aspect, the sum of the one-hot encoding of each classification is used instead of the integer form or the one-hot encoding form input to the generator G, which can make the generator G generate fake samples that meet the multi-label classification, and is helpful for the training of the discriminator D.
[0082] (3) The application provides a hardware and software integrated solution for vehicle-mounted network intrusion detection, which has a USB-CAN device and a computer on the hardware, and an intrusion detection discriminator, software for communication with the USB-CAN and a result visualization host computer on the software. The solution can be modified to adapt to intrusion detection on other buses. The hardware uses a third-party USB-CAN device, and the software is completely developed based on the application. BRIEF DESCRIPTION OF DRAWINGS
[0083] In order to more clearly illustrate the technical solutions of the embodiments of the present application or the prior art, the drawings needed to be used in the embodiments or prior art description will be briefly introduced. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative labor.
[0084] Figure 1 is the flowchart of the vehicle-mounted network intrusion detection method based on improved ACGAN of the present application.
[0085] Figure 2 is the schematic diagram of the data preprocessing process of the present application.
[0086] Figure 3 is the complete flowchart of training and detection of the present application.
[0087] Figure 4 is the network structure diagram of the generator G of the present application.
[0088] Figure 5 is the network structure diagram of the discriminator D of the present application. DETAILED DESCRIPTION
[0089] The present application will be further described in combination with the following specific embodiments and drawings. The process, conditions, experimental methods, etc. for implementing the present application are the general knowledge and common sense in the art, and the present application does not have special limitations.
[0090] The present application first collects CAN messages through a USB-CAN device, screens out standard data frames, then pre-processes, converts the CAN ID batch into CAN ID images suitable for inputting into a neural network model, and assigns appropriate labels to these CAN ID images, then uses the CAN ID images, uses the Adam optimization algorithm to train the generator G and the discriminator D, and finally deploys the discriminator D to an embedded device connected to the CAN bus. The collected CAN ID images will be input into the discriminator D, and the discriminator D will output the CAN message state within the CAN ID image range, including whether the CAN message is subjected to one or more known attacks and whether there is an unknown attack. The present application can detect known attack types and classify them; can detect unknown types of attacks; can detect multiple CAN bus attacks within a certain range; and can improve the accuracy of multi-label classification results. The specific description is as follows:
[0091] Step 1: Collect CAN message data frames and screen out standard data frames.
[0092] Step 2: preprocess the collected standard data frame ID, batch convert it into CAN ID image suitable for inputting into the neural network model, and assign appropriate labels to the CAN ID image.
[0093] Step 3: build the generator G and the discriminator D, use the CAN ID image, and use the Adam optimization algorithm to train the generator G and the discriminator D.
[0094] Step 4: deploy the discriminator D to the computer connected to the CAN bus using the USB-CAN device, input the collected CAN ID image into the discriminator D, and the discriminator D outputs the CAN message state in the CAN ID image range, including whether the CAN message is subjected to one or more known attacks and whether there is an unknown attack.
[0095] In the present application, the step 2 comprises:
[0096] Step 2.1: extract the CAN ID part of the CAN message, represented by three hexadecimal numbers, and fill the high bits with zeros if less than three.
[0097] Step 2.2: one-hot encoding of the three hexadecimal numbers of the CAN ID to form an encoding data with a length of 3*16=48.
[0098] Step 2.3: take 48 consecutive CAN IDs as a group, and group the one-hot encoded data into a 48*48 image.
[0099] Step 2.4: the known classification label set is {Normal, DoS, Fuzzy, Spoofing}, and the label of the image is the one-hot encoding of each classification label in the CAN message to which the CAN ID belongs. For example, if there is only DoS Attack in the CAN message to which the 48 CAN IDs in the image belong, the image label is [0, 1, 0, 0]; if there are Fuzzy Attack and Spoofing Attack in the CAN message to which the 48 CAN IDs in the image belong, the image label is [0, 0, 1, 1].
[0100] In the present application, the step 3 comprises:
[0101] Step 3.1: randomly initialize the parameters of the generator G and the discriminator D.
[0102] Step 3.2: input the noise vector z obeying normal distribution and the random image label gen_label into the generator G to obtain the image gen_img output by the generator G.
[0103] Step 3.3: input gen img into discriminator D, the discriminator D judges the input image, and gets the probability that the input image is a real image validity and its predicted label pred label. Wherein, the manifestation of the predicted label pred label is as described in step 2.4, traversing the output value of the four Sigmoid functions in the discriminator D responsible for different classification, when greater than or equal to the threshold value T, the corresponding position of the predicted label pred label is assigned a value of 1.
[0104] Step 3.4: calculate the loss function L of the generator G using the following formula G :
[0105] L G =L C -L S
[0106] L C =E[log P(C=c|X real )]+E[log P(C=c|X fake )]
[0107] L S =E[log P(S=real|X real )]+E[log P(S=fake|X fake )]
[0108] Wherein, L C is the loss function of classification, L S is the loss function of true and false judgment, E represents mathematical expectation, P(C|X) represents the probability that X belongs to category C given the input sample X, and P(S|X) represents the probability that the data source of X is S given the input sample X.
[0109]
[0110]
[0111]
[0112] Wherein, N is the number of samples in a batch, l n is the loss function corresponding to the nth sample, M is the number of elements in the classification label set, is the loss function corresponding to the ith classification in the nth sample, w i is a hyperparameter for processing the sample imbalance problem between labels, is the predicted value of the discriminator D for the ith classification of the nth sample (the value range is [0, 1]), is the true value of the ith classification of the nth sample (0 or 1).
[0113]
[0114] l n = -w[y n *log x n + (1-y n )*log(1-x n )]
[0115] where N is the number of samples in a batch, l n is the loss function corresponding to the nth sample, w is a hyperparameter used to handle the sample imbalance problem between labels, x n is the prediction value of the discriminator D for the data source of the nth sample (the value range is [0, 1]), y n is the true value of the data source of the nth sample (0 or 1).
[0116] Step 3.5: Update the parameters of the generator G with the Adam optimizer after back propagation.
[0117] Step 3.6: Input the real image and the image gen_img output by the generator G into the discriminator D in turn, and get the outputs real_validity, real_pred_label and fake_validity, fake_pred_label respectively.
[0118] Step 3.7: Calculate the loss function L D of the discriminator D using the following formula:
[0119] L D = L C + L S
[0120] where L C is the loss function of classification, and L S is the loss function of true and false judgment, and the specific expansion formula is as described in step 3.4.
[0121] Step 3.8: Update the parameters of the discriminator D with the Adam optimizer after back propagation.
[0122] Step 3.9: Train the generator G and the discriminator D alternately, that is, repeat steps 3.2 to 3.8 to obtain a better discriminator D.
[0123] In the present application, the neural network structure of the generator G is as follows:
[0124] The first layer is a linear layer, the input vector is 100-dimensional, and the output is 18432-dimensional.
[0125] The second layer is a batch normalization layer, and the input and output are both 128*12*12 tensors.
[0126] The third layer is an up-sampling layer, the scale factor is 2, the input is a 128*12*12 tensor, and the output is a 128*24*24 tensor.
[0127] The fourth layer is a convolution layer, the convolution kernel size is 3*3, the stride is 1, the padding is 1, and the input and output are both 128*24*24 tensors.
[0128] The fifth layer is a batch normalization layer, and the input and output are both 128*24*24 tensors.
[0129] The sixth layer is a LeakyReLU layer, the negative slope is 0.2, and the input and output are both 128*24*24 tensors.
[0130] The seventh layer is an up-sampling layer, the scale factor is 2, the input is a 128*24*24 tensor, and the output is a 128*48*48 tensor.
[0131] The eighth layer is a convolution layer, the convolution kernel size is 3*3, the stride is 1, the padding is 1, the input is a 128*48*48 tensor, and the output is a 64*48*48 tensor.
[0132] The ninth layer is a batch normalization layer, and the input and output are both 64*48*48 tensors.
[0133] The tenth layer is a LeakyReLU layer, the negative slope is 0.2, and the input and output are both 64*48*48 tensors.
[0134] The eleventh layer is a convolution layer, the convolution kernel size is 3*3, the stride is 1, the padding is 1, the input is a 64*48*48 tensor, and the output is a 1*48*48 tensor.
[0135] The twelfth layer is a Tanh layer, and the input and output are both 1*48*48 tensors.
[0136] In the present application, the neural network structure of the discriminator D is as follows:
[0137] The first layer is a convolution layer, the convolution kernel size is 3*3, the stride is 2, the padding is 1, the input is a 1*48*48 tensor, and the output is a 16*24*24 tensor.
[0138] The second layer is a LeakyReLU layer, the negative slope is 0.2, and the input and output are both 16*24*24 tensors.
[0139] The third layer is a Dropout layer, the dropout probability is 0.25, and the input and output are both 16*24*24 tensors.
[0140] The fourth layer is a convolutional layer, the convolution kernel size is 3*3, the stride is 2, the padding is 1, the input is a 16*24*24 tensor, and the output is a 32*12*12 tensor.
[0141] The fifth layer is a LeakyReLU layer, the negative slope is 0.2, and the input and output are both 32*12*12 tensors.
[0142] The sixth layer is a Dropout layer, the dropout probability is 0.25, and the input and output are both 32*12*12 tensors.
[0143] The seventh layer is a batch normalization layer, and the input and output are both 32*12*12 tensors.
[0144] The eighth layer is a convolutional layer, the convolution kernel size is 3*3, the stride is 2, the padding is 1, the input is a 32*12*12 tensor, and the output is a 64*6*6 tensor.
[0145] The ninth layer is a LeakyReLU layer, the negative slope is 0.2, and the input and output are both 64*6*6 tensors.
[0146] The tenth layer is a Dropout layer, the dropout probability is 0.25, and the input and output are both 64*6*6 tensors.
[0147] The eleventh layer is a batch normalization layer, and the input and output are both 64*6*6 tensors.
[0148] The twelfth layer is a convolutional layer, the convolution kernel size is 3*3, the stride is 2, the padding is 1, the input is a 64*6*6 tensor, and the output is a 128*3*3 tensor.
[0149] The thirteenth layer is a LeakyReLU layer, the negative slope is 0.2, and the input and output are both 128*3*3 tensors.
[0150] The fourteenth layer is a Dropout layer, the dropout probability is 0.25, and the input and output are both 128*3*3 tensors.
[0151] The fifteenth layer is a batch normalization layer, and the input and output are both 128*3*3 tensors.
[0152] The sixteenth layer is composed of five linear layers, which are responsible for judging true or false, judging whether it contains a Normal message, judging whether it contains a DoS message, judging whether it contains a Fuzzy message, judging whether it contains a Spoofing message, and the input vector is 1152-dimensional and the output vector is 1-dimensional.
[0153] The seventeenth layer is composed of five Sigmoid layers, and the input vector and the output vector are both 1-dimensional.
[0154] Embodiment 1
[0155] The content of this embodiment is the training phase of the model.
[0156] Connect the computer and the automobile CAN bus using the USB-CAN device, filter out the standard data frame in the matching software of USB-CAN, and store the intercepted message in text form on the computer. Run the data preprocessing script, read the CAN message in text form, intercept the CAN ID part of the CAN message and batch convert it into a 48*48 image, and assign a label to it according to the message type of the initial CAN message corresponding to the image. First, randomly initialize the parameters of the generator G and the discriminator D. Second, train the generator G. Input the noise vector z obeying the normal distribution and the random image label gen_label into the generator G, and get the image gen_img output by the generator G. Input gen_img into the discriminator D to get the probability that gen_img is a real image validity and its predicted label pred_label, and then use validity and pred_label to calculate the loss function of generator G and update the parameters of generator G using Adam optimizer. Third, train the discriminator D. Input the real image and the image gen_img output by the generator G into the discriminator D in turn to get the real probability real_validity, the real predicted label real_pred_label and the fake probability fake_validity, the fake predicted label fake_pred_label, and then use them to calculate the loss function of the discriminator D and update the parameters of the discriminator D using the Adam optimizer. Finally, alternately train the generator G and the discriminator D to obtain a better discriminator D, and draw the threshold of each classification sigmoid function and the curve of the sum of F1 scores of each classification, and adjust the threshold to make the sum of F1 scores optimal.
[0157] Embodiment 2
[0158] The content of the embodiment is the application stage of the model. The computer and the automobile CAN bus are connected by using a USB-CAN device, standard data frames are screened out in the matching software of the USB-CAN, the intercepted messages are converted into text form and stored on the computer. The data pretreatment script is run, the CAN messages in text form are read, the CAN ID part of the CAN messages is intercepted and batch converted into 48*48 images. The images are successively input into the trained discriminator D to obtain the probability validity of the images being real images and the predicted label pred_label thereof. If all values of pred_label are less than the threshold of the corresponding classification sigmoid function, the host computer shows the user the result: there is an unknown attack. If one or more values in pred_label are greater than or equal to the threshold of the corresponding classification sigmoid function, all the classifications meeting the condition are combined to obtain a multi-label classification result, then validity is judged, if validity is less than 0.5, there is an unknown attack, if validity is greater than or equal to 0.5, there is no unknown attack, finally the host computer shows the user the result: the multi-label classification result and the position attack result.
[0159] The protection scope of the present application is not limited to the above embodiments. Changes and advantages that can be thought of by those skilled in the art without departing from the spirit and scope of the present application are included in the present application, and are protected by the appended claims.
Claims
1. A method for intrusion detection in vehicular networks based on an improved ACGAN, characterized in that, Includes the following steps: Step 1: Complete the acquisition of CAN message data frames and filter standard data frames; Step 2: Preprocess the acquired standard data frame IDs, convert them in batches into CAN ID images suitable for inputting into the neural network model, and assign appropriate labels to these CAN ID images; Step 3: Construct generator G and discriminator D. Using CAN ID images, train generator G and discriminator D using the Adam optimization algorithm. Step 3 includes: Step 3.1: Randomly initialize the parameters of the generator G and the discriminator D; Step 3.2: Input a noise vector z that follows a normal distribution and a random image label gen_label into the generator G to obtain the image gen_img output by the generator G; Step 3.3: Input gen_img into discriminator D. Discriminator D judges the input image and obtains the probability validity that the input image gen_img is a real image and its predicted label pred_label. Iterate through the output values of the four Sigmoid functions in discriminator D that are responsible for different classifications. When the output value is greater than or equal to the threshold T, the corresponding position of the predicted label pred_label is assigned a value of 1. Step 3.4: Calculate the loss function L of generator G using the following formula. G : L G =L C -L S , L C =E[logP(C=c|X real )]+E[logP(C=c|X fake )], L S =E[logP(S=real|X real )]+E[logP(S=fake|X fake )], Among them, L C It is the loss function for classification, L S It is the loss function for judging true and false, E represents the mathematical expectation, P(C|X) represents the probability that X belongs to class C given input sample X, and P(S|X) represents the probability that the data source of X is S given input sample X. Where N is the number of samples in a batch, l n Let M be the loss function corresponding to the nth sample, and M be the number of elements in the classification label set (4). Let w be the loss function corresponding to the i-th category in the n-th sample. i These are hyperparameters used to address the problem of sample imbalance between labels. It is the predicted value of the discriminator D for the i-th category of the n-th sample, and the predicted value ranges from [0,1]. It is the true value of the nth sample in the ith category, and the true value is 0 or 1; l n =-w[y n *logx n +(1-y n )*log(1-x n )], Where N is the number of samples in a batch, l n Let x be the loss function corresponding to the nth sample, w be the hyperparameter used to handle the sample imbalance problem between labels, and x be the loss function corresponding to the nth sample. n It is the predicted value of the discriminator D for the nth sample data source, and the predicted value ranges from [0,1]. n It is the true value from the source of the nth sample data, and the true value is 0 or 1; Step 3.5: Update the parameters of generator G using the Adam optimizer after backpropagation; Step 3.6: Input the real image and the image gen_img output by the generator G into the discriminator D in turn, and obtain the output real probability real_validity, real prediction label real_pred_label and fake probability fake_validity, fake prediction label fake_pred_label respectively. Step 3.7: Calculate the loss function L of discriminator D using the following formula. D : L D =L C +L S , Among them, L C It is the loss function for classification, L S It is the loss function for judging whether something is true or false; Step 3.8: Update the parameters of the discriminator D using the Adam optimizer after backpropagation; Step 3.9: Train the generator G and discriminator D alternately, i.e., repeat steps 3.2 to 3.8 to obtain the discriminator D for intrusion detection; Step 4: Deploy the discriminator D to a computer connected to the CAN bus using a USB-CAN device. The acquired CANID image will be input into the discriminator D, and the discriminator D will output the CAN message status within the range of the CAN ID image, including whether the CAN message has been subjected to one or more known attacks and whether there are any unknown attacks.
2. The vehicular network intrusion detection method based on improved ACGAN as described in claim 1, characterized in that, In step 1, you first need to obtain all the messages on the CAN bus by connecting to the vehicle's OBD port, and then filter out the standard data frames based on the fact that both the RTR bit and the IDE bit are present and their values are both 0.
3. The vehicular network intrusion detection method based on improved ACGAN as described in claim 1, characterized in that, Step 2 includes: Step 2.1: Extract the CAN ID portion of the CAN message and represent it as a three-digit hexadecimal number, padding with zeros in the high-order bits if it is less than three digits; Step 2.2: Perform one-hot encoding on the three hexadecimal digits of the CAN ID. Each digit is encoded using 1 according to the rules of hexadecimal numbers, forming encoded data with a length of 3*16=48. Step 2.3: Concatenate the three lines of one-hot encoded data of the same CAN ID to form encoded data of length 1*48=48; group the one-hot encoded data into a 48*48 image by taking 48 consecutive CAN IDs as a group; Step 2.4: Given the classification label set {Normal, DoS, Fuzzy, Spoofing}, representing normal, DoS, fuzzy, and spoofing respectively; the image label is the sum of the one-hot encodings of each classification label in the CAN message to which the CAN ID belongs.
4. The vehicular network intrusion detection method based on improved ACGAN as described in claim 1, characterized in that, In steps 3.5 and 3.8, the learning rate of the Adam optimizer is set to 0.0002, the exponential decay rate of the first moment estimate is set to 0.5, and the exponential decay rate of the second moment estimate is set to 0.
999.
5. The vehicular network intrusion detection method based on improved ACGAN as described in claim 1, characterized in that, The specific neural network structure of the generator G is as follows: The first layer is a linear layer with a 100-dimensional input vector and a 18432-dimensional output. The second layer is a batch normalization layer, with both input and output being 128*12*12 tensors; The third layer is an upsampling layer with a scaling factor of 2. The input is a tensor of 128*12*12 and the output is a tensor of 128*24*24. The fourth layer is a convolutional layer with a kernel size of 3*3, a stride of 1, and a padding of 1. Both the input and output are tensors of 128*24*24. The fifth layer is a batch normalization layer, with both input and output being tensors of size 128*24*24; The sixth layer is a LeakyReLU layer with a negative slope of 0.2, and both the input and output are tensors of size 128*24*24. The seventh layer is an upsampling layer with a scaling factor of 2. The input is a tensor of 128*24*24 and the output is a tensor of 128*48*48. The eighth layer is a convolutional layer with a kernel size of 3*3, a stride of 1, and a padding of 1. The input is a tensor of 128*48*48, and the output is a tensor of 64*48*48. The ninth layer is a batch normalization layer, with both input and output being 64*48*48 tensors; The tenth layer is a LeakyReLU layer with a negative slope of 0.2, and both the input and output are tensors of size 64*48*48. The eleventh layer is a convolutional layer with a kernel size of 3*3, a stride of 1, and a padding of 1. The input is a tensor of 64*48*48, and the output is a tensor of 1*48*48. The twelfth layer is the Tanh layer, with both input and output being 1*48*48 tensors.
6. The vehicular network intrusion detection method based on improved ACGAN as described in claim 1, characterized in that, The specific neural network structure of the discriminator D is as follows: The first layer is a convolutional layer with a kernel size of 3*3, a stride of 2, and a padding of 1. The input is a tensor of 1*48*48, and the output is a tensor of 16*24*24. The second layer is a LeakyReLU layer with a negative slope of 0.2, and both the input and output are tensors of size 16*24*24; The third layer is the Dropout removal layer, with a dropout removal probability of 0.
25. Both the input and output are tensors of size 16*24*24. The fourth layer is a convolutional layer with a kernel size of 3*3, a stride of 2, and a padding of 1. The input is a tensor of 16*24*24, and the output is a tensor of 32*12*12. The fifth layer is a LeakyReLU layer with a negative slope of 0.2, and both the input and output are 32*12*12 tensors; The sixth layer is the Dropout removal layer, with a dropout removal probability of 0.
25. Both the input and output are 32*12*12 tensors. The seventh layer is a batch normalization layer, with both input and output being 32*12*12 tensors; The eighth layer is a convolutional layer with a kernel size of 3*3, a stride of 2, and a padding of 1. The input is a tensor of 32*12*12, and the output is a tensor of 64*6*6. The ninth layer is a LeakyReLU layer with a negative slope of 0.2, and both the input and output are 64*6*6 tensors; The tenth layer is the Dropout removal layer, with a dropout removal probability of 0.
25. Both the input and output are 64*6*6 tensors. The eleventh layer is a batch normalization layer, with both input and output being 64*6*6 tensors; The twelfth layer is a convolutional layer with a kernel size of 3*3, a stride of 2, and a padding of 1. The input is a tensor of 64*6*6, and the output is a tensor of 128*3*3. The thirteenth layer is a LeakyReLU layer with a negative slope of 0.2, and both the input and output are tensors of size 128*3*3; The fourteenth layer is the Dropout removal layer, with a dropout removal probability of 0.
25. Both the input and output are tensors of size 128*3*3. The fifteenth layer is a batch normalization layer, with both input and output being 128*3*3 tensors; The sixteenth layer consists of five linear layers, which are responsible for determining whether the message is true or false, whether it contains a Normal message, whether it contains a DoS message, whether it contains a Fuzzy message, and whether it contains a Spoofing message. The input vectors are all 1152-dimensional, and the output vectors are all 1-dimensional. The seventeenth layer consists of five sigmoid layers, with both the input and output vectors being one-dimensional.
7. The vehicular network intrusion detection method based on improved ACGAN as described in claim 1, characterized in that, The method can detect and classify known attack types, and it can also detect unknown attack types.
8. A detection system for implementing the detection method as described in any one of claims 1-7, characterized in that, The system includes a CAN message acquisition module, a data preprocessing module, a generator module, a discriminator module, and a result output module. The CAN message acquisition module consists of a USB-CAN device, which is used to collect raw CAN message data from the CAN bus and transmit the CAN message data to the data preprocessing module via the USB interface; The data preprocessing module is deployed on a personal computer and is responsible for filtering out standard data frames and converting the CAN IDs of these standard data frames into two-dimensional images, which are then used as input to the discriminator module. The generator module accepts a noise vector that follows a normal distribution and image labels as input, and outputs a fake CAN ID image that resembles the image label type. The discriminator module accepts a CAN ID image as input and outputs whether the CAN ID image is subject to an unknown attack and the multi-label classification result of the CAN ID image. The result output module receives the output of the discriminator module and displays it to the user through the host computer interface, so that the user can know whether a CAN message on the CAN bus is subject to an unknown attack and what types of CAN messages it contains.
9. The application of the detection method as described in any one of claims 1-7, or the detection system as described in claim 8, in vehicle network intrusion detection.
Citation Information
Patent Citations
A hyperspectral image classification method based on superpixel sample expansion and generative adversarial network
CN109948693A
Text-to-image generation method based on hybrid network model
CN110751698A