Malicious code analysis method and system based on PGD attack adversarial training
Through the malicious code analysis method based on PGD attack adversarial training, the Markov image is generated by disassembled opcode sequences in the asm file, and the malicious code detection model MadInG adv is trained, which solves the problem of malicious code detection in the data category distribution imbalance and malicious code variant scenarios, achieving higher detection accuracy and generalization ability and robustness of the detector.
Patent Information
- Application Number
- CN202411801510.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-09
- Publication Date
- 2025-03-28
- Estimated Expiration
- 2044-12-09
AI Technical Summary
Malicious code detection faces the problem of low detection accuracy in scenarios such as unbalanced data category distribution and malicious code variants.
Malicious code analysis method based on PGD attack adversarial training is adopted to extract opcode sequences from the disassembled asm file of malicious code, generate Markov images, and train a malicious code detection model based on image analysis and generation of adversarial networks, MadInG adv.
It improves the accuracy of malicious code detection in scenarios such as data category distribution imbalance and malicious code variants, and enhances the generalization ability and robustness of malicious code detectors.
Smart Images

Figure CN119720197A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of malicious code detection, and in particular to a malicious code analysis method and system based on PGD attack adversarial training. Background Art
[0002] Malicious code detection is an important part of network security. However, with the rapid development of computer technology, the number of malicious code adversarial samples and new malicious code variants has increased, and the evasion ability of malicious code has been enhanced. Malicious code detection faces huge challenges. In recent years, intelligent malicious code detection methods have gradually received attention and achieved good results. However, the training samples used to build malicious code detection models are prone to problems such as small data volume and unbalanced data category distribution, which affects the accuracy of model decision-making. Summary of the invention
[0003] In view of this, the purpose of the present invention is to provide a malicious code analysis method and system based on PGD attack adversarial training, starting from the perspective of image analysis and combining the idea of adversarial learning, to achieve malicious code detection and improve the accuracy of detection in scenarios such as unbalanced data category distribution and malicious code variants.
[0004] To achieve the above object, the present invention adopts the following technical solution: a malicious code analysis method based on PGD attack adversarial training, comprising the following steps:
[0005] Step S1, extracting the malicious code operation code sequence from the disassembled asm file of the malicious code;
[0006] Step S2, generating a corresponding Markov image according to the obtained operation code sequence;
[0007] Step S3: Using the generated Markov image as input, training a malicious code detection model MadInG adv based on image analysis and generative adversarial network, and realizing malicious code detection through the trained model.
[0008] In a preferred embodiment, in step S1, extracting the malicious code operation code sequence from the disassembled asm file of the malicious code specifically includes the following steps:
[0009] Step S1A1, find the code section position in the disassembled asm file by matching Segmenttype:Pure code, and obtain the code section name;
[0010] Step S1A2, matching the code section content according to the obtained code section name, and reading the content in the code section line by line;
[0011] Step S1A3, matching the content in the code section with the regular expression \s([A-F0-9]{2}\s)+\s*([az]+) to obtain the operation code contained in the code section;
[0012] Step S1A4, repeating steps S1A2 to S1A3 until the file reading is completed, and obtaining the operation code sequence of the malicious code.
[0013] In a preferred embodiment, in step S2, a corresponding Markov image is generated according to the obtained operation code sequence, and the specific steps include:
[0014] Step S2A1: Calculate operation code b i Followed by b j The frequency of occurrence;
[0015] Step S2A2: Calculate operation code b i Followed by b j The probability of
[0016] Step S2A3: Calculate the pixel value of the Markov image according to the Markov transition probability matrix. The calculation method is as follows:
[0017]
[0018] Among them, TM is the transition probability matrix, TM[i][j] represents the operation code b i Followed by b j The probability of, MP is the maximum probability in the transition probability matrix TM, mod is the remainder function.
[0019] In a preferred embodiment, step S3 specifically includes the following steps:
[0020] Step S3A1, input the Markov image dataset T, initialize the generator G and its parameter θ, the discriminator D and its discriminator parameter ω in the MadInG adv model;
[0021] Step S3A2: Perform PGD attack on the discriminator to obtain adversarial sample X adv , generate adversarial examples X adv The specific formula is as follows:
[0022]
[0023] X adv ={x′1x′2,...,x′ m}
[0024] Among them, α represents the size of the perturbation when updating the adversarial sample each time, J(x′ i , y) represents the loss function of the model, clipx,ε is a projection operation, is the loss function J(x′ i , y) with respect to input x′ i The gradient of , which indicates the direction of increasing loss, Indicates that only the direction of the gradient is retained, while the magnitude is ignored, thereby controlling each update to a fixed step size α, x′ i is the adversarial sample generated in the ith iteration during the PGD attack, X adv is a Markov image dataset T = {(x1, y1), (x2, y2), ..., (x m ,y m )}Adversarial samples obtained after multiple iterations in PGD attack;
[0025] Step S3A3: Fix the generator parameters and use adversarial sample X adv , real sample X real And generate samples X fake Train the discriminator and update the discriminator parameters ω. The specific formula for parameter update is as follows:
[0026] L S = E[logP(S = real | X real )]+E[logP(S=fake|X fake )]+E[logP(S=fake|X adv )]
[0027]
[0028] Among them, S is the true or false output result of the discriminator input data, C is the output classification result of the discriminator input data, E represents the expectation, c is the correct category of the input sample, and L S is the cost function of data authenticity, L C is the cost function of data classification accuracy, g ω Yes (L S +L C ) With respect to the gradient of ω, Adam is the optimizer of the generator and discriminator in MadInG adv. The goal of the optimizer is to maximize L S +L C ;
[0029] Step S3A4, fix the discriminator parameters, use the generated samples to train the generator, and update the generator parameters θ. The specific formula for parameter update is as follows:
[0030]
[0031] θ←Adam(g θ ,θ,α,β1,β2)
[0032] Among them, g θ Yes (L S -L C ) with respect to the gradient of θ, the goal of the optimizer is to minimize L S -L C ;
[0033] Step S3A5, repeating steps S3A2 to S3A4 until the number of iterations is reached, and obtaining a trained discriminator D′;
[0034] Step S3A6: construct a malicious code detector D0 with the same structure and parameters as the discriminator, and implement malicious code detection through D0.
[0035] The present invention also provides a malicious code analysis system based on PGD attack adversarial training, which runs the above-mentioned malicious code analysis method based on PGD attack adversarial training.
[0036] The present invention also provides a computer-readable storage medium, comprising:
[0037] The computer readable storage medium has a computer program stored thereon;
[0038] When the computer program is run by the processor, a malicious code analysis method based on PGD attack adversarial training as described is executed.
[0039] Compared with the prior art, the present invention has the following beneficial effects: a PGD attack adversarial training module is introduced in model training, thereby achieving higher malicious code detection accuracy in scenarios such as unbalanced data category distribution and malicious code variants. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] Figure 1 This is the overall framework of the method of the preferred embodiment of the present invention.
[0041] Figure 2 This is the Markov image generation process of the preferred embodiment of the present invention.
[0042] Figure 3 This is the process of obtaining the malicious code operation code sequence of the preferred embodiment of the present invention. DETAILED DESCRIPTION
[0043] The present invention will be further described below in conjunction with the accompanying drawings and embodiments.
[0044] It should be noted that the following detailed descriptions are illustrative and are intended to provide further explanation of the present application. Unless otherwise specified, all technical and scientific terms used herein have the same meanings as those commonly understood by those skilled in the art to which the present application belongs.
[0045] It should be noted that the terms used herein are only for describing specific embodiments and are not intended to limit the exemplary embodiments according to the present application; as used herein, unless the context clearly indicates otherwise, the singular form is also intended to include the plural form. In addition, it should be understood that when the terms "comprise" and / or "include" are used in this specification, they indicate the presence of features, steps, operations, devices, components and / or their combinations.
[0046] The present invention provides a malicious code analysis method based on projected gradient descent (PGD) attack adversarial training, as shown in the attached Figure 1-3 As shown in the figure. Specifically, it includes malicious code Markov image generation and malicious code detection model MadInG adv based on PGD attack adversarial training. Extract malicious code opcode sequence from the disassembled asm file of malicious code; generate corresponding Markov image according to the malicious code opcode sequence; introduce auxiliary classification generative adversarial network ACGAN model, further in the game process between generator and discriminator, construct discriminator adversarial training algorithm based on PGD attack, and finally use the learned image features to build malicious code detector by migrating discriminator.
[0047] The present invention improves the accuracy of the model in detecting malicious code in scenarios such as imbalanced data category distribution and malicious code variants, and enhances the generalization ability and robustness of the malicious code detector.
[0048] The specific steps are as follows:
[0049] Step S1, extracting the malicious code operation code sequence from the disassembled asm file of the malicious code;
[0050] Step S2, generating a corresponding Markov image according to the obtained operation code sequence;
[0051] Step S3: Using the generated Markov image as input, training a malicious code detection model MadInG adv based on image analysis and generative adversarial network, and realizing malicious code detection through the trained model.
[0052] In one embodiment of the present invention, in step S1, the malicious code operation code sequence is extracted from the disassembled asm file of the malicious code, and the process is as shown in the attached figure. Figure 2 As shown, the specific steps include:
[0053] Step S1A1, find the code section location in the disassembled asm file by matching Segment type: Pure code, and obtain the code section name;
[0054] Step S1A2, matching the code section content according to the obtained code section name, and reading the content in the code section line by line;
[0055] Step S1A3, matching the content in the code section with the regular expression \s([A-F0-9]{2}\s)+\s*([az]+) to obtain the operation code contained in the code section;
[0056] Step S1A4, repeat S1A2-S1A3 until the file is read completely, and obtain the operation code sequence of the malicious code;
[0057] In one embodiment of the present invention, in step S2, a corresponding Markov image is generated according to the obtained operation code sequence, and the process is as shown in the attached figure. Figure 3 As shown, the specific steps include:
[0058] Step S2A1: Calculate operation code b i Followed by b j The frequency of occurrence;
[0059] Step S2A2: Calculate operation code b i Followed by b j The probability of
[0060] Step S2A3: Calculate the pixel value of the Markov image according to the Markov transition probability matrix. The calculation method is as follows:
[0061]
[0062] Among them, TM is the transition probability matrix, TM[i][j] represents the operation code b i Followed by b j The probability of MP is the maximum probability in the transition probability matrix TM, and mod is the remainder function. The specific algorithm for generating Markov images based on operation codes is shown in Algorithm 1: Algorithm 1. Markov image generation algorithm based on operation codes
[0063]
[0064] In step S3, the generated Markov image is used as input to train a malicious code detection model MadInG adv based on image analysis and generative adversarial network, and malicious code detection is implemented through the trained model. The specific steps include:
[0065] Step S3A1, input the Markov image dataset T, initialize the generator G and its parameters θ, the discriminator D and its parameters ω in the MadInG adv model;
[0066] Step S3A2: Perform PGD attack on the discriminator to obtain adversarial sample X adv , generate sample Xadv The specific formula is as follows:
[0067]
[0068] X adv ={x′1,x′2,...,x′ m}
[0069] Among them, α represents the size of the perturbation when updating the adversarial sample each time, J(x′ i , y) represents the loss function of the model, clip x,ε is a projection operation, is the loss function J(x′ i , y) with respect to input x′ i The sign of the gradient of , which indicates the direction of increasing loss, Indicates that only the direction of the gradient is retained, while the magnitude is ignored, thereby controlling each update to a fixed step size α, x′ i is the adversarial sample generated in the ith iteration during the PGD attack, X adv is a Markov image dataset T = {(x1, y1), (x2, y2), ..., (x m ,y m )} The adversarial sample obtained after multiple iterations in the PGD attack, the specific process of PGD attack on the discriminator is shown in Algorithm 2:
[0070]
[0071]
[0072] Step S3A3: Fix the generator parameters and use adversarial sample X adv , real sample X real And generate samples X fake Train the discriminator and update the discriminator parameters ω. The specific formula for parameter update is as follows:
[0073] L S =E[logP(S=real|X real )]+E[logP(S=fake|X fake )]+E[logP(S=fake|X adv )]
[0074]
[0075] Among them, S is the true or false output result of the discriminator input data, C is the output classification result of the discriminator input data, E represents the expectation, c is the correct category of the input sample, and L S is the cost function of data authenticity, LC is the cost function of data classification accuracy, g ω Yes (L S +L C ) With respect to the gradient of ω, Adam is the optimizer of the generator and discriminator in MadInG adv. The goal of the optimizer is to maximize L S +L C ;
[0076] Step S3A4, fix the discriminator parameters, use the generated samples to train the generator, and update the generator parameters θ. The specific formula for parameter update is as follows:
[0077]
[0078] θ←Adam(g θ ,θ,α,β1,β2)
[0079] Among them, g θ Yes (L S -L C ) with respect to the gradient of θ, the goal of the optimizer is to minimize L S -L C ;
[0080] Step S3A5, repeat S3A2-S3A4 until the number of iterations is reached, and obtain the trained discriminator D′;
[0081] Step S3A6: construct a malicious code detector D0 with the same structure and parameters as the discriminator, and implement malicious code detection through D0.
[0082] The entire model training process involved in step S3 is shown in Algorithm 3:
[0083]
[0084] The above is only a preferred embodiment of the present invention, and does not limit the present invention in other forms. Any technician familiar with the profession may use the above disclosed technical content to change or modify it into an equivalent embodiment with equivalent changes. However, any simple modification, equivalent change and modification made to the above embodiment according to the technical essence of the present invention without departing from the technical solution of the present invention still belongs to the protection scope of the technical solution of the present invention.
Claims
1. A malicious code analysis method based on PGD attack adversarial training, characterized in that: The steps include: Step S1, extracting the malicious code operation code sequence from the disassembled asm file of the malicious code; Step S2, generating a corresponding Markov image according to the obtained operation code sequence; Step S3: Using the generated Markov image as input, training a malicious code detection model MadInG adv based on image analysis and generative adversarial network, and realizing malicious code detection through the trained model.
2. According to a malicious code analysis method based on PGD attack adversarial training according to claim 1, it is characterized in that: In step S1, extracting the malicious code operation code sequence from the disassembled asm file of the malicious code specifically includes the following steps: Step S1A1, find the code section position in the disassembled asm file by matching Segmenttype:Pure code, and obtain the code section name; Step S1A2, matching the code section content according to the obtained code section name, and reading the content in the code section line by line; Step S1A3, matching the content in the code section with the regular expression \s([A-F0-9]{2}\s)+\s*([az]+) to obtain the operation code contained in the code section; Step S1A4, repeating steps S1A2 to S1A3 until the file reading is completed, and obtaining the operation code sequence of the malicious code.
3. According to a malicious code analysis method based on PGD attack adversarial training according to claim 1, it is characterized in that: In step S2, a corresponding Markov image is generated according to the obtained operation code sequence, and the specific steps include: Step S2A1: Calculate operation code b i Followed by b j The frequency of occurrence; Step S2A2: Calculate operation code b i Followed by b j probability; Step S2A3: Calculate the pixel value of the Markov image according to the Markov transition probability matrix. The calculation method is as follows: Among them, TM is the transition probability matrix, TM[i][j] represents the operation code b i Followed by b j The probability of, MP is the maximum probability in the transition probability matrix TM, mod is the remainder function.
4. According to a malicious code analysis method based on PGD attack adversarial training according to claim 1, it is characterized in that: Step S3 specifically includes: Step S3A1, input the Markov image dataset T, initialize the generator G and its parameter θ, the discriminator D and its discriminator parameter ω in the MadInG adv model; Step S3A2: Perform PGD attack on the discriminator to obtain adversarial sample X adv , generate adversarial examples X adv The specific formula is as follows: X adv ={x′1,x′2,…,x′ m } Among them, α represents the size of the perturbation when updating the adversarial sample each time, J(x′ i ,y) represents the loss function of the model, clip x,ε is a projection operation, is the loss function J(x′ i ,y) with respect to input x′ i The gradient of , which indicates the direction of increasing loss, Indicates that only the direction of the gradient is retained, while the magnitude is ignored, thereby controlling each update to a fixed step size α, x′ i is the adversarial sample generated in the ith iteration during the PGD attack, X adv is a Markov image dataset T = {(x1,y1),(x2,y2),…,(x m ,y m )}Adversarial samples obtained after multiple iterations in PGD attack; Step S3A3: Fix the generator parameters and use adversarial sample X adv , real sample X real And generate samples X fake Train the discriminator and update the discriminator parameters ω. The specific formula for parameter update is as follows: L S =E[logP(S=real|X real )]+E[logP(S=fake|X fake )]+E[logP(S=fake|X adv )] L C =E[logP(C=c|X real )]+E[logP(C=c|X fake )]+E[logP(C=c|X adv )] ω←Adam(g ω ,θ,α,β1,β2) Among them, S is the true or false output result of the discriminator input data, C is the output classification result of the discriminator input data, E represents the expectation, c is the correct category of the input sample, and L S is the cost function of data authenticity, L C is the cost function of data classification accuracy, g ω Yes (L S +L C ) With respect to the gradient of ω, Adam is the optimizer of the generator and discriminator in MadInG adv. The goal of the optimizer is to maximize L S +L C ; Step S3A4, fix the discriminator parameters, use the generated samples to train the generator, and update the generator parameters θ. The specific formula for parameter update is as follows: θ←Adam(g θ ,θ,α,β1,β2) Among them, g θ Yes (L S -L C ) with respect to the gradient of θ, the goal of the optimizer is to minimize L S -L C ; Step S3A5, repeating steps S3A2 to S3A4 until the number of iterations is reached, and obtaining a trained discriminator D′; Step S3A6: construct a malicious code detector D0 with the same structure and parameters as the discriminator, and implement malicious code detection through D0.
5. A malicious code analysis system based on PGD attack adversarial training, characterized in that Run a malicious code analysis method based on PGD attack adversarial training as described in any one of claims 1-4 above.
6. A computer-readable storage medium, characterized in that: include: The computer readable storage medium has a computer program stored thereon; When the computer program is run by a processor, it executes a malicious code analysis method based on PGD attack adversarial training as described in any one of claims 1 to 4.
Citation Information
Patent Citations
Malicious code image-oriented interpretability evaluation method
CN117313091A
Malicious code detection method and device, electronic equipment and storage medium
CN117540382A
KR20210079494A