Message detection method and apparatus, and electronic device
By constructing an undirected heterogeneous graph and utilizing a graph neural network model to detect SQL injection attacks, the problem of low detection accuracy in existing technologies is solved, achieving higher detection accuracy and lower false positive and false negative rates.
Patent Information
- Application Number
- CN202410993418.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-23
- Publication Date
- 2024-11-19
AI Technical Summary
Existing methods for detecting SQL injection attacks suffer from low accuracy, particularly due to high false positive and false negative rates caused by high cost of feature acquisition, insufficient data samples, and flexible attack bypass methods.
By parsing the messages to be detected, an abstract syntax tree is constructed and an undirected heterogeneous graph is generated. A graph neural network model is used for detection. Combining syntactic semantics and structural features, the undirected heterogeneous graph is constructed and pruned to optimize it, thereby reducing the false alarm rate and the false negative rate.
It improves the accuracy of SQL injection attack detection, reduces false positive and false negative rates, enhances the model's generalization ability and scalability, and is suitable for training scenarios with a small number of labeled samples.
Smart Images

Figure CN118981771A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the fields of data processing and information security, and more specifically, to a message detection method, device and electronic equipment. Background Art
[0002] SQL injection attacks are a type of attack against databases. Attackers insert or add malicious SQL statements to the input parameters of applications or users, and modify the parameters submitted by users to the backend to interact with the database in order to trick the database into executing malicious SQL statements, thereby achieving illegal purposes such as data modification and theft.
[0003] Regarding the detection of SQL injection attacks, the detection methods in the related art are mainly based on feature analysis and rule detection. However, the features used for feature analysis in the detection methods in the related art are obtained by security experts through feature mining and maintenance, which has high feature acquisition costs and limited ability to identify SQL injection attacks. Another method of detecting SQL injection attacks through machine learning or deep learning requires a large number of data samples to extract Euclidean space vector features for model training, in order to enable the model to have the ability to identify unknown SQL injection attacks. However, due to problems such as insufficient data sample accumulation, single data samples, and high flexibility in bypassing SQL injection attacks, the model has insufficient generalization ability in actual application scenarios, and has a high false alarm rate and missed rate. In addition, there is also a SQL injection attack detection method based on semantic analysis, which has a low false alarm rate, but also faces the problem of a high missed rate.
[0004] To address the above-mentioned problems, no effective solution has been proposed yet. Summary of the invention
[0005] The embodiments of the present application provide a method, device and electronic device for detecting a message, so as to at least solve the technical problem of low detection accuracy of detecting whether a message is subjected to an injection attack in the related art.
[0006] According to one aspect of an embodiment of the present application, a method for detecting a message is provided, comprising: parsing a message to be detected to obtain target key information, wherein the target key information includes parameter values of message fields; parsing the target key information by a syntax parsing tool to obtain a parsing result, and constructing an abstract syntax tree based on the parsing result; constructing an undirected heterogeneous graph based on lexical units in the abstract syntax tree, target key information, and structural information in the parsing result, wherein the undirected heterogeneous graph includes multiple types of nodes and multiple edges, the edges are used to connect nodes with associated relationships, and the types of nodes include lexical units, target key information, and structural information; inputting the undirected heterogeneous graph into a target model to obtain a detection result of the message to be detected, wherein the target model is trained by multiple groups of training samples, and each group of training samples includes an undirected heterogeneous graph corresponding to the sample message and a detection result.
[0007] Furthermore, constructing an undirected heterogeneous graph based on lexical units in an abstract syntax tree, target key information and structural information in parsing results includes: determining the target key information as a first node, extracting multiple lexical units from the parsing results, determining each lexical unit as a second node, extracting multiple structural information from the parsing results, and determining each structural information as a third node; determining a target lexical unit connected to the target key information from the abstract syntax tree, and connecting an edge between the first node and the second node corresponding to the target lexical unit; determining target structural information associated with the target key information from the parsing results, and connecting an edge between the first node and the third node corresponding to the target structural information; extracting multiple groups of lexical units with logical relationships from the parsing results, and connecting edges between the second nodes corresponding to the lexical units in each group of lexical units; determining the weight of each edge, and constructing an undirected heterogeneous graph based on the first node, the second node, the third node, the edges connecting the nodes, and the weights of the edges.
[0008] Furthermore, determining the weight of each edge, and constructing an undirected heterogeneous graph based on the first node, the second node, the third node, the edges connecting the nodes, and the weights of the edges include: determining attribute characteristics of each type of node, wherein the attribute characteristics include at least one of the following: statistical characteristics, text characteristics, and distribution characteristics, and the distribution characteristics are characteristics of the distribution state of the nodes in the abstract syntax tree; constructing an initial undirected heterogeneous graph based on each type of node, the edges connecting the nodes, the weights of the edges, and the attribute characteristics of the nodes; performing pruning operations on the initial undirected heterogeneous graph through a preset pruning strategy to obtain an undirected heterogeneous graph.
[0009] Furthermore, determining the weight of each edge includes: for each edge, determining the starting node and the ending node on the path corresponding to the edge, and determining N intermediate nodes between the starting node and the ending node, where N is a non-negative integer; determining the type weight of the edge based on the node types of the starting node and the ending node, and determining at least one of the logical relationship weight and the path feature weight of the edge based on the path between the starting node and the ending node; calculating the statistical value of at least one of the logical relationship weight and the path feature weight and the type weight to obtain the weight of the edge.
[0010] Furthermore, determining the type weight of the edge based on the node types of the starting node and the ending node includes: when there is a second node in the starting node and the ending node, determining the lexical unit type of the second node, and determining the type weight that has a mapping relationship with the lexical unit type from a weight mapping relationship table; or, when there is no second node in the starting node and the ending node, determining the type weight of the edge as a first preset value, wherein the weight mapping relationship table contains multiple groups of mapping relationships, each group of mapping relationships contains a lexical unit type and a type weight.
[0011] Furthermore, at least one of the logical relationship weight and the path feature weight of the edge is determined based on the path between the starting node and the ending node, including: when the starting node and the ending node are both second nodes, determining the path length of the path, and calculating the logical relationship weight of the edge based on the path length; when at least one of the starting node and the ending node is not the second node, determining the logical relationship weight of the edge as a second preset value; and / or, when the second node is included in the intermediate nodes, determining the type weight of each intermediate node, and calculating the sum of the type weights of all the intermediate nodes in the path to obtain the path feature weight; when the second node is not included in the intermediate nodes, determining the path feature weight as a third preset value.
[0012] Furthermore, a pruning operation is performed on the initial undirected isomorphic graph through a preset pruning strategy to obtain an undirected isomorphic graph, including: calculating a first contribution evaluation value of each node in the initial undirected isomorphic graph, and calculating a second contribution evaluation value of each edge in the initial undirected isomorphic graph; removing nodes whose first contribution evaluation values are less than a first evaluation value threshold from the initial undirected isomorphic graph, and removing edges whose second contribution evaluation values are less than a second evaluation value threshold from the initial undirected isomorphic graph, to obtain an undirected isomorphic graph.
[0013] Furthermore, parsing the message to be detected to obtain target key information includes: extracting multiple parameter values in the message to be detected, performing a decoding operation on each parameter value, and obtaining a plaintext result of each parameter value; eliminating non-contributory parameter values from the plaintext result of each parameter value through a preset screening strategy to obtain the remaining multiple target parameter values, wherein the preset screening strategy includes at least one of the following: preset list screening and key string screening, and the non-contributory parameter value is a parameter value that does not contribute to injection attack detection; performing a generalization processing operation on each target parameter value to obtain multiple target key information.
[0014] According to another aspect of an embodiment of the present application, a message detection device is also provided, including: a parsing unit, used to parse the message to be detected and obtain target key information, wherein the target key information includes parameter values of message fields; a first construction unit, used to parse the target key information through a syntax parsing tool, obtain a parsing result, and construct an abstract syntax tree based on the parsing result; a second construction unit, used to construct an undirected heterogeneous graph based on lexical units in the abstract syntax tree, target key information and structural information in the parsing result, wherein the undirected heterogeneous graph includes multiple types of nodes and multiple edges, the edges are used to connect nodes with associated relationships, and the types of nodes include lexical units, target key information and structural information; an input unit, used to input the undirected heterogeneous graph into a target model to obtain a detection result of the message to be detected, wherein the target model is trained by multiple groups of training samples, and each group of training samples includes an undirected heterogeneous graph corresponding to the sample message and a detection result.
[0015] According to another aspect of an embodiment of the present application, an electronic device is also provided, which includes one or more processors; a storage device for storing one or more programs, when the one or more programs are executed by one or more processors, the one or more processors are implemented to run the programs, wherein the programs are configured to execute the above-mentioned message detection method when running.
[0016] In the present application, a method for parsing a message to be detected is adopted to obtain target key information, wherein the target key information includes parameter values of message fields; the target key information is parsed by a syntax parsing tool to obtain a parsing result, and an abstract syntax tree is constructed based on the parsing result; an undirected heterogeneous graph is constructed based on lexical units in the abstract syntax tree, target key information, and structural information in the parsing result, wherein the undirected heterogeneous graph includes multiple types of nodes and multiple edges, and the edges are used to connect nodes with associated relationships, and the types of nodes include lexical units, target key information, and structural information; the undirected heterogeneous graph is input into a target model to obtain a detection result of the message to be detected, wherein the target model is trained by multiple groups of training samples, and each group of training samples includes an undirected heterogeneous graph corresponding to a sample message and a detection method for a message of a detection result.
[0017] As can be seen from the above content, the message detection method proposed in this application, compared with the method in the related art that only extracts statistical features or text features or their combined features through machine learning or deep learning methods for detection, constructs an undirected heterogeneous graph and extracts structural information, enriches feature expression, and enhances the generalization of the SQL injection attack detection model. The undirected heterogeneous graph is constructed using an abstract syntax tree, and the grammatical semantic features and structural features of the SQL injection sample are considered at the same time, which greatly reduces the false alarm rate and the missed alarm rate while ensuring the recall rate. Detecting messages based on the target model only requires a small number of labeled samples for semi-supervised training of the model. For situations in this field and other fields where a large number of labeled samples are required to achieve better results for the model, it has good versatility and extensibility, and helps to reduce the false alarm rate and missed alarm rate of injection attack detection.
[0018] In addition, the message detection method proposed in this application can also be used in combination with other methods, such as rule detection methods, semantic engine detection methods, etc., to further reduce the false alarm rate and missed alarm rate, improve user satisfaction and enhance user stickiness. The message detection method proposed in this application can also be transplanted to other scenarios that also use text or images for classification, and has good versatility.
[0019] It can be seen that the technical solution of the present application achieves the purpose of reducing the false alarm rate and missed alarm rate of injection attack detection, thereby achieving the effect of improving the accuracy of detecting injection attacks, and further solving the technical problem of low detection accuracy of whether a message has been subjected to an injection attack in the related technology. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0021] Figure 1 is a flow chart of a method for detecting a message according to an embodiment of the present application;
[0022] Figure 2 is a schematic diagram of the structure of an abstract syntax tree according to an embodiment of the present application;
[0023] Figure 3 is a schematic diagram of a method for obtaining target key information according to an embodiment of the present application;
[0024] Figure 4 is a flow chart of a method for detecting a SQL injection attack according to an embodiment of the present application;
[0025] Figure 5 is a schematic diagram of a message detection device according to an embodiment of the present application;
[0026] Figure 6 is a schematic diagram of an electronic device according to an embodiment of the present application. DETAILED DESCRIPTION
[0027] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present application.
[0028] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0029] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data for display, data for analysis, etc.) involved in this disclosure are all information and data authorized by the user or fully authorized by all parties.
[0030] It should be noted that the embodiments or examples of the present disclosure are not exhaustive, but are only illustrative of some embodiments or examples, and are not intended to be specific limitations on the scope of protection of the present disclosure. In the absence of contradiction, each step in a certain embodiment or example can be implemented as an independent example, and the steps can be combined arbitrarily. For example, the scheme after removing some steps in a certain embodiment or example can also be implemented as an independent example, and the order of the steps in a certain embodiment or example can be arbitrarily exchanged. In addition, the optional methods or optional examples in a certain embodiment or example can be combined arbitrarily; in addition, the various embodiments or examples can be combined arbitrarily, for example, some or all steps of different embodiments or examples can be combined arbitrarily, and a certain embodiment or example can be combined arbitrarily with the optional methods or optional examples of other embodiments or examples.
[0031] In order to solve the problem of low accuracy in detecting whether a message is subjected to injection attack in the related technology, the following method can be used:
[0032] In one embodiment, a Web attack detection method based on a hypergraph aggregation network is provided, the method comprising: obtaining HTTP (Hypertext Transfer Protocol) request data and preprocessing it, converting the preprocessed HTTP request text data into character-level vertex representation, using a space as a separator of the HTTP request text data, and using the separated sentences as a hyperedge set, each sentence containing multiple character vertices, and constructing an association matrix based on the inclusion relationship between sentences and character vertices, inputting the vertex representation and the association matrix into a pre-trained hypergraph aggregation network model, and obtaining a Web attack detection result.
[0033] Among them, a hypergraph is a graph in which each edge can contain more than two vertices, and the number of vertices contained in each edge is the same and is k, which can be called a k-order hypergraph, among which the 2nd-order hypergraph is the graph we usually see.
[0034] However, this embodiment uses characters as vertices, uses space-separated sentences as hyperedge sets, and uses the inclusion relationship between sentences and characters as the association matrix, ignoring the association between words in the sentence. Words are more vector-expressive, and using characters as vertex representation will cause semantic loss when expressing vertex vectors. At the same time, Web attacks have the characteristics of field locality, that is, most of the data in HTTP requests are normal. Using the entire HTTP to build an association matrix will introduce more noise, which will have a greater impact on the results and increase the false alarm rate.
[0035] Based on this, the present application hopes to provide a solution that can solve the above-mentioned technical problems, the details of which will be described in the subsequent embodiments.
[0036] Example 1
[0037] According to an embodiment of the present application, an embodiment of a method for detecting a message is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0038] Figure 1 is a flow chart of a message detection method according to an embodiment of the present application, such as Figure 1 As shown, the method comprises the following steps:
[0039] Step S101, parsing a message to be detected to obtain target key information, wherein the target key information includes parameter values of message fields.
[0040] In step S101, the message to be detected may be an HTTP message, and the target key information may be a target Payload (key information). An HTTP message may contain multiple target Payloads, and Payload is key information extracted from the HTTP message, and the key information may be a parameter value of a message field.
[0041] The message detection method provided in the embodiment of the present application can be applied to the detection scenario for SQL injection attacks, and can also be applied to other detection scenarios, for example, XSS (Cross Site Scripting) attacks, command execution vulnerabilities, or code execution vulnerabilities. It can be understood that the embodiment of the present application has different limitations on this specific application scenario.
[0042] The message detection method provided in the embodiment of the present application can be executed by a message detection device, which can be deployed in a firewall, WAF (Web Application Firewall), etc., or in other hardware devices, such as IPS (Intrusion Prevention System) and other devices.
[0043] In order to effectively detect the parameter values maliciously inserted into the message by the attacker, it is necessary to parse the HTTP message, extract multiple fields, perform pre-processing operations such as decoding and filtering on the fields, and obtain the target key information.
[0044] Step S102: parse the target key information by using a syntax parsing tool to obtain a parsing result, and construct an abstract syntax tree based on the parsing result.
[0045] In step S102, the syntax parsing tool may be an SQL syntax parsing tool. An abstract syntax tree is an abstract syntax structure used to represent a programming language. It is usually represented by a tree structure. The nodes represent the syntax structure and corresponding information in the program. The abstract syntax tree may also be referred to as an Abstract Syntax Tree, or AST for short. The SQL syntax parsing tool performs lexical and grammatical analysis on the SQL injection payload (i.e., the target key information) to obtain a parsing result, and then constructs an abstract syntax tree based on the parsing result. The structural characteristics of the abstract syntax tree are used to represent the SQL injection payload, which can greatly improve the generalization of the injection attack detection model.
[0046] For example, Figure 2is a schematic diagram of the structure of an abstract syntax tree according to an embodiment of the present application, such as Figure 2 As shown in the figure, SELECT*FROM a WHERE 1=1 is the payload, DML, Wildcard, Keyword, Identifier, Where, Name, Integer, and Comparison are the token types in the abstract syntax tree. Select, *, from, a, where, 1, = are parameter values.
[0047] Step S103, constructing an undirected heterogeneous graph based on lexical units in the abstract syntax tree, target key information and structural information in the parsing result, wherein the undirected heterogeneous graph contains multiple types of nodes and multiple edges, the edges are used to connect nodes with associated relationships, and the types of nodes include lexical units, target key information and structural information.
[0048] In step S103, the lexical unit is the Token type in the abstract syntax tree. The structural information can be a hierarchical structure parsed from the Payload, and an undirected heterogeneous graph refers to a graph containing different types of nodes and edges. Different types of nodes and edges often have different types of attributes. Attributes refer to feature vectors that characterize nodes and edges. When using a graph neural network, different types of nodes and edges may need to be modeled using features of different dimensions depending on the complexity. For example, in an embodiment of the present application, an undirected heterogeneous graph is constructed using the relationship between the abstract syntax tree structure and the Payload, Token type, and Payload hierarchy. Payload, Token type, and structural information are used as nodes in an undirected heterogeneous graph, and the connection relationship between each Token type in the abstract syntax tree and the relationship between the structural information in the parsing result of the Payload are used as edges to construct an undirected heterogeneous graph.
[0049] In addition, edge weights and node features can be added to the undirected heterogeneous graph, such as calculating the comprehensive weight of the edge including the token type weight, the logical relationship weight between tokens, and the path weight, and pruning the graph at the same time. Then, statistical features, text features, and AST features are extracted from the Payload type nodes, and after splicing, the features are reduced in dimension using the dimensionality reduction method and used as the node features of the Payload type.
[0050] Step S104, inputting the undirected heterogeneous graph into the target model to obtain the detection result of the message to be detected, wherein the target model is trained by multiple groups of training samples, and each group of training samples includes the undirected heterogeneous graph corresponding to the sample message and the detection result.
[0051] In step S104, the target model may be a graph neural network model, which is a general term for a type of deep neural network used to process graph data, such as GCN (Graph Convolution Network), GAN (Graph Attention Network), and GraphSAGE (Graph Aggregation Network). By training a graph neural network model for a graph classification task, i.e., the target model, a detection result of whether a message to be detected has an SQL injection attack is output based on the input undirected heterogeneous graph.
[0052] When training the target model, the construction method of the undirected heterogeneous graph corresponding to the sample message can refer to the construction method of the undirected heterogeneous graph corresponding to the message to be detected, which will not be described in detail here.
[0053] Here, the detection result of the message to be detected can be used to indicate whether there are network threats such as SQL injection attacks, cross-site scripting attacks, command execution vulnerabilities, or code execution vulnerabilities in the message.
[0054] It should be noted that the message detection method provided in the embodiment of the present application constructs an undirected heterogeneous graph based on an abstract syntax tree, and performs network threat detection such as SQL injection attack detection by a target model. Only a small number of labeled samples are required for semi-supervised training of the model. It has good versatility and scalability for situations in this field and other fields where a large number of labeled samples are required to achieve better results for the model.
[0055] The embodiment of the present application obtains target key information by parsing the message to be detected, wherein the target key information includes parameter values of message fields; parses the target key information by a syntax parsing tool to obtain parsing results, and constructs an abstract syntax tree based on the parsing results; constructs an undirected heterogeneous graph based on lexical units in the abstract syntax tree, target key information, and structural information in the parsing results, wherein the undirected heterogeneous graph includes multiple types of nodes and multiple edges, and the edges are used to connect nodes with associated relationships, and the types of nodes include lexical units, target key information, and structural information; inputs the undirected heterogeneous graph into a target model to obtain a detection result of the message to be detected, wherein the target model is trained by multiple groups of training samples, and each group of training samples includes an undirected heterogeneous graph corresponding to the sample message and a message of the detection result.
[0056] Compared with the method of detecting only statistical features or text features or their combined features by machine learning or deep learning methods in the related art, an undirected heterogeneous graph is constructed and structural information is extracted, the feature expression is enriched, the generalization of the detection model of SQL injection attacks is enhanced, and the undirected heterogeneous graph is constructed by using an abstract syntax tree, while the grammatical semantic features and structural features of the SQL injection sample are considered, and the false alarm rate and the missed alarm rate are greatly reduced while ensuring the recall rate. Based on the target model, the message is detected, and only a small number of labeled samples are required for semi-supervised training of the model. For the situation where a large number of labeled samples are required to make the model achieve better results in this field and other fields, it has good versatility and extensibility. In addition, the message detection method proposed in this application can also be used in combination with other methods, such as rule detection methods, semantic engine detection methods, etc., to further reduce the false alarm rate and missed alarm rate, improve user satisfaction and enhance user stickiness. The message detection method proposed in this application can also be transplanted to other scenes that also use text or images for classification, and has good versatility.
[0057] It can be seen that the technical solution of the embodiment of the present application achieves the purpose of reducing the false alarm rate and missed alarm rate of injection attack detection, thereby achieving the effect of improving the accuracy of detecting injection attacks, and further solving the technical problem of low detection accuracy of whether a message is subjected to an injection attack in the related technology.
[0058] In order to capture more structural features and semantic information in SQL statements, an undirected heterogeneous graph is constructed using an abstract syntax tree, target key information, and structural information in the parsing results. Optionally, in the message detection method provided in an embodiment of the present application, constructing an undirected heterogeneous graph based on lexical units in the abstract syntax tree, target key information, and structural information in the parsing results includes: determining the target key information as a first node, extracting multiple lexical units from the parsing results, determining each lexical unit as a second node, extracting multiple structural information from the parsing results, and determining each structural information as a third node; determining a target lexical unit connected to the target key information from the abstract syntax tree, and connecting an edge between the first node and the second node corresponding to the target lexical unit; determining target structural information associated with the target key information from the parsing results, and connecting an edge between the first node and the third node corresponding to the target structural information; extracting multiple groups of lexical units with logical relationships from the parsing results, and connecting edges between the second nodes corresponding to the lexical units in each group of lexical units; determining the weight of each edge, and constructing an undirected heterogeneous graph based on the first node, the second node, the third node, the edges connecting the nodes, and the weights of the edges.
[0059] Exemplarily, the undirected heterogeneous graph constructed by the embodiment of the present application includes three types of nodes, a first node, a second node, and a third node. The first node is a node with target key information as the node, also known as a Payload node, which treats the entire SQL statement as a separate node. The second node is a node with a lexical unit, that is, a Token type, that is, a node with the type of Token obtained by parsing the target key information using a grammar parsing tool. The second node can provide detailed information on the structure of the SQL statement, such as operators, field names, etc., which can help the neural network capture the semantics and structural information of the SQL statement. The third node is a node with structural information as the node, that is, a hierarchical type node, such as a parameterized node, a subquery node, a function block node, etc.
[0060] Among them, parameterized nodes refer to treating parameters or variables in SQL statements as separate nodes, which can effectively capture patterns in dynamically generated SQL query statements. For example, the ? in SELECT*FROM a WHERE id=? is a parameterized node, which can effectively identify attempts to use parameters for SQL injection. Subquery nodes treat subquery statements in SQL queries as independent nodes, which are distinguished from the main query nodes, which helps the target model better understand the structural hierarchy of SQL queries and the relationship between main and subqueries. For example, SELECT*FROM(SELECT name FROM a)AS u WHERE u.name='John', (SELECT name FROM users) is regarded as a subquery node. Functional block nodes refer to the further subdivision of SQL queries into different functional blocks, such as SELECT clause, FROM clause, WHERE clause, etc. Each block can be an independent node. For example, SELECT*FROM a WHERE 1=1 can be divided into three different nodes: SELECT*, FROM a, and WHERE 1=1.
[0061] In some embodiments, determining the weight of each edge may include: setting the weight of each edge to a preset value, for example, the preset value is 1.
[0062] In some embodiments, the weight of each edge can be determined based on at least one of the type weight, logical relationship weight, and path feature weight of the edge. For example, the type weight of the edge is determined based on the node types of the start node and the end node of the path containing the edge. Alternatively, the logical relationship weight and path feature weight of the edge are determined based on the path containing the edge. Alternatively, the path feature weight of the edge is determined based on the path containing the edge.
[0063] Among them, the type weight of the edge can be used to characterize the influence of the node types of the starting node and the ending node on the path corresponding to the edge on the edge, the logical relationship weight can be used to characterize the logical relationship between the starting node and the ending node on the path corresponding to the edge, and the path feature weight can be used to characterize the influence of the node types of each node on the path corresponding to the edge on the edge. The path corresponding to the edge can be understood as: the path containing the edge.
[0064] For example, Figure 2 As shown, the edge between the Token node (Where) and the Token node (Integer) has a starting node of Where and an ending node of Integer, and the path corresponding to the edge is Where-Comparison-Integer. The nodes on the path include Where, Comparison, and Integer. The type weight of this edge is the sum of the Token type weight of the Where node and the Token type weight of the Integer node. The logical relationship weight of this edge is 1 / (1+d), where d = the number of edges on the path. The path corresponding to this edge contains two edges, Where-Comparison and Comparison-Integer, so the logical relationship weight = 1 / (1+2) = 1 / 3. The path feature weight of this edge can be the sum of the Token type weights of the three nodes, Where, Comparison, and Integer.
[0065] The embodiment of the present application can effectively capture the structural complexity and semantic information of SQL statements through this multi-type node construction, thereby providing richer feature information for the target model and promoting the model to more accurately identify SQL injection attacks.
[0066] In some examples, the undirected heterogeneous graph constructed by the embodiments of the present application includes three types of edges. The first type is the edge between the Payload node and the Token type node, that is, the Token type obtained by parsing the Payload; the second type is the edge between the Token type node and the Token type node, which is used to represent the logical relationship of the internal structure of the SQL statement; the third type is the edge between the Payload node and the hierarchical type node, which is used to enhance the logical relationship between the SQL statement and the internal structure.
[0067] The embodiment of the present application uses an abstract syntax tree, target key information, and structural information in the parsing results to construct an undirected heterogeneous graph, while taking into account the grammatical semantic features and structural features of SQL statements. The syntax tree vector representation for the SQL injection payload can effectively reduce the underreporting rate and false alarm rate of the detection model and improve the accuracy of detecting injection attacks.
[0068] In some examples, in order to ensure the accuracy of the features used to detect SQL injection attacks in an undirected heterogeneous graph, an undirected heterogeneous graph is constructed by nodes, edges, edge weights and node attribute features. Optionally, in the message detection method provided in an embodiment of the present application, the weight of each edge is determined, and the undirected heterogeneous graph is constructed based on the first node, the second node, the third node, the edges connecting the nodes and the edge weights, including: determining the attribute features of each type of node, wherein the attribute features include at least one of the following: statistical features, text features and distribution features, and the distribution features are features of the distribution state of the nodes in the abstract syntax tree; constructing an initial undirected heterogeneous graph based on each type of node, the edges connecting the nodes, the edge weights and the node attribute features; performing a pruning operation on the initial undirected heterogeneous graph through a preset pruning strategy to obtain an undirected heterogeneous graph.
[0069] Exemplarily, in addition to using the constructed undirected heterogeneous graph to learn the structural information of samples, the graph neural network model can also learn the attribute characteristics of nodes. The attribute characteristics added to the nodes in the undirected heterogeneous graph in the embodiment of the present application are mainly for feature extraction of the Payload node type, and other more types of node features can also be mined. The characteristics of the Payload node type mainly include the following three aspects: statistical characteristics, text characteristics, and distribution characteristics. An initial undirected heterogeneous graph is constructed by each type of node, the edges connecting the nodes, the weights of the edges, and the attribute characteristics of the nodes, and then the initial undirected heterogeneous graph is pruned and optimized to remove features with low contribution to detecting SQL injection attacks, thereby obtaining an undirected heterogeneous graph.
[0070] Among them, statistical features include SQL keyword proportion, SQL keyword position information, abnormal distribution or proportion of numbers / letters, information entropy, Payload length, maximum length of consecutive letters / non-letters, etc. Text features, such as word2vec (Word to Vector, word vector), TFIDF (Term Frequency-Inverse Document Frequency, information retrieval and text mining) and other tools are used to extract the text vector features of the Payload. In addition, in order to more reasonably represent the contextual relevance of the Payload, pre-trained models such as natural language processing models can also be used for feature extraction. Distribution features refer to the distribution features of the Token type in the abstract syntax tree. For the AST result, the depth-first search algorithm is used to extract the path information from the Payload node to each leaf node. For example, the left subtree is represented by 1 and the right subtree is represented by 0. Finally, the unified dimension operation is performed to obtain the path features; in addition to the path features, the degree distribution features of the Token type, the sequence features of the Token type, and the depth distribution features of the child nodes can also be extracted.
[0071] The embodiment of the present application constructs an undirected heterogeneous graph through graph structure information, node attribute characteristics and edge weight information, maximizes the mining of potential internal correlation information of SQL statements, and improves the detection accuracy of the target model.
[0072] Optionally, in the message detection method provided in the embodiment of the present application, determining the weight of each edge includes: for each edge, determining the starting node and the ending node on the path corresponding to the edge, and determining N intermediate nodes between the starting node and the ending node, where N is a non-negative integer; determining the type weight of the edge based on the node type of the starting node and the ending node, and determining at least one of the logical relationship weight and the path feature weight of the edge based on the path between the starting node and the ending node; calculating the statistical value of at least one of the logical relationship weight and the path feature weight and the type weight to obtain the weight of the edge.
[0073] For example, the edge weight is a critical part of accurately capturing the structure and semantic features of SQL statements and the results of model detection of SQL injection attacks. This application comprehensively considers the calculation of edge weights of various types to enhance the detection capability of the target model. The edge weight is calculated by the type weight based on the token type, the logical relationship weight based on the logical relationship between tokens, and the path feature weight. The edge weight calculation formula is as follows:
[0074] w=f(w(t),w{i,j},w p );
[0075] Where f is a function used to calculate the statistical value, which can represent the addition, weighted average or other reasonable calculation functions between type weight, logical relationship weight and path feature weight. w(t) is the type weight, w{i,j} is the logical relationship weight, w p is the path feature weight.
[0076] The embodiment of the present application represents the weight of the edge by comprehensively combining type weight, logical relationship weight and path feature weight, which can express more feature information in the undirected heterogeneous graph, thereby improving the detection capability of the target model.
[0077] It can be understood that in some embodiments, for each edge, when calculating the weight of each edge, a unified weight calculation method is used. For example, the type weight of each edge is used as the weight of each edge. For another example, the weight of each edge is calculated based on the type weight and logical relationship weight of each edge. For another example, the weight of each edge is calculated based on the type weight, logical relationship weight and path feature weight of each edge.
[0078] Optionally, in the message detection method provided in the embodiment of the present application, determining the type weight of the edge based on the node types of the starting node and the ending node includes: when there is a second node in the starting node and the ending node, determining the lexical unit type of the second node, and determining the type weight that has a mapping relationship with the lexical unit type from a weight mapping relationship table; or, when there is no second node in the starting node and the ending node, determining the type weight of the edge as a first preset value, wherein the weight mapping relationship table contains multiple groups of mapping relationships, each group of mapping relationships contains a lexical unit type and a type weight.
[0079] Exemplarily, the calculation of the type weight of the edge can be determined based on the Token type node, that is, the second node. Different Token types have obvious differences in the importance of distinguishing SQL injections. For example, conditional operators may have higher risks than numeric types. Therefore, when calculating the type weight of the edge, it is necessary to first determine whether the starting node and the end node of the edge are the second node. If the starting node and the end node of the edge connection are both Token type nodes, the type weights of the starting node and the end node are determined by the weight mapping relationship table, and the sum of the type weights of the starting node and the end node is used as the type weight of the edge. If only one of the starting node and the end node of the edge connection is a Token type node, the type weight of the Token type node is used as the type weight of the edge. If the starting node and the end node of the edge connection are not Token type nodes, the first preset value is used as the type weight of the edge, for example, the first preset value is set to 1. The weight mapping relationship table can be a table set by expert experience. Let w(t) represent the type weight of the Token type, then the type weight of Token type t is w(t).
[0080] Optionally, in the message detection method provided in the embodiment of the present application, at least one of the logical relationship weight and the path feature weight of the edge is determined based on the path between the starting node and the ending node, including: when the starting node and the ending node are both second nodes, determining the path length of the path, and calculating the logical relationship weight of the edge based on the path length; when at least one of the starting node and the ending node is not the second node, determining the logical relationship weight of the edge as a second preset value; and / or, when the second node is included in the intermediate nodes, determining the type weight of each intermediate node, and calculating the sum of the type weights of all the intermediate nodes in the path to obtain the path feature weight; when the second node is not included in the intermediate nodes, determining the path feature weight as a third preset value.
[0081] In some examples, the first preset value, the second preset value, and the third preset value may be the same or different. For example, the first preset value, the second preset value, and the third preset value are all preset to 1.
[0082] For example, the calculation of the logical relationship weight of the edge can be calculated by the following formula:
[0083]
[0084] Among them, d{i,j} represents Token i With Token j The path length between them. The path length can be the number of edges on the path, and w{i,j} means that the closer the Token type nodes are, the greater the logical relationship weight and the higher the correlation. There is a strong logical relationship between the tokens in the SQL statement, such as the comparison operator used in the WHERE clause and the field and value it compares, which indicates important information about the filtering condition.
[0085] It should be noted that the logical relationship weight is also determined based on the Token type nodes. If the starting node and the ending node of the edge connection are both Token type nodes, the logical relationship weight of the edge is calculated by the above formula. If at least one of the starting node and the ending node of the edge connection is not a Token type node, the second preset value is used as the logical relationship weight of the edge, and the second preset value can be set to 1.
[0086] Furthermore, for the calculation of path feature weight, the path features from Payload to Token are considered, that is, which intermediate nodes are connected. This calculation method can help capture the "access pattern" from Payload to a specific Token, reflecting the structural complexity of the SQL statement. For example, if there are a series of intermediate nodes in the path that are Token type nodes, and each Token type node has a corresponding type weight, then the path feature weight can be the sum of the type weights of the intermediate nodes of each Token type in the path, or the path feature weight w p It can be the weighted product of the type weights of each intermediate node of the Token type in the path, etc. If there is no Token type node in the intermediate node in the path, the third preset value is used as the path feature weight of the edge, and the third preset value can be set to 1.
[0087] The embodiment of the present application calculates the sum of the comprehensive type weight, the logical relationship weight and the path feature weight as the edge weight, so that the edge weight can contain more feature information.
[0088] In order to save computing resources, it is necessary to prune the initial undirected heterogeneous graph to remove features with low contribution to detecting SQL injection attacks. Optionally, in the message detection method provided in the embodiment of the present application, a pruning operation is performed on the initial undirected heterogeneous graph through a preset pruning strategy to obtain the undirected heterogeneous graph, including: calculating a first contribution evaluation value of each node in the initial undirected heterogeneous graph, and calculating a second contribution evaluation value of each edge in the initial undirected heterogeneous graph; removing nodes whose first contribution evaluation values are less than a first evaluation value threshold from the initial undirected heterogeneous graph, and removing edges whose second contribution evaluation values are less than a second evaluation value threshold from the initial undirected heterogeneous graph, to obtain the undirected heterogeneous graph.
[0089] Furthermore, after obtaining the undirected heterogeneous graph, the method further includes: performing a dimension reduction operation on the attribute features in the undirected heterogeneous graph according to a preset feature dimension reduction strategy to obtain the undirected heterogeneous graph after the dimension reduction operation is performed, and inputting the undirected heterogeneous graph after the dimension reduction operation into the target model to obtain the detection result of the message to be detected.
[0090] For example, the undirected heterogeneous graph constructed in the above manner has a relatively complex structure in some scenarios, and there are certain requirements for the consumption of computing resources. In addition, the importance of some nodes or edges in the undirected heterogeneous graph is relatively low, and the impact on the final detection effect is relatively low. Therefore, in order to reduce the consumption of computing resources and the impact on the detection effect, the undirected heterogeneous graph is pruned and optimized.
[0091] For example, to optimize the nodes in an undirected heterogeneous graph, the optimization of the nodes can be performed with the help of a graph structure analysis tool to analyze the importance of the nodes, and by evaluating the contribution of the nodes, that is, the first contribution evaluation value, the nodes with smaller contribution can be pruned. The first contribution evaluation value of the node can be evaluated by the PageRank algorithm (an importance ranking algorithm). The PageRank algorithm takes into account the degree of the node and the importance of the adjacent nodes. In addition, you can also choose evaluation methods such as degree centrality and betweenness centrality to evaluate the contribution and prune the nodes. By setting the first evaluation value threshold. When the first contribution evaluation value is lower than the threshold, the pruning operation is performed, that is, the node is removed.
[0092] For the optimization of undirected heterogeneous graph edges, the optimization of edges can also be evaluated and pruned with the help of the PageRank algorithm of the graph structure analysis tool. In addition to analyzing the importance of nodes, the algorithm can also analyze the importance of edges. The second contribution evaluation value calculated by it can represent the importance transmitted through the edge. The higher the importance of the node connected by the edge, the higher its second contribution evaluation value. Therefore, the pruning threshold θ, that is, the second evaluation value threshold, can be set. Pruning is performed when the PageRank value is lower than this threshold.
[0093] In addition, the attribute features of the Payload type nodes can also be optimized for the undirected heterogeneous graph. For example, the dimension of the attribute features can be reduced, but the vast majority of the information of the original features needs to be retained to reduce the consumption of computing resources without having much impact on the detection results. The original features can be reduced in dimension using the principal component analysis dimensionality reduction method to retain more than 95% of the original information. Other dimensionality reduction methods can also be used, such as t-SEN (Transportation Security Enhancement Network, a method for describing and analyzing the behavior of complex systems). This embodiment does not specifically limit the feature dimensionality reduction strategy.
[0094] The embodiment of the present application prunes the initial undirected heterogeneous graph, removes nodes, edges, and attribute features that have low contribution to detecting SQL injection attacks, and saves computing resources.
[0095] Optionally, in the message detection method provided in the embodiment of the present application, parsing the message to be detected to obtain target key information includes: extracting multiple parameter values in the message to be detected, performing a decoding operation on each parameter value, and obtaining a plaintext result of each parameter value; eliminating non-contributory parameter values from the plaintext result of each parameter value through a preset screening strategy to obtain the remaining multiple target parameter values, wherein the preset screening strategy includes at least one of the following: preset list screening and key string screening, and the non-contributory parameter value is a parameter value that does not contribute to injection attack detection; performing a generalization processing operation on each target parameter value to obtain multiple target key information.
[0096] For example, Figure 3 is a schematic diagram of a method for obtaining target key information according to an embodiment of the present application, such as Figure 3 As shown, by extracting fields in the HTTP stream that may contain SQL injection attacks, such as URL (Uniform Resource Locator), REFEREN (reference information), COOKIE (used to store information sent by the server to the client), and parsing these fields to extract parameter values, namely Payload, and performing decoding operations including but not limited to URL decoding, Base64 decoding, hexadecimal decoding, etc., and filtering out Payloads that are obviously not SQL injections through a preset list, that is, non-contributory parameter values. Pre-filter the Payload using a preset list or preset rules such as whether it contains a key string, remove the non-contributory parameter values, and generalize the remaining multiple target parameter values to obtain the target Payload, that is, the target key information.
[0097] The embodiment of the present application constructs an abstract syntax tree and an undirected heterogeneous graph by acquiring target key information, thereby detecting SQL injection attacks in messages through the undirected heterogeneous graph.
[0098] Furthermore, performing a generalized processing operation on each target parameter value includes: extracting non-critical information from the target parameter value, and when the extracted non-critical information includes numbers, replacing the numbers in the non-critical information with preset numerical values; when the extracted non-critical information includes non-numeric strings, adjusting the non-numeric strings in the non-critical information to a preset format, wherein the non-numeric strings include at least one of the following: IP address, domain name, and uniform characters.
[0099] Exemplarily, generalizing each target parameter value can extract non-critical information, and generalizing the non-critical information, such as replacing numbers with "1", unifying upper and lower case, unifying characters such as IP addresses / domain names / URLs, etc.
[0100] The embodiment of the present application performs a generalization processing operation on the spliced target parameter values to eliminate the interference of non-critical information to obtain target key information with common characteristics, and to a certain extent improves the generalization of the SQL injection attack detection method.
[0101] According to another embodiment of the present application, a method for detecting a SQL injection attack is also provided. Figure 4 is a flow chart of a method for detecting a SQL injection attack according to an embodiment of the present application, such as Figure 4 As shown, the method includes: when the input message to be detected is an HTTP message or a Payload, parsing the HTTP message field, obtaining the target Payload, parsing the value in the field according to the composition rules of each field in the HTTP message to obtain the corresponding parameters and parameter values, performing Payload preprocessing, pre-filtering, recursive decoding and generalization processing according to preset rules to obtain the Payload to be detected, and after generalization processing, extracting the statistical features, text features and AST (Abstract Syntax Tree) features of the Payload and performing dimensionality reduction processing, constructing an undirected heterogeneous graph and performing pruning optimization at the same time, and then using the trained graph neural network model to detect the Payload to determine whether there is an SQL injection attack in the HTTP message.
[0102] Compared with the current mainstream machine learning / deep learning method that only extracts statistical features or text features or their combined features, the SQL injection attack detection method proposed in the embodiment of the present application constructs an undirected heterogeneous graph of the payload and extracts graph structure features, enriches feature expression, enhances the generalization of the SQL injection attack detection model, and greatly reduces the false alarm rate and the missed alarm rate of the existing network environment while ensuring the recall rate. In addition, other methods can be used in combination, such as rule detection methods, semantic engine detection methods, etc., to further reduce the false alarm rate and missed alarm rate, improve user satisfaction and enhance user stickiness.
[0103] Example 2
[0104] According to an embodiment of the present application, a message detection device embodiment is also provided, wherein: Figure 5 is a schematic diagram of a message detection device according to an embodiment of the present application, such as Figure 5 As shown, the device comprises:
[0105] The parsing unit 501 is used to parse the message to be detected to obtain target key information, wherein the target key information includes parameter values of message fields;
[0106] The first construction unit 502 is used to parse the target key information through a syntax parsing tool to obtain a parsing result, and construct an abstract syntax tree based on the parsing result;
[0107] The second construction unit 503 is used to construct an undirected heterogeneous graph based on the lexical units in the abstract syntax tree, the target key information and the structural information in the parsing result, wherein the undirected heterogeneous graph contains multiple types of nodes and multiple edges, the edges are used to connect the nodes with associated relationships, and the types of nodes include lexical units, target key information and structural information;
[0108] The input unit 504 is used to input the undirected heterogeneous graph into the target model to obtain the detection result of the message to be detected, wherein the target model is trained by multiple groups of training samples, and each group of training samples includes the undirected heterogeneous graph corresponding to the sample message and the detection result.
[0109] The message detection device provided in the embodiment of the present application, through the parsing unit 501, parses the message to be detected to obtain the target key information, wherein the target key information includes the parameter value of the message field; the first construction unit 502, parses the target key information through the syntax parsing tool, obtains the parsing result, and constructs the abstract syntax tree based on the parsing result; the second construction unit 503, constructs an undirected heterogeneous graph based on the lexical unit in the abstract syntax tree, the target key information and the structural information in the parsing result, wherein the undirected heterogeneous graph contains multiple types of nodes and multiple edges, the edges are used to connect the nodes with associated relationships, and the types of nodes include lexical units, target key information and structural information; the input unit 504, inputs the undirected heterogeneous graph into the target model, and obtains the detection result of the message to be detected, wherein the target model is obtained by training multiple groups of training samples, and each group of training samples includes the undirected heterogeneous graph corresponding to the sample message and the detection result. The purpose of reducing the false alarm rate and the false negative rate of injection attack detection is achieved, thereby achieving the effect of improving the accuracy of detecting injection attacks, and then solving the technical problem of low detection accuracy of detecting whether a message is subjected to injection attacks in the related technology.
[0110] Optionally, in the message detection device provided in the embodiment of the present application, the second construction unit 503 includes: a first determination module, used to determine the target key information as the first node, extract multiple lexical units from the parsing result, determine each lexical unit as the second node, extract multiple structural information from the parsing result, and determine each structural information as the third node; a second determination module, used to determine the target lexical unit connected to the target key information from the abstract syntax tree, and connect the edge between the first node and the second node corresponding to the target lexical unit; a third determination module, used to determine the target structural information associated with the target key information from the parsing result, and connect the edge between the first node and the third node corresponding to the target structural information; a first extraction module, used to extract multiple groups of lexical units with logical relationships from the parsing result, and connect the edges between the second nodes corresponding to the lexical units in each group of lexical units; a construction module, used to determine the weight of each edge, and construct an undirected heterogeneous graph based on the first node, the second node, the third node, the edges connecting the nodes, and the weights of the edges.
[0111] Optionally, in the message detection device provided in the embodiment of the present application, the construction module includes: a first determination submodule, used to determine the attribute characteristics of each type of node, wherein the attribute characteristics include at least one of the following: statistical characteristics, text characteristics and distribution characteristics, and the distribution characteristics are characteristics of the distribution state of the nodes in the abstract syntax tree; a construction submodule, used to construct an initial undirected heterogeneous graph based on each type of node, the edges connecting the nodes, the weights of the edges and the attribute characteristics of the nodes; a pruning submodule, used to perform pruning operations on the initial undirected heterogeneous graph through a preset pruning strategy to obtain an undirected heterogeneous graph.
[0112] Optionally, in the message detection device provided in the embodiment of the present application, the first determination submodule includes: a node determination module, which is used to determine the starting node and the ending node on the path corresponding to each edge, and determine the N intermediate nodes between the starting node and the ending node, where N is a non-negative integer; a weight determination module, which is used to determine the type weight of the edge based on the node type of the starting node and the ending node, and determine at least one of the logical relationship weight and the path feature weight of the edge based on the path between the starting node and the ending node; a first calculation module, which is used to calculate the statistical value of at least one of the logical relationship weight and the path feature weight and the type weight to obtain the weight of the edge.
[0113] Optionally, in the message detection device provided in the embodiment of the present application, the weight determination module includes: a type weight determination module, which is used to determine the lexical unit type of the second node when there is a second node between the starting node and the ending node, and determine the type weight that has a mapping relationship with the lexical unit type from the weight mapping relationship table; or, when there is no second node between the starting node and the ending node, determine the type weight of the edge as a first preset value, wherein the weight mapping relationship table contains multiple groups of mapping relationships, each group of mapping relationships contains a lexical unit type and a type weight.
[0114] Optionally, in the message detection device provided in the embodiment of the present application, the weight determination module also includes: a logical relationship weight determination module, which is used to determine the path length of the path when the starting node and the ending node are both second nodes, and calculate the logical relationship weight of the edge based on the path length, and when at least one of the starting node and the ending node is not the second node, the logical relationship weight of the edge is determined to be a second preset value; and / or, a path feature weight determination module, which is used to determine the type weight of each intermediate node when the intermediate node includes the second node, and calculate the sum of the type weights of all the intermediate nodes in the path to obtain the path feature weight, and when the intermediate node does not include the second node, the path feature weight is determined to be a third preset value.
[0115] Optionally, in the message detection device provided in the embodiment of the present application, the pruning submodule includes: a second calculation module, used to calculate the first contribution evaluation value of each node in the initial undirected isomorphic graph, and calculate the second contribution evaluation value of each edge in the initial undirected isomorphic graph; a removal module, used to remove nodes whose first contribution evaluation values are less than the first evaluation value threshold from the initial undirected isomorphic graph, and remove edges whose second contribution evaluation values are less than the second evaluation value threshold from the initial undirected isomorphic graph, to obtain a target undirected isomorphic graph; a dimensionality reduction module, used to perform dimensionality reduction operations on attribute features in the target undirected isomorphic graph according to a preset feature dimensionality reduction strategy, to obtain an undirected isomorphic graph after the pruning operation is performed.
[0116] Optionally, in the message detection device provided in the embodiment of the present application, the parsing unit 501 includes: a second extraction module, used to extract multiple parameter values in the message to be detected, perform a decoding operation on each parameter value, and obtain a plaintext result of each parameter value; a screening module, used to eliminate non-contributory parameter values from the plaintext result of each parameter value through a preset screening strategy to obtain the remaining multiple target parameter values, wherein the preset screening strategy includes at least one of the following: preset list screening and key string screening, and the non-contributory parameter value is a parameter value that does not contribute to injection attack detection; a processing module, used to perform a generalized processing operation on each target parameter value to obtain multiple target key information.
[0117] The message detection device includes a processor and a memory. The above-mentioned parsing unit 501, the first construction unit 502, the second construction unit 503 and the input unit 504 are all stored in the memory as program units, and the processor executes the above-mentioned program units stored in the memory to realize corresponding functions.
[0118] The processor contains a kernel, which retrieves the corresponding program unit from the memory. One or more kernels can be set, and the purpose of reducing the false positive rate and false negative rate of injection attack detection is achieved by adjusting the kernel parameters, thereby achieving the effect of improving the accuracy of injection attack detection.
[0119] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.
[0120] An embodiment of the present invention provides a computer-readable storage medium on which a program is stored. When the program is executed by a processor, a method for detecting a message is implemented.
[0121] An embodiment of the present invention provides a processor, which is used to run a program, wherein a method for detecting a message is executed when the program is running.
[0122] Figure 6 is a schematic diagram of an electronic device according to an embodiment of the present application. Figure 6As shown, the electronic device 601 includes a processor, a memory, and a program stored in the memory and can be run on the processor. When the processor executes the program, the following steps are implemented: parsing the message to be detected to obtain target key information, wherein the target key information includes parameter values of message fields; parsing the target key information through a syntax parsing tool to obtain parsing results, and constructing an abstract syntax tree based on the parsing results; constructing an undirected heterogeneous graph based on the lexical units in the abstract syntax tree, the target key information, and the structural information in the parsing results, wherein the undirected heterogeneous graph contains multiple types of nodes and multiple edges, and the edges are used to connect nodes with associated relationships, and the types of nodes include lexical units, target key information, and structural information; inputting the undirected heterogeneous graph into the target model to obtain the detection result of the message to be detected, wherein the target model is trained by multiple groups of training samples, and each group of training samples includes an undirected heterogeneous graph corresponding to the sample message and a detection result. The device in this article can be a server, a PC, a PAD, a mobile phone, etc.
[0123] The present application also provides a computer program product, which, when executed on a data processing device, is suitable for executing a program that is initialized with the following method steps: parsing a message to be detected to obtain target key information, wherein the target key information includes parameter values of message fields; parsing the target key information through a syntax parsing tool to obtain parsing results, and constructing an abstract syntax tree based on the parsing results; constructing an undirected heterogeneous graph based on lexical units in the abstract syntax tree, target key information, and structural information in the parsing results, wherein the undirected heterogeneous graph includes multiple types of nodes and multiple edges, and the edges are used to connect nodes with associated relationships, and the types of nodes include lexical units, target key information, and structural information; inputting the undirected heterogeneous graph into a target model to obtain a detection result of the message to be detected, wherein the target model is trained by multiple groups of training samples, and each group of training samples includes an undirected heterogeneous graph corresponding to the sample message and a detection result.
[0124] Example 3
[0125] According to an embodiment of the present application, an electronic device is also provided, which includes one or more processors; a storage device for storing one or more programs, when the one or more programs are executed by the one or more processors, the one or more processors are enabled to run the programs, wherein the program is configured to execute the above-mentioned message detection method at runtime.
[0126] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.
[0127] In the above embodiments of the present application, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, please refer to the relevant description of other embodiments.
[0128] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only schematic. For example, the division of the units can be a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.
[0129] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple units. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
[0130] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0131] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, in essence, or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, disk or optical disk and other media that can store program codes.
[0132] The above is only a preferred implementation of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.
Claims
1. A message detection method, characterized in that: include: Parsing the message to be detected to obtain target key information, wherein the target key information includes parameter values of message fields; Parsing the target key information by using a syntax parsing tool to obtain a parsing result, and constructing an abstract syntax tree based on the parsing result; Constructing an undirected heterogeneous graph based on the lexical units in the abstract syntax tree, the target key information, and the structural information in the parsing result, wherein the undirected heterogeneous graph includes multiple types of nodes and multiple edges, the edges are used to connect nodes with an associated relationship, and the types of the nodes include the lexical units, the target key information, and the structural information; The undirected heterogeneous graph is input into a target model to obtain a detection result of the message to be detected, wherein the target model is trained by multiple groups of training samples, and each group of training samples includes an undirected heterogeneous graph corresponding to a sample message and a detection result.
2. The method according to claim 1, characterized in that Constructing an undirected heterogeneous graph based on the lexical units in the abstract syntax tree, the target key information and the structural information in the parsing result includes: Determine the target key information as a first node, extract multiple lexical units from the parsing result, determine each lexical unit as a second node, extract multiple structural information from the parsing result, and determine each structural information as a third node; Determine a target lexical unit connected to the target key information from the abstract syntax tree, and connect an edge between the first node and a second node corresponding to the target lexical unit; Determine target structure information associated with the target key information from the parsing result, and connect an edge between the first node and a third node corresponding to the target structure information; Extracting multiple groups of lexical units having logical relationships from the parsing results, and connecting edges between second nodes corresponding to lexical units in each group of lexical units; The weight of each edge is determined, and the undirected heterogeneous graph is constructed based on the first node, the second node, the third node, the edges connecting the nodes, and the weights of the edges.
3. The method according to claim 2, characterized in that Determining the weight of each edge, and constructing the undirected heterogeneous graph based on the first node, the second node, the third node, the edges connecting the nodes, and the weights of the edges includes: Determine attribute features of each type of node, wherein the attribute features include at least one of the following: statistical features, text features, and distribution features, and the distribution features are features of the distribution state of the nodes in the abstract syntax tree; Constructing an initial undirected heterogeneous graph based on each type of node, the edges connecting the nodes, the weights of the edges, and the attribute features of the nodes; A pruning operation is performed on the initial undirected heterogeneous graph using a preset pruning strategy to obtain the undirected heterogeneous graph.
4. The method according to claim 2, characterized in that: Determining the weight of each edge involves: For each edge, determine the starting node and the ending node on the path corresponding to the edge, and determine N intermediate nodes between the starting node and the ending node, where N is a non-negative integer; Determine the type weight of the edge based on the node types of the start node and the end node, and determine at least one of the logical relationship weight and the path feature weight of the edge based on the path between the start node and the end node; The statistical value of at least one of the logical relationship weight and the path feature weight and the type weight is calculated to obtain the weight of the edge.
5. The method according to claim 4, characterized in that Determining the type weight of the edge based on the node types of the start node and the end node includes: In the case where there is a second node between the start node and the end node, determining the lexical unit type of the second node, and determining the type weight that has a mapping relationship with the lexical unit type from a weight mapping relationship table; or, When there is no second node between the starting node and the ending node, the type weight of the edge is determined to be a first preset value, wherein the weight mapping relationship table includes multiple groups of mapping relationships, each group of mapping relationships includes a lexical unit type and a type weight.
6. The method according to claim 4 or 5, characterized in that: Determining at least one of a logical relationship weight and a path feature weight of the edge based on the path between the start node and the end node includes: In the case where both the starting node and the ending node are the second node, determining the path length of the path, and calculating the logical relationship weight of the edge based on the path length, and in the case where at least one of the starting node and the ending node is not the second node, determining the logical relationship weight of the edge as a second preset value; and / or, When the intermediate node includes the second node, the type weight of each intermediate node is determined, and the sum of the type weights of all the intermediate nodes in the path is calculated to obtain the path characteristic weight. When the intermediate node does not include the second node, the path characteristic weight is determined to be a third preset value.
7. The method according to claim 3, characterized in that Performing a pruning operation on the initial undirected heterogeneous graph by using a preset pruning strategy to obtain the undirected heterogeneous graph includes: Calculating a first contribution evaluation value of each node in the initial undirected isomorphic graph, and calculating a second contribution evaluation value of each edge in the initial undirected isomorphic graph; Nodes whose first contribution evaluation values are less than a first evaluation value threshold are removed from the initial undirected isomorphic graph, and edges whose second contribution evaluation values are less than a second evaluation value threshold are removed from the initial undirected isomorphic graph to obtain the undirected isomorphic graph.
8. The method according to claim 1, characterized in that: Parse the message to be detected and obtain the target key information including: Extracting multiple parameter values from the message to be detected, performing a decoding operation on each parameter value, and obtaining a plaintext result of each parameter value; Eliminating non-contributory parameter values from the plaintext results of each parameter value through a preset screening strategy to obtain the remaining multiple target parameter values, wherein the preset screening strategy includes at least one of the following: preset list screening and key string screening, and the non-contributory parameter value is a parameter value that does not contribute to injection attack detection; A generalization operation is performed on each target parameter value to obtain multiple target key information.
9. A message detection device, characterized in that: include: A parsing unit, used for parsing the message to be detected to obtain target key information, wherein the target key information includes parameter values of message fields; A first construction unit is used to parse the target key information by a syntax parsing tool to obtain a parsing result, and construct an abstract syntax tree based on the parsing result; A second construction unit is used to construct an undirected heterogeneous graph based on the lexical units in the abstract syntax tree, the target key information and the structural information in the parsing result, wherein the undirected heterogeneous graph contains multiple types of nodes and multiple edges, the edges are used to connect nodes with associated relationships, and the types of the nodes include the lexical units, the target key information and the structural information; An input unit is used to input the undirected heterogeneous graph into a target model to obtain a detection result of the message to be detected, wherein the target model is trained by multiple groups of training samples, and each group of training samples includes an undirected heterogeneous graph corresponding to the sample message and a detection result.
10. An electronic device, characterized in that: The electronic device includes one or more processors; a storage device for storing one or more programs, when the one or more programs are executed by the one or more processors, the one or more processors are enabled to run the programs, wherein the program is configured to execute the message detection method described in any one of claims 1-8 when running.
