A malware test sample generation method and system based on goal-oriented reinforcement learning

By employing a goal-oriented reinforcement learning approach, the high-dimensional state and sparse reward problems of malware detection in black-box scenarios are addressed, generating efficient and highly concealed test samples suitable for commercial antivirus software and cloud-based detection APIs. This enhances the robustness evaluation of the detector and the verification of defense mechanisms.

CN123178261APending Publication Date: 2026-11-27Chinese People's Liberation Army Cyberspace Force Information Engineering University
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611311899.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-08-27
Publication Date
2026-11-27

AI Technical Summary

Technical Problem

Existing reinforcement learning-based malware detection methods face challenges in black-box scenarios, such as high-dimensional state spaces, sparse rewards, and dependence on detector features, resulting in low generation efficiency, low success rate, and poor representativeness.

Method used

We employ a goal-oriented reinforcement learning approach, constructing a low-dimensional observation state by screening important modifiable features, generating a target vector with a benign feature distribution using a diffusion model, and introducing a post-experience replay algorithm to provide dense reward signals, thereby reducing dimensionality and improving learning efficiency.

Benefits of technology

It achieves excellent test results on multiple detectors, generates test samples with a high false positive rate, few queries, and low file expansion rate. It has versatility and efficiency in black-box scenarios and retains the functional integrity of the samples.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123178261A_ABST
    Figure CN123178261A_ABST
Patent Text Reader

Abstract

The application discloses a malware test sample generation method and system based on target-oriented reinforcement learning. Firstly, the important modifiable feature screening (IMFS) technology is used to extract the low-dimensional features of the malware, and a diffusion model is trained according to the low-dimensional features to generate a target vector of benign features, so as to solve the problems of unknown feature space of a black-box detector and excessively high state dimension. In the target-oriented reinforcement learning process, an intelligent agent modifies the malware to interact with the detector, and combines a historical experience replay (HER) algorithm to use a target reward to relieve the reward sparsity problem, so that the test sample of the detector is efficiently generated. The application significantly improves the generation effectiveness and concealment of the test sample, gets rid of the dependence on the feature space of the target detector, has a strong generalization capability in a black-box scene, effectively relieves the reward sparsity problem in the reinforcement learning, improves the training efficiency and strategy quality, and greatly compresses the state space dimension and reduces the strategy search complexity.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of network security technology, specifically relating to a method and system for generating malware test samples based on goal-oriented reinforcement learning. This method is particularly suitable for generating test samples for static malware detection systems based on deep neural networks in black-box scenarios, and can be applied to security testing, robustness evaluation, and defense mechanism verification of malware detection systems. Background Technology

[0002] With the widespread application of deep neural networks (DNNs) in static malware detection, their powerful feature extraction and pattern recognition capabilities have significantly improved detection efficiency and accuracy. However, numerous studies have confirmed that DNN models have inherent vulnerabilities; even minor perturbations to the input samples can lead to incorrect predictions. This characteristic makes evaluating the robustness of AI-based detection systems to carefully modified input samples a crucial issue in the field of artificial intelligence security.

[0003] In the field of malware adversarial example generation, existing methods are mainly divided into three categories: gradient-based methods, optimization / evolutionary methods, and reinforcement learning-based methods. Gradient-based methods typically operate in the feature space, making it difficult to inversely map perturbations into a legitimate PE file format. Furthermore, they require white-box or gray-box access permissions, limiting their application in real-world black-box scenarios. Optimization / evolutionary methods, such as genetic algorithms, can work in black-box scenarios, but they often require a large number of queries, resulting in high testing costs. Excessive modification can also lead to an increase in the size of the generated test sample files, affecting the effectiveness and representativeness of the tests.

[0004] Reinforcement learning-based test sample generation methods have attracted considerable attention in recent years. These methods, through interactive learning between the agent and the environment, modify PE files in a structured and constrained manner via sequential decision-making. This naturally solves the problems of file format compliance and excessive file expansion rate, and effectively controls query costs. One of the most representative early works is the framework proposed by Anderson et al. in 2018. This work was the first to systematically apply deep Q-networks to adversarial modification of PE files, defining a set of safe actions, such as appending harmless bytes to specific sections, to ensure that file functionality is not compromised.

[0005] Since then, researchers have continuously improved reinforcement learning-based methods, such as employing the A3C or PPO algorithms to enhance the stability of policy learning. Other studies have attempted to introduce prior knowledge to guide learning, such as using SHAP values ​​to mine important features and enrich sparse reward signals. These studies have collectively driven the development of reinforcement learning-based test sample generation techniques.

[0006] Although reinforcement learning-based methods have made significant progress in evaluating the robustness of malware detection models, they still have the following drawbacks in practical applications:

[0007] First, existing technologies generally rely on prior knowledge of the target detector's internal feature extraction mechanism when constructing the agent's observation state. They typically require prior knowledge of the feature set used by the target detector, such as the EMBER feature set, and the parsing of the PE file into corresponding feature vectors, which are then used as state input to the agent. However, in real-world black-box scenarios, commercial antivirus software or cloud-based detection APIs usually only accept the raw PE file as input and return a simple "malicious / benign" label; their internal feature extraction process is completely invisible to the tester. This reliance on feature definitions makes existing methods unsuitable for direct application to real black-box detectors, significantly reducing their versatility and practicality.

[0008] Secondly, directly using high-dimensional raw features as the state space results in an excessively large policy search space for reinforcement learning agents. Even with a pre-defined feature set, the dimensionality often reaches thousands of dimensions. Agents searching for policies in this high-dimensional, sparse state space face the "curse of dimensionality," which not only significantly increases the complexity and time cost of model training but also makes the learning process difficult to converge, reducing the efficiency and success rate of test sample generation.

[0009] Finally, existing methods typically employ sparse reward mechanisms, where the agent receives a positive reward only when it ultimately causes the detector to make a misclassification, receiving no feedback throughout the modification process. This extremely sparse reward signal forces the agent to engage in a large amount of ineffective exploration, significantly increasing training costs. This directly leads to a low success rate in constructing test samples, and to achieve the testing objective, the agent may adopt suboptimal and excessive modification strategies, increasing the extent of modification to the original malware sample, thereby affecting the representativeness of the test samples and the effectiveness of the evaluation. Summary of the Invention

[0010] This invention addresses the technical bottlenecks of existing methods, such as high state space dimensionality, sparse rewards, and dependence on detector feature definitions. It proposes a method and system for generating malware test samples based on goal-oriented reinforcement learning. First, a method is developed that does not rely on the feature space definition of the target detector, enabling the test sample generation framework to directly process raw PE files and construct an efficient observation space independent of the detector. Second, a technique is designed to effectively compress the agent's observation state space, significantly reducing dimensionality while ensuring no loss of key information, thereby improving the training efficiency, stability, and convergence speed of reinforcement learning. Third, a scheme is proposed to alleviate the reward sparsity problem by providing the agent with denser and more instructive intermediate reward signals, guiding it to efficiently learn a test sample generation strategy with high success rate and high stealth.

[0011] To achieve the above objectives, the present invention adopts the following technical solution:

[0012] This invention proposes a method for generating malware test samples based on goal-oriented reinforcement learning, comprising:

[0013] Step 1: Extract initial feature vectors for malware samples and benign samples respectively. Filter the initial feature vectors by important and modifiable features, and select low-dimensional feature vectors based on feature importance and modifiability. Then, normalize the low-dimensional feature vectors.

[0014] Step 2: Train the diffusion model using the low-dimensional feature vector of the benign sample; add noise to the low-dimensional feature vector of the malicious software sample and input it into the diffusion model, and generate an initial target vector that conforms to the benign feature distribution through reverse denoising.

[0015] Step 3: In the current round, the low-dimensional feature vector of the current malware sample is concatenated with the current target vector to form the agent's observation state; the agent selects an action from the preset action space based on the observation state, modifies the PE file of the malware sample using the selected action, and generates a test sample; the test sample is submitted to the target detector, and the judgment result returned by the target detector is obtained; the environmental reward is calculated based on the judgment result; the distance between the current low-dimensional feature vector and the current target vector is calculated, and the target reward is calculated based on the distance; the environmental reward and the target reward are added together to obtain the total reward.

[0016] Step 4: Store the trajectory data generated in the current round into the experience buffer pool; sample training trajectories from the experience buffer pool; for each sampled trajectory, use the post-experience replay algorithm to select the subsequent state in the trajectory as the new target; recalculate the total reward of each step in the trajectory based on the new target; and update the network parameters of the agent using the recalculated data.

[0017] Step 5: Repeat steps 3 and 4 until the preset termination condition is met.

[0018] Furthermore, the important modifiable feature screening includes:

[0019] Calculate the SHAP value of each initial feature for the preset proxy model, and use the SHAP value to quantify the importance of the feature;

[0020] Calculate the average distance change of each preset action to each initial feature, and use the average distance change to quantify the modifiability of the feature;

[0021] Feature filtering is performed based on the SHAP value and the average distance change.

[0022] Furthermore, the initial feature vector is an EMBER feature vector, and the filtering includes:

[0023] It retains all dimensions of byte histogram features, byte entropy histogram features, and string information features;

[0024] Select and retain the machine type field, checksum field, and timestamp field from the file header information features;

[0025] Discard general information features and import / export information features.

[0026] Furthermore, the training method for the diffusion model described in step 2 is as follows:

[0027] Using the low-dimensional feature vectors of benign samples as training data, a one-dimensional denoising diffusion probability model is trained, enabling the model to restore the noisy feature vectors to feature vectors that conform to the benign feature distribution.

[0028] Furthermore, the post-hoc experience replay algorithm described in step 4 selects subsequent states in the trajectory as the new target, specifically as follows:

[0029] From the current training status Select the first from the subsequent states each state As a new objective, the aforementioned It is a preset positive integer.

[0030] Furthermore, the environmental reward is calculated as follows:

[0031] When the test sample is determined to be benign by the target detector, the reward value is... Otherwise, it is 0, where As a discount factor, Index for the current round;

[0032] The target reward is calculated as follows:

[0033] If the distance between the current low-dimensional feature vector and the current target vector is less than or equal to a preset threshold When the reward is 1, the reward value is 1; otherwise, it is 0.

[0034] Furthermore, in step 3, after the agent selects an action from the preset action space based on the observation state, it selects specific modification content from the candidate content pool corresponding to the selected action through Thompson sampling, and updates the Beta distribution parameters of the Thompson sampling based on whether the environmental reward is obtained in the current round.

[0035] A second aspect of this invention proposes a malware test sample generation system based on goal-oriented reinforcement learning, comprising:

[0036] The feature filtering module is used to extract initial feature vectors for malicious software samples and benign samples respectively. Through important and modifiable feature filtering, low-dimensional feature vectors are selected from the initial feature vectors based on feature importance and feature modifiability, and the low-dimensional feature vectors are normalized.

[0037] The target generation module is used to train a diffusion model using the low-dimensional feature vector of the benign sample; after adding noise to the low-dimensional feature vector of the malicious software sample, it is input into the diffusion model and generated by reverse denoising to conform to the benign feature distribution.

[0038] The reinforcement learning interaction module is used to concatenate the low-dimensional feature vector of the current malware sample with the current target vector in the current round to form the agent's observation state. The agent selects an action from a preset action space based on the observation state, modifies the PE file of the malware sample using the selected action, and generates a test sample. The test sample is submitted to the target detector, and the judgment result returned by the target detector is obtained. The environment reward is calculated based on the judgment result. The distance between the current low-dimensional feature vector and the current target vector is calculated, and the target reward is calculated based on the distance. The environment reward and the target reward are added together to obtain the total reward.

[0039] The experience replay and training module is used to store the trajectory data generated in the current round into the experience buffer pool; sample training trajectories from the experience buffer pool; for each sampled trajectory, use the post-experience replay algorithm to select the subsequent state in the trajectory as the new target; recalculate the total reward of each step in the trajectory based on the new target; and update the network parameters of the agent using the recalculated data.

[0040] The iteration control module is used to control the reinforcement learning interaction module and the experience playback and training module to be executed repeatedly until a preset termination condition is met.

[0041] A third aspect of the present invention provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the method described in any of the preceding claims.

[0042] A fourth aspect of the present invention provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the method described in any of the preceding claims.

[0043] Compared with the prior art, the present invention has the following beneficial effects:

[0044] (i) Significantly improve the effectiveness and concealment of test sample generation.

[0045] This invention achieves superior performance on various mainstream heterogeneous detectors using a goal-oriented reinforcement learning framework. Experimental results show that in tests against MalConv, a deep learning detector based on raw byte sequences, the detector's false positive rate reaches 97.67%, significantly higher than the random baseline level (87.51%). Simultaneously, the generated test samples require only an average of 5.73 queries to successfully induce a false positive, demonstrating significantly better generation efficiency than existing methods; the average file size increase is only 4.57%, effectively maintaining the sample's stealth and reducing the risk of being flagged as anomaly by other security tools. Verification experiments show that the API call sequence of the generated test samples is highly consistent with the original samples, proving that the modifications did not destroy the original functionality of the samples and ensured the functional integrity of the test samples.

[0046] (ii) It eliminates the dependence on the feature space of the target detector and has strong generalization ability in black-box scenarios.

[0047] This invention constructs a low-dimensional observation state independent of the target detector's feature space through an important modifiable feature selection mechanism. The agent only needs to submit the original PE file to the detector and obtain the binary classification result to complete the interaction and learning, without requiring any prior knowledge of the detector's internal feature extraction process or model parameters. This mechanism enables the invention to be directly applied to detectors in real-world black-box scenarios such as commercial antivirus software and cloud-based detection APIs, greatly expanding its application scope in practical security testing. Furthermore, as a general-purpose architecture, this framework can seamlessly adapt to various mainstream reinforcement learning algorithms such as DQN, A3C, and PPO, demonstrating excellent algorithm compatibility.

[0048] (iii) Effectively alleviate the reward sparsity problem in reinforcement learning and improve training efficiency and strategy quality.

[0049] This invention introduces a goal-oriented reinforcement learning mechanism. It generates an initial target vector conforming to a benign feature distribution through a diffusion model and employs a post-hoc experience replay algorithm to provide the agent with dense intermediate reward signals based on target distance. This effectively solves the problem of low learning efficiency caused by extremely sparse reward signals in existing methods. This composite reward architecture enables the agent to obtain continuous and meaningful feedback during training, significantly accelerating model convergence, reducing training costs, and guiding the agent to learn the optimal strategy that minimizes the cost of modification to induce misjudgments by the detector, thus avoiding the problem of compromising sample concealment due to excessive modification.

[0050] (iv) Significantly compress the state space dimension and reduce the complexity of policy search.

[0051] This invention employs an important modifiable feature selection mechanism, integrating two metrics: SHAP value (feature importance) and Average Distance Change (ADV) (feature modifiability). This compresses the agent's observed state from over 2000 dimensions of the original EMBER features to several hundred dimensions, effectively alleviating the "curse of dimensionality" problem caused by high-dimensional state spaces, reducing the complexity of policy search, and improving the stability and convergence speed of reinforcement learning training. Simultaneously, this selection mechanism retains the most valuable feature information for decision-making while compressing dimensionality, ensuring the effectiveness of the state representation. Attached Figure Description

[0052] Figure 1 This is one of the overall flowcharts of a method for generating malware test samples based on goal-oriented reinforcement learning, provided in an embodiment of the present invention.

[0053] Figure 2 The second overall flowchart of a method for generating malware test samples based on goal-oriented reinforcement learning provided in an embodiment of the present invention;

[0054] Figure 3 A schematic diagram of the architecture of a malware test sample generation system based on goal-oriented reinforcement learning provided in an embodiment of the present invention;

[0055] Figure 4 This is a schematic diagram of an electronic device structure provided in an embodiment of the present invention. Detailed Implementation

[0056] The present invention will be further explained below with reference to the accompanying drawings and specific embodiments:

[0057] like Figure 1 , Figure 2 As shown, a method for generating malware test samples based on goal-oriented reinforcement learning includes:

[0058] S1: Extract initial feature vectors for malware samples and benign samples respectively. Filter the samples based on important and modifiable features. Select low-dimensional feature vectors from the initial feature vectors according to feature importance and modifiability, and normalize the low-dimensional feature vectors.

[0059] S2: Train the diffusion model using the low-dimensional feature vector of the benign sample; add noise to the low-dimensional feature vector of the malicious software sample and input it into the diffusion model, and generate an initial target vector that conforms to the benign feature distribution through reverse denoising.

[0060] S3: In the current round, the low-dimensional feature vector of the current malware sample is concatenated with the current target vector to form the agent's observation state; the agent selects an action from a preset action space based on the observation state, modifies the PE file of the malware sample using the selected action, and generates a test sample; the test sample is submitted to the target detector, and the judgment result returned by the target detector is obtained; the environmental reward is calculated based on the judgment result; the distance between the current low-dimensional feature vector and the current target vector is calculated, and the target reward is calculated based on the distance; the environmental reward and the target reward are added together to obtain the total reward;

[0061] S4: Store the trajectory data generated in the current round into the experience buffer pool; sample training trajectories from the experience buffer pool; for each sampled trajectory, use the post-experience replay algorithm to select the subsequent state in the trajectory as the new target; recalculate the total reward of each step in the trajectory based on the new target; and update the network parameters of the agent using the recalculated data.

[0062] S5: Repeat S3 and S4 until the preset termination condition is met.

[0063] This invention first utilizes Important Modifiable Feature Screening (IMFS) technology to extract low-dimensional features of malware, and then trains a diffusion model based on these features to generate target vectors of benign features, thereby addressing the problems of unknown feature space and excessively high state dimensionality in black-box detectors. During the goal-oriented reinforcement learning process, the agent interacts with the detector by modifying malware, and combines this with the Historical Experience Replay (HER) algorithm to alleviate the reward sparsity problem using goal rewards, thus efficiently generating test samples for the detector.

[0064] Furthermore, the method specifically includes:

[0065] (I) Overall Technical Concept

[0066] This invention proposes a method called "A Goal-Oriented Reinforcement Learning-Based Robustness Evaluation Framework for Malware Detection Models," aiming to address the core challenges faced by existing reinforcement learning methods in black-box testing scenarios. Firstly, to address the issues of unknown feature space in black-box malware detectors and excessively high state dimensionality in reinforcement learning, the Important Modifiable Feature Selection (IMFS) method is used. Using SHAP values ​​and the average distance change (ADV) of actions as evaluation criteria, low-dimensional features are extracted from malware samples. This feature space is independent of the detector's feature space.

[0067] Simultaneously, the same features are extracted from a large number of benign samples to train a feature vector diffusion model, which aims to generate target vectors with benign feature distributions. When constructing the initial target for goal-oriented reinforcement learning, the low-dimensional features of the current malware sample are noise-added and input into the diffusion model. The diffusion model is then used to generate the initial target, and the low-dimensional features and the initial target are used together as the initial observations for reinforcement learning.

[0068] During reinforcement learning, the agent selects modification actions based on observations, uses these actions to modify malware samples, and then obtains a new state. The modified malware sample interacts with the target detector, and the agent provides environmental rewards based on the detector's feedback. Once the detector is successfully misclassified or the maximum number of modifications is reached, one round of the training process ends, and the training trajectory is saved to the experience buffer.

[0069] Then, the HER algorithm is used to select the training state. The following each state As a new goal or using the original goal Target identification is performed, and additional target rewards are given based on the distance to the target. The final reward will be calculated by combining environmental rewards and objective rewards. The updated reward data is used as training data for the agent, and the updated agent is trained. By adding additional rewards, the problem of sparse rewards in reinforcement learning when constructing malware test samples is alleviated.

[0070] (ii) Important Modifiable Feature Screening Mechanism

[0071] Because the specific input features relied upon by the target detector are unknown to the tester in a black-box scenario, the agent cannot use feature representations consistent with those of the detector for observation. To address this issue, a general low-dimensional state observation space needs to be constructed. For the agent, the features of the observed values ​​not only need to reflect the current state but can also be affected by added actions. Therefore, the SHAP value is used to reflect the importance of features, and the Average Distance Variation (ADV) of different actions reflects the degree of modifiability, i.e., Important Modifiable Feature Selection (IMFS). Here, the SHAP value is a game theory-based model interpretability analysis method. Its core advantage lies in its ability to quantify the contribution of each feature to the model output, thereby helping to select features with high value for the agent's observations; ADV is the average size by which each action can change a feature, reflecting the degree of influence of the action that modifies the feature.

[0072] Compared to using raw bytes directly as observations, the features used in the EMBER feature set can reduce the dimensionality to over 2000 dimensions. However, some of these features have less value for reinforcement learning observations. Therefore, based on this, they are further filtered according to the degree of influence of actions on each EMBER feature.

[0073] The average distance change is calculated by taking the distance of each feature class before and after the action modification, after removing the value of the original feature class. The average distance change is defined as follows:

[0074]

[0075] in This refers to a sample of malware. This represents the sample after one modification. Indicates the first Each feature class Represents the features of the original sample. This represents the modified sample features. Representation of features middle The first of the class features Each element.

[0076] The IMFS mechanism uses both metrics for filtering: byte histograms, byte entropy histograms, and string information are retained because they have high SHAP importance and are significantly affected by all actions (high ADV values); general information and import / export information are discarded because they have low importance and are difficult to modify by actions; for the most important file header information, the parts that can be modified by actions, such as machine type, checksum, and timestamp, are further filtered out. Through this filtering, the observation dimension is significantly compressed from over 2000 dimensions to several hundred dimensions. Finally, to eliminate the differences in numerical scale between different features, the filtered low-dimensional feature vectors are normalized to their minimum and maximum values, mapping them to the [0,1] interval, thereby accelerating model convergence and improving training stability.

[0077] (III) Goal-oriented reinforcement learning

[0078] To alleviate the problem of sparse rewards in malware test sample construction during various reinforcement learning methods, goal-oriented reinforcement learning is introduced, which provides additional rewards based on distance from the target. With the introduction of these additional rewards, the reward function of reinforcement learning... It consists of two parts. The first is the sparse reward provided by the environment. The reward is only given when the modified malware is identified as benign by the detector; the base reward is then combined with a discount factor. of The final environmental reward is obtained by multiplying by powers. Here, the base reward is set to 10, defined as follows:

[0079]

[0080] Secondly, there are additional rewards given based on the objective. Current state With the goal When the target is close enough, an additional target reward will be given, which is set to 1 here, defined as follows:

[0081]

[0082] Ultimately, the environmental reward and the goal reward are summed to form the final reward function. This mechanism significantly improves policy optimization efficiency by integrating realistic environmental feedback with goal-oriented reward signals. This composite reward architecture effectively drives the generation process of test samples, enabling malware samples to successfully evaluate the detection system's identification capabilities.

[0083]

[0084] Before reinforcement learning training begins, an initial goal is constructed using a diffusion model in the goal-oriented approach. Although the diffusion model was initially proposed for image generation tasks, its core process of progressive noise addition and denoising is universal. Using low-dimensional feature vectors from benign samples as the training dataset, the dimensions of the model's input and output are adjusted to extend it to the generation of low-dimensional continuous feature vectors in this task. After training, the model can generate target vectors conforming to a benign feature distribution from noise or other noisy feature vectors.

[0085] During training, an experience playback mechanism is used to process the trajectory data generated by the agent's interactions. Stored in the experience replay pool. Since the agent has difficulty approaching the target in the early stages of training, using only the initial target would slow down the training speed of the entire algorithm. Therefore, hindsight experience replay (HER) is used to specifically implement the target-oriented algorithm: for each trajectory, through... Achieve goals independently The construction should be based on the initial target, rather than always using the initial target. Combined with experimental findings from HER, To select its own subsequent state as the new target, and to maximize the effectiveness and convergence efficiency of goal-oriented training, the current training state should be selected. The following each state As a new target, a target determination is made.

[0086] As one possible implementation method, to verify the effectiveness of the present invention, all experiments in this embodiment were run in a CentOS 7 Python 3.9.12 environment. The server was equipped with an Intel(R) Xeon(R) Gold 6238 CPU, 187GB of RAM, and an NVIDIA A100 40GB GPU. The dataset consisted of raw malware samples obtained from the publicly available VirusShare platform. Reinforcement learning was performed using the classic DQN as an example, and the target detector was the MalConv deep learning detector based on raw byte sequences.

[0087] This embodiment of a method for generating malware test samples based on goal-oriented reinforcement learning includes:

[0088] Step 1: Important Modifiable Feature Filter (IMFS)

[0089] Extract EMBER features (approximately 2381 dimensions) from all samples.

[0090] Calculate SHAP values: Use a pre-trained LightGBM model to calculate the SHAP value of each EMBER feature and evaluate its importance in maliciousness determination. Retain feature classes with high SHAP values, such as "byte histogram", "byte entropy histogram", "string information", and "file header information".

[0091] Calculate ADV (Average Distance Change): For each preset action, calculate its impact on various EMBER features. Retain features that can be significantly modified by the actions.

[0092] Feature fusion: Combining SHAP value and ADV, a low-dimensional feature vector (dimensionality far below 2381) is ultimately selected as the observation basis for the agent. For example, the complete byte histogram, byte entropy histogram, and string information are retained, and modifiable fields such as "machine type", "checksum", and "timestamp" are selected from the file header information.

[0093] Normalization: Max-Min normalization is performed on the selected low-dimensional feature vectors to map them to the [0,1] interval, thereby accelerating the convergence of the DQN neural network.

[0094] Step 2: Diffusion Model Training and Target Generation

[0095] Using the low-dimensional feature vectors of the 5000 benign samples extracted in step one, a one-dimensional denoising diffusion probability model is trained. When generating test samples for a single malware sample, Gaussian noise is added to its low-dimensional feature vector. The noisy feature vector is then input into the trained diffusion model, and through a reverse denoising process, a "target feature vector" conforming to a benign distribution is generated. .

[0096] Step 3: Goal-Oriented DQN Evaluation Cycle

[0097] Initial state: Low-dimensional features of the current malware The target features generated in step S2 The data are spliced ​​together to form the initial observations of DQN. .

[0098] Interaction process (maximum 32 rounds):

[0099] Action selection: DQN selects actions based on current observations. Output a Q-value vector and select the action with the highest Q-value. (For example, "internobulary filling").

[0100] Content selection: For the selected action Thompson sampling is used to select a specific data block from its corresponding pool of candidate content (e.g., 50 internodal data blocks from benign samples) for filling.

[0101] Perform modification: Apply the selected data block to the corresponding location in the original malware's PE file to generate a new test sample.

[0102] Environmental feedback:

[0103] Submit the new sample to the MalConv detector.

[0104] Environmental awards If MalConv classifies it as benign, then a sparse reward is awarded. (γ is the discount factor); otherwise, it is 0.

[0105] Store in the buffer pool: Store the state tuple Store in the buffer pool, according to the trajectory of each sample.

[0106] Termination condition: The test ends when the sample successfully deceives MalConv or the maximum number of queries (32) is reached.

[0107] Step 4: Post-hoc Experience Replay (HER) and DQN Training

[0108] DQN samples batches of data from a buffer for training. For each complete evaluation trajectory (whether successful or not), it uses the original target data. In addition to training, a subsequent state in the trajectory is randomly selected. As a new goal According to the new goals Recalculate the target reward for each step in the trajectory. Total Rewards Update its network parameters based on the new goals and rewards.

[0109] At the same time, based on the total reward r obtained, the Beta distribution parameters of the Thompson sampling under the corresponding action are updated (α is increased for success and β is increased for failure) to optimize future content selection.

[0110] This embodiment strictly follows the above process to conduct robustness evaluation tests on the MalConv detector. The detector's false positive rate is as high as 97.67%, far exceeding the random baseline (87.51%). In terms of stealth, the average number of queries required for success is only 5.73 interactions, which is extremely efficient; the average expansion rate (file size) only increases by 4.57%, maintaining strong stealth and making it difficult for file size-based detection mechanisms to identify it as an anomaly.

[0111] Functional integrity: Verified in the Cuckoo sandbox, the API call sequence of the test sample is highly consistent with the original sample, proving that the selected actions do not break its original functionality.

[0112] Based on the same inventive concept as the above-described method embodiments, such as Figure 3 As shown, this invention also proposes a malware test sample generation system based on goal-oriented reinforcement learning, comprising:

[0113] The feature filtering module is used to extract initial feature vectors for malicious software samples and benign samples respectively. Through important and modifiable feature filtering, low-dimensional feature vectors are selected from the initial feature vectors based on feature importance and feature modifiability, and the low-dimensional feature vectors are normalized.

[0114] The target generation module is used to train a diffusion model using the low-dimensional feature vector of the benign sample; after adding noise to the low-dimensional feature vector of the malicious software sample, it is input into the diffusion model and generated by reverse denoising to conform to the benign feature distribution.

[0115] The reinforcement learning interaction module is used in the current round to concatenate the low-dimensional feature vector of the current malware sample with the current target vector as the agent's observation state. The agent selects an action from a preset action space based on the observation state, modifies the PE file of the malware sample using the selected action, and generates a test sample. The test sample is submitted to the target detector, and the judgment result returned by the target detector is obtained. The environment reward is calculated based on the judgment result. The distance between the current low-dimensional feature vector and the current target vector is calculated, and the target reward is calculated based on the distance. The environment reward and the target reward are added together to obtain the total reward.

[0116] The experience replay and training module is used to store the trajectory data generated in the current round into the experience buffer pool; sample training trajectories from the experience buffer pool; for each sampled trajectory, use the post-experience replay algorithm to select the subsequent state in the trajectory as the new target; recalculate the total reward of each step in the trajectory based on the new target; and update the network parameters of the agent using the recalculated data.

[0117] The iteration control module is used to control the reinforcement learning interaction module and the experience playback and training module to be executed repeatedly until a preset termination condition is met.

[0118] The specific functions of each module mentioned above correspond exactly to the steps in the aforementioned method embodiments, and will not be repeated here.

[0119] Figure 4 An example is a schematic diagram of the physical structure of an electronic device, such as... Figure 4As shown, the electronic device may include a processor, a communications interface, a memory, and a communication bus, wherein the processor, communications interface, and memory communicate with each other via the communication bus. The processor can invoke logical instructions in the memory to execute the malware test sample generation method based on goal-oriented reinforcement learning provided in the above-described method embodiments.

[0120] Furthermore, when the logical instructions in the aforementioned memory are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, essentially, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0121] Based on the same inventive concept as the above-described method embodiments, the present invention also provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the method for generating malware test samples based on goal-oriented reinforcement learning as described above.

[0122] The computer-readable storage medium can be any tangible medium capable of storing program code, including but not limited to: read-only memory (ROM), random access memory (RAM), magnetic disk, optical disk (such as CD-ROM, DVD), flash drive, portable hard disk, magneto-optical disk, etc. The processor can be a central processing unit (CPU), graphics processing unit (GPU), digital signal processor (DSP), application-specific integrated circuit (ASIC), field-programmable gate array (FPGA), or other programmable logic device.

[0123] Those skilled in the art will understand that all or part of the processes in the above method embodiments can be implemented by hardware related to computer program instructions. The computer program can be stored in a computer-readable storage medium, and when executed, it can include the processes described in the above method embodiments. The storage medium can be a magnetic disk, optical disk, read-only memory (ROM), or random access memory (RAM), etc.

[0124] Since the program flow executed in this storage medium embodiment is exactly the same as that in the aforementioned method embodiment, the specific steps will not be repeated here.

[0125] It should be noted that the method and system for generating malware test samples based on goal-oriented reinforcement learning described in this invention are themselves positioned for legitimate network security assessment and defense enhancement scenarios. Specifically, this invention is directly applied to the following legitimate purposes: (1) Security testing of malware detection systems—by generating targeted test samples, verifying the security protection capabilities of the detection system when facing unknown variants or adversarial inputs, and discovering potential security blind spots; (2) Robustness evaluation of detection models—using test samples dynamically generated by reinforcement learning, systematically evaluating the stability and generalization ability of the detection model under different perturbation conditions, providing quantitative basis for model optimization; (3) Verification and reinforcement of defense mechanisms—simulating the evasion strategies that malicious code may adopt in real environments, testing the effectiveness of existing defense mechanisms, and thus guiding the improvement and enhancement of defense strategies. The above application scenarios are all recognized legitimate research and practice activities in the field of network security.

[0126] It is important to emphasize that the test samples generated by this invention are limited to use in the aforementioned legitimate security testing, robustness assessment, and defense verification scenarios. They are strictly prohibited from being used for any form of actual network attack, malicious code propagation, information system damage, or other acts that violate laws and regulations. The technical solution of this invention itself does not involve any illegal means or content that endangers public safety. Its core contribution lies in using reinforcement learning algorithms to improve the efficiency and relevance of test sample generation, thereby contributing to the positive improvement of network security defense capabilities. The social effects of this invention are positive and constructive. Its implementation depends on the legitimate intent of the user. Any potential abuse is not an attribute of this invention itself and should not affect its patentability.

[0127] The above description is only a preferred embodiment of the present invention. It should be noted that those skilled in the art can make several improvements and modifications without departing from the principle of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.

Claims

1. A method for generating malware test samples based on goal-oriented reinforcement learning, characterized in that, include: Step 1: Extract initial feature vectors for malware samples and benign samples respectively. Filter the initial feature vectors by important and modifiable features, and select low-dimensional feature vectors based on feature importance and modifiability. Then, normalize the low-dimensional feature vectors. Step 2: Train the diffusion model using the low-dimensional feature vector of the benign sample; add noise to the low-dimensional feature vector of the malicious software sample and input it into the diffusion model, and generate an initial target vector that conforms to the benign feature distribution through reverse denoising. Step 3: In the current round, the low-dimensional feature vector of the current malware sample is concatenated with the current target vector to form the observation state of the agent; the agent selects an action from the preset action space based on the observation state, and uses the selected action to modify the PE file of the malware sample to generate a test sample. The test sample is submitted to the target detector, the judgment result returned by the target detector is obtained, and the environmental reward is calculated based on the judgment result. Calculate the distance between the current low-dimensional feature vector and the current target vector, and calculate the target reward based on the distance; Add the environmental reward to the objective reward to obtain the total reward; Step 4: Store the trajectory data generated in the current round into the experience buffer pool; Training trajectories are sampled from the experience buffer pool. For each sampled trajectory, the subsequent state in the trajectory is selected as the new target using the post-experience replay algorithm. The total reward of each step in the trajectory is recalculated based on the new target, and the network parameters of the agent are updated using the recalculated data. Step 5: Repeat steps 3 and 4 until the preset termination condition is met.

2. The method for generating malware test samples based on goal-oriented reinforcement learning according to claim 1, characterized in that, The important modifiable feature screening includes: Calculate the SHAP value of each initial feature for the preset proxy model, and use the SHAP value to quantify the importance of the feature; Calculate the average distance change of each preset action to each initial feature, and use the average distance change to quantify the modifiability of the feature; Feature filtering is performed based on the SHAP value and the average distance change.

3. The method for generating malware test samples based on goal-oriented reinforcement learning according to claim 2, characterized in that, The initial feature vector is an EMBER feature vector, and the filtering includes: It retains all dimensions of byte histogram features, byte entropy histogram features, and string information features; Select and retain the machine type field, checksum field, and timestamp field from the file header information features; Discard general information features and import / export information features.

4. The method for generating malware test samples based on goal-oriented reinforcement learning according to claim 1, characterized in that, The training method for the diffusion model described in step 2 is as follows: Using the low-dimensional feature vectors of benign samples as training data, a one-dimensional denoising diffusion probability model is trained, enabling the model to restore the noisy feature vectors to feature vectors that conform to the benign feature distribution.

5. The method for generating malware test samples based on goal-oriented reinforcement learning according to claim 1, characterized in that, The post-hoc experience replay algorithm described in step 4 selects subsequent states in the trajectory as the new target, specifically as follows: From the current training status Select the first from the subsequent states each state As a new objective, the aforementioned It is a preset positive integer.

6. The method for generating malware test samples based on goal-oriented reinforcement learning according to claim 1, characterized in that, The environmental reward is calculated as follows: When the test sample is determined to be benign by the target detector, the reward value is... Otherwise, it is 0, where As a discount factor, Index for the current round; The target reward is calculated as follows: If the distance between the current low-dimensional feature vector and the current target vector is less than or equal to a preset threshold When the reward is 1, the reward value is 1; otherwise, it is 0.

7. The method for generating malware test samples based on goal-oriented reinforcement learning according to claim 1, characterized in that, In step 3, the agent selects an action from the preset action space based on the observation state, selects specific modification content from the candidate content pool corresponding to the selected action through Thompson sampling, and updates the Beta distribution parameters of the Thompson sampling based on whether the environmental reward is obtained in the current round.

8. A malware test sample generation system based on goal-oriented reinforcement learning, characterized in that, include: The feature filtering module is used to extract initial feature vectors for malicious software samples and benign samples respectively. Through important and modifiable feature filtering, low-dimensional feature vectors are selected from the initial feature vectors based on feature importance and feature modifiability, and the low-dimensional feature vectors are normalized. The target generation module is used to train a diffusion model using the low-dimensional feature vector of the benign sample; after adding noise to the low-dimensional feature vector of the malicious software sample, it is input into the diffusion model and generated by reverse denoising to conform to the benign feature distribution. The reinforcement learning interaction module is used to concatenate the low-dimensional feature vector of the current malware sample with the current target vector in the current round as the observation state of the agent; the agent selects an action from the preset action space according to the observation state, and uses the selected action to modify the PE file of the malware sample to generate a test sample. The test sample is submitted to the target detector, the judgment result returned by the target detector is obtained, and the environmental reward is calculated based on the judgment result. Calculate the distance between the current low-dimensional feature vector and the current target vector, and calculate the target reward based on the distance; Add the environmental reward to the objective reward to obtain the total reward; The experience playback and training module is used to store the trajectory data generated in the current round into the experience buffer pool; Training trajectories are sampled from the experience buffer pool. For each sampled trajectory, the subsequent state in the trajectory is selected as the new target using the post-experience replay algorithm. The total reward of each step in the trajectory is recalculated based on the new target, and the network parameters of the agent are updated using the recalculated data. The iteration control module is used to control the reinforcement learning interaction module and the experience playback and training module to be executed repeatedly until a preset termination condition is met.

9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the method as described in any one of claims 1 to 7.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the method as described in any one of claims 1 to 7.