SQL (Structured Query Language) injection attack detection method and equipment and computer program product
By building an integrated SQL injection attack model and a large language model, and combining feature vectors and prediction probabilities, the problem of insufficient semantic understanding in SQL injection attack detection is solved, and more efficient SQL injection attack identification is achieved.
Patent Information
- Application Number
- CN202511247813.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-03
- Publication Date
- 2025-10-03
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Existing SQL injection attack detection methods have insufficient understanding of the semantics of SQL statements, resulting in poor detection results.
By constructing a SQL injection attack integrated model and a SQL injection attack large language model, combining feature vectors and prediction probability results, the SQL injection attack integrated model is used for preliminary detection. When the confidence score is not high, the prediction result is determined jointly with the SQL injection attack large language model through a weighted voting mechanism.
It improves the semantic understanding of SQL statements, enhances the ability to identify SQL injection attacks, improves detection results and reduces the consumption of computing resources.
Smart Images

Figure CN120750665A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of artificial intelligence technology, and in particular to a SQL injection attack detection method, device, and computer program product. Background Art
[0002] SQL injection attacks are a widespread network security threat. Currently, the main methods for detecting SQL injection attacks can be divided into two categories: rule-based detection methods and traditional machine learning detection methods. However, both detection methods suffer from insufficient understanding of the semantics of SQL statements, resulting in poor detection results. Summary of the Invention
[0003] The present disclosure provides a SQL injection attack detection method, device, and computer program product. The method determines a first prediction probability result for a query SQL statement using an SQL injection attack integrated model. Furthermore, if the first prediction probability result meets a first preset condition, the method determines whether the query SQL statement is a SQL injection attack statement based on the SQL injection attack integrated model and a large SQL injection attack language model. This method addresses the problem of insufficient semantic understanding of SQL statements.
[0004] In one aspect, the present embodiment provides a SQL injection attack detection method, the method comprising: determining a first prediction probability result of a SQL injection attack integrated model for a SQL statement to be queried, the SQL injection attack integrated model being at least used to detect whether the SQL statement to be queried is a SQL injection attack statement; and in response to the first prediction probability result meeting a first preset condition, determining whether the SQL statement to be queried is a SQL injection attack statement based on the SQL injection attack integrated model and the SQL injection attack large language model.
[0005] In an embodiment of the present disclosure, it also includes: determining an SQL statement data set based on normal SQL query statements and SQL injection attack statements, the SQL statement data set including an SQL statement training set and an SQL statement test set, and the SQL statement data set including at least multiple SQL statement samples; determining feature vectors of the multiple SQL statement samples, the feature vectors being used at least for training and / or testing an SQL injection attack integrated model; and generating an SQL injection attack integrated model based on the feature vectors of the multiple SQL statement samples.
[0006] In an embodiment of the present disclosure, determining feature vectors of multiple SQL statement samples includes: determining lexical units of the SQL statement samples, each SQL statement sample includes multiple lexical units; determining a word vector for each lexical unit; and determining context-related features of the SQL statement samples based on the multiple word vectors and a first weight of each word vector, the context-related features being used at least to determine the feature vector.
[0007] In an embodiment of the present disclosure, determining the feature vectors of multiple SQL statement samples also includes: determining a word frequency weight score for each lexical unit, where the word frequency weight score is determined by at least the frequency of the lexical unit and the inverse document frequency; determining the continuous word frequency of the SQL statement sample; and determining the feature vector of the SQL statement sample based on the context-related features, word frequency weight score, and continuous word frequency of the SQL statement sample.
[0008] In an embodiment of the present disclosure, generating an SQL injection attack integrated model includes: training a first learning model based on a feature vector of a SQL statement training set, the first learning model including at least one or more of a random forest model, a support vector machine model, and a long short-term memory model; and constructing an SQL injection attack integrated model based on first output information of the first learning model and a second learning model, the first output information being input information of the second learning model, the second learning model including at least one or more of a logistic regression model and a gradient boosting model.
[0009] In an embodiment of the present disclosure, the method further includes: matching prompt word templates for SQL statement samples based on attribute information of the SQL statement samples; and fine-tuning the large language model based on the SQL statement samples included in the SQL statement training set and the prompt word templates corresponding to the SQL statement samples included in the SQL statement training set to generate a large language model for SQL injection attacks.
[0010] In an embodiment of the present disclosure, determining whether a SQL statement to be queried is a SQL injection attack statement based on a SQL injection attack integrated model and a SQL injection attack large language model includes: determining a confidence score of the SQL injection attack integrated model based on a first prediction probability result; and in response to the confidence score being less than a preset value, determining whether the SQL statement to be queried is a SQL injection attack statement based on a second weight, a third weight, the first prediction probability result, and the SQL injection attack large language model.
[0011] In an embodiment of the present disclosure, determining whether the SQL statement to be queried is a SQL injection attack statement based on the second weight, the third weight, the first predicted probability result, and the SQL injection attack large language model includes: inputting the SQL statement to be queried into the SQL injection attack large language model to generate a second predicted probability result; and determining whether the SQL statement to be queried is a SQL injection attack statement based on the second weight and the first predicted probability result, and the third weight and the second predicted probability result.
[0012] On the other hand, an embodiment of the present disclosure provides a network device, including: a memory for storing computer-readable instructions; and a processor for running the computer-readable instructions, so that the network device executes the SQL injection attack detection method.
[0013] On the other hand, an embodiment of the present disclosure provides a computer program product, including a computer program, which implements the above-mentioned SQL injection attack detection method when executed by a processor. BRIEF DESCRIPTION OF THE DRAWINGS
[0014] The above and other purposes, features, and advantages of the present disclosure will become more apparent through a more detailed description of the embodiments of the present disclosure in conjunction with the accompanying drawings. The accompanying drawings are intended to provide a further understanding of the embodiments of the present disclosure and constitute a part of the specification. Together with the embodiments of the present disclosure, they are used to explain the present disclosure and are not intended to limit the present disclosure. In the drawings, the same reference numerals generally represent the same components or steps.
[0015] Figure 1 The following schematically illustrates an environmental application diagram according to an embodiment of the present disclosure.
[0016] Figure 2 A flowchart of a method for detecting SQL injection attacks according to an embodiment of the present disclosure is schematically illustrated.
[0017] Figure 3 A flowchart of building an integrated SQL injection attack model according to an embodiment of the present disclosure is schematically illustrated.
[0018] Figure 4 The flowchart of determining feature vectors of multiple SQL statement samples according to an embodiment of the present disclosure is schematically illustrated.
[0019] Figure 5 A flowchart for generating an SQL injection attack integrated model according to an embodiment of the present disclosure is schematically illustrated.
[0020] Figure 6 The flowchart of generating a large language model of SQL injection attacks according to an embodiment of the present disclosure is schematically illustrated.
[0021] Figure 7 A flowchart for determining whether a SQL statement to be queried is a SQL injection attack statement based on an SQL injection attack integrated model and a SQL injection attack large language model according to an embodiment of the present disclosure is schematically illustrated.
[0022] Figure 8 The flowchart of determining whether a SQL statement to be queried is a SQL injection attack statement based on the second weight, the third weight, the first prediction probability result, and the SQL injection attack large language model according to an embodiment of the present disclosure is schematically illustrated.
[0023] Figure 9 A schematic diagram of a SQL injection attack detection method according to an embodiment of the present disclosure is schematically illustrated.
[0024] Figure 10 The block diagram of a network device according to an embodiment of the present disclosure is schematically illustrated.
[0025] Figure 11 The block diagram of a computer program product according to an embodiment of the present disclosure is schematically illustrated. DETAILED DESCRIPTION
[0026] In order to make the purpose, technical solutions and advantages of the present disclosure more apparent, the following will describe in detail exemplary embodiments of the present disclosure with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of the present disclosure, rather than all the embodiments of the present disclosure, and it should be understood that the present disclosure is not limited to the exemplary embodiments described herein.
[0027] Figure 1 The following schematically illustrates an environmental application diagram according to an embodiment of the present disclosure.
[0028] like Figure 1 As shown, it includes a terminal device 101, a first network device 102, and a second network device 103. The terminal device 101 and the first network device 102 can perform real-time data transmission, the terminal device 101 and the second network device 103 can perform real-time data transmission, and the first network device 102 and the second network device 103 can perform real-time data transmission.
[0029] A user's terminal device 101 can access a webpage / application stored on and provided by second network device 103. For example, an attacker could exploit a vulnerability in a web application's input field through terminal device 101 and inject malicious SQL code, attempting to gain illegal permissions or destroy data by manipulating the database (deployed on second network device 103). Terminal device 101 can be a smartphone, tablet, laptop, or other device. Second network device 103 can be a server or other network device with computing capabilities.
[0030] Furthermore, first network device 102 can detect the SQL statement entered by the user to determine whether it is a SQL injection attack statement. First network device 102 can be a network device with computing capabilities, such as a server. In some embodiments, first network device 102 can detect the SQL statement based on an integrated SQL injection attack model or a large SQL injection attack language model to determine whether it is a SQL injection attack statement.
[0031] SQL injection attacks are a widespread network security threat. Currently, both rule-based and traditional machine learning-based detection methods lack semantic understanding of SQL statements, resulting in poor detection results.
[0032] For example, suppose a rule-based system is configured to detect the string "OR 1=1" because it is a common SQL injection pattern. An attacker could simply modify this pattern to use "OR '1'='1" or add extra whitespace and comments to bypass the rule. Similarly, if a traditional machine learning-based system does not have sufficient semantic understanding to learn the semantic structure of SQL statements, it will not be able to correctly distinguish between intentionally constructed malicious queries and actual valid database queries. For example, a machine learning model might be trained to identify this type of SQL injection attack: SELECT FROM users WHERE id = 1 UNION SELECT FROM secrets; However, if the attacker makes some changes to the attack statement, uses different keywords or adds some irrelevant text, making the query look more complex, it may be difficult to identify based on traditional machine learning models alone. For example: SELECT FROM users WHERE id = 1 OR '1'='1' / Injection Attacks / UNION SELECTload_file(' / etc / passwd') FROM secrets; Based on this, the disclosed embodiments provide a SQL injection attack detection method. This method determines a first prediction probability result based on an integrated SQL injection attack model. If the first prediction probability result meets preset conditions, the method then jointly determines a prediction result for the SQL statement to be queried based on the integrated SQL injection attack model and a large SQL injection attack language model. This method utilizes the large SQL injection attack language model to deeply interpret the true intent of the SQL statement to be queried, improving the ability to understand the semantics of the SQL statement to be queried. This effectively addresses the issues of semantic ambiguity and weak ability to identify deformation attacks, further improving detection effectiveness.
[0033] Next, this article will combine Figure 2-Figure 9 A method for detecting SQL injection attacks according to an embodiment of the present disclosure is introduced in detail.
[0034] Figure 2 A flowchart of a method for detecting SQL injection attacks according to an embodiment of the present disclosure is schematically illustrated.
[0035] like Figure 2 As shown, a SQL injection attack detection method according to an embodiment of the present disclosure includes S201 and S202: S201. Determine a first prediction probability result of the SQL injection attack integrated model for the SQL statement to be queried. The SQL injection attack integrated model is at least used to detect whether the SQL statement to be queried is a SQL injection attack statement.
[0036] In an embodiment of the present disclosure, when determining whether a query SQL statement is a SQL injection attack statement, the SQL injection attack integrated model can be used to output a first prediction probability result of whether the query SQL statement is a SQL injection attack statement. The first prediction probability result can be expressed as:
[0037] in, f d It can be a feature vector of the SQL statement to be queried.
[0038] In embodiments of the present disclosure, the first predicted probability result may include multiple predicted probabilities. For example, the first predicted probability result for the SQL statement to be queried may be: a probability of 0.85 for belonging to the "attack class" and a probability of 0.15 for belonging to the "non-attack class." Alternatively, the first predicted probability result for the SQL statement to be queried may be: a probability of 0.45 for belonging to the "attack class" and a probability of 0.55 for belonging to the "non-attack class." The probability of 0.45 for belonging to the "attack class" may indicate that the SQL injection attack integrated model determines that the SQL statement to be queried has a probability of 0.45 for belonging to the "attack class."
[0039] like Figure 3 As shown, an embodiment of the present disclosure provides a method for constructing an SQL injection attack integrated model. The method for constructing an SQL injection attack integrated model may include S301, S302 and S303.
[0040] Figure 3 A flowchart of building an integrated SQL injection attack model according to an embodiment of the present disclosure is schematically illustrated.
[0041] S301. Determine an SQL statement data set based on normal SQL query statements and SQL injection attack statements. The SQL statement data set includes an SQL statement training set and an SQL statement test set. The SQL statement data set includes at least a plurality of SQL statement samples.
[0042] In embodiments of the present disclosure, SQL query statements from various sources, such as open source datasets, samples collected by scanning tools, and internally accumulated samples, can be collected and integrated. A model can be trained using historical SQL query statements to generate an integrated SQL injection attack model. The integrated SQL injection attack model can use the extracted features to learn the correlation between these features and "target labels" (e.g., whether the SQL statement is an injection attack), thereby determining whether the SQL statement constitutes an SQL injection attack.
[0043] In an embodiment of the present disclosure, multiple normal SQL query statements and multiple SQL injection attack statements can be obtained, and a SQL statement dataset can be formed by the multiple normal SQL query statements and the multiple SQL injection attack statements. For example, a Kaggle dataset including multiple normal SQL query statements and multiple SQL injection attack statements can be obtained.
[0044] In an embodiment of the present disclosure, the SQL statement dataset is explicitly divided into a SQL statement training set and a SQL statement test set, where the total number of samples in the SQL statement dataset is N. The SQL statement training set can at least be used to train the SQL injection attack integrated model, and the SQL statement test set can at least be used to test the SQL injection attack integrated model.
[0045] In some embodiments, the multiple SQL statement samples in the acquired SQL statement dataset can also be preprocessed. For example, the SQL statement samples can be cleaned, capitalized, comment-removed, noise removed, missing values processed, encoding converted, and duplicate removed. Preprocessing the SQL statement samples can remove redundant noise, unify data formats, and extract key semantic information, paving the way for subsequent feature vector extraction and SQL injection attack integrated model training. In some embodiments, if the multiple SQL statement sample data used is processed open source data, data cleaning is not required.
[0046] S302: Determine feature vectors of multiple SQL statement samples, where the feature vectors are at least used to train and / or test an integrated SQL injection attack model.
[0047] In embodiments of the present disclosure, feature vectors can be extracted from multiple SQL statement samples in an SQL statement dataset through feature engineering. By extracting feature vectors from the SQL statement samples, the SQL injection attack integrated model can be controlled to better predict areas of concern. Feature vectors extracted from multiple SQL statement samples in a SQL statement training set can be used to train the SQL injection attack integrated model. Feature vectors extracted from multiple SQL statement samples in a SQL statement test set can be used to test the SQL injection attack integrated model.
[0048] like Figure 4 As shown, the above S302 includes S401, S402, S403, S404, S405 and S406. Figure 4 The flowchart of determining feature vectors of multiple SQL statement samples according to an embodiment of the present disclosure is schematically illustrated.
[0049] S401: Determine lexical units of an SQL statement sample, where each SQL statement sample includes multiple lexical units.
[0050] In the embodiments of the present disclosure, a lexical unit can be a minimum set of semantic units obtained after tokenization of a SQL statement sample, and each lexical unit represents a basic component of the SQL statement sample. By tokenizing multiple SQL statement samples, multiple lexical units can be obtained, and each SQL statement sample includes multiple lexical units. In some embodiments, a lexical analyzer can be used to parse multiple SQL statement samples in an SQL statement data set to generate a lexical unit sequence (d) = {t1, t2, ... t M}, where t is a lexical unit and M is the number of lexical units.
[0051] S402: Determine the word vector of each lexical unit.
[0052] In an embodiment of the present disclosure, each lexical unit can be converted into a word vector, which can be directly processed by the SQL injection attack integrated model, such as calculating the similarity between two lexical units through vector distance, thereby determining the degree of association between the two lexical units. By converting lexical units into word vectors, the model can better understand the relationship between multiple lexical units, so that the SQL statement sample can be understood through the "digital association" of word vectors. In some embodiments, each lexical unit can be converted into a word vector V using the pre-trained word vector model Word2Vec. t ∈R d , where d is the dimension of the word vector.
[0053] S403: Determine a context-related feature of the SQL statement sample based on the multiple word vectors and the first weight of each word vector. The context-related feature is at least used to determine a feature vector.
[0054] In an embodiment of the present disclosure, a corresponding first weight can be set for each word vector. The size of the first weight can be used to represent the importance of the word vector in the SQL statement sample. For example, in injection detection, the first weight of words such as OR and UNION will be increased, and the first weight of common keywords such as SELECT and FROM will be decreased.
[0055] In the embodiments of the present disclosure, by multiplying each word vector by its corresponding first weight, the importance of different word vectors can be distinguished, so that word vectors that are more critical to the current task can have a "greater impact" and less important word vectors can have a "smaller impact."
[0056] Furthermore, the product of multiple word vectors and the corresponding first weight can be fused to determine the context-related features of the SQL statement sample. For example, multiple products can be fused by summing them. A single word vector can only reflect local information. By fusion (average or weighted summation), multiple word vectors can be integrated into a context-related feature, so that the SQL injection attack integration model understands the connection between word vectors and word vectors, thereby accurately grasping the true meaning and logic of the entire statement, rather than viewing each word vector in isolation. In some embodiments, the context-related features of a SQL statement sample can be implemented by the following formula:
[0057] in, v t is the word vector included in the SQL statement sample, α j is the first weight, M The number of word vectors included in the SQL statement sample.
[0058] According to embodiments of the present disclosure, in scenarios such as SQL injection detection, the relationship between lexical units is often the key to determining whether a statement is malicious. Many malicious features of SQL injection attacks are not individual lexical units, but rather the order in which specific words are combined. By determining the contextual association features of SQL statement samples, the association between lexical units can be accurately captured, helping the model distinguish between "normal" and "malicious" combinations.
[0059] S404: Determine a word frequency weight score for each lexical unit, where the word frequency weight score is determined by at least the frequency and inverse document frequency of the lexical unit.
[0060] In an embodiment of the present disclosure, in the SQL statement sample, the frequency of occurrence of each lexical unit is different. In some cases, lexical units that appear frequently are helpful in determining the type of SQL statement sample, but similarly, lexical units that appear frequently can also cause certain obstacles to determining the type of SQL statement sample. For example, in the SQL statement sample, basic keywords such as "SELECT" and "FROM" appear frequently in almost all statements, and they are not very helpful in distinguishing normal SQL statements from SQL injection attack statements. Therefore, the weight of such words can be reduced by the inverse document frequency of the lexical unit, while the weight of words that only appear in specific types of text can be increased. For example, "DROP" rarely appears in normal SQL statements. If "DROP" appears twice in a certain SQL statement sample, its inverse document frequency will be relatively high, becoming a key feature for distinguishing attacks.
[0061] Therefore, in the embodiment of the present disclosure, the word frequency weight score of each lexical unit can be determined, and the word frequency weight score can be used to indicate the degree of contribution of the lexical unit to the current SQL statement sample. TF-IDF It can be calculated by the following formula: TF-IDF(t,d)=TF(t,d)×IDF(t) in, TF(t,d) is a lexical unit Frequency in SQL statement samples, IDF(t) is a lexical unit The inverse document frequency of TF-IDF(t,d) is the word frequency weight score of each lexical unit.
[0062] S405: Determine the frequency of consecutive words in the SQL statement sample.
[0063] In an embodiment of the present disclosure, the continuous word frequency of a SQL statement sample can be determined by an N-gram model. The continuous word frequency can be extracted by a sliding window and can be implemented by the following formula:
[0064] Where Z is the normalization factor.
[0065] S406 : Determine a feature vector of the SQL statement sample based on the contextual features, word frequency weight score, and continuous word frequency of the SQL statement sample.
[0066] In an embodiment of the present disclosure, the feature vector of an SQL statement sample can be determined by the context-related features of the SQL statement sample, the word frequency weight score of the SQL statement sample, and the continuous word frequency of the SQL statement sample. The word frequency weight score of the SQL statement sample can be jointly determined by the word frequency weight scores of multiple lexical units. In some embodiments, the feature vector of the SQL statement sample can be implemented by the following formula: f d = [ TF-IDF(d),N-gram(d),c d ] return Figure 3 ,S303, based on the feature vectors of multiple SQL statement samples, generate an SQL injection attack integration model.
[0067] In an embodiment of the present disclosure, when feature vectors of multiple SQL statement samples are determined, a model can be trained using the multiple feature vectors to generate an integrated SQL injection attack model.
[0068] like Figure 5 As shown, the above S303 may include S501 and S502. Figure 5 A flowchart for generating an SQL injection attack integrated model according to an embodiment of the present disclosure is schematically illustrated.
[0069] S501. Based on the feature vectors of the SQL statement training set, train a first learning model, where the first learning model includes at least one or more of a random forest model, a support vector machine model, and a long short-term memory model.
[0070] In an embodiment of the present disclosure, random forest (RF), support vector machine (SVM) and long short-term memory network (LSTM) can be selected as the first learning model, and the first learning model can be trained using feature vectors corresponding to multiple SQL statement samples in the SQL statement training set.
[0071] In some embodiments, the training process is formulated as an optimization problem:
[0072] in, is sample d i The eigenvector of is the loss function, y i is sample d i The true label.
[0073] S502. Based on the first output information of the first learning model and the second learning model, construct an SQL injection attack integrated model, where the first output information is the input information of the second learning model, and the second learning model includes at least one or more of a logistic regression model and a gradient boosting model.
[0074] In an embodiment of the present disclosure, the first output information of all first learning models is spliced into new input information, and the second learning model is trained using the new input information to generate an SQL injection attack integrated model.
[0075] In an embodiment of the present disclosure, the second learning model may be a logistic regression model (LR) or a gradient boosted tree model (GBDT). Further, the SQL injection attack integrated model may be implemented by the following formula: Ensemble(f d )=LR / GBDT(RF(f d ),SVM(f d ),LSTM(f d )) According to the embodiments of the present disclosure, a SQL injection attack integrated model is generated by training a first learning model and using the first output of the first learning model as input to a second learning model. This allows different first learning models to provide diverse local judgments, while the second learning model performs global optimization and integration. This allows the advantages of different learning models to be combined to achieve higher prediction accuracy in complex tasks.
[0076] return Figure 2 S202: In response to the first prediction probability result meeting the first preset condition, determine whether the SQL statement to be queried is a SQL injection attack statement based on the SQL injection attack integrated model and the SQL injection attack large language model.
[0077] In an embodiment of the present disclosure, the SQL injection attack integrated model may use a first predicted probability result for a query SQL statement to include the probability of whether the query SQL statement is a SQL injection attack statement. For example, the first predicted probability result for the query SQL statement is 0.4 for the attack class and 0.6 for the non-attack class. In this case, the first predicted probability result can be used to determine whether further identification of the query SQL statement is required based on the SQL injection attack large language model.
[0078] In the embodiments of the present disclosure, the SQL injection attack large language model can be used to accurately identify the semantics of the SQL statement to be queried. Combining the SQL injection attack integrated model and the SQL injection attack large language model can significantly improve the model's ability to understand the semantics of the SQL statement to be queried, thereby effectively improving the detection effect of SQL injection attacks.
[0079] In an embodiment of the present disclosure, the first preset condition may be that the maximum value of the multiple predicted probabilities included in the first predicted probability result is less than a preset value. For example, the first preset condition may be that the maximum value of the multiple predicted probabilities included in the first predicted probability result is less than 0.65. In this case, if the first predicted probability result of the SQL statement to be queried is: 0.4 for the attack class and 0.6 for the non-attack class, the maximum value of the multiple predicted probabilities is 0.6, and 0.6 is less than 0.65. Therefore, it can be determined that the first predicted probability result of the SQL statement to be queried meets the first preset condition.
[0080] In the embodiments of the present disclosure, for computational efficiency reasons, using both the SQL injection attack integrated model and the SQL injection attack large language model during the reasoning process to determine whether a query SQL statement is a SQL injection attack statement will significantly reduce reasoning efficiency. Therefore, the SQL injection attack integrated model can be used to perform preliminary detection of the query SQL statement. Furthermore, based on the first predicted probability result and the first preset condition, a determination is made as to whether the SQL injection attack large language model is needed for further identification.
[0081] In the embodiments of the present disclosure, the SQL statements to be queried may be SQL statement samples included in the SQL statement test set in the aforementioned SQL statement dataset. It is understood that the SQL statement samples included in the SQL statement training set can be used to train the SQL injection attack integrated model, and the SQL statement samples included in the SQL statement test set can be used to further validate the SQL injection attack integrated model.
[0082] In the embodiment of the present disclosure, a method for generating a large language model of SQL injection attack is also proposed. Figure 6 As shown, the generation of a large language model for SQL injection attacks in an embodiment of the present disclosure includes S601 and S602.
[0083] Figure 6 The flowchart of generating a large language model of SQL injection attacks according to an embodiment of the present disclosure is schematically illustrated.
[0084] S601: Match a prompt word template for the SQL statement sample based on the attribute information of the SQL statement sample.
[0085] In the embodiments of the present disclosure, multiple adaptive prompt word templates can be designed for different SQL statement types and attack characteristics, resulting in a prompt word template set. This allows the large language model for SQL injection attacks to precisely focus on key features, improving detection or analysis effectiveness and strengthening the large model's identification of SQL attacks. For example, multiple adaptive prompt word templates can be designed based on SQL statement operations (query, insert, delete, etc.), high-frequency features (such as true conditions, comment characters, special functions, etc.), and subtle or mixed attack characteristics.
[0086] Furthermore, based on the type and attack characteristics of the SQL statement sample, the most appropriate prompt word template is selected or generated for the SQL statement sample to avoid redundancy or omission of the general prompt word template.
[0087] In the embodiments of the present disclosure, SQL statement samples can be segmented to determine attribute information for each SQL statement sample, which can include type and attack characteristics. For example, the NLTK tool can be used to convert unstructured SQL statement samples into structured lexical units, and the type and attack characteristics of the SQL statement sample can be determined based on the multiple lexical units.
[0088] In some embodiments, the type of SQL statement sample can be determined by keyword matching. For example, if the keyword SELECT is included, the SQL statement sample can be determined to be a query statement, and if the keyword DROP / DELETE is included, the SQL statement sample can be determined to be a dangerous operation statement. In some embodiments, attack signatures can be matched based on a known attack pattern library. For example, if OR 1=1 is detected, the attack signature can be identified as a constant true condition injection signature.
[0089] In some embodiments, a neural network can be trained to automatically generate appropriate prompt word templates. The neural network can select or generate the most appropriate prompt word template for a SQL statement sample. Furthermore, the prompt word template set can be dynamically adjusted based on the neural network's inference results (e.g., attack detection accuracy and false positive rate).
[0090] S602: Based on the SQL statement samples included in the SQL statement training set and the prompt word templates corresponding to the SQL statement samples included in the SQL statement training set, fine-tune the large language model to generate a SQL injection attack large language model.
[0091] In an embodiment of the present disclosure, a large language model, such as Jiutian, GPT4, Qwen, etc., can be selected, and the large language model can be fine-tuned using the SQL statement samples included in the SQL statement training set and the prompt word templates corresponding to the SQL statement samples.
[0092] In some embodiments, the fine-tuning process for a large language model is expressed as:
[0093] in, Indicates the corresponding prompt word template and SQL statement samples The true label.
[0094] In the case of generating a large language model for SQL injection attacks, such as Figure 7 As shown, the above S202 includes S701 and S702.
[0095] Figure 7 A flowchart for determining whether a SQL statement to be queried is a SQL injection attack statement based on an SQL injection attack integrated model and a SQL injection attack large language model according to an embodiment of the present disclosure is schematically illustrated.
[0096] S701. Determine a confidence score of the SQL injection attack integrated model based on the first prediction probability result.
[0097] In embodiments of the present disclosure, the confidence score can be used to reflect the degree of trust the SQL injection attack integrated model has in the first predicted probability result. For example, a higher confidence score based on the first predicted probability result indicates that the SQL injection attack integrated model is more certain that the first predicted probability result is correct. For example, when the SQL injection attack integrated model determines that a certain SQL statement or SQL statement sample to be queried is a SQL injection attack statement, a confidence score of 0.9 is more reliable than a confidence score of 0.6.
[0098] In the embodiments of the present disclosure, even if different SQL statements / SQL statement samples to be queried have the same predicted category (all predicted as attack), the maximum values of the multiple predicted probabilities included in the first predicted probability result may differ. This difference can indicate the accuracy of the SQL injection attack integrated model in determining whether the SQL statement to be queried is a SQL injection attack statement. Therefore, the first predicted probability result can be used to determine the confidence score of the SQL injection attack integrated model, allowing for a more detailed assessment of the query SQL statement.
[0099] In embodiments of the present disclosure, the confidence score of the SQL injection attack integrated model can be expressed by calculating the maximum value of the predicted probabilities. For example, if the first predicted probability result for the SQL statement to be queried is 0.4 for the attack class and 0.6 for the non-attack class, the confidence score can be the maximum value of the predicted probabilities in the first predicted probability result. In this case, the confidence score of the SQL statement to be queried is 0.6.
[0100] S702: In response to the confidence score being less than a preset value, determine whether the SQL statement to be queried is a SQL injection attack statement based on the second weight, the third weight, the first prediction probability result, and the SQL injection attack large language model.
[0101] In embodiments of the present disclosure, the preset value can be pre-set, for example, 0.7, 0.6, or 0.8, etc. If the confidence score is greater than the preset value, the first predicted probability result of the SQL injection attack integrated model can be directly used to determine whether the SQL statement to be queried is a SQL injection attack statement. If the confidence score is less than the preset value, different weights can be assigned based on the performance and reliability of the SQL injection attack integrated model and the SQL injection attack large language model to obtain a final SQL injection attack determination result.
[0102] According to the embodiments of the present disclosure, after preliminary detection of a target SQL statement using the SQL injection attack integrated model, a decision is made based on the confidence score and a preset value to determine whether to feed the target SQL statement into the SQL injection attack large language model, rather than directly fusing the results of the SQL injection attack integrated model and the SQL injection attack large language model. If the confidence score falls below a threshold, different weights are assigned to each model based on its performance and reliability to produce the final SQL injection attack determination result. This not only improves the accuracy of SQL injection attack identification but also minimizes the increase in computing resources.
[0103] In the embodiments of the present disclosure, Figure 8 As shown, the above S702 includes S801 and S802.
[0104] Figure 8 The flowchart of determining whether a SQL statement to be queried is a SQL injection attack statement based on the second weight, the third weight, the first prediction probability result, and the SQL injection attack large language model according to an embodiment of the present disclosure is schematically illustrated.
[0105] S801: Input the SQL statement to be queried into the SQL injection attack large language model to generate a second prediction probability result.
[0106] If the confidence score is less than a preset value, the SQL statement to be queried may be input into a large SQL injection attack language model to generate a second predicted probability result. In some cases, based on the attribute information of the SQL statement to be queried, a prompt word template is matched to the SQL statement to be queried from a set of prompt word templates. Furthermore, the prompt word template and the large SQL injection attack language model are used to determine the second predicted probability result for the SQL statement to be queried.
[0107] In some embodiments, using SQL injection to attack a large language model, generating a second prediction probability result can be achieved by the following formula:
[0108] in, is the second predicted probability result, Prediction function for large language models against SQL injection attacks.
[0109] S802: Determine whether the SQL statement to be queried is an SQL injection attack statement based on the second weight and the first prediction probability result, and the third weight and the second prediction probability result.
[0110] In the embodiments of the present disclosure, different weights can be assigned to the SQL injection attack integrated model and the SQL injection attack large language model based on information such as their performance and reliability. The prediction result for the SQL statement to be queried is determined by multiplying the SQL injection attack integrated model by the second weight and the SQL injection attack large language model by the third weight.
[0111] In some embodiments, the prediction result of the SQL statement to be queried can be implemented by the following formula:
[0112] in, is the predicted result of the SQL statement to be queried, is the second weight, is the third weight, is the first predicted probability result.
[0113] Figure 9 A schematic diagram of a SQL injection attack detection method according to an embodiment of the present disclosure is schematically illustrated.
[0114] like Figure 9 As shown, S901, determine an SQL statement data set. Based on normal SQL query statements and SQL injection attack statements, determine an SQL statement data set, where the SQL statement data set includes at least a plurality of SQL statement samples.
[0115] S902: Train an SQL injection attack integrated model. Train an SQL injection attack integrated model based on the SQL statement training set in the SQL statement dataset.
[0116] S903: Prompt word template construction. Based on the different types and attack characteristics of SQL statements, multiple adaptive prompt word templates are designed to obtain a prompt word template set. This allows the most appropriate prompt word template to be selected or generated for the SQL statement sample based on its type and attack characteristics.
[0117] S904: Fine-tune the large language model to generate a large language model for SQL injection attacks. Fine-tune the large language model based on SQL statement samples and prompt word templates.
[0118] S905. Determine a first prediction probability result based on the SQL injection attack integrated model. Use the SQL injection attack integrated model to detect test data, and the result is the first prediction probability result. The test data can be the SQL statement to be queried or a sample SQL statement in a test set of SQL statements in the SQL statement dataset.
[0119] S906: Determine whether the confidence score is less than a preset value and use the maximum value of the multiple predicted probabilities included in the first predicted probability result as the confidence score.
[0120] S907: Determine a second prediction probability result based on the SQL injection attack large language model. If the confidence score is less than a preset value, input the test data into the SQL injection attack large language model for further inspection to obtain a second prediction probability result.
[0121] S908. Output the final result. If the confidence score is greater than the preset value, the final prediction result is the first prediction probability result determined based on the SQL injection attack integrated model. If the confidence score is less than the preset value, the final prediction result is the prediction result determined based on the second weight, the first prediction probability result, the third weight, and the second prediction probability result.
[0122] Figure 10 A block diagram of a network device according to an embodiment of the present disclosure is schematically illustrated; like Figure 10 As shown, the network device 1000 according to an embodiment of the present disclosure includes a memory 1001 and a processor 1002 .
[0123] The memory 1001 is configured to store computer-readable instructions. The processor 1002 is configured to execute the computer-readable instructions to enable the network device to execute the SQL injection attack detection method.
[0124] Figure 11 Schematically illustrates a block diagram of a computer program product according to an embodiment of the present disclosure; like Figure 11As shown, a computer program product 1100 according to an embodiment of the present disclosure includes a computer program 1101. When the computer program 1101 is executed by a processor, the above-mentioned SQL injection attack detection method is implemented.
[0125] In the above, with reference to the accompanying drawings, a method, device, and computer program product for detecting SQL injection attacks according to an embodiment of the present disclosure are described. By constructing an SQL injection attack integrated model and a SQL injection attack large language model, and using the SQL injection attack integrated model to determine the first predicted probability result of the SQL statement to be queried. When the confidence score of the first predicted probability result is not high, the SQL injection attack integrated model and the SQL injection attack large language model jointly determine the prediction result through a weighted voting mechanism. This can improve the model's semantic understanding of SQL statements. And only when the confidence score is not high, the SQL statement to be queried is handed over to the SQL injection attack large language for further prediction, which can reduce the need for additional computing resources to a certain extent and improve resource utilization.
[0126] The basic principles of the present disclosure have been described above in conjunction with specific embodiments. However, it should be noted that the advantages, strengths, and effects mentioned in this disclosure are merely illustrative and not restrictive, and should not be construed as necessarily possessed by each embodiment of the present disclosure. Furthermore, the specific details disclosed above are provided for illustrative purposes and to facilitate understanding, rather than as limitations. These details do not limit the present disclosure to necessarily being implemented using these specific details.
[0127] The block diagrams of the devices, devices, equipment, and systems involved in this disclosure are merely illustrative examples and are not intended to require or imply that they must be connected, arranged, or configured in the manner shown in the block diagrams. As will be appreciated by those skilled in the art, these devices, devices, equipment, and systems can be connected, arranged, or configured in any manner. Words such as "include," "comprise," "have," and the like are open-ended words, meaning "including but not limited to," and can be used interchangeably therewith. The words "or" and "and" used herein refer to the words "and / or" and can be used interchangeably therewith, unless the context clearly indicates otherwise. The word "such as" used herein refers to the phrase "such as but not limited to," and can be used interchangeably therewith.
[0128] Additionally, as used herein, "or" used in a list of items beginning with "at least one" indicates a separate list, so that, for example, a list of "at least one of A, B, or C" means A or B or C, or AB or AC or BC, or ABC (i.e., A and B and C). Furthermore, the word "exemplary" does not mean that the example described is preferred or better than other examples.
[0129] It should also be noted that in the system and method of the present disclosure, each component or each step can be decomposed and / or recombined. Such decomposition and / or recombination should be regarded as equivalent solutions of the present disclosure.
[0130] Various changes, substitutions, and modifications may be made to the techniques described herein without departing from the teachings defined by the appended claims. Furthermore, the scope of the claims of this disclosure is not limited to the specific aspects of the processes, machines, manufactures, compositions of things, means, methods, and actions described above. Currently existing or later developed processes, machines, manufactures, compositions of things, means, methods, or actions that perform substantially the same function or achieve substantially the same results as the corresponding aspects described herein may be utilized. Accordingly, the appended claims include within their scope such processes, machines, manufactures, compositions of things, means, methods, or actions.
[0131] The above description of the disclosed aspects is provided to enable any person skilled in the art to make or use the present disclosure. Various modifications to these aspects will be readily apparent to those skilled in the art, and the general principles defined herein may be applied to other aspects without departing from the scope of the present disclosure. Therefore, the present disclosure is not intended to be limited to the aspects shown herein, but rather to be accorded the widest scope consistent with the principles and novel features disclosed herein.
[0132] The above description has been provided for the purpose of illustration and description. In addition, this description is not intended to limit the embodiments of the present disclosure to the forms disclosed herein. Although a number of example aspects and embodiments have been discussed above, those skilled in the art will recognize certain variations, modifications, alterations, additions, and sub-combinations thereof.
Claims
1. A method for detecting SQL injection attacks, characterized in that: The method comprises: Determine a first prediction probability result of the SQL injection attack integrated model for a query SQL statement, wherein the SQL injection attack integrated model is at least used to detect whether the query SQL statement is a SQL injection attack statement; and In response to the first prediction probability result meeting a first preset condition, it is determined whether the SQL statement to be queried is the SQL injection attack statement based on the SQL injection attack integrated model and the SQL injection attack large language model.
2. The SQL injection attack detection method according to claim 1, characterized in that: Also includes: Determine an SQL statement data set based on normal SQL query statements and SQL injection attack statements, wherein the SQL statement data set includes an SQL statement training set and an SQL statement test set, and the SQL statement data set includes at least a plurality of SQL statement samples; Determining feature vectors of a plurality of SQL statement samples, wherein the feature vectors are at least used for training and / or testing the SQL injection attack integrated model; and Based on the feature vectors of the plurality of SQL statement samples, the SQL injection attack integrated model is generated.
3. The SQL injection attack detection method according to claim 2, characterized in that: Determining the feature vectors of the plurality of SQL statement samples includes: Determine lexical units of the SQL statement sample, each of the SQL statement samples includes a plurality of lexical units; Determining a word vector for each of the lexical units; and Based on the multiple word vectors and the first weight of each word vector, a context-related feature of the SQL statement sample is determined, where the context-related feature is at least used to determine the feature vector.
4. The SQL injection attack detection method according to claim 3, characterized in that: The determining of the feature vectors of the plurality of SQL statement samples further includes: Determining a term frequency weight score for each of the lexical units, the term frequency weight score being determined by at least the frequency and the inverse document frequency of the lexical unit; Determining the frequency of consecutive words in the SQL statement sample; and A feature vector of the SQL statement sample is determined based on the context-related features of the SQL statement sample, the word frequency weight score, and the continuous word frequency.
5. The SQL injection attack detection method according to claim 2, wherein: Generating the SQL injection attack integrated model includes: Training a first learning model based on the feature vectors of the SQL statement training set, where the first learning model includes at least one or more of a random forest model, a support vector machine model, and a long short-term memory model; and Based on the first output information of the first learning model and the second learning model, the SQL injection attack integrated model is constructed, the first output information is the input information of the second learning model, and the second learning model includes at least one or more of a logistic regression model and a gradient boosting model.
6. The SQL injection attack detection method according to claim 2, wherein: Also includes: Matching a prompt word template for the SQL statement sample based on the attribute information of the SQL statement sample; as well as Based on the SQL statement samples included in the SQL statement training set and the prompt word templates corresponding to the SQL statement samples included in the SQL statement training set, the large language model is fine-tuned to generate the SQL injection attack large language model.
7. The SQL injection attack detection method according to claim 6, wherein: The determining whether the SQL statement to be queried is the SQL injection attack statement based on the SQL injection attack integrated model and the SQL injection attack large language model includes: Determining a confidence score of the SQL injection attack integrated model based on the first prediction probability result; and In response to the confidence score being less than a preset value, determining whether the SQL statement to be queried is the SQL injection attack statement based on the second weight, the third weight, the first prediction probability result, and the SQL injection attack large language model.
8. The SQL injection attack detection method according to claim 7, wherein: The determining whether the SQL statement to be queried is the SQL injection attack statement based on the second weight, the third weight, the first prediction probability result, and the SQL injection attack large language model includes: Inputting the SQL statement to be queried into the SQL injection attack large language model to generate a second prediction probability result; and Based on the second weight and the first prediction probability result, and the third weight and the second prediction probability result, it is determined whether the SQL statement to be queried is the SQL injection attack statement.
9. A network device, characterized in that: include: a memory for storing computer-readable instructions; as well as A processor is configured to run the computer-readable instructions so that the network device executes the SQL injection attack detection method according to any one of claims 1 to 8.
10. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the SQL injection attack detection method according to any one of claims 1 to 8 is implemented.
Citation Information
Patent Citations
Safety operation method and device based on multi-agent cooperation
CN119299241A
Abnormal data detection and classification method based on deep learning
CN119312224A
Method, model and equipment for identifying hint injection attack aiming at large language model
CN120371961A