Android malicious software adversarial sample generation method and computer program product
By constructing a sensitive function call graph of Android software and using a large natural language model, the similarity between software is calculated to generate adversarial samples, which solves the problem of adversarial sample generation in the existing technology relying on assumptions and achieves efficient and stable adversarial sample generation effects. .
Patent Information
- Application Number
- CN202410980266.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-22
- Publication Date
- 2024-10-29
AI Technical Summary
The existing methods for generating adversarial samples for Android malware rely on strong assumptions and are difficult to work effectively in actual environments, and the results are greatly affected by environmental variables and uncertain factors.
By constructing a sensitive function call graph of Android software, using a large natural language model for embedding, calculating the similarity between software, and generating adversarial samples based on the cosine similarity algorithm, it avoids relying on strong assumptions and achieves efficient and stable adversarial sample generation.
Without relying on strong assumptions, efficient and stable adversarial samples are successfully generated based on the semantic and structural information of sensitive function call graphs, which significantly improves the effectiveness of adversarial sample generation for Android malware.
Smart Images

Figure CN118862071A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer information security technology, and in particular to a method for generating an Android malware adversarial sample and a computer program product. Background Art
[0002] At present, the mainstream method for detecting Android (Android system) malware is the detection method based on machine learning. These detection methods in the prior art all face a common problem: the vulnerability to adversarial samples. Existing adversarial sample generation methods for Android software classification models have shown significant effects in evading detection and can bypass many existing security measures. However, these methods usually rely on strong assumptions, such as a complete understanding of the internal structure or parameters of the classification model, which is difficult to achieve in actual software. In addition, these adversarial sample generation methods perform well in laboratory environments, but in real-world scenarios, due to various environmental variables and uncertain factors, their actual effects are often greatly reduced. Therefore, how to achieve efficient and stable adversarial sample generation without relying on strong assumptions has become an important challenge in current research. Summary of the invention
[0003] In view of the shortcomings of the prior art, the present invention proposes an Android malware adversarial sample generation method and a computer program product to solve the technical problem that the generation of adversarial samples in the prior art relies on assumptions, and once used in real scenarios, its actual effect is often greatly reduced due to various environmental variables and uncertain factors.
[0004] The technical solution adopted by the present invention is as follows:
[0005] In a first aspect, a method for generating an Android malware adversarial sample is provided, comprising the following steps:
[0006] Build an Android software dataset, decompile multiple Android software in the dataset, and generate Smali files;
[0007] Parse the Smali file to extract all methods and their function call relationships;
[0008] Construct a function call graph according to the function call relationship and perform pruning based on the sensitive API to obtain a sensitive function call graph;
[0009] Convert the sensitive function call graph into natural language paragraphs, embed the natural language paragraphs using a natural language large model, and obtain a vector representation of the Android software;
[0010] According to the vector representation of the Android software, the similarity between the Android software is calculated based on the cosine similarity algorithm;
[0011] Dividing the Android software dataset into a training set and a test set, using the training set to train the Android malware classification model, and using the test set to test it;
[0012] According to the test results of the test set and the similarity between Android software, the original malicious sample set and the perturbation set are constructed;
[0013] Generate adversarial samples based on the original malicious sample set and the perturbation set.
[0014] Furthermore, constructing a sensitive function call graph according to the function call relationship includes:
[0015] Extract all function call relationships from each method, convert the function call relationships into directed connections between two nodes, and obtain a directed graph with all methods as nodes and the call relationships between them as edges as a function call graph;
[0016] According to the function call graph, a sensitive function call graph is constructed using a function call graph pruning method based on sensitive APIs.
[0017] Furthermore, the function call graph pruning method based on sensitive API includes:
[0018] Preset sensitive API set;
[0019] For the preset sensitive API set, find the sensitive API nodes in each function call graph;
[0020] Taking these sensitive API nodes as the starting point, a breadth-first search is performed to retain only the function call relationships within the n-hop range around the sensitive API in the function call graph.
[0021] Furthermore, the sensitive function call graph is converted into a natural language paragraph, including: analyzing the type, name, and package name information of the caller API and the called API in the function call relationship, and converting the API into natural language in a predetermined "type-name-class-authority" format and using the "invokes" keyword to connect the API pairs into a complete natural language statement; converting each function call relationship in the sensitive function call graph into a natural language statement one by one; and combining the converted natural language statements into paragraphs.
[0022] Furthermore, according to the vector representation of Android software, the similarity between Android software is calculated based on the cosine similarity algorithm. The formula for calculating the similarity of Android software is:
[0023]
[0024] in, For APK i With APK j The similarity between For SFCG i With SFCG j Similarity between SFCG i For APK i The obtained sensitive function call graph, SFCG j For APK j The obtained sensitive function call graph, For SFCG i The vector representation generated by BERT is For SFCG j Vector representation generated by BERT.
[0025] Furthermore, a set of malware in the test set that is correctly classified as malicious is obtained as the original malicious sample set.
[0026] Furthermore, based on the similarity calculation results between Android software, the Smali files containing the function call relationships in the sensitive function call graphs of the benign software sets that are most similar to the original malicious sample sets are extracted to form a perturbation set.
[0027] Furthermore, the average similarity calculation formula of benign software is:
[0028]
[0029] in, is the average similarity between benign software i and the malware collection, is the similarity between benign software i and malware j, and m is the number of software in the Android malware collection.
[0030] Furthermore, generating adversarial samples according to the original malicious sample set and the perturbation set includes:
[0031] The original software sample of the original malicious sample set is decompiled, and a perturbation is randomly selected from the perturbation set using a random search strategy, and the perturbation is inserted into the Smali directory corresponding to the class where the API is located.
[0032] In a second aspect, a computer program product is provided, including a computer program / instruction, which, when executed by a processor, implements the steps of the method for generating Android malware adversarial samples described in the first aspect.
[0033] It can be seen from the above technical solution that the beneficial technical effects of the present invention are as follows:
[0034] Without relying on strong assumptions, perturbations are inserted into Android malware based on the semantic and structural information of sensitive function call graphs to achieve efficient and stable adversarial sample generation, which shows good results in the task of generating adversarial samples for Android malware. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] In order to more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the following is a brief introduction to the drawings required for the specific embodiments or the prior art description. In all the drawings, similar elements or parts are generally identified by similar reference numerals. In the drawings, the elements or parts are not necessarily drawn according to the actual scale.
[0036] Figure 1 This is a flow chart of a method for generating adversarial samples according to an embodiment of the present invention;
[0037] Figure 2 This is an example of the API entity structure;
[0038] Figure 3 This is an example of the method entity structure in Smali. DETAILED DESCRIPTION
[0039] The following embodiments of the technical solution of the present invention are described in detail in conjunction with the accompanying drawings. The following embodiments are only used to more clearly illustrate the technical solution of the present invention, and are therefore only used as examples, and cannot be used to limit the protection scope of the present invention.
[0040] It should be noted that, unless otherwise specified, the technical terms or scientific terms used in this application should have the common meanings understood by those skilled in the art to which the present invention belongs.
[0041] Example
[0042] This embodiment provides a method for generating an Android malware adversarial sample. Figure 1 As shown, the method comprises the following steps:
[0043] Step 1: Build an Android software dataset, decompile multiple Android software in the dataset, and generate Smali files
[0044] In some embodiments, a large number of Android software samples from a public dataset (such as AndroZoo) are collected to ensure that the construction of the Android software dataset covers a wide range of areas, and the samples in the Android software dataset include malware and benign software. In this embodiment, the collected Android software experimental dataset contains a total of 26,447 APKs (Android application packages), of which 9,308 malicious samples are from the open source AndroZoo, and 17,139 benign samples are from AndroZoo.
[0045] Use an Android software decompilation tool (such as the decompilation tool Apktool officially provided by Google) to decompile each collected Android software and generate a Smali file corresponding to its source code. The Smali file contains the bytecode of the software, which is convenient for further analysis.
[0046] Step 2: Parse the Smali file and extract all methods and their function call relationships
[0047] In a specific implementation, the method for parsing the Smali file is as follows:
[0048] Read each Smali file in turn and identify the keywords in Smali: the ".class" keyword corresponds to the name of the class corresponding to the Smali file, the ".method" keyword defines the beginning of the method, and the ".end method" keyword defines the end of the method. Each method is regarded as the smallest divisible unit; the ".invoke" keyword defines the calling relationship, thereby extracting all methods and their function calling relationships in the class.
[0049] Based on the extracted function call relationship, a directed function call graph can be constructed in the subsequent steps, which can reflect the behavior pattern of APK and plays a vital role in Android malware detection and adversarial sample generation tasks. The parsing method of Smali file in this step is customized by the inventor, and the extracted function call relationship is more comprehensive and complete than the function call relationship extracted by commonly used tools such as FlowDroid and Androguard.
[0050] Step 3: Construct a function call graph based on the function call relationship and prune based on the sensitive API to obtain a sensitive function call graph
[0051] First, we extract all the function call relationships from each method and convert them into directed connections between two nodes, thus obtaining a directed graph with all methods as nodes and the call relationships between them as edges, which is the function call graph (FCG) of the software. FCG represents the call relationship between methods and is the basis for further analysis and generation of adversarial samples.
[0052] Then, according to FCG, a sensitive function call graph (SFCG) pruning method based on sensitive APIs is used to construct the sensitive function call graph (SFCG). Sensitive APIs (application programming interfaces), in this embodiment, are system APIs related to sensitive permissions, and the set of these APIs is defined as a sensitive API set.
[0053] The inventor's customized function call graph (FCG) pruning method based on sensitive API specifically includes the following steps:
[0054] 1. Preset sensitive API set. When building SFCG, you need to preset a sensitive API set. The specific method is: collect the mapping relationship between sensitive permissions and APIs, collect and organize multiple permissions and API mapping relationships, such as AXplore, PSCout, etc., and conduct a comprehensive analysis of these mapping relationships to extract which APIs are related to sensitive permissions, and obtain a set of all sensitive APIs as the preset sensitive API set. According to the APK data sample of this embodiment, a total of 550 sensitive APIs are obtained as the preset sensitive API set.
[0055] 1. For the preset sensitive API set, find the sensitive API nodes in each FCG.
[0056] 2. Borrowing the idea of the N-grams algorithm, take these sensitive API nodes as the starting point, perform a breadth-first search (BFS), and only retain the function call relationships within the n-hop range around the sensitive API in the FCG. Specifically, the sensitive API nodes are traversed by the BFS algorithm, and all function call relationships within the n-hop range of these nodes and their surroundings are recorded. Preferably, the value of n here is 2, and this value is determined after conducting experiments by balancing factors such as the size of the graph and the information retained by the computational cost. During the traversal process, the nodes and edges in the original FCG that are not within the n-hop range around the sensitive API are removed to obtain a simplified sensitive function call graph (SFCG). This method effectively removes irrelevant call relationships and highlights the call path of sensitive APIs.
[0057] Through this pruning method based on the N-grams algorithm combined with the BFS algorithm, the complexity of the function call graph can be greatly simplified while retaining key sensitive API call relationships, thereby improving the efficiency and effectiveness of malware detection and adversarial sample generation.
[0058] Step 4: Convert the sensitive function call graph into natural language paragraphs, embed the natural language paragraphs using the natural language big model, and obtain the vector representation of Android software
[0059] In the subsequent steps, the similarity between samples will be calculated. In order to convert the similarity calculation problem of SFCG obtained by APK conversion into the cosine similarity calculation problem of vectors, SFCG needs to be converted into a vector.
[0060] First, the sensitive function call graph is converted into natural language paragraphs, which specifically includes: analyzing the type, name, package name and other information of the caller API and the called API in the function call relationship, and converting the API into natural language according to the predetermined "type-name-class-authority" format, and using the "invokes" keyword to connect the API pairs into a complete natural language statement, and then converting each function call relationship in the sensitive function call graph into a natural language statement one by one. In the converted natural language, each statement can clearly express the detailed information of the call relationship. The converted natural language statements are combined into paragraphs so that each SFCG corresponds to a natural language paragraph. These paragraphs describe the call process involving sensitive operations in Android software.
[0061] Then, the natural language model BERT is used to embed the generated natural language paragraphs to obtain the vector representation of the paragraphs. The BERT model can simultaneously consider the contextual information of words and capture the semantic information of natural language paragraphs, which is convenient for subsequent similarity calculations.
[0062] Compared with other methods such as Graph2Vec, the vector representation of Android software obtained by this step method can not only focus on the structural information in SFCG, but also make full use of the semantic information of the nodes in SFCG, that is, the semantic information of the API itself, which is more helpful for subsequent similarity calculation tasks and adversarial sample generation tasks.
[0063] Step 5: Calculate the similarity between Android software based on the cosine similarity algorithm according to the vector representation of Android software
[0064] By using the cosine similarity algorithm to measure the similarity between vectors, we can get the similarity between SFCGs and then the similarity between Android software. The similarity reflects the similarity of different Android software in sensitive operation calls.
[0065] Specifically: The cosine similarity between SFCGs extracted and pruned by APK is used as the measure of similarity between APKs. The formula for calculating Android software similarity is:
[0066]
[0067] in, For APK i With APK j The similarity between For SFCG i With SFCG j Similarity between SFCG i For APK i The obtained sensitive function call graph, SFCG j For APK j The obtained sensitive function call graph, For SFCG i The vector representation generated by BERT is For SFCG j Vector representation generated by BERT.
[0068] Step 6: Divide the Android software dataset into a training set and a test set, use the training set to train the Android malware classification model, and use the test set for testing
[0069] The Android software dataset (AndroZoo, etc.) is divided into a training set and a test set to ensure that the ratio of malware and benign software in the training set and the test set is similar to ensure the effectiveness of model training. The training set is used to train an Android malware classification model that needs to generate adversarial samples, and the test set is used for testing to evaluate the accuracy and robustness of the model.
[0070] In a specific implementation manner, the training set and the test set are divided in a ratio of 8:2.
[0071] Step 7: Construct the original malicious sample set and the perturbation set based on the test results of the test set and the similarity between Android software
[0072] Get the set of malware in the test set that is correctly classified as malicious as the original malicious sample set for generating adversarial samples.
[0073] According to the similarity calculation results between Android software in step 5, from the benign software set that is most similar to the original malicious sample set, extract the Smali files containing the function call relationships in the SFCG to form a perturbation set. Specifically:
[0074] According to the above-mentioned APK similarity calculation method based on cosine similarity, the similarity of all malware in the benign software and malware set is calculated respectively, and sorted according to the average similarity to obtain the set of benign software that is most similar to the malware as the set of candidate software for perturbation extraction. The average similarity calculation formula of benign software is:
[0075]
[0076] In the above formula, is the average similarity between benign software i and the malware collection, is the similarity between benign software i and malware j, and m is the number of software in the Android malware collection.
[0077] Based on the above formula, a set of candidate software for perturbation extraction is obtained. Next, the Smali files corresponding to each function call in the SFCG of these candidate software are extracted as perturbations to construct a perturbation set. For each benign software in the set of candidate software for perturbation extraction, each function call in its SFCG is divided into a caller and a callee. According to the above-mentioned custom function call extraction algorithm, the class file where the caller method is located must be in the path indicated by the class name in the Smali directory after Apktool decompiled it. Therefore, according to the class name of the caller method, its corresponding class file can be found from the path specified by Smali, and the file is taken as a perturbation unit and added to the perturbation set. Parse and search all function call relationships in SFCG one by one, and add all class files where the caller method is located to the perturbation set. After processing each benign software in the set of candidate software for perturbation extraction, the construction of the perturbation set is completed.
[0078] Step 8: Generate adversarial samples based on the original malicious sample set and the perturbation set
[0079] The original software sample of the original malicious sample set is decompiled, and a random search strategy is used to randomly select a perturbation from the perturbation set. The perturbation is inserted into the Smali directory corresponding to the class where the API is located, for example, it can be inserted into the Smali file of the original sample, or directly inserted into a new Smali file.
[0080] Specifically, for the original malware in the original malicious sample set, use Apktool to decompile it, and then randomly select a perturbation from the perturbation set, which corresponds to a class file. Insert the perturbation into the decompiled Smali directory, and the insertion path is the path composed of the prefix of the class to which the perturbation belongs. Then randomly select a method from the original software, and insert the constructed function call that calls the perturbation into the line before the ".end method" keyword of its method. Finally, use Apktool to repackage and re-sign the decompiled directory to generate an adversarial sample.
[0081] For the generated adversarial sample, input it into the classification model trained in step 1 for prediction, and adjust the adversarial sample generation process according to the change in the confidence output by the classification model. If the classification model correctly predicts that the sample is malware, it is necessary to determine whether the current perturbation should be retained based on the change in confidence: if the confidence decreases, the perturbation is retained; otherwise, the perturbation is canceled, and the previous malware version is rolled back, and the above generation process is repeated. If the number of queries has reached the upper limit, the adversarial sample generation fails; if the classification model incorrectly predicts that the sample is benign software, the sample can successfully deceive the classification model, and the adversarial sample generation is successful.
[0082] In some embodiments, for the adversarial samples generated by the Android malware adversarial sample generation method described above, the following method is used for iterative optimization and effectiveness verification:
[0083] The regenerated samples are used as adversarial samples and input into the Android malware classification model for query. According to the output of the classification model, the parameters and strategies of the random search process are adjusted. The selection and insertion position of the perturbations are optimized to improve the success rate of deception of adversarial samples. New adversarial samples are continuously generated through repeated iterations until they are successfully generated to deceive the Android malware classification model, or the upper limit of the number of queries to the Android malware classification model is reached (i.e., generation fails).
[0084] The present invention conducts a complete experiment on the detection effect of the Android malware classification model. The experimental data set contains a total of 26447 APKs, of which 9308 malicious samples are from the open source AndroZoo and 17139 benign samples are from AndroZoo; precision, accuracy, recall, area under the ROC curve (AUC) and F1-score are selected as evaluation indicators of the performance of the Android software classification model; adversarial success rate (ASR), average query times (AQ), average modification times (AT) and average adversarial load (AS) are selected as evaluation indicators of the performance of the Android malware adversarial sample generation method. Among all 21158 samples of the trained Android software classification model, the test set contains 5289 samples, of which 1680 samples are correctly predicted as malware. The initial F1-score of the Android malware classification model is 92.26%, the precision is 91.40%, the accuracy is 93.41%, the recall is 93.12% and the AUC value is 97.69%. After simulating adversarial attacks on 100 randomly selected malware that were correctly predicted to be malware, the adversarial success rate (ASR) was 93.5%, the average number of queries (AQ) was 3.1, the average number of modifications (AT) was 1.8, and the average adversarial payload (AS) was 1.7%.
[0085] In some embodiments, a computer program product is also provided, including a computer program / instruction, which, when executed by a processor, implements the steps of the Android malware adversarial sample generation method described above.
[0086] The technical solution provided in this embodiment does not rely on strong assumptions. Based on the semantic and structural information of sensitive function call graphs, perturbations are inserted into Android malware to achieve efficient and stable adversarial sample generation, which shows good results in the task of generating adversarial samples for Android malware.
[0087] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein by equivalents. These modifications or replacements do not make the essence of the corresponding technical solutions deviate from the scope of the technical solutions of the embodiments of the present invention, and they should all be included in the scope of the claims and specification of the present invention.
Claims
1. A method for generating adversarial samples of Android malware, characterized in that: The following steps are involved: Build an Android software dataset, decompile multiple Android software in the dataset, and generate Smali files; Parse the Smali file to extract all methods and their function call relationships; Construct a function call graph according to the function call relationship and perform pruning based on the sensitive API to obtain a sensitive function call graph; Convert the sensitive function call graph into natural language paragraphs, embed the natural language paragraphs using a natural language large model, and obtain a vector representation of the Android software; According to the vector representation of the Android software, the similarity between the Android software is calculated based on the cosine similarity algorithm; Dividing the Android software dataset into a training set and a test set, using the training set to train the Android malware classification model, and using the test set to test it; According to the test results of the test set and the similarity between Android software, the original malicious sample set and the perturbation set are constructed; Generate adversarial samples based on the original malicious sample set and the perturbation set.
2. The method for generating an Android malware adversarial sample according to claim 1, characterized in that: Constructing a sensitive function call graph according to the function call relationship, including: Extract all function call relationships from each method, convert the function call relationships into directed connections between two nodes, and obtain a directed graph with all methods as nodes and the call relationships between them as edges as a function call graph; According to the function call graph, a sensitive function call graph is constructed using a function call graph pruning method based on sensitive APIs.
3. The method for generating an Android malware adversarial sample according to claim 1, characterized in that: Function call graph pruning method based on sensitive API, including: Preset sensitive API set; For the preset sensitive API set, find the sensitive API nodes in each function call graph; Taking these sensitive API nodes as the starting point, a breadth-first search is performed to retain only the function call relationships within the n-hop range around the sensitive API in the function call graph.
4. The method for generating Android malware adversarial samples according to claim 1, characterized in that: Convert sensitive function call graphs into natural language paragraphs, including: analyzing the type, name, and package name information of the caller API and the called API in the function call relationship, converting the API into natural language in the predetermined "type-name-class-authority" format, and using the "invokes" keyword to connect the API pairs into a complete natural language statement; Convert each function call relation in the sensitive function call graph into a natural language statement one by one; Group the converted natural language sentences into paragraphs.
5. The method for generating Android malware adversarial samples according to claim 1, characterized in that: According to the vector representation of Android software, the similarity between Android software is calculated based on the cosine similarity algorithm. The formula for calculating the similarity of Android software is: in, For APK i With APK j The similarity between For SFCG i With SFCG j Similarity between SFCG i For APK i The obtained sensitive function call graph, SFCG j For APK j The obtained sensitive function call graph, For SFCG i The vector representation generated by BERT is For SFCG j Vector representation generated by BERT.
6. The method for generating an Android malware adversarial sample according to claim 5, characterized in that: The malware set in the test set that is correctly classified as malicious is obtained as the original malicious sample set.
7. The method for generating Android malware adversarial samples according to claim 6, characterized in that: According to the similarity calculation results between Android software, the Smali files containing the function call relationships in the sensitive function call graph are extracted from the benign software set that is most similar to the original malicious sample set to form a perturbation set.
8. The method for generating Android malware adversarial samples according to claim 7, characterized in that: The average similarity calculation formula for benign software is: in, is the average similarity between benign software i and the malware collection, is the similarity between benign software i and malware j, and m is the number of software in the Android malware collection.
9. The method for generating an Android malware adversarial sample according to claim 1, characterized in that: Generating adversarial samples according to the original malicious sample set and the perturbation set includes: The original software sample of the original malicious sample set is decompiled, and a perturbation is randomly selected from the perturbation set using a random search strategy, and the perturbation is inserted into the Smali directory corresponding to the class where the API is located.
10. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instruction is executed by a processor, the steps of the method according to any one of claims 1 to 9 are implemented.
Citation Information
Cited By
Universal adversarial sample generation method for Android malicious software
CN121637496A
An android malware universal adversarial sample generation method
CN121637496B
