Constructing identification model and attack identification method, device, equipment and storage medium
By building a recognition model and using word segmentation and word embedding vectors to train neural networks, the problem of false positives and false negatives when WAF identifies SQLI attacks is solved, and the recognition accuracy is improved.
Patent Information
- Application Number
- CN202110335549.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-03-29
- Publication Date
- 2024-09-13
- Estimated Expiration
- 2041-03-29
AI Technical Summary
Existing web application firewalls (WAF) are prone to false positives or false negatives when identifying Structured Query Language Injection (SQLI) attacks, especially when the corpus is not strong enough or the production environment is not updated in a timely manner.
By building a recognition model, a training sample set of structured query language is obtained, word segmentation is processed and converted into a representation vector, and the neural network model is trained with the word embedding vector to generate a model that can identify SQLI attacks.
It effectively reduces the false positive and false negative rates of SQLI attacks and improves the identification accuracy.
Smart Images

Figure CN112966507B
Abstract
Description
Technical Field
[0001] The present application relates to the field of network technology, and in particular to a method, device, equipment and storage medium for building an identification model and attack identification. Background Art
[0002] Web application firewall (WAF) is a popular security product on the market. It can effectively block structured query language injection attacks (SQLI, the full name of Structured Query Language Injection; Structured Query Language, SQL for short, the full name of Structured Query Language) in the scene to achieve the purpose of protecting Web applications.
[0003] At present, most WAFs on the market provide protection based on rule matching, and some use a combination of artificial intelligence (AI) and rules. As Web services become more and more complex, the corresponding attack methods also become more complex. In order to cope with this situation, WAF needs to become more intelligent.
[0004] AI-enabled WAF has become a major trend in the iteration of WAF products. More and more machine learning and deep learning models are being applied to WAF, and have shown good results. The methods of using AI to identify SQLI in WAF are also changing with the passage of time and technological updates. Each method will have problems of varying degrees in the production environment. There is currently no unified method in the industry, and each manufacturer is also updating its own technical level.
[0005] In addition to general rules, a more intelligent method for existing WAFs to identify SQLI is to use an open source SQLI semantic analysis library. After performing semantic analysis on the request message, it matches more than 8,000 built-in SQLI features through a binary search algorithm until the message is identified as an attack, or all SQLI features are traversed.
[0006] The disadvantage of this method is that if the corpus is not strong enough or the production environment corpus is not updated in time, there will be false positives or false negatives. Summary of the invention
[0007] The present application provides a method, apparatus, device and storage medium for building an identification model and attack identification, so as to effectively identify SQLI attacks and reduce false positives or false negatives.
[0008] In a first aspect, an embodiment of the present application provides a method for constructing a recognition model, comprising:
[0009] Obtain a training sample set of structured query language injection attacks;
[0010] According to the vocabulary of the structured query language, each sample in the training sample set is segmented to obtain a segmented sample of each sample, and then converted to obtain a representation vector of each segmented sample;
[0011] Obtain the first word embedding vector corresponding to each of the segmented samples;
[0012] Obtaining a second word embedding vector corresponding to each word in the vocabulary;
[0013] Based on the representation vector and the first word embedding vector of each sample, and the second word embedding vector of each word in the vocabulary, a preset neural network model is trained to obtain a recognition model for the structured query language injection attack.
[0014] Optionally, obtaining a training sample set of structured query language injection attack includes:
[0015] Obtaining an original training sample set of structured query language injection attacks;
[0016] Preprocessing the original training sample set to obtain the training sample set;
[0017] Wherein, the preprocessing includes:
[0018] removing interference data from the original training sample set; and / or
[0019] The encoded data of the structured query language in the original training sample set is decoded into original data of the structured query language.
[0020] Optionally, the interference data includes at least one of the following: comment statements, special symbols, repeated samples, ambiguous data, single-character samples and single-digit samples.
[0021] Optionally, the process of constructing the vocabulary of the structured query language includes:
[0022] Extract the words, characters and numbers contained in each sample in the vocabulary to construct the sample set;
[0023] After filtering the extracted words, characters and numbers, the entries included in the vocabulary are obtained, and the index value corresponding to each entry is obtained;
[0024] The word library is generated, which includes each of the words and the index value corresponding to each of the words.
[0025] Optionally, obtaining the index value corresponding to each of the entries includes:
[0026] Counting the frequency of occurrence of each term in the sample;
[0027] Sorting each of the terms in descending order of frequency of occurrence to obtain a sorting result;
[0028] The ranking of the term in the sorting result is used as the index value of the term.
[0029] Optionally, performing word segmentation processing on each sample in the training sample set according to the vocabulary of the structured query language to obtain a word segmentation sample of each sample, and converting to obtain a representation vector of each word segmentation sample, includes:
[0030] The following processing is performed on each sample:
[0031] According to the vocabulary of the structured query language, the sample is segmented to obtain each segmentation contained in the sample;
[0032] Obtaining the index value corresponding to each of the word segments from the word library;
[0033] Sort the index values corresponding to each of the participles according to the order in which each of the participles appears in the sample;
[0034] The index value sequence obtained after sorting is used as the representation vector corresponding to the sample.
[0035] Optionally, the first word embedding vector includes a frequency-based word embedding vector;
[0036] The frequency-based word embedding vector includes at least one of a counting vector, a frequency vector based on single word segmentation statistics, and a frequency vector based on n-gram statistics.
[0037] Optionally, obtaining a first word embedding vector corresponding to the word segmented sample includes:
[0038] Counting the number of times each word in the vocabulary appears in the word segmentation sample, and obtaining a count vector of the word segmentation sample according to the counted number of times;
[0039] Wherein, a row of the counting vector corresponds to a segmented sample, a column of the counting vector corresponds to an entry in the vocabulary, the value of an element in the j-th column of the counting vector represents the number of times the target entry appears in the target sample, the target sample is the segmented sample corresponding to the row where the element is located, and the target entry is the j-th entry in the vocabulary;
[0040] and / or
[0041] The following processing is performed on each term in the word library: the number of times the term appears in the word segmentation sample is counted, and the word frequency corresponding to the term is obtained according to the counted number of times and the total number of words in the word segmentation sample; the target number of samples in the training sample set containing the term is obtained; the inverse text frequency index of the term is obtained according to the target number of samples and the total number of samples in the training sample set; the element value corresponding to the term is obtained according to the word frequency of the term and the inverse text frequency index of the term;
[0042] According to the element value corresponding to each of the entries in the vocabulary, the frequency vector of the word segmentation sample based on the statistics of a single word segmentation is obtained;
[0043] and / or
[0044] The word library is reconstructed into a reconstructed word library by using n-gram grammar, and each segmentation of the segmented sample is reorganized by using n-gram grammar to obtain a reconstructed sample, and each reconstructed term in the reconstructed word library is processed as follows: the number of times the reconstructed term appears in the reconstructed sample is counted, and the word frequency corresponding to the reconstructed term is obtained according to the counted number of times and the total number of words in the reconstructed sample; the number of reconstructed samples in the training sample set containing the reconstructed term is obtained; the inverse text frequency index of the reconstructed term is obtained according to the number of reconstructed samples and the total number of reconstructed samples in the training sample set; the element value corresponding to the reconstructed term is obtained according to the word frequency of the reconstructed term and the inverse text frequency index of the reconstructed term;
[0045] According to the element value corresponding to each of the reconstructed terms in the reconstructed vocabulary, the frequency vector of the reconstructed sample based on the n-gram statistics is obtained as the frequency vector of the word segmented sample based on the n-gram statistics.
[0046] Optionally, obtaining the second word embedding vector corresponding to each word in the vocabulary includes:
[0047] The following processing is performed for each entry in the vocabulary:
[0048] The term and the post-segmentation samples of each sample are input into a Word2vec model to obtain a second word embedding vector of the term predicted by the Word2vec model based on context information of the term contained in the post-segmentation samples.
[0049] Optionally, the neural network model includes an input layer, an embedding layer, a fully connected layer and an output layer connected in series in sequence, the weights of the neurons used in the embedding layer are a matrix composed of the second word embedding vectors corresponding to each of the terms, and the parameters of the neurons used in the embedding layer are fixed;
[0050] The step of training a preset neural network model based on the representation vector and the first word embedding vector of each sample and the second word embedding vector of each word in the vocabulary to obtain the recognition model of the structured query language injection attack includes:
[0051] A training process includes:
[0052] The representation vector of each of the samples is input into the neurons of the embedding layer through the input layer, and after the matrix composed of the second word embedding vectors of each word in the vocabulary is superimposed on the representation vector through the neurons of the embedding layer, an abstract matrix carrying the sample semantics corresponding to the sample is obtained;
[0053] Through the neurons in the fully connected layer, the first word embedding vector of each sample is superimposed on the corresponding abstract matrix to obtain the superimposed abstract matrix corresponding to each sample, and the superimposed abstract matrix is predicted through an activation function to obtain a one-dimensional matrix;
[0054] Outputting the one-dimensional matrix through the output layer, the elements in the one-dimensional matrix are used to indicate whether the prediction result of the sample is a structured query language injection attack;
[0055] Calculating a prediction error according to a prediction result of each of the samples and whether each of the samples is a true result of a structured query language injection attack;
[0056] Determining whether the prediction error is greater than a preset error value;
[0057] If yes, back-propagate the prediction error to the fully connected layer, adjust the parameters of the fully connected layer according to the prediction error, and then return to perform the next training process;
[0058] Otherwise, the neural network model is determined as the recognition model.
[0059] In a second aspect, an embodiment of the present application provides an attack identification method, including:
[0060] Obtaining the structured query statement carried in the request message as the statement to be identified;
[0061] According to the vocabulary of the structured query language, the sentence to be recognized is segmented to obtain the segmentation result of the sentence to be recognized, and converted to obtain a representation vector of the segmentation result;
[0062] Obtain a first word embedding vector corresponding to the word segmentation result;
[0063] Inputting the representation vector into a recognition model to obtain a recognition result output by the recognition model;
[0064] According to the identification result, determining whether the request message has a structured query language injection attack;
[0065] Among them, the recognition model is constructed using the method described in the first aspect, and the fully connected layer in the recognition model superimposes the first word embedding vector and the abstract matrix output by the embedding layer.
[0066] In a third aspect, an embodiment of the present application provides a device for constructing an attack identification model, including:
[0067] A first acquisition module is used to acquire a training sample set of structured query language injection attack;
[0068] A word segmentation module is used to perform word segmentation processing on each sample in the training sample set according to the vocabulary of the structured query language, obtain a word segmentation sample of each sample, and convert it to obtain a representation vector of each word segmentation sample;
[0069] A second acquisition module is used to obtain the first word embedding vector corresponding to each of the segmented samples;
[0070] A third acquisition module is used to obtain a second word embedding vector corresponding to each word in the vocabulary;
[0071] The fourth acquisition module is used to train a preset neural network model based on the representation vector and the first word embedding vector of each sample, and the second word embedding vector of each term in the vocabulary, so as to obtain the recognition model of the structured query language injection attack.
[0072] In a fourth aspect, an embodiment of the present application provides an attack identification device, including:
[0073] A first acquisition module is used to acquire a structured query statement carried in the request message as a statement to be identified;
[0074] A word segmentation module, used for performing word segmentation processing on the sentence to be recognized according to the vocabulary of the structured query language, obtaining the word segmentation result of the sentence to be recognized, and converting to obtain a representation vector of the word segmentation result;
[0075] A second acquisition module is used to obtain a first word embedding vector corresponding to the word segmentation result;
[0076] A third acquisition module, used for inputting the representation vector into a recognition model to obtain a recognition result output by the recognition model;
[0077] A judgment module, used for judging whether the request message has a structured query language injection attack according to the identification result;
[0078] Wherein, the recognition model is constructed by adopting the method described in any one of the first aspects, and the fully connected layer in the recognition model superimposes the first word embedding vector and the abstract matrix output by the embedding layer.
[0079] In a fifth aspect, an embodiment of the present application provides an electronic device, comprising: a processor, a memory, and a communication bus, wherein the processor and the memory communicate with each other via the communication bus;
[0080] The memory is used to store computer programs;
[0081] The processor is used to execute the program stored in the memory to implement the method for constructing an attack identification model described in any one of the first aspects, or to implement the attack identification method described in the second aspect.
[0082] In a sixth aspect, an embodiment of the present application provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the method for constructing an attack identification model as described in any one of the first aspects, or implements the attack identification method as described in the second aspect.
[0083] The above technical solution provided by the embodiment of the present application has the following advantages over the prior art: the method provided by the embodiment of the present application, by constructing a vocabulary of structured language, uses the vocabulary to segment the samples of SQLI attacks, obtains the representation vector and the first word embedding vector of the sample after segmentation, and obtains the second word embedding vector of each word in the vocabulary, and trains the neural network model based on the representation vector, the first word embedding vector and the second word embedding vector to obtain a recognition model capable of identifying SQLI attacks. The recognition model is constructed after analyzing the SQLI samples using the natural language processing method, so that the constructed recognition model can achieve low false positives and low false negatives for SQLI, and effectively identify SQLI attacks. BRIEF DESCRIPTION OF THE DRAWINGS
[0084] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.
[0085] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0086] Figure 1A This is a schematic diagram of the structure of the artificial neural network in the embodiment of the present application;
[0087] Figure 1B This is a schematic diagram of the system architecture of the recognition model application in the embodiment of the present application;
[0088] Figure 2 This is a schematic diagram of the method flow for constructing a recognition model in an embodiment of the present application;
[0089] Figure 3 A schematic diagram of the process of constructing a vocabulary library of a structured query language in an embodiment of the present application;
[0090] Figure 4 A schematic diagram of the process of obtaining a representation vector in an embodiment of the present application;
[0091] Figure 5 A schematic diagram of the process of obtaining a frequency vector based on a single word segmentation statistic in an embodiment of the present application;
[0092] Figure 6 A schematic diagram of a process of obtaining a frequency vector based on n-gram statistics in an embodiment of the present application;
[0093] Figure 7 This is a schematic diagram of the CBOW model structure in the embodiment of the present application;
[0094] Figure 8 This is a schematic diagram of the Skip gram model structure in the embodiment of the present application;
[0095] Fig. 9 A schematic diagram of the process of obtaining a recognition model in an embodiment of the present application;
[0096] Fig.10 A schematic diagram of the process of attack identification in an embodiment of the present application;
[0097] Fig.11 A schematic diagram of the structure of an apparatus for constructing an attack identification model in an embodiment of the present application;
[0098] Fig.12 This is a schematic diagram of the structure of the attack identification device in the embodiment of the present application;
[0099] Fig.13 This is a schematic diagram of the structure of an electronic device in an embodiment of the present application. DETAILED DESCRIPTION
[0100] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, 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 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 making creative work are within the scope of protection of this application.
[0101] First, the technical terms involved in the embodiments of the present application are explained as follows:
[0102] SQLI, or SQL injection attack, is a method of inserting malicious SQL statements, such as SQL queries or addition statements, into the input parameters of an application, and then parsing the SQL statements on the backend SQL server to execute the attack. It is currently one of the most common means for hackers to attack databases. The threats brought by SQLI are mainly as follows: 1. Disassembling the backend database and stealing sensitive information from the website; 2. Bypassing authentication, such as bypassing verification to log in to the backend of the website; 3. Using the stored procedures of the database to perform operations such as escalating privileges.
[0103] NLP, the full name in English: Natural Language Processing, Chinese name: Natural Language Processing, as a hot research direction in the field of AI, has also shown its important significance in fields such as information security. In recent years, with the gradual maturity of pre-trained language models, the performance of natural language processing tasks represented by grammar annotation, text generation, semantic logic reasoning, automatic question answering, etc. has been greatly improved, which also provides unprecedented technical support for processing information security-related text content analysis. In the text content related to information security, although SQL statements do not belong to the category of natural language, the idea of text processing in NLP can also be used for the analysis of SQLI statements.
[0104] Word embedding, as an important means of text processing, aims to convert text into numbers that can be recognized by computers, and these numbers can carry the information expressed by the original text. The commonly used word embedding conversion idea is to map the words in the text into a vector through a dictionary. Based on this idea, there are many word embedding methods, which can be roughly divided into two categories: 1. Frequency-based word embedding vectors, related algorithms such as count vectors, TF-IDF vectors, co-occurrence matrix vectors, etc.; 2. Prediction-based word embedding vectors, related algorithms such as Word2vec.
[0105] URL encoding is a format used by browsers to package form inputs. It converts characters into a format that can be safely transmitted on the Internet. URL stands for Uniform Resource Locator.
[0106] Artificial Neural Network, ANN for short, also known as Neural Network, is a model that imitates the structure and function of biological nerves, through which an approximate estimate of the target function is generated. Neural network is calculated by connecting a large number of artificial neurons. It can change its internal structure according to the changes in input information and is an adaptive system. In statistical learning methods, neural networks can be used as supervised learning models as well as unsupervised learning models.
[0107] The general structure of an artificial neural network is as follows Figure 1A As shown. The neural network consists of an input layer (input), a hidden layer and an output layer (output). The hidden layer consists of one or more layers. Each circle in the figure represents a neuron, and each neuron has a corresponding input weight w, an offset b and an activation function, where w and b are the parameters of the neuron. If the S-shaped generating curve (Sigmoid) is used as the activation function, the information transmission formula between neurons is y=sig(w*x+b), x is the input information pointing to this neuron, y is the output information of this neuron, and sig represents the S-shaped generating curve. The neural network transmits information from the input layer in the direction of the arrow until the output result is generated.
[0108] The neural network determines the parameters of each neuron through two processes: forward propagation and back propagation. During the forward propagation process, information is transmitted along the direction of the arrow in the figure. The neural network initializes parameters within a certain range and obtains the corresponding error value after information transmission. If the error cannot meet the required accuracy, it will enter the back propagation process. The back propagation process feeds back the output to each neuron in the previous layer, and gradually adjusts the parameters of each neuron through the error signal, adjusting the parameters in the direction that makes the error signal smaller. After training, the error signal is continuously reduced, and the neural network model used for classification is finally obtained.
[0109] In the embodiment of the present application, based on the idea of natural language processing, a method for constructing a recognition model for identifying SQLI attacks is proposed. The recognition model constructed by this method can be applied to Figure 1B In the system architecture shown in the figure, the system architecture includes a terminal 10 and a server 11, wherein the server 11 is configured with a recognition model constructed by the method.
[0110] Terminal 10 sends a request message to the server;
[0111] The server 11 obtains the request message sent by the terminal 10, and when the request message carries a structured query statement, the recognition model is used to perform SQLI attack recognition on the structured query statement.
[0112] In the first embodiment of the present application, Figure 2 As shown, the specific method flow for building the recognition model is as follows:
[0113] Step 201: Obtain a training sample set of structured query language injection attack.
[0114] In an optional embodiment, the specific process of obtaining a training sample set for a structured query language injection attack includes: obtaining an original training sample set for a structured query language injection attack; removing interference data from the original training sample set, and decoding the encoded data of the structured query language in the original training sample set into original data of the structured query language to obtain the training sample set.
[0115] The interference data may include at least one of the following: comment statements, special symbols, repeated data, ambiguous data, single character samples, and single digit samples. It should be noted that all data that does not belong to SQLI can be classified as interference data. This is only an example. If there are other data that may interfere with SQLI recognition, they are also within the scope of interference data.
[0116] Specifically, the original training sample set includes the collected malicious samples, including the publicly available, influential, and relatively typical SQLI samples collected from the Internet, as well as SQLI samples collected in business scenario applications. For example, the SQLI samples include open source SQLI semantic analysis libraries, official sample libraries of database vendors, etc., with a total of 86,781 samples.
[0117] After obtaining the original training sample set, the samples in the original training sample set are preprocessed to clean the sample data in the original training sample set. The preprocessing mainly includes the following processing procedures:
[0118] Remove comment sentences, special symbols, and ambiguous data from the samples in the original training sample set; remove duplicate samples, single-character samples, and single-digit samples in the original training sample set; and / or decode samples with encoded data such as transcoding or escaping in the original training sample set into original data of the structured query language.
[0119] The original training sample set after the above processing is used as the training sample set obtained in step 201.
[0120] For example, the URL-encoded sample is as follows:
[0121] F****%27)%2c(1%2c2%2c3%2c4%2c5%2c(SELECT+IF+((ASCII(SUBSTRING(se_games.admin_pw% 2c1%2c1)%3d%271%27)+%26+1%2c+benchmark(20000%2cCHAR(0))%2c0)+FROM+se_games))%2f*;
[0122] After decoding and restoring the sample, the following SQL statement is obtained:
[0123] F****'),(1,2,3,4,5,(SELECT IF((ASCII(SUBSTRING(se_games.admin_pw,1,1)='1')&1,benchmark(20000,CHAR(0)),0)FROM se_games)) / *.
[0124] Step 202, according to the vocabulary of the structured query language, perform word segmentation processing on each sample in the training sample set to obtain a word segmentation sample of each sample, and convert each word segmentation sample to obtain a representation vector of each sample.
[0125] It should be noted that word segmentation is an important step in NLP. Through word segmentation, long texts such as sentences, paragraphs, and articles are decomposed into data structures with words as units, which is convenient for subsequent processing and analysis. The sentences in the SQLI sample do not belong to the category of natural language and cannot be implemented according to the current mainstream Chinese or English word segmentation methods. If the word segmentation is based on a single character, the granularity is too small and cannot express the complete meaning. For example, the character "a" will appear in "and" and "admin", but it will express completely different SQL statements. However, the granularity of the sentence is too large, and the sentence carries too much information, which is not suitable for subsequent text analysis. Therefore, it is necessary to establish a corresponding vocabulary for SQLI word segmentation and segment the sample according to the vocabulary.
[0126] In an optional embodiment, if Figure 3 As shown in FIG. 1 , the process of constructing the vocabulary of the structured query language includes:
[0127] Step 301, extracting the words, characters and numbers contained in each sample in the vocabulary to construct the sample set;
[0128] Step 302, after filtering the extracted words, characters and numbers, obtain the entries contained in the vocabulary, and obtain the index value corresponding to each entry;
[0129] Step 303: Generate a vocabulary containing each term and the index value corresponding to each term.
[0130] The index value of a term is used to uniquely identify the term in the vocabulary. There are many ways to configure the index value, as long as the index value of each term in the vocabulary is unique.
[0131] In an optional embodiment, the specific process of obtaining the index value corresponding to each term includes: counting the frequency of occurrence of each term in the sample; sorting each term in descending order of the frequency of occurrence to obtain a sorting result; and using the ranking of the term in the sorting result as the index value of the term.
[0132] According to the frequency of occurrence of the entry, the index value of the entry is determined, and the entries with high frequency of occurrence are arranged at the front of the dictionary, so that when looking up the word library, commonly used word segments can be quickly indexed, thereby improving the efficiency of word segmentation.
[0133] After extracting the words, characters and numbers contained in each sample in the vocabulary construction sample set, the extracted words, characters and numbers are used as initial entries to obtain an initial vocabulary. The entries in the initial vocabulary are screened, which can be manual screening, to obtain entries that can represent SQLI semantics, and the filtered entries are used to form the vocabulary that is finally used.
[0134] For example, "1=1" is usually used as a basis for judging true in SQLI; "#" is often used as a comment character in SQLI; "rlike" is used as a fuzzy matching symbol in SQLI; "@" is a local variable identifier; and "@@" is a global variable identifier. For example, the word library obtained after screening is ["1=1", "#", "rlike", "@@", "@"].
[0135] In an optional embodiment, if Figure 4 As shown, after obtaining the vocabulary of the structured query language, each sample in the training sample set is segmented according to the vocabulary of the structured query language to obtain the segmented samples of each sample, and then converted to obtain the representation vector of each segmented sample, including:
[0136] Perform the following processing on each sample:
[0137] Step 401, performing word segmentation processing on the sample according to the vocabulary of the structured query language to obtain each word segmentation contained in the sample;
[0138] Step 402, obtaining the index value corresponding to each word segment from the word library;
[0139] Step 403, sorting the index value corresponding to each participle according to the order in which each participle appears in the sample;
[0140] Step 404: Use the index value sequence obtained after sorting as the representation vector corresponding to the sample.
[0141] For example, suppose a sample is "select-sin(((@version)),2from bar where". After word segmentation, the representation vector of the sample is [34,69,5,11,88,324,513,66]. That is, for each word in the word segmentation result ["select", "-sin", "@", "version", "2", "from", "bar", "where"], the index value in the vocabulary is searched, and the corresponding word is replaced by the found index value to obtain the representation vector.
[0142] By obtaining the representative vector of the sample, the sample is mathematized to facilitate use in subsequent calculations.
[0143] Step 203, obtaining the first word embedding vector corresponding to each segmented sample.
[0144] In an optional embodiment, the first word embedding vector includes a frequency-based word embedding vector; the frequency-based word embedding vector includes at least one of a counting vector, a frequency vector based on single word segmentation statistics, and a frequency vector based on n-gram grammar statistics.
[0145] Among them, the count vector is expressed in English as Count-Vector, which can convert text into numbers that are convenient for machine learning models to process.
[0146] In an optional embodiment, the specific process of obtaining the count vector includes: counting the number of times each term in the vocabulary appears in the post-segmentation sample, and obtaining the count vector of the post-segmentation sample according to the counted number of times. A row of the count vector corresponds to a post-segmentation sample, a column of the count vector corresponds to an term in the vocabulary, the value of the j-th column element in the count vector represents the number of times the target term appears in the target sample, the target sample is the post-segmentation sample corresponding to the row where the element is located, and the target term is the j-th term in the vocabulary.
[0147] For example, assuming the vocabulary is ["select", "form", "bar", "where"], a sample is "selectselect from from from bar where", which is converted into the count vector of the sample [2,3,1,1]. It can be understood that this is only for the sake of ease of understanding. Assuming that there are only 4 tokens in the vocabulary, the number of tokens contained in the application vocabulary is much larger than 4. For example, if the vocabulary contains 63,000 tokens, the number of columns in the count vector is 63,000.
[0148] In an optional embodiment, term frequency (TF)-inverse document frequency index (IDF) is used to calculate a frequency vector based on a single word segment. Different from the count vector, the frequency vector calculated by TF-IDF not only considers the frequency of occurrence of the word segment in a single sample, but also considers the frequency of occurrence of the word segment in the entire vocabulary.
[0149] like Figure 5 As shown in the figure, for a sample, the specific process of obtaining the frequency vector based on a single word segmentation statistics includes:
[0150] Step 501, perform the following processing on each term in the vocabulary: count the number of times the term appears in the sample after word segmentation, and obtain the word frequency corresponding to the term according to the counted number of times and the total number of words in the sample after word segmentation; obtain the target number of samples in the training sample set that contain the term; obtain the inverse text frequency index of the term according to the target number of samples and the total number of samples in the training sample set; obtain the element value corresponding to the term according to the word frequency of the term and the inverse text frequency index of the term;
[0151] Step 502: According to the element value corresponding to each word in the vocabulary, a frequency vector of the word segmentation sample based on single word segmentation statistics is obtained.
[0152] That is, TF = (the number of times a word appears in the sample) / (the total number of words in the sample).
[0153] IDF = log(N / n), where N is the total number of samples and n is the number of samples in which the word appears.
[0154] For example, there are two samples: "select from bar where", "1union select version()".
[0155] For the two samples, the TF of "select" is 1 / 4=0.25; the IDF of "select" is log(2 / 2)=0; then the TF-IDF of "select" corresponding to the two samples is 0.25*0=0.
[0156] For the second sample, the TF of "union" is 1 / 4=0.25; the IDF of "union" is log(2 / 1)=0.69; then the TF-IDF of "union" corresponding to the second sample is 0.25*0.69=0.17.
[0157] After calculating the TF-IDF of each word in each sample in this way, the frequency vector of the sample can be obtained.
[0158] After obtaining the frequency vector of each sample, a total frequency vector can be integrated to obtain a total frequency vector, in which a row of the total frequency vector corresponds to a segmented sample, and a column of the frequency vector corresponds to an entry in the vocabulary.
[0159] In an optional embodiment, TF-IDF (n-gram) is used to calculate a frequency vector based on n-gram statistics. The method of obtaining a frequency vector is similar to that of TF-IDF, except that the vocabulary used is not composed of a single token, but multiple tokens. Since the frequency vector obtained based on a single token cannot represent the contextual semantics of the sample, the frequency vector obtained using multiple tokens will carry the contextual semantics of the token to more accurately describe the sample. For example, if n is 2 and 2-gram is used, "select from" in the sample will be used as a token, and the frequency vector will be calculated using TF-IDF.
[0160] There is no specific limitation on the value of n, as long as n is greater than 1 and not greater than a preset value. By setting the preset value, excessive calculation can be avoided.
[0161] like Figure 6 As shown, the specific process of obtaining the frequency vector based on n-gram statistics includes:
[0162] Step 601, reconstructing the vocabulary into a reconstructed vocabulary by using n-grams, and reorganizing each segmentation of the segmented sample by using n-grams to obtain a reconstructed sample, and performing the following processing on each reconstructed term in the reconstructed vocabulary: counting the number of times the reconstructed term appears in the reconstructed sample, and obtaining the word frequency corresponding to the reconstructed term according to the counted number of times and the total number of words in the reconstructed sample; obtaining the number of reconstructed samples in the training sample set that contain the reconstructed term; obtaining the inverse text frequency index of the reconstructed term according to the number of reconstructed samples and the total number of reconstructed samples in the training sample set; obtaining the element value corresponding to the reconstructed term according to the word frequency of the reconstructed term and the inverse text frequency index of the reconstructed term;
[0163] Step 602: Obtain the frequency vector of the reconstructed sample based on the n-gram statistics according to the element value corresponding to each reconstructed term in the reconstructed vocabulary, as the frequency vector of the sample after word segmentation based on the n-gram statistics.
[0164] After obtaining the frequency vector of each sample based on n-gram statistics, a total frequency vector can be integrated to obtain a total frequency vector, in which a row of the total frequency vector corresponds to a reconstructed sample, and a column of the frequency vector corresponds to a reconstructed term in the reconstructed vocabulary.
[0165] Step 204, obtaining the second word embedding vector corresponding to each word in the vocabulary.
[0166] In an optional embodiment, obtaining the second word embedding vector corresponding to each word in the vocabulary includes: performing the following processing on each word in the vocabulary:
[0167] The word entry and the segmented samples of each sample are input into the Word2vec model to obtain the second word embedding vector of the word entry predicted by the Word2vec model based on the context information of the word entry contained in the segmented samples. The second word embedding vector can represent the contextual semantics of the word entry.
[0168] The Word2vec model includes a continuous bag-of-words model or a skip-words model, or includes both a continuous bag-of-words model and a skip-words model.
[0169] Specifically, the Word2vec model includes the Continuous Bag of Words model (CBOW) and the Skip Gram model. When using it, you can set it to use only the CBOW model or the Skip Gram model. Both the CBOW model and the Skip Gram model are shallow neural network models.
[0170] Among them, the CBOW model structure is as follows Figure 7 As shown, the model is used to predict the term by giving the context of the term, and the context can be a term or a group of terms, that is, the CBOW model predicts the term using the words around the term, thereby obtaining the second word embedding vector of the term.
[0171] Specifically, the term and each sample after word segmentation are input into the trained CBOW model. The CBOW model extracts the context segmentation of the term from each sample after word segmentation, and predicts the term based on the context segmentation of the term. The network parameters of the CBOW model when the term is obtained are used as the second word embedding vector of the term.
[0172] The process of training the CBOW model is as follows: the term and the segmented samples of each sample are input into the initial CBOW model, the CBOW model extracts the context segmentation of the term from each segmented sample, and predicts the predicted term based on the context segmentation of the term. If the predicted term is inconsistent with the term, the network parameters of the CBOW model are adjusted until the predicted term is consistent with the term. The training process is repeated until the prediction accuracy reaches the set ratio value, and a CBOW model that can be applied is obtained.
[0173] Among them, the Skip gram model structure is as follows Figure 8 As shown in the figure, the Skip gram model is the opposite of the CBOW model. Given a term, it predicts the context of the term to obtain the second word embedding vector of the term.
[0174] Specifically, the term and each sample after word segmentation are input into the trained Skip gram model, and the Skip gram model predicts the context of the term. When the predicted context of the term is consistent with the context of the term extracted from the sample after word segmentation, the parameters of the Skip gram model are used as the second word embedding vector of the term.
[0175] The process of training the Skip gram model is as follows: the entry and the segmented samples of each sample are input into the initial Skip gram model, the Skip gram model predicts the context of the entry, and the predicted context is compared with the context extracted from the segmented samples. When the two are inconsistent, the network parameters of the Skip gram model are adjusted until the predicted context is consistent with the extracted context. The training process is repeated until the prediction accuracy is higher than the set ratio value, and an applicable Skip gram model is obtained.
[0176] Step 205: Based on the representation vector and the first word embedding vector of each sample and the second word embedding vector of each word in the vocabulary, a preset neural network model is trained to obtain a recognition model for structured query language injection attacks.
[0177] In an optional embodiment, the neural network model includes an input layer (Input), an embedding layer (embedding), a fully connected layer and an output layer (Output) connected in series.
[0178] The weights of the neurons used in the embedding layer are a matrix consisting of the second word embedding vectors corresponding to each term, and the parameters of the neurons used in the embedding layer are fixed.
[0179] Specifically, Fig. 9As shown, based on the representation vector and the first word embedding vector of each sample, and the second word embedding vector of each word in the vocabulary, the preset neural network model is trained to obtain a recognition model for structured query language injection attacks, including:
[0180] Step 901, inputting the representation vector of each sample into the neurons of the embedding layer through the input layer, and superimposing the matrix composed of the second word embedding vector of each word in the vocabulary on the representation vector through the neurons of the embedding layer, thereby obtaining an abstract matrix carrying the sample semantics corresponding to each sample;
[0181] Step 902: superimpose the first word embedding vector of each sample into the corresponding abstract matrix through the neurons in the fully connected layer to obtain the superimposed abstract matrix corresponding to each sample, and predict the superimposed abstract matrix through the activation function to obtain a one-dimensional matrix;
[0182] Step 903: output the one-dimensional matrix through the output layer, and the elements in the one-dimensional matrix are used to indicate whether the prediction result of the sample is a structured query language injection attack;
[0183] Step 904, calculating a prediction error according to the prediction result of each sample and whether each sample is a true result of a structured query language injection attack;
[0184] Step 905, determining whether the prediction error is greater than a preset error value, if so, executing step 906, otherwise, executing step 907;
[0185] Step 906, back-propagating the prediction error to the fully connected layer, adjusting the parameters of the fully connected layer according to the prediction error, and then returning to step 901;
[0186] Step 907: determine the neural network model as a recognition model.
[0187] The length of the representation vector input into the input layer is a preset value. The representation vector with a length less than the preset value is padded with zeros. For example, the preset value is 300 dimensions.
[0188] The recognition model may use the function RELU as an activation function. After the one-dimensional matrix is obtained in the output layer, the one-dimensional matrix may be normalized by, for example, a Softmax layer. Specifically, the one-dimensional matrix after normalization may include two elements, which respectively represent the probability that the input sample is a SQLI attack and the probability that the input sample is not a SQLI attack (i.e., the probability of a normal sample). When the probability that the input sample is a SQLI attack is greater than a preset probability, the input sample may be determined to be a SQLI attack, otherwise the input sample may be determined not to be a SQLI attack.
[0189] The information transfer function of the neuron is y=f(w*x+b), and w and b may specifically be parameters of the neuron expressed in a matrix form.
[0190] By setting the parameters w and b of the neuron, a one-dimensional matrix is finally output, and the elements in the matrix are the probability values for predicting whether a SQLI attack occurs.
[0191] In an optional embodiment, after the recognition model is obtained through training, a test sample set is used to test the recognition model. The test sample set and the training sample set used in the training process together constitute a vocabulary sample set for constructing a vocabulary.
[0192] According to the process similar to the recognition model construction process, SQLI recognition is performed on each sample in the test sample set, and the SQLI recognition effect of the recognition model is evaluated according to the recognition results.
[0193] The evaluation criteria include accuracy, recall and precision.
[0194] Accuracy: Accuracy represents the ratio of the number of samples correctly classified by the network model to the total number of samples in a given test set.
[0195]
[0196] Recall: Recall represents the ratio of the number of SQLI samples predicted correctly by the network model to the number of actual SQLI samples on a given test set.
[0197]
[0198] Precision: Precision represents the ratio of the number of SQLI samples predicted correctly by the network model to the number of samples predicted as SQLI by the classifier on a given test set.
[0199]
[0200] Among them, TP represents the number of correctly classified positive samples, TN represents the number of correctly classified negative samples, FP represents the number of incorrectly classified positive samples, and FN represents the number of incorrectly classified negative samples.
[0201] The method provided in the embodiment of the present application constructs a vocabulary of structured language, uses the vocabulary to segment SQLI attack samples, obtains the representation vector and the first word embedding vector of the segmented samples, and obtains the second word embedding vector of each word in the vocabulary. Based on the representation vector, the first word embedding vector and the second word embedding vector, the neural network model is trained to obtain a recognition model capable of identifying SQLI attacks. The recognition model is constructed after analyzing the SQLI samples using the natural language processing method, so that the constructed recognition model can achieve low false positives and low false negatives for SQLI, and effectively identify SQLI attacks.
[0202] like Fig.10 As shown in the figure, based on the recognition model constructed above, the specific process of attack recognition is as follows:
[0203] Step 1001, obtaining a structured query statement carried in a request message as a statement to be identified;
[0204] Step 1002, performing word segmentation processing on the sentence to be recognized according to the vocabulary of the structured query language, obtaining the word segmentation result of the sentence to be recognized, and converting to obtain a representation vector of the word segmentation result;
[0205] Step 1003, obtaining a first word embedding vector corresponding to the word segmentation result;
[0206] Step 1004, inputting the representation vector into a recognition model to obtain a recognition result output by the recognition model, wherein the fully connected layer in the recognition model superimposes the first word embedding vector and the abstract matrix output by the embedding layer;
[0207] Step 1005: determine whether the request message contains a structured query language injection attack based on the identification result.
[0208] Based on the same concept, an apparatus for constructing an attack identification model is provided in the embodiment of the present application. The specific implementation of the apparatus can be found in the description of the method embodiment part, and the repetitive parts will not be repeated. Fig.11 As shown, the device mainly includes:
[0209] The first acquisition module 1101 is used to acquire a training sample set of structured query language injection attack;
[0210] The word segmentation module 1102 is used to perform word segmentation processing on each sample in the training sample set according to the vocabulary of the structured query language, obtain a word segmentation sample of each sample, and convert each word segmentation sample to obtain a representation vector;
[0211] The second acquisition module 1103 is used to obtain the first word embedding vector corresponding to each of the segmented samples;
[0212] A third acquisition module 1104 is used to obtain a second word embedding vector corresponding to each word in the vocabulary;
[0213] The fourth acquisition module 1105 is used to train a preset neural network model based on the representation vector and the first word embedding vector of each sample, and the second word embedding vector of each term in the vocabulary, to obtain the recognition model of the structured query language injection attack.
[0214] Based on the same concept, an attack identification device is provided in the embodiment of the present application. The specific implementation of the device can refer to the description of the method embodiment part, and the repeated parts will not be repeated. Fig.12 As shown, the device mainly includes:
[0215] The first acquisition module 1201 is used to acquire a structured query statement carried in the request message as a statement to be identified;
[0216] The word segmentation module 1202 is used to perform word segmentation processing on the sentence to be recognized according to the vocabulary of the structured query language, obtain the word segmentation result of the sentence to be recognized, and convert it into a representation vector of the word segmentation result;
[0217] The second acquisition module 1203 is used to obtain a first word embedding vector corresponding to the word segmentation result;
[0218] A third acquisition module 1204 is used to input the representation vector into a recognition model to obtain a recognition result output by the recognition model, wherein the fully connected layer in the recognition model superimposes the first word embedding vector with an abstract matrix output by the embedding layer;
[0219] The judgment module 1205 is used to judge whether the request message contains a structured query language injection attack according to the identification result.
[0220] Based on the same concept, an electronic device is also provided in the embodiment of the present application, such as Fig.13 As shown, the electronic device mainly includes: a processor 1301, a memory 1302 and a communication bus 1303, wherein the processor 1301 and the memory 1302 communicate with each other through the communication bus 1303. The memory 1302 stores a program that can be executed by the processor 1301, and the processor 1301 executes the program stored in the memory 1302 to implement the following steps:
[0221] Obtain a training sample set of structured query language injection attacks;
[0222] According to the vocabulary of the structured query language, each sample in the training sample set is segmented to obtain a segmented sample of each sample, and then converted to obtain a representation vector of each segmented sample;
[0223] Obtain the first word embedding vector corresponding to each of the segmented samples;
[0224] Obtaining a second word embedding vector corresponding to each word in the vocabulary;
[0225] Based on the representation vector and the first word embedding vector of each sample, and the second word embedding vector of each word in the vocabulary, a preset neural network model is trained to obtain a recognition model for the structured query language injection attack.
[0226] or
[0227] Obtaining the structured query statement carried in the request message as the statement to be identified;
[0228] According to the vocabulary of the structured query language, the sentence to be recognized is segmented to obtain the segmentation result of the sentence to be recognized, and converted to obtain a representation vector of the segmentation result;
[0229] Obtain a first word embedding vector corresponding to the word segmentation result;
[0230] Inputting the representation vector into a recognition model to obtain a recognition result output by the recognition model, wherein the fully connected layer in the recognition model superimposes the first word embedding vector with an abstract matrix output by the embedding layer;
[0231] According to the identification result, it is determined whether the request message contains a structured query language injection attack.
[0232] The communication bus 1303 mentioned in the above electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus. The communication bus 1303 can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Fig.13 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0233] The memory 1302 may include a random access memory (RAM) or a non-volatile memory, such as at least one disk memory. Alternatively, the memory may also be at least one storage device located away from the processor 1301.
[0234] The above-mentioned processor 1301 can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc., and can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components.
[0235] In another embodiment of the present application, a computer-readable storage medium is provided, in which a computer program is stored. When the computer program runs on a computer, the computer executes the method for constructing an identification model described in the above embodiment, or the attack identification method.
[0236] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer instruction is loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network or other programmable device. The computer instruction can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer instruction is transmitted from a website site, a computer, a server or a data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, microwave, etc.) mode to another website site, computer, server or data center. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server, a data center, etc. that contains one or more available media integration. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape, etc.), an optical medium (e.g., a DVD) or a semiconductor medium (e.g., a solid-state hard disk), etc.
[0237] It should be noted that, in this article, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0238] The foregoing is merely a specific embodiment of the present invention, which enables those skilled in the art to understand or implement the present invention. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features claimed herein.
Claims
1. A method for constructing a recognition model, characterized in that: include: Obtain a training sample set of structured query language injection attacks; According to the vocabulary of the structured query language, each sample in the training sample set is segmented to obtain a segmented sample of each sample, and then converted to obtain a representation vector of each segmented sample; Obtain the first word embedding vector corresponding to each of the segmented samples; Obtaining a second word embedding vector corresponding to each word in the vocabulary; Based on the representation vector and the first word embedding vector of each sample, and the second word embedding vector of each word in the vocabulary, a preset neural network model is trained to obtain a recognition model of the structured query language injection attack; The neural network model includes an input layer, an embedding layer, a fully connected layer and an output layer connected in series in sequence, the weights of the neurons used in the embedding layer are a matrix composed of the second word embedding vectors corresponding to each term, and the parameters of the neurons used in the embedding layer are fixed; based on the representation vector and the first word embedding vector of each sample, and the second word embedding vector of each term in the vocabulary, the preset neural network model is trained to obtain the recognition model of the structured query language injection attack, including: a training process includes: inputting the representation vector of each sample into the neurons of the embedding layer through the input layer, and superimposing the matrix composed of the second word embedding vector of each term in the vocabulary on the representation vector through the neurons of the embedding layer, so as to obtain the sample semantics corresponding to each sample. abstract matrix; through the neurons in the fully connected layer, the first word embedding vector of each sample is superimposed on the corresponding abstract matrix to obtain the superimposed abstract matrix corresponding to each sample, and the superimposed abstract matrix is predicted by the activation function to obtain a one-dimensional matrix; the one-dimensional matrix is output through the output layer, and the elements in the one-dimensional matrix are used to indicate whether the prediction result of the sample is a structured query language injection attack; according to the prediction result of each sample and whether each sample is the actual result of the structured query language injection attack, the prediction error is calculated; whether the prediction error is greater than the preset error value; if so, the prediction error is back-propagated to the fully connected layer, and after adjusting the parameters of the fully connected layer according to the prediction error, it returns to execute the next training process; otherwise, the neural network model is determined as the recognition model; Wherein, the first word embedding vector includes a frequency-based word embedding vector; the frequency-based word embedding vector includes at least one of a count vector, a frequency vector based on a single word segmentation, and a frequency vector based on n-gram grammar statistics; The step of obtaining the second word embedding vector corresponding to each word in the vocabulary includes: performing the following processing on each word in the vocabulary: inputting the word and the segmented samples of each word into a Word2vec model, and obtaining the second word embedding vector of the word predicted by the Word2vec model based on the context information of the word contained in the segmented samples; According to the vocabulary of the structured query language, each sample in the training sample set is segmented to obtain a segmented sample of each sample, and then converted to obtain a representation vector of each segmented sample. The process includes: performing the following processing on each sample: according to the vocabulary of the structured query language, the sample is segmented to obtain each segmented word contained in the sample; an index value corresponding to each segmented word is obtained from the vocabulary; the index value corresponding to each segmented word is sorted according to the order in which each segmented word appears in the sample; and the index value sequence obtained after sorting is used as the representation vector corresponding to the sample.
2. The method for constructing a recognition model according to claim 1, characterized in that: The step of obtaining a training sample set of structured query language injection attack includes: Obtaining an original training sample set of structured query language injection attacks; Preprocessing the original training sample set to obtain the training sample set; Wherein, the preprocessing includes: removing interference data from the original training sample set; and / or The encoded data of the structured query language in the original training sample set is decoded into original data of the structured query language.
3. The method for constructing a recognition model according to claim 2, characterized in that: The interference data includes at least one of the following: comment sentences, special symbols, repeated samples, ambiguous data, single-character samples and single-digit samples.
4. The method for constructing a recognition model according to claim 1, characterized in that: The process of constructing the vocabulary of the structured query language includes: Extract the words, characters and numbers contained in each sample in the vocabulary to construct the sample set; After filtering the extracted words, characters and numbers, the entries included in the vocabulary are obtained, and the index value corresponding to each entry is obtained; The word library is generated, which includes each of the words and the index value corresponding to each of the words.
5. The method for constructing a recognition model according to claim 4, characterized in that: The obtaining of the index value corresponding to each of the entries includes: Counting the frequency of occurrence of each term in the sample; Sorting each of the terms in descending order of frequency of occurrence to obtain a sorting result; The ranking of the term in the sorting result is used as the index value of the term.
6. The method for constructing a recognition model according to claim 1, characterized in that: Obtaining the first word embedding vector corresponding to the word segmented sample includes: Counting the number of times each word in the vocabulary appears in the word segmentation sample, and obtaining a count vector of the word segmentation sample according to the counted number of times; Wherein, a row of the counting vector corresponds to a segmented sample, a column of the counting vector corresponds to an entry in the vocabulary, the value of an element in the j-th column of the counting vector represents the number of times the target entry appears in the target sample, the target sample is the segmented sample corresponding to the row where the element is located, and the target entry is the j-th entry in the vocabulary; and / or The following processing is performed on each term in the word library: the number of times the term appears in the word segmentation sample is counted, and the word frequency corresponding to the term is obtained according to the counted number of times and the total number of words in the word segmentation sample; the target number of samples in the training sample set containing the term is obtained; the inverse text frequency index of the term is obtained according to the target number of samples and the total number of samples in the training sample set; the element value corresponding to the term is obtained according to the word frequency of the term and the inverse text frequency index of the term; According to the element value corresponding to each of the entries in the vocabulary, the frequency vector of the word segmentation sample based on the statistics of a single word segmentation is obtained; and / or The word library is reconstructed into a reconstructed word library by using n-gram grammar, and each segmentation of the segmented sample is reorganized by using n-gram grammar to obtain a reconstructed sample, and each reconstructed term in the reconstructed word library is processed as follows: the number of times the reconstructed term appears in the reconstructed sample is counted, and the word frequency corresponding to the reconstructed term is obtained according to the counted number of times and the total number of words in the reconstructed sample; the number of reconstructed samples in the training sample set containing the reconstructed term is obtained; the inverse text frequency index of the reconstructed term is obtained according to the number of reconstructed samples and the total number of reconstructed samples in the training sample set; the element value corresponding to the reconstructed term is obtained according to the word frequency of the reconstructed term and the inverse text frequency index of the reconstructed term; According to the element value corresponding to each of the reconstructed terms in the reconstructed vocabulary, the frequency vector of the reconstructed sample based on the n-gram statistics is obtained as the frequency vector of the word segmented sample based on the n-gram statistics.
7. An attack identification method, characterized in that: include: Obtaining the structured query statement carried in the request message as the statement to be identified; According to the vocabulary of the structured query language, the sentence to be recognized is segmented to obtain the segmentation result of the sentence to be recognized, and converted to obtain a representation vector of the segmentation result; Obtain a first word embedding vector corresponding to the word segmentation result; Inputting the representation vector into a recognition model to obtain a recognition result output by the recognition model; According to the identification result, determining whether the request message has a structured query language injection attack; Wherein, the recognition model is constructed by adopting the method described in any one of claims 1 to 6, and the fully connected layer in the recognition model superimposes the first word embedding vector with the abstract matrix output by the embedding layer.
8. A device for constructing an attack identification model, characterized in that: include: A first acquisition module is used to acquire a training sample set of structured query language injection attack; A word segmentation module is used to perform word segmentation processing on each sample in the training sample set according to the vocabulary of the structured query language, obtain a word segmentation sample of each sample, and convert it to obtain a representation vector of each word segmentation sample; A second acquisition module is used to obtain the first word embedding vector corresponding to each of the segmented samples; A third acquisition module is used to obtain a second word embedding vector corresponding to each word in the vocabulary; A fourth acquisition module, configured to train a preset neural network model based on the representation vector and the first word embedding vector of each sample, and the second word embedding vector of each word in the vocabulary, to obtain a recognition model for the structured query language injection attack; The neural network model includes an input layer, an embedding layer, a fully connected layer and an output layer connected in series in sequence, the weights of the neurons used in the embedding layer are a matrix composed of the second word embedding vectors corresponding to each term, and the parameters of the neurons used in the embedding layer are fixed; based on the representation vector and the first word embedding vector of each sample, and the second word embedding vector of each term in the vocabulary, the preset neural network model is trained to obtain the recognition model of the structured query language injection attack, including: a training process includes: inputting the representation vector of each sample into the neurons of the embedding layer through the input layer, and superimposing the matrix composed of the second word embedding vector of each term in the vocabulary on the representation vector through the neurons of the embedding layer, so as to obtain the sample semantics corresponding to each sample. abstract matrix; through the neurons in the fully connected layer, the first word embedding vector of each sample is superimposed on the corresponding abstract matrix to obtain the superimposed abstract matrix corresponding to each sample, and the superimposed abstract matrix is predicted by the activation function to obtain a one-dimensional matrix; the one-dimensional matrix is output through the output layer, and the elements in the one-dimensional matrix are used to indicate whether the prediction result of the sample is a structured query language injection attack; according to the prediction result of each sample and whether each sample is the actual result of the structured query language injection attack, the prediction error is calculated; whether the prediction error is greater than the preset error value; if so, the prediction error is back-propagated to the fully connected layer, and after adjusting the parameters of the fully connected layer according to the prediction error, it returns to execute the next training process; otherwise, the neural network model is determined as the recognition model; Wherein, the first word embedding vector includes a frequency-based word embedding vector; the frequency-based word embedding vector includes at least one of a count vector, a frequency vector based on a single word segmentation, and a frequency vector based on n-gram grammar statistics; The step of obtaining the second word embedding vector corresponding to each word in the vocabulary includes: performing the following processing on each word in the vocabulary: inputting the word and the segmented samples of each word into a Word2vec model, and obtaining the second word embedding vector of the word predicted by the Word2vec model based on the context information of the word contained in the segmented samples; According to the vocabulary of the structured query language, each sample in the training sample set is segmented to obtain a segmented sample of each sample, and then converted to obtain a representation vector of each segmented sample. The process includes: performing the following processing on each sample: according to the vocabulary of the structured query language, the sample is segmented to obtain each segmented word contained in the sample; an index value corresponding to each segmented word is obtained from the vocabulary; the index value corresponding to each segmented word is sorted according to the order in which each segmented word appears in the sample; and the index value sequence obtained after sorting is used as the representation vector corresponding to the sample.
9. An attack identification device, characterized in that: include: A first acquisition module is used to acquire a structured query statement carried in the request message as a statement to be identified; A word segmentation module, used for performing word segmentation processing on the sentence to be recognized according to the vocabulary of the structured query language, obtaining the word segmentation result of the sentence to be recognized, and converting to obtain a representation vector of the word segmentation result; A second acquisition module is used to obtain a first word embedding vector corresponding to the word segmentation result; A third acquisition module, used for inputting the representation vector into a recognition model to obtain a recognition result output by the recognition model; A judgment module, used for judging whether the request message has a structured query language injection attack according to the identification result; Wherein, the recognition model is constructed by adopting the method described in any one of claims 1 to 6, and the fully connected layer in the recognition model superimposes the first word embedding vector with the abstract matrix output by the embedding layer.
10. An electronic device, characterized in that: include: A processor, a memory and a communication bus, wherein the processor and the memory communicate with each other via the communication bus; The memory is used to store computer programs; The processor is used to execute the program stored in the memory to implement the method for constructing the recognition model described in any one of claims 1 to 6, or to implement the attack recognition method described in claim 7.
11. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, it implements the method for constructing an identification model as described in any one of claims 1 to 6, or implements the attack identification method as described in claim 7.
