A method for detecting malicious third-party component packages in Maven repositories

By building component package datasets in Maven repository, generating sensitive behavior subgraphs and using heterogeneous graph neural network model, the inaccurate semantic representation of malicious code and insufficient fine-grained static analysis in malicious detection of third-party component packages in Maven repository are solved. The problem of this is to realize malicious component package detection with high accuracy and low false alarm rate.

CN118133284BActive Publication Date: 2024-11-22SICHUAN UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410385472.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-04-01
Publication Date
2024-11-22
Estimated Expiration
2044-04-01

AI Technical Summary

Technical Problem

The existing technology has problems such as inaccurate semantic representation of malicious code and insufficient fine-grained static analysis in the malicious detection of third-party component packages in Maven warehouses, which leads to poor robustness of the model and is difficult to achieve high accuracy and low false alarm detection. .

Method used

By collecting Java component packages and malicious samples from Maven central repository, building component package datasets, setting up sensitive API call collections, generating method call graphs and sensitive data flow analysis, obtaining vector representations of sensitive behavior subgraphs, and using heterogeneous graph neural The network model is classified in the whole graph and malicious detection is carried out.

Benefits of technology

It improves the accuracy and recall of malicious component package detection, reduces the noise impact of the model on irrelevant semantics, enhances the semantic representation ability of code, and achieves detection effects of high accuracy and low false alarm rates.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118133284B_ABST
    Figure CN118133284B_ABST
Patent Text Reader

Abstract

A malicious detection method for third-party component packages in Maven warehouses, firstly constructs a component package data set and sets a sensitive API call set as a heuristic rule for subsequent subgraph extraction; in view of the characteristic that the component package has no fixed entry method, uses specific rules to obtain the user's potential use API as the entry method set of the call graph generation algorithm, and applies the context-sensitive pointer analysis algorithm to the call graph generation; uses the sensitive API call set as a heuristic rule to obtain a call subgraph, then generates an inter-procedural control flow graph for the call subgraph, and analyzes the sensitive data flow at the same time to construct a sensitive behavior subgraph; obtains the vector representation of the nodes and edges of the sensitive behavior subgraph as the input of the heterogeneous graph GCN model, performs model training and detects malicious component packages. The present invention can enhance the code characterization capability of the malicious behavior of the component package, reduce the noise during model training, improve the detection accuracy and reduce the false alarm rate.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of software security, and specifically designs a method for detecting maliciousness of third-party component packages in a Maven repository. Background Art

[0002] Using reusable open source component packages to quickly and efficiently develop large-scale software projects has become the mainstream of modern software development. Developers can use related build tools to conveniently use third-party components, or publish their own components to the software source, thus forming a software supply chain. According to statistics, Java is still the preferred programming language for enterprise software project development, and nearly 60% of software projects independently developed by domestic enterprises account for. As a package ecosystem for Java component packages, Maven's number of open source projects and growth rate are both at the forefront of mainstream package ecosystems. However, attackers can also inject malicious code into open source component packages or release malicious software packages, and use the dependency chain between components to spread to other components or projects, thereby bringing huge security risks to the Java open source component ecosystem.

[0003] Maliciousness detection of third-party component packages in Maven is a branch of malicious code detection tasks. A typical scenario for malicious code detection is that for a given software, specific rules are used for matching or pre-trained machine learning models are used for prediction, and the output is whether the software is malware. The process of maliciousness detection of Maven component packages includes: after analyzing the Java bytecode files in the target component package set, the intermediate representation of each component package is obtained, and the control flow and data flow representation of the code semantics are obtained based on the intermediate representation using a static program analysis algorithm; after obtaining the corresponding code representation, the vectorized representation is obtained using a feature embedding method, and used as training data for the deep learning model. After the training is completed, the model is used to identify the maliciousness of the component package.

[0004] The detection method based on source code text features extracts sensitive fields and text statistical features from the source code for machine learning classification. Although detection can be achieved, there are problems such as poor scalability and model generalization effect and high dependence on the decompilation engine; the method based on runtime features can execute the program in a controlled environment to obtain the dynamic behavior characteristics of the program and the impact on the system environment, but there are problems such as high difficulty and high cost. The method based on the combination of program static analysis and deep learning is currently the mainstream method in the field of malicious code detection research, including malicious component package detection tasks, but the existing methods still have problems such as inaccurate semantic representation of malicious code and insufficient granularity of static analysis: for example, existing studies have converted the entire component package into an inter-procedural control flow graph without considering the semantic features of the malicious code part separately, which introduces a lot of noise into the training of the deep learning model; or the lack of fine-grained analysis of the sensitive operation data flow of the component package makes the semantic representation of the code insufficient, making it difficult to train a more robust model. Summary of the invention

[0005] In view of this, the present invention provides a maliciousness detection method for third-party component packages in Maven warehouses, aiming to perform real-time detection of potential malicious component packages in Maven warehouses, and help network security practitioners obtain software supply chain attack threats in a timely and rapid manner.

[0006] A method for detecting maliciousness of a third-party component package in a Maven repository, the method comprising:

[0007] Step 1: Collect Java component packages from the Maven central repository as benign samples, collect malicious JAR packages from mainstream malware sample libraries as malicious samples, and build a component package dataset;

[0008] Step 2: Set up a sensitive API call set that meets the characteristics of Java programs and open source component packages;

[0009] Step 3: Generate a component package method call graph and divide the call subgraph based on sensitive API calls;

[0010] Step 4: Perform inter-procedural control flow analysis and sensitive data flow analysis to obtain sensitive behavior subgraphs;

[0011] Step 5: Obtain the vector representation of the nodes and the vector representation of the edges in the sensitive behavior subgraph, which together constitute the vector representation of the sensitive behavior subgraph;

[0012] Step 6: Use the sensitive behavior subgraph vector representation of the component package sample as input to train the heterogeneous graph neural network model, perform whole-graph classification, and obtain malicious detection results.

[0013] Preferably, in step 1, the component package data set construction process includes:

[0014] Use a web crawler to crawl third-party component packages in the top 150 popular categories on the Maven central repository, and select the latest version of each component package; collect malicious JAR packages as malicious samples from mainstream malware sample libraries, including VirusShare, VirusTotal, IT question-and-answer community StackOverFlow, and code hosting platforms GitHub and Gitee.

[0015] Preferably, in step 2, the Java sensitive API call set construction process includes:

[0016] According to Java official documents, existing literature and technical reports, and malicious code samples, a set of Java sensitive API calls is set; further, according to different sensitive behaviors, the API calls in Java are divided into categories such as data transmission, script execution, command execution, file operation, environment information reading, encoding encryption and decryption; these sensitive APIs are grouped into a set M sens , where each API is represented using its method signature.

[0017] Preferably, in step 3, the component package calls the subgraph partitioning process including:

[0018] For a given component package, a static program analysis framework suitable for Java language is used to analyze the component package and generate its intermediate language representation IR;

[0019] Analyze the IR of the component package to obtain the associated information of all methods and classes in the component package: for classes, obtain information about their access modifiers, parent classes, static variables, static methods, and class signatures; for methods, obtain information about their access modifiers, parameter types, return value types, method signatures, parameter names, and internal method bodies;

[0020] To obtain the potential entry method of the component package, if the method m meets the following conditions:

[0021] Condition 1. The access modifier of m is Public or Protect;

[0022] Condition 2.m belongs to class C m The access modifier is Public or the class C m There is a subclass in the subclass of The access modifier is Public and Method m is not rewritten;

[0023] If m satisfies both condition 1 and condition 2, then the method is called a user-callable method, denoted by mclient ;

[0024] Condition 3.m is a static initializer and belongs to class C m The access modifier is Public;

[0025] Condition 4. m belongs to m client And the method is a static method or its class C m is instantiable;

[0026] If condition 3 or condition 4 is met, method m is a potential entry method, denoted by m entry ;

[0027] Apply the potential entry method identification rule to all methods in the component package to filter out potential entry methods m entry , and serves as the entry node set M for the call graph generation algorithm entry ;

[0028] A pointer analysis algorithm is applied to the IR of the component package to generate a pointer flow graph to represent the flow of pointers in the program. A two-layer call point sensitive 2-CFA is used as a context sensitive strategy, and the first two call points are used as context information to distinguish the pointer pointing relationship in different contexts.

[0029] In the process of the pointer analysis, the method call relationship is obtained according to the analysis result, and a method call graph MCG is constructed: G = (V, E), where V represents a set of reachable method nodes in the component package, and E represents a set of method node pairs with call relationships, and the method node pairs are represented by edges between nodes in the method call graph;

[0030] Use the Java sensitive API call set M described in step 2 sens , for each sensitive API call m in the set i ∈M sens , search from G's reachable method node set V using regular matching according to its method signature. If a method node v is matched i , then according to the node v i Get its k-hop induced subgraph

[0031] right To prune, first remove the edges that cannot reach v along the call edge. i , and then delete the remaining nodes with Disconnected nodes, the processed results are used as sensitive call subgraphs

[0032] Preferably, in step 4, the sensitive behavior subgraph construction process includes:

[0033] Use the sensitive call subgraph constructed in step 3 to obtain the control flow graph CFG of each developer-defined method, and expand the sensitive call subgraph into an inter-procedural control flow graph ICFG;

[0034] Perform definition reachability analysis on each CFG. If there is a def-use chain or use-def chain between basic blocks, there is a data dependency edge. This is used to construct the data dependency graph DDG of the developer's custom method.

[0035] Using the sensitive API call set described in step 2, search for basic blocks b containing sensitive API calls in the data dependency graph based on method subsignature regular matching. sens , and b sens As the starting node, use breadth-first traversal to traverse the data dependency graph and obtain b sens A reachable subgraph of , where all data dependency edges are added as sensitive data flow edges to CFG;

[0036] By performing data flow analysis on sensitive API calls and obtaining sensitive behavior information, we can obtain a sensitive behavior subgraph with stronger code semantic representation capabilities. The sensitive behavior subgraph consists of basic blocks and edges. The basic blocks represent the information of method calls and statements within methods. The edge information includes five types of edges: ordinary edges of the control flow graph within the procedure, call-return edges connecting call points and return points, call edges and return edges representing control flow information between procedures, and sensitive data flow edges.

[0037] Preferably, in step 5, the process of extracting the vector representation of the sensitive behavior subgraph includes:

[0038] Based on the sensitive behavior subgraph described in step 4, in order to avoid affecting the training of the Doc2vec model, data preprocessing is performed on the basic blocks in the subgraph, and the line number of the statement contained in the call statement IR generated in the static analysis framework and the index information in the control flow graph are removed;

[0039] Add the fully qualified class name before the variables and parameters in the basic block so that it can contain more code semantics; use the processed basic block as a corpus to train the Doc2Vec model and obtain the vector representation of each subgraph node;

[0040] Based on the sensitive behavior subgraph described in step 4, one-hot encoding is used to obtain the vector representation of the edges in the subgraph. The embedding representation of the relationship between nodes is a 5-dimensional vector, where the first dimension is used to indicate whether there is a sensitive data flow between nodes. If there is a sensitive data flow, the bit is 1, otherwise it is 0; the second to fifth dimensions represent the four types of edge relationships in the inter-procedural control flow graph;

[0041] The sensitive behavior subgraph is a heterogeneous graph, and its node feature vectors and edge feature vectors together constitute its vector representation.

[0042] Preferably, in step 6, the training process of the component package maliciousness detection model includes:

[0043] The vector representations of all sensitive behavior subgraphs of a single sample in the component package dataset constitute a vector representation set. The labels of all vector representations in the vector representation set of benign samples are marked as 0, and the labels of all vectors in the vector representation set of malicious samples are marked as 1.

[0044] The labeled vector representation set is divided into five parts, 80% of the data is used as the training set of the heterogeneous graph convolutional network model, and 20% of the data is used as the test set and validation set of the heterogeneous graph convolutional network model;

[0045] The sensitive behavior subgraph vector representations of different dimensions are built into a graph batch, and each graph batch has the same dimension;

[0046] The batched graph is input into the heterogeneous graph GCN, and the sensitive behavior subgraph is predicted as a malicious behavior subgraph in the form of whole-graph classification;

[0047] A component package with a malicious behavior subgraph greater than or equal to one is determined as a malicious component package;

[0048] The accuracy, recall rate and false positive rate are used as evaluation indicators to evaluate the detection performance of the model.

[0049] The present application provides a method for detecting maliciousness of third-party component packages in Maven repositories: first, according to the characteristics of Java programs and open source components, a sensitive API call set is collected as a heuristic rule for subsequent subgraph extraction; according to the characteristics of the Maven component package, the user's potential API is obtained as the entry method set of the call graph generation algorithm, and the pointer analysis algorithm and the context-sensitive strategy are applied to the call graph generation to obtain a more accurate method call graph; the sensitive API call set is used as a heuristic rule to obtain a call subgraph and eliminate program semantics unrelated to sensitive behavior; then the inter-procedural control flow graph is generated for the call subgraph, and sensitive data flow analysis is performed at the same time to construct a sensitive behavior subgraph; vector representations of nodes and edges of the sensitive behavior subgraph are obtained as inputs of a heterogeneous graph GCN model to train the model; compared with the prior art, the beneficial effects of the present invention are: using program static analysis technology to obtain rich code semantics of the component package, and using the sensitive API calls therein as the analysis core to perform subgraph division, thereby reducing the noise brought to the model by semantics unrelated to malicious behavior; using the sensitive data flow information inside the method to further enhance the code semantic representation capability of the subgraph, thereby ensuring the high accuracy and low false alarm rate of the detection model. BRIEF DESCRIPTION OF THE DRAWINGS

[0050] In order to more clearly illustrate the technical solutions in this embodiment or the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0051] Figure 1 A system framework diagram of a Maven repository component package maliciousness detection model provided in an embodiment of the present application;

[0052] Figure 2 A schematic diagram of the decompiled code of the malicious sample component package provided in the embodiment of the present application;

[0053] Figure 3 A schematic diagram of an intermediate representation of a malicious sample component package provided in an embodiment of the present application;

[0054] Figure 4 A schematic diagram of a sensitive behavior subgraph provided in an embodiment of the present application. DETAILED DESCRIPTION

[0055] The specific implementation of the present invention is further described in detail below in conjunction with the accompanying drawings and specific implementations. The following examples or drawings are used to illustrate the present invention, but are not used to limit the scope of the present invention.

[0056] See also Figure 1 , Figure 1 The system framework diagram of the malicious detection method for component packages in the Maven repository provided in the embodiment of the present application includes:

[0057] Step 1: Collect Java component packages from the Maven central repository as benign samples, collect malicious JAR packages from mainstream malware sample libraries as malicious samples, and build a component package dataset.

[0058] Step 2: Set up a sensitive API call set that conforms to the characteristics of Java programs and open source component packages.

[0059] Step 3: Generate a component package method call graph and divide the call subgraph based on sensitive API calls.

[0060] Step 4: Perform inter-procedural control flow analysis and sensitive data flow analysis to obtain sensitive behavior subgraphs.

[0061] Step 5: Obtain the vector representation of the nodes and the vector representation of the edges in the sensitive behavior subgraph, which together constitute the vector representation of the sensitive behavior subgraph.

[0062] Step 6: Use the sensitive behavior subgraph vector representation of the component package sample as input to train the heterogeneous graph neural network model, perform whole-graph classification, and obtain malicious detection results.

[0063] The specific steps for constructing the component package dataset include:

[0064] Step 1a: In an embodiment of the present invention, the top 150 component package categories ranked by popularity are selected from the Maven Repository, such as "Test Frameworks&Tools", "Logging Frameworks", and "JavaSpecifications", and the Android component package categories, such as "Android Package" and "AndroidPlatform", are removed; each category is ranked according to popularity in the Maven Repository, and the top 150 component packages are selected, and for each component package, the latest version is selected; a web crawler is constructed to collect the selected component packages to form a benign sample set.

[0065] Optionally, during the sample collection process, if the number of component packages in a certain category in the Maven Repository does not reach 150, the number of collections in the category is adjusted according to actual conditions, and some data that meets the requirements is selected as samples.

[0066] Step 1b: Collect malicious Java package samples from mainstream malicious sample sharing libraries, such as VirusShare and VirusTotal; at the same time, collect malicious JAR packages from the IT question-and-answer community StackOverFlow, as well as code hosting platforms Gitee and GitHub to form a malicious sample set.

[0067] The specific steps for constructing a sensitive API call set include:

[0068] Step 2a: Identify the component types of malicious behaviors based on Java official documents, existing literature, technical reports, and malicious code samples; specifically, the malicious behavior fragments in the malicious component package cover script execution, command execution, data transmission, file operation, encoding and decryption, and environmental information reading.

[0069] Step 2b: Determine the relevant sensitive API calls based on different types of malicious behaviors; specifically, in the form of method signatures, the script execution API may include:<groovy.lang.GroovyShell:java.lang.Object evaluate(java.lang.StringscriptText)> ,<javax.script.ScriptEngine Object eval(Stringscript)> ; The command execution API may include:<java.lang.Runtime:Runtime getRuntime()> ,<java.lang.Runtime:Process exec(String|String[])> ;Data transmission APIs may include:<java.net.InetAddress:java.net.InetAddress getByAddress(byte[])> ,<java.net.URLConnection:java.io.OutputStream getOutputStream()> ; The collected sensitive API calls are classified and sorted according to their functions, and each API is represented by its method signature to form a sensitive API call set M sens .

[0070] The specific steps for dividing the component package call subgraph include:

[0071] Step 3a: For a given component package sample, use the public Tai-e program static analysis framework to parse the component package. This process converts the component package from the JAR file into an intermediate language representation IR (Intermediate Representation), such as Figure 2 The following is the decompiled code of the malicious sample in this embodiment. Figure 3 The figure shows the intermediate representation of the malicious sample, where each class file in the JAR package is converted into a tir file.

[0072] Step 3b: Use Tai-e to analyze the converted tir file and obtain the associated information of all methods and classes in the component package: for classes, obtain the information of their access modifiers, parent classes, static variables, static methods, and class signatures; for methods, obtain the information of their access modifiers, parameter types, return value types, method signatures, parameter names, and internal method bodies; and based on the relevant information of classes and methods, find the potential entry method of the component package. If method m is an entry method, it must meet the following judgment conditions:

[0073] Condition 1. The access modifier of m is Public or Protect;

[0074] Condition 2.m belongs to class C m The access modifier is Public or the class C m There is a subclass in the subclass of The access modifier is Public and Method m is not rewritten;

[0075] If m satisfies both condition 1 and condition 2, then the method is called a user-callable method, denoted by m client ;

[0076] Condition 3.m is a static initializer and belongs to class C m The access modifier is Public;

[0077] Condition 4. m belongs to m client And the method is a static method or its class C m is instantiable;

[0078] If condition 3 or condition 4 is met, method m is a potential entry method, denoted by m entry ;

[0079] Apply the entry method identification rules to all methods in the component package to filter out all potential entry methods m entry , and used as the method call graph MCG (Method Call Graph) to build the entry node set required by the algorithm.

[0080] Step 3c: Use Tai-e to analyze the converted tir file of the component package, use the potential entry method set described in step 3b as the algorithm entry of pointer analysis, generate a pointer flow graph PFG (PointerFlow Graph) to represent the flow between pointers in the program, and provide pointer pointing information to specific objects for the construction of the method call graph; use 2-CFA (2-call-site-sensitive) as a context-sensitive strategy, based on the first two call points as context information, distinguish the pointer pointing relationship in different contexts to improve the accuracy of pointer analysis, and construct a pointer flow graph containing context information.

[0081] Optionally, if the accuracy of the analysis strategy based on call site context sensitivity cannot meet the requirements during pointer analysis, the analysis strategy based on object context sensitivity can be selected to obtain the best accuracy, but at the expense of a certain efficiency; the analysis strategy based on type context sensitivity can obtain the best efficiency, with an accuracy between that based on call site and that based on object context sensitivity.

[0082] Step 3d: Use the pointer flow graph described in step 3c as the basic information of the call graph generation algorithm to construct a method call graph G = (V, E) of the component package, where V represents the set of reachable method nodes in the component package, and E represents the set of method node pairs with a call relationship, and the method node pairs are represented in G by edges between nodes.

[0083] Step 3e: Use the Java sensitive API call set M described in step 2b sens , for each sensitive APIm in the set i ∈M sens , search in G's method node set V using regular matching according to its method signature. If a method node v is matched i ∈V, then from v i Start to get G and v i The distance between the nodes does not exceed k, and the call edges between the nodes form v i A k-hop induced subgraph of Multiple values ​​of k can be set, and the effects of subsequent detection models under different k values ​​can be compared to determine the optimal k value.

[0084] Step 3f: Change the For further pruning, since G is a directed graph, v cannot be reached along the call edge i The nodes and corresponding call edges are deleted; after completion, the pruned nodes are Nodes that are no longer connected and their call edges are deleted, and the processed results are used as sensitive call subgraphs

[0085] Optionally, if a sensitive API m j ∈M sens Already exists in the partitioned sensitive call subgraph If m is not used j Perform subsequent node search and subgraph partitioning.

[0086] The specific steps for constructing the sensitive behavior subgraph include:

[0087] Step 4a: Based on the sensitive call subgraph described in step 3f, use Tai-e to perform intra-procedural control flow analysis on each developer-defined method, obtain its control flow graph CFG (Control Flow Graph), and expand the call subgraph into an inter-procedural control flow graph ICFG (Interprocedural Control Flow Graph).

[0088] Step 4b: Perform a Reaching Definition Analysis on each CFG. For a variable r, if basic block b i The variable r is assigned a value, and b j In a method call, the variable r is used as the method argument p, and there is a i to b j CFG path, on which the value of variable r is not overwritten, then b i and b j There is a definition-use relationship, namely, a def-use chain; conversely, for the actual parameter p, the basic block b j With b i There is a use-def relationship, namely the use-def chain. After analyzing all basic blocks, isolated nodes that have no data dependency with other basic blocks are removed, and the data dependency graph DDG (Data Dependence Graph) is established using the def-use chain and the use-def chain as data dependency edges.

[0089] Step 4c: Using the sensitive API call set described in step 2b, first find the method call basic block B in the DDG invoke , and use regular matching in B invoke Search for the target method subsignature m i ∈M sens The basic block b sens , with b sens As the starting node, use breadth-first traversal to traverse the data dependency graph and obtain b sens A reachable subgraph of , all data dependency edges of the reachable subgraph are added to CFG as sensitive data flow edges.

[0090] Step 4d: The nodes of the constructed sensitive behavior subgraph are basic blocks, i.e., intermediate representations of code statements; the sensitive behavior subgraph contains five types of edges: common edges of CFG, call-return edges connecting call points and return points, call edges and return edges representing inter-procedural control flow information, and sensitive data flow edges; by performing data flow analysis on sensitive API calls and obtaining sensitive behavior information, we can obtain the following: Figure 4 The sensitive behavior subgraph is shown.

[0091] The specific steps for extracting vector representation of sensitive behavior subgraphs include:

[0092] Step 5a: To avoid affecting the training of the Doc2vec model, data preprocessing is performed on the basic blocks in the sensitive behavior subgraph, and the line number of each call statement IR (i.e., basic block) generated by Tai-e and the index information in the control flow graph are removed.

[0093] Step 5b: Since the types of variables and method parameters are hidden in the code statement IR generated by Tai-e, each variable and parameter is represented as "r1", "r2", etc. in the order of their appearance. In order to include more code semantics in the basic block, the fully qualified class name of each variable and parameter is appended in front of it, for example, "(java.lang.String)r1".

[0094] Step 5c: The basic blocks in the sensitive behavior subgraph represent the intermediate representation of the code statement, which is regarded as a short document. The basic blocks of all sensitive behavior subgraphs extracted from the component bag dataset form a corpus for training the Doc2Vec model.

[0095] Step 5d: Set the dimension of the node embedding vector to 20 dimensions. After completing the training of the Doc2Vec model, obtain the vector representation of the node from the model.

[0096] Step 5e: Use one-hot encoding to obtain the vector representation of the edges in the sensitive behavior subgraph, and set the embedding representation of the relationship between nodes to a 5-dimensional vector, where the first dimension indicates whether there is a sensitive data flow between nodes. If so, it is set to 1, otherwise it is 0; the second to fifth dimensions represent the type of edge, the corresponding dimensions are set to 1, and the rest are 0.

[0097] The specific steps for implementing malicious detection of component packages include:

[0098] Step 6a: Label the vector representation of all sensitive behavior subgraphs of benign samples as 0, i.e., normal behavior subgraphs; label the vector representation of all sensitive behavior subgraphs of malicious samples as 1, i.e., malicious behavior subgraphs, which are different from normal behavior subgraphs. Figure 1 The vector representation data set is composed of the same structure; the vector representation data set is divided, 80% of the data is taken as the training set required for subsequent model training, 10% of the data is taken as the test set, and 10% of the data is taken as the validation set.

[0099] Step 6b: Take the vector representation dataset as input, use the batching method in whole-graph classification, group multiple sub-graph vector representations with different dimensions into a batch, and perform training iterations on the whole graph batch. Specifically, set the batch size to 32, select the Adam optimizer, and the heterogeneous graph neural network model includes:

[0100] Use three graph convolution layers. In each graph convolution layer, different types of edges and connected nodes in the vector representation are regarded as subgraphs, and graph convolution calculations are performed on the subgraphs corresponding to the five types of edges.

[0101] Using ReLU as the activation function and sum as the aggregation function, the average of the graph convolution aggregation results of the five seed graphs is taken as the input of the next layer of graph convolution. The calculation process is shown in the following formula:

[0102]

[0103] Among them A (k) represents the subgraph adjacency matrix corresponding to the kth edge type, X (i) Represents the node feature vector matrix of the i-th layer graph convolution, W i (k) Represents the weight matrix of the kth edge type in the i-th layer of graph convolution;

[0104] Use the graph readout layer to reduce the data dimension and obtain graph embedding. Specifically, select mean readout as the graph readout method and calculate the representation of a single graph by the mean readout value.

[0105] A multi-layer perceptron with 3 layers is used to convert the graph embedding into a softmax output (p0, p1), where p0+p1=1, which is used to determine whether a sensitive behavior subgraph is a malicious behavior subgraph;

[0106] After 100 rounds of training, the malicious behavior subgraph detection model is obtained.

[0107] Optionally, to prevent the model from overfitting and improve generalization ability, you can monitor the performance of the model on the validation set during training and stop training when the model performance no longer improves; specifically, monitor the loss of the model on the validation set in each round, and stop training in advance when the loss increases five times in a row to obtain better model performance.

[0108] Step 6c: Use the trained malicious behavior subgraph detection model to determine the maliciousness of all sensitive behavior subgraphs in the component package to be detected. If there are more than or equal to 1 sensitive behavior subgraphs that are determined to be malicious behavior subgraphs, the component package is determined to be a malicious component package.

[0109] It should be noted that, for the above method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the order of the actions described, because according to the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and processes involved are not necessarily required by the present application.

[0110] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of complete software embodiments or embodiments in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.

[0111] Finally, it should be noted that the above is only a preferred embodiment of the present invention and is not intended to limit the present invention. Although the present invention has been described in detail with reference to the aforementioned embodiments, it is still possible for those skilled in the art to modify the technical solutions described in the aforementioned embodiments or to make equivalent replacements for some of the technical features therein.

[0112] Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention should be included in the protection scope of the present invention.

Claims

1. A method for detecting maliciousness of third-party component packages in a Maven repository, characterized in that: The method comprises: Step 1: Collect Java component packages from the Maven central repository as benign samples, collect malicious JAR packages from mainstream malware sample libraries as malicious samples, and build a component package dataset; Step 2: Set up a sensitive API call set that matches the characteristics of Java programs and open source components; Step 3: Use the public Tai-e static analysis framework to analyze the component package and generate an intermediate language representation; based on the intermediate language, extract the association information of all methods and classes in the component package; through the potential entry method determination rules, screen out all possible entry methods and generate the entry as the call graph algorithm of context-sensitive pointer analysis; based on the pointer analysis results, obtain the method call relationship and build the call graph of the component package; through regular matching of sensitive API method signatures, extract the corresponding k-hop induced subgraph in the call graph, and prune the results to form a sensitive call subgraph; Step 4: Based on the sensitive call subgraph, a control flow graph is generated for each developer’s custom method and expanded into an inter-procedural control flow graph; a definition reachability analysis is performed on each control flow graph to construct a data dependency graph; by regular matching of sensitive API method signatures, the data dependency graph is searched and a breadth-first traversal is performed starting from the matching basic blocks, and all data dependency edges in the reachable subgraph are added to the control flow graph, and finally the inter-procedural control flow graph is enhanced into a sensitive behavior subgraph; Step 5: Perform data preprocessing on the basic blocks in the sensitive behavior subgraph, use the processed basic blocks as corpus to train the Doc2vec model, and obtain the vector representation of the subgraph nodes; obtain the vector representation of the subgraph edges through one-hot encoding, and the embedding vector of the relationship between nodes is 5-dimensional. The first dimension indicates whether there is sensitive data flow between nodes, and the second to fifth dimensions represent the four edge types in the inter-procedural control flow graph; the vectors of nodes and edges together constitute the overall vector representation of the sensitive behavior subgraph; Step 6: Use the sensitive behavior subgraph vector representation of the component package sample as input to train the heterogeneous graph neural network model, perform whole-graph classification, and obtain malicious detection results.

2. A method for detecting maliciousness of third-party component packages in a Maven repository according to claim 1, characterized in that: In step 1: We use web crawlers to crawl third-party component packages in the top 150 popular categories on the Maven central repository. We select the latest version of each component package as benign samples. We collect malicious JAR packages as malicious samples from mainstream malware sample libraries, including VirusShare, VirusTotal, IT question-and-answer community StackOverFlow, and code hosting platforms GitHub and Gitee.

3. A method for detecting maliciousness of third-party component packages in a Maven repository according to claim 1, characterized in that: In step 2: According to Java official documents, existing literature and technical reports, and malicious code samples, a set of Java sensitive API calls is set; further, according to different sensitive behaviors, API calls in Java are divided into categories such as data transmission, script execution, command execution, file operation, environment information reading, encoding encryption and decryption; These sensitive APIs are organized into sets, where each API is represented by its method signature.

4. A method for detecting maliciousness of third-party component packages in a Maven repository according to claim 1, characterized in that: In step 3: For a given component package, Tai-e, a public Java static program analysis framework, is used to analyze the component package and generate its intermediate language representation IR. Analyze the IR of the component package to obtain the associated information of all methods and classes in the component package: for classes, obtain information about their access modifiers, parent classes, static variables, static methods, and class signatures; for methods, obtain information about their access modifiers, parameter types, return value types, method signatures, parameter names, and internal method bodies; A method for analyzing potential user-available APIs in a component package is used to set a set of effective discrimination conditions to screen all methods in the component package. If a method m meets the following discrimination conditions: Condition 1. The access modifier of m is Public or Protect; Condition 2.m belongs to class C m The access modifier is Public; or C m There is a subclass in the subclass of Its access modifier is Public and Method m is not rewritten; If m satisfies both condition 1 and condition 2, then the method is called a user-callable method, denoted by m client ; Condition 3.m is a static initializer and belongs to class C m The access modifier is Public; Condition 4. m belongs to m client And the method is a static method, or its class C m is instantiable; If condition 3 or condition 4 is met, method m is a potential entry method, denoted by m entry ; Apply the entry method identification rule to all methods in the component package, filter out potential entry methods, and use them as the entry node set M of the call graph generation algorithm. entry ; A pointer analysis algorithm is applied to the IR of the component package to generate a pointer flow graph to represent the flow of pointers in the program. A two-layer call point sensitive 2-CFA is used as a context sensitive strategy, and the first two call points are used as context information to distinguish the pointer pointing relationship in different contexts. In the process of the pointer analysis, the method call relationship is obtained according to the analysis result, and a method call graph MCG is constructed: G = (V, E), where V represents a set of all reachable method nodes in the component package, and E represents a set of method node pairs with call relationships, and the method node pairs are represented by edges between nodes in the call graph; Based on the sensitive API call set described in step 2, for each sensitive API call m in the set i ∈M sens , search from G's reachable method node set V using regular matching according to its method signature. If a method node v is matched i , then according to the node v i Get its k-hop induced subgraph right To prune, first remove the edges that cannot reach v along the call edge. i , and then delete the remaining nodes with Disconnected nodes, the processed results are used as sensitive call subgraphs 5. A method for detecting maliciousness of third-party component packages in a Maven repository according to claim 1, characterized in that: In step 4: Using sensitive call subgraph Get the control flow graph CFG of each developer-defined method, expand the sensitive call subgraph into an inter-procedural control flow graph ICFG; perform definition reachability analysis in CFG. If there is a def-use chain or use-def chain between basic blocks in CFG, there is a data dependency edge, thereby constructing the data dependency graph DDG of the developer-defined method; Using the sensitive API call set described in step 2, search for basic blocks b containing sensitive API calls in the data dependency graph based on method signature regular matching. sens , and b sens As the starting node, use breadth-first traversal to traverse the data dependency graph and obtain b sens A reachable subgraph of ; Add all data dependency edges in the reachable subgraph as sensitive data flow edges to the CFG; By performing data flow analysis on sensitive API calls and obtaining sensitive behavior information, a sensitive behavior subgraph with stronger code semantic representation capability is obtained; the sensitive behavior subgraph consists of basic blocks and edges, where basic blocks are used to represent information about method calls and statements within methods; edge information includes five types: ordinary edges of the control flow graph (CFG), call-return edges connecting call points and return points, call edges and return edges representing cross-process control flow information, and edges used to represent sensitive data flows.

6. A method for detecting maliciousness of third-party component packages in a Maven repository according to claim 1, characterized in that: In step 5: Based on the sensitive behavior subgraph described in step 4, in order to avoid affecting the training of the Doc2vec model, the basic blocks in the sensitive behavior subgraph are preprocessed, and the line number of the statement contained in the call statement IR generated in the static analysis framework and the index information in the control flow graph are removed; Add fully qualified class names before variables and parameters in basic blocks to make them contain more code semantics; Use the processed basic blocks as the corpus to train the Doc2Vec model and obtain the vector representation of each subgraph node; Use one-hot encoding to represent the edges in the subgraph as a 5-dimensional vector, where the first dimension indicates whether there is a sensitive data flow between nodes. If there is a sensitive data flow, the bit is 1, otherwise it is 0; the second to fifth dimensions represent the four types of edge relationships in ICFG; The sensitive behavior subgraph is a heterogeneous graph, and the node feature vectors and edge feature vectors together constitute its vector representation.

7. A method for detecting maliciousness of third-party component packages in a Maven repository according to claim 1, characterized in that: In step 6: In the component package dataset, all sensitive behavior subgraphs of a single sample are extracted and vectorized to form a vector representation set; the vector representation labels of all sensitive behavior subgraphs of benign samples are marked as 0, and the vector representation labels of sensitive behavior subgraphs of malicious samples are marked as 1; The labeled vector representation set is divided into five parts, 80% of the data is used to train the heterogeneous graph convolutional network model, and the remaining 20% ​​of the data is used as the test set and validation set; The vector representation dataset is used as the input of the model, and the batching method in whole-image classification is used to combine multiple sensitive behavior sub-image vector representations with different dimensions into image batches; The batched graphs are input into the heterogeneous graph convolutional network (GCN), and the corresponding hyperparameters are set. After a certain number of rounds of training, a model for malicious behavior subgraph detection is obtained. The trained malicious behavior subgraph detection model is used to determine the maliciousness of all sensitive behavior subgraphs in the component package to be detected. If any sensitive behavior subgraph is determined to be malicious, the component package is determined to be a malicious component package.