Confusion coding SQL and command injection attack detection method based on deep learning

Through the codeBERT-GRU/MCSPP model, context representation is generated and dual-stream feature extraction and fusion is performed, which solves the problem of difficult to identify obfuscation encoding and cross-attack type detection in the prior art, and achieves efficient and accurate injection attack detection.

CN120474803APending Publication Date: 2025-08-12XIAN UNIV OF POSTS & TELECOMM
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202510742060.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-05
Publication Date
2025-08-12

AI Technical Summary

Technical Problem

The prior art is difficult to effectively identify malicious payloads that have been transformed through multiple encodings, and it is difficult to realize joint detection of SQL injection and command injection, and the real-time detection efficiency is low.

Method used

The codeBERT-GRU/MCSPP model is used to generate context representations through CodeBERT, and the dual-stream feature extraction is combined with GRU and MCSPP modules, and the gated feature fusion mechanism is used to fuse the features and finally input the classifier for detection.

Benefits of technology

Improve the detection accuracy and robustness of obfuscated SQL and command injection attacks, and realize efficient cross-attack type detection, meeting the millisecond response requirements of web applications.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120474803A_ABST
    Figure CN120474803A_ABST
Patent Text Reader

Abstract

A confusion coding SQL and command injection attack detection method based on deep learning comprises the following steps: step 1, preprocessing data to obtain a preprocessed data set; step 2, inputting the data set into a pre-training model CodeBERT, and generating a context representation containing context information and semantic information; 3, double-flow features are extracted, context representation is input into a GRU module and an MCSPP module in a double-flow mode, and output of the same dimension is generated by two paths by extracting GRU hidden layer features and connecting feature vectors extracted by MCSPP for feature fusion; 4, the feature vectors output by the GRU module and the MCSPP module form a tuple, the tuple is input to a gating unit, and fused features are obtained; step 5, identification and classification: inputting the fused features into a feature classifier for identification and classification, outputting three results corresponding to three categories of Bengn, CMDi and SQLi, obtaining probabilities of the samples on the three categories, and obtaining a final detection result; the method has the characteristic of improving the detection accuracy and robustness.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of network security technology, and specifically relates to a method for detecting obfuscated coded SQL and command injection attacks based on deep learning. Background Art

[0002] With the rapid development of information technology and the accelerated advancement of digitalization, various network applications have become deeply integrated into all areas of social production and life. In this context, web application systems, as important carriers of network services, carry massive amounts of user data and critical business logic. However, these systems often expose service interfaces, making them high-value targets for cyberattacks. According to statistics, data breaches caused by cyberattacks worldwide are increasing by more than 25% annually, with injection attacks accounting for as much as 34% of the economic losses (Verizon's "2023 Data Breach Investigations Report").

[0003] (1) Technical characteristics and hazards of injection attacks

[0004] According to the "Top 10 Web Application Security Risks in 2022" (OWASP Top10) released by the OWASP Foundation, injection attacks have ranked among the top three for twelve consecutive years. The main forms of attack include: 1) SQL injection (SQLi): Illegally accessing or tampering with database content by constructing malicious SQL query statements. Typical attack modes include union queries (UNION-based), Boolean blind injections (Boolean-based Blind) and time blind injections (Time-based Blind). 2) Command injection (OS Command Injection): Injecting illegal commands into the system shell to achieve unauthorized system operations. The Cloudflare security report shows that the number of command injection attack attempts monitored in 2023 increased by 68% year-on-year.

[0005] The core hazards of this type of attack are manifested in three aspects: (1) destroying data confidentiality (such as stealing user privacy data); (2) destroying data integrity (such as tampering with transaction records); and (3) destroying service availability (such as clearing critical data through the "DROP TABLE" statement).

[0006] (2) Existing defense technologies and their limitations

[0007] The current mainstream injection attack defense system mainly adopts the following technical routes:

[0008] 1) Static detection based on rule matching

[0009] Typical implementation: Web application firewall (WAF) performs request filtering through a regular expression rule library

[0010] Technical defects:

[0011] oRule hysteresis: can only defend against known attack patterns (such as detecting fixed syntax such as "SELECT * FROM users")

[0012] o Obfuscation bypass risk: Unable to effectively identify attack payloads that have undergone URL encoding (such as %27 replacing single quotes), Unicode encoding (such as \u0027), or case variation (such as SeLeCt)

[0013] o High false positive rate: Normal business requests may be mistakenly intercepted because they contain similar SQL keywords (such as the word "union" in the product description)

[0014] 2) Representative studies of traditional machine learning methods include:

[0015] Feature engineering + classifier (such as SVM, decision tree) solution:

[0016] o 21-dimensional hand-crafted features constructed by Phan et al. (2021) (including SQL keyword density, special character frequency, etc.)

[0017] N-gram+TF-IDF feature representation adopted by Uwagbole et al. (2020)

[0018] Main limitations:

[0019] o Weak feature generalization ability: Difficult to adapt to evolving obfuscation techniques (such as multi-layer nested encoding)

[0020] oLack of semantic understanding: Unable to interpret the context difference between "1'OR'1'='1" and normal query parameters

[0021] o Difficulty detecting across attack types: Dedicated SQL injection detection models cannot identify command injection attacks

[0022] (3) Application status of deep learning technology

[0023] Technological advancements in recent years have shown that deep neural networks offer unique advantages in attack detection:

[0024] 1) Single model solution

[0025] Text CNN (Kim et al., 2022): Capturing local encoding patterns through character-level convolutions

[0026] Bi-LSTM (Jaydeep et al., 2023): Modeling temporal dependencies of request parameters

[0027] BERT variants (Dongzhe et al., 2023): Leveraging pre-trained language models to understand semantic context

[0028] 2) Existing technical bottlenecks

[0029] Insufficient multi-scale feature fusion: Existing models either focus on character-level encoding features (such as CNN) or semantic understanding (such as BERT), making it difficult to simultaneously capture:

[0030] o Micro-level encoding obfuscation features (such as Base64 segmentation)

[0031] o Malicious semantic features at the macro level (such as system command execution intent)

[0032] Low real-time detection efficiency: The computational complexity of Transformer-type models restricts their application in high-speed network environments.

[0033] Weak generalization across attack types: Dedicated detection models require separate training for SQL injection and command injection.

[0034] 4. Technical issues to be resolved

[0035] Based on the above analysis, the current injection attack detection field urgently needs to break through the following technical bottlenecks:

[0036] 1) Obfuscated encoding parsing challenges: How to effectively identify malicious payloads that have undergone multiple encoding conversions;

[0037] 2) Multimodal feature fusion: how to collaboratively utilize character-level encoding features and high-level semantic features;

[0038] 3) Cross-attack type detection: How to build a unified model to achieve joint detection of SQL injection and command injection;

[0039] 4) Real-time guarantee: Meet the millisecond-level response requirements of Web applications while maintaining high accuracy. Summary of the Invention

[0040] To overcome the deficiencies of the above-mentioned prior art, the purpose of the present invention is to provide a deep learning-based obfuscated SQL and command injection attack detection method to improve the detection capability of SQL injection and command injection attacks, especially the recognition rate of attack payloads that have undergone advanced coding obfuscation. This method integrates the advantages of deep learning models to more efficiently and comprehensively capture attack behavior patterns, providing a more reliable solution for network security protection.

[0041] To achieve the above objectives, the technical solution adopted by the present invention is: a deep learning-based obfuscated coded SQL and command injection attack detection method, also known as codeBERT-GRU / MCSPP, which includes the following steps:

[0042] Step 1: data preprocessing to obtain the preprocessed data set;

[0043] The pre-trained model CodeBERT is used to encode the payload part of the URL request. The obtained word sequence, mask sequence, and label sequence together constitute the preprocessed dataset;

[0044] Step 2: Generate context representation

[0045] Input the dataset obtained in step 1 into the pre-trained model CodeBERT to generate a contextual representation containing contextual information and semantic information;

[0046] Step 3: Extract dual-stream features

[0047] The context representation obtained in step 2 is input into the GRU module and MCSPP module in a dual-stream form. By extracting the GRU hidden layer features and concatenating the feature vectors extracted by MCSPP, the GRU module and MCSPP module both produce outputs of the same dimension for feature fusion in step 4.

[0048] Step 4: Gated feature fusion

[0049] Using the gated weighted feature fusion mechanism, the feature vectors of size (batch, 128) output by the GRU module and the MCSPP module in step 3 are combined into a tuple and input into the gate unit. The gate unit calculates the fusion coefficient gate in the range of (0, 1) through the trainable weight matrix W and the sigmoid activation function, as shown in formula (1):

[0050] gate=σ(W·[F gru ||F mcspp ]) (1)

[0051] In formula (1), || represents the concatenation of features. The weight matrix W is a trainable parameter that can dynamically adjust the size of the fusion coefficient according to the coding features and temporal features of the sequence. Specifically, when the coding content in the sequence is richer, the weight of the features extracted by the MCSPP module will increase. When the temporal features of the sequence are more significant, the weight of the features extracted by the GRU module will increase. Formula (2) is used for feature fusion:

[0052] F fused =gate·F gru +(1-gate)·F mcspp (2)

[0053] In formula (2), gate is the fusion coefficient calculated in step 4, F gru and F mcsppThey are the features extracted by the GRU module and the features extracted by the MCSPP module, F fused It is the feature after fusion;

[0054] Step 5: Identify categories

[0055] The fused features obtained in step 4 are input into the feature classifier for identification and classification, and three results are output, corresponding to the three categories of Benign, CMDi, and SQLi. The probability of the sample in these three categories is obtained through Softmax activation to obtain the final detection result.

[0056] L2 regularization is introduced in the parameter optimization process of codeBERT-GRU / MCSPP, and L2 regularization is applied to all trainable parameters in codeBERT-GRU / MCSPP. L2 regularization can effectively suppress model complexity, prevent overfitting and improve generalization ability by penalizing excessive weight values in codeBERT-GRU / MCSPP. Its update method is shown in formula (3):

[0057]

[0058] In formula (3), w represents the weight parameter of the model, η is the learning rate, and λ is the regularization coefficient, which is used to control the regularization strength.

[0059] The specific steps of step 1 are as follows:

[0060] In step 1-1, the URL payload is segmented using the RoBERTa tokenizer. This tokenizer uses bytes as its basic unit and can more flexibly handle various input texts. It can segment the URL payload, which alternates between words and encoded characters, into more fine-grained subword units.

[0061] Step 1-2: Add [CLS] and [SEP] before and after the segmented subword units to mark the beginning and end of the sentence, and obtain the segmented and encoded word sequence;

[0062] Step 1-3: Map all subword units in the word segmentation sequence obtained in step 1-2 to corresponding IDs according to the vocabulary;

[0063] Steps 1-4: Set the maximum length of the word segmentation sequence to 64, pad the sequence that is less than 64, and generate a mask sequence of the same length to identify whether each unit is padded;

[0064] In steps 1-5, one-hot encode the labels corresponding to the payload to obtain a label sequence of length 3, which is used in the codeBERT-GRU / MCSPP training and evaluation process.

[0065] Steps 1-7, the word segmentation sequence obtained in step 1-2, the mask sequence obtained in step 1-4, and the label sequence obtained in step 1-5 together constitute the preprocessed data set.

[0066] The step 2, the context representation, is specifically performed as follows:

[0067] Step 2-1, constructing a data set for detecting injection attacks, using the payload part in the uniform resource locator URL as the original data constituting the data set;

[0068] Input the segmented and encoded word sequence and mask sequence into the embedding layer of the pre-trained model CodeBERT to generate word embedding vectors and position embedding vectors;

[0069] Step 2-2: Use the first four Transformer layers in the pre-trained model CodeBERT as encoders.

[0070] In step 2-3, the output of the encoder in step 2-2 is reduced from 728 dimensions to 128 dimensions to obtain the context representation.

[0071] In step 3, the GRU module is responsible for extracting the temporal information of the word segmentation sequence, and the MCSPP module extracts character encoding and semantic information through multi-scale convolution and pyramid pooling technology.

[0072] The GRU module is specifically implemented as follows:

[0073] The GRU module is used to further extract the sequence timing information from the context representation, capture the calling order of the eval and base64_decode functions, identify the position of key characters in the text and their influence on subsequent characters, and capture the timing dependency by controlling the update gate and reset gate. The specific process is shown in formula (4):

[0074]

[0075] In formula (4), Z t Is the output of the update gate, used to control the hidden state h of the previous moment t-1 The degree of retention, r t Is the output of the reset gate, which is used to determine the previous hidden state to the current candidate hidden state The degree of influence, where σ represents the Sigmoid activation function, W z 、W r , W are the weight matrices of update gate, reset gate and candidate hidden state respectively, h t Represents the hidden state at the current moment, controlled by the update gate h t-1 and The weighted summation is obtained. In addition, x t represents the input vector at the current moment, and are the bias terms of the update gate and reset gate respectively, b z 、b r Together with the weight matrix, it acts on the input vector and the hidden state of the previous moment to generate the output of the update gate and the reset gate. ⊙ represents the element-level multiplication used to calculate r t For h t-1 The impact of t For h t-1 and The weighted value is obtained by using only one layer of GRU in codeBERT-GRU / MCSPP, so the hidden state h of the last time step is extracted. t As features extracted by the GRU module.

[0076] Step 3-1, adjust the dimension order of the context representation to meet the requirements of the convolution function, and obtain the data after the dimension order is adjusted;

[0077] In step 3-2, the data after adjusting the dimensional order in step 3-1 is input into three convolutional neural networks of different scales. Among them, the networks with convolution kernels of 2 and 3 can extract the encoding information of %, 28 and %, 3, B as well as fine-grained local features; the network with a larger convolution kernel of 5 can recognize base64 encoded characters with a length that is a multiple of 4 and common Unicode encoded characters; the network with a convolution kernel of 5 can also recognize coarse-grained injected character combinations;

[0078] In step 3-3, the convolution result is introduced into nonlinearity through the ReLu activation function to enhance the expression and generalization ability of the network; three different convolutional layers obtain outputs of three different dimensions. In order to make the data dimension input to the fully connected layer consistent and enhance the robustness of the model, a pyramid pooling SPP structure is connected to each convolution layer. The pyramid pooling SPP structure consists of three different maximum pooling layers. The three different maximum pooling layers divide the data into 1, 2, and 4 pooling areas respectively, and select the maximum value from each pooling area. The maximum pooling layer automatically adjusts the pooling window, step size, and padding size according to the size of the input data. For a one-dimensional sequence, its size is set to (b, c, l), where b, c, and l represent the batch size, number of channels, and sequence length, respectively. The number of pooling areas is set to n, and the parameters of the maximum pooling layer are calculated according to formula (5). In the formula, k, s, and p represent the pooling window size, step size, and padding size.

[0079]

[0080] Step 3-4: concatenate the outputs of all the maximum pooling layers to obtain a feature vector with the same dimension;

[0081] For the SPP structure with the default number of pooling regions of 1, 2, and 4, the dimension of the feature vector obtained by the final concatenation is shown in formula (6):

[0082]

[0083] In formula (6), level, n i , noc represent the number of pooling layers, the number of pooling regions of the corresponding layers, and the number of convolutional layers, respectively.

[0084] The feature classifier is composed of two fully connected layers and ReLu and Dropout in between; ReLu is used to introduce nonlinearity to enhance the model's ability to learn complex features, and Dropout prevents overfitting by randomly discarding parameters.

[0085] The beneficial effects of the present invention are:

[0086] Since the present invention uses the first four Transformer layers in CodeBERT as encoders, CodeBERT is more suitable for processing short URL payloads and significantly reduces computational overhead.

[0087] Since the present invention adopts the payload part in the URL as the original data constituting the data set, it has the advantage of more efficiently constructing the data set for detecting injection attacks.

[0088] The detection method of the present invention is based on CodeBert, gated recurrent unit (GRU) and multi-scale convolutional pooling pyramid (MCSPP). By combining advanced natural language processing technology and deep learning architecture, it can more effectively handle obfuscated coded attack payloads and improve detection accuracy and robustness.

[0089] The present invention adopts a gated weighted feature fusion mechanism, which has the advantage of avoiding information redundancy caused by simple splicing of multi-module features.

[0090] The present invention introduces L2 regularization during the parameter optimization process of codeBERT-GRU / MCSPP and applies it to all trainable parameters in codeBERT-GRU / MCSPP. L2 regularization can effectively suppress model complexity, prevent overfitting, and improve generalization ability by penalizing excessively large weight values in codeBERT-GRU / MCSPP.

[0091] In response to the problems existing in injection attack detection, the present invention proposes a method for detecting obfuscated coded SQL and command injection attacks based on deep learning. This method generates context representations through CodeBERT, combines GRU and MCSPP modules for dual-stream feature extraction, and fuses the features through a gated feature fusion mechanism, and finally inputs the features into a classifier for detection. By leveraging BERT's powerful contextual semantic understanding capabilities, the payload in the URL request is encoded into a context representation rich in semantic information, and a dual-stream structure is used to give full play to the advantages of GRU in extracting temporal features and MCSPP in extracting character encoding and semantic information. Experimental results show that this method achieves an accuracy rate and F1 score of over 99%, and outperforms the current most advanced detection methods on HTTPParamsDataset. Therefore, the method proposed in the present invention provides a brand-new solution for injection attack detection. BRIEF DESCRIPTION OF THE DRAWINGS

[0092] Figure 1 Data preprocessing flow chart of the present invention.

[0093] Figure 2 This is the overall structure diagram of the pre-training model CodeBERT of the present invention.

[0094] Figure 3 Schematic diagram of the structure of the MCSPP module of the present invention.

[0095] Figure 4 This is a schematic diagram of the proportion of data set categories divided according to an embodiment of the present invention.

[0096] FIG5( a ) shows the accuracy trend of the training set and the validation set according to an embodiment of the present invention.

[0097] FIG5( b ) shows the loss value trend of the training set and the validation set according to an embodiment of the present invention.

[0098] Figure 6 These are trend charts of four indicators evaluated on the validation set in Example 2 of the present invention.

[0099] Figure 7 The figure is a bar graph showing comparative experimental results of the present invention.

[0100] Figure 8 This is the confusion matrix diagram of the ablation experiment of the present invention.

[0101] Figure 9 Flow chart of the method of the present invention DETAILED DESCRIPTION

[0102] The present invention will be further described in detail below with reference to the accompanying drawings and embodiments.

[0103] See also Figure 9The deep learning-based obfuscated SQL and command injection attack detection method, called codeBERT-GRU / MCSPP, includes the following steps:

[0104] Step 1: data preprocessing to obtain the preprocessed data set;

[0105] By encoding the payload part of the URL request, the obtained word sequence, mask sequence, and label sequence together constitute the preprocessed data set;

[0106] The pre-trained model CodeBERT is composed of word embedding vectors, segment embedding vectors and position embedding vectors. Among them, the word embedding vector is generated by a sequence that has been segmented and encoded, the segment embedding vector is generated by a sequence that distinguishes paragraphs, and the position embedding vector is generated by a fixed position encoding inside the model. In addition, the mask sequence is used to mark the filling position to avoid the pre-trained model CodeBERT from calculating the filling part. For the URL attack payload, since it is regarded as an independent sentence as a whole and does not distinguish paragraphs, only the sequence that has been segmented and encoded and the mask sequence are used as the input of the pre-trained model CodeBERT to reduce computational redundancy. In order to meet the input requirements of the pre-trained model CodeBERT and the model evaluation requirements, this embodiment adopts Figure 1 The pre-processing process shown;

[0107] The process of the pre-training model CodeBERT proposed in this paper mainly includes generating context representation, dual-stream feature extraction, gated feature fusion and recognition classification. The overall structure is shown in Figure 2 As shown;

[0108] Step 2: Generate context representation

[0109] The dataset obtained in step 1 is input into the pre-trained model CodeBERT to generate a contextual representation containing contextual information and semantic information. The pre-trained model CodeBERT has stronger code processing capabilities by being trained on a bimodal dataset of natural language and programming language. Therefore, when processing SQL / command injection payloads containing code statements, CodeBERT has a significant advantage over other encoder models.

[0110] Taking eval%28%22php%20r%20%22eval%28base64_decode%28%27c3lzdGVtKCJscyAtbGEiKTs=%27%29%29%3B%22%20" as an example, CodeBERT can identify the semantic associations between the keywords eval, php, and base64_decode, and understand their dangers when executed.

[0111] Step 3: Extract dual-stream features

[0112] The context representation obtained in step 2 is input into the GRU module and MCSPP module in a dual-stream form. By extracting the GRU hidden layer features and concatenating the feature vectors extracted by MCSPP, the GRU module and MCSPP module both produce outputs of the same dimension for feature fusion in step 4.

[0113] Step 4: Gated feature fusion

[0114] Using the gated weighted feature fusion mechanism, the feature vectors of size (batch, 128) output by the GRU module and the MCSPP module in step 3 are combined into a tuple and input into the gate unit. The gate unit calculates the fusion coefficient gate in the range of (0, 1) through a trainable weight matrix W and a sigmoid activation function, as shown in formula (1):

[0115] gate=σ(W·[F gru ||F mcspp ]) (1)

[0116] In formula (1), || represents the concatenation of features. The weight matrix W is a trainable parameter that can dynamically adjust the size of the fusion coefficient according to the coding features and temporal features of the sequence. Specifically, when the coding content in the sequence is richer, the weight of the features extracted by the MCSPP module will increase. When the temporal features of the sequence are more significant, the weight of the features extracted by the GRU module will increase. Formula (2) is used for feature fusion.

[0117] F fused =gate·F gru +(1-gate)·F mcspp (2)

[0118] In formula (2), gate is the fusion coefficient calculated in step 4, F gru and F mcspp They are the features extracted by the GRU module and the features extracted by the MCSPP module, F fused It is the feature after fusion;

[0119] Step 5: Identify categories

[0120] The fused features obtained in step 4 are input into the feature classifier for identification and classification, and three results are output, corresponding to the three categories of Benign, CMDi, and SQLi. The probability of the sample in these three categories is obtained through Softmax activation to obtain the final detection result.

[0121] L2 regularization is introduced in the parameter optimization process of codeBERT-GRU / MCSPP, and L2 regularization is applied to all trainable parameters in codeBERT-GRU / MCSPP. L2 regularization can effectively suppress model complexity, prevent overfitting and improve generalization ability by penalizing excessive weight values in codeBERT-GRU / MCSPP. Its update method is shown in formula (3):

[0122]

[0123] In formula (3), w represents the weight parameter of the model, η is the learning rate, and λ is the regularization coefficient, which is used to control the regularization strength.

[0124] The specific steps of step 1 are as follows:

[0125] In step 1-1, the URL payload is segmented using the RoBERTa tokenizer. This tokenizer uses bytes as its basic unit and can more flexibly handle various input texts. It can segment the URL payload, which alternates between words and encoded characters, into more fine-grained subword units.

[0126] Step 1-2: Add [CLS] and [SEP] before and after the segmented subword units to mark the beginning and end of the sentence, and obtain the segmented and encoded word sequence;

[0127] Step 1-3: Map all subword units in the word segmentation sequence obtained in step 1-2 to corresponding IDs according to the vocabulary;

[0128] In steps 1-4, given that the URL payload is shorter than natural language or code snippets, the maximum length of the word segmentation sequence is set to 64. Sequences shorter than 64 are padded, and a mask sequence of the same length is generated to identify whether each unit is padded.

[0129] In steps 1-5, one-hot encode the labels corresponding to the payload to obtain a label sequence of length 3, which is used in the codeBERT-GRU / MCSPP training and evaluation process.

[0130] Steps 1-7, the word segmentation sequence obtained in step 1-2, the mask sequence obtained in step 1-4, and the label sequence obtained in step 1-5 together constitute the preprocessed data set.

[0131] The step 2, the context representation, is specifically performed as follows:

[0132] Step 2-1, constructing a data set for detecting injection attacks, using the payload part in the uniform resource locator URL as the original data constituting the data set;

[0133] Input the segmented and encoded word sequence and mask sequence into the embedding layer of the pre-trained model CodeBERT to generate word embedding vectors and position embedding vectors;

[0134] Step 2-2: Use the first four Transformer layers in the pre-trained model CodeBERT as encoders.

[0135] In step 2-3, the output of the encoder in step 2-2 is reduced from 728 dimensions to 128 dimensions to obtain the context representation.

[0136] In step 3, the GRU module is responsible for extracting the temporal information of the word segmentation sequence, and the MCSPP module extracts character encoding and semantic information through multi-scale convolution and pyramid pooling technology.

[0137] The GRU module is specifically implemented as follows:

[0138] The GRU module is used to further extract the sequence timing information from the context representation, capture the calling order of the eval and base64_decode functions, identify the position of key characters in the text and their influence on subsequent characters, and capture the timing dependency by controlling the update gate and reset gate. The specific process is shown in formula (4):

[0139]

[0140] In formula (4), Z t Is the output of the update gate, used to control the hidden state h of the previous moment t-1 The degree of retention, r t Is the output of the reset gate, which is used to determine the previous hidden state to the current candidate hidden state The degree of influence, where σ represents the Sigmoid activation function, W z 、W r , W are the weight matrices of update gate, reset gate and candidate hidden state respectively, h t Represents the hidden state at the current moment, controlled by the update gate h t-1 and The weighted summation is obtained. In addition, x t represents the input vector at the current moment, and are the bias terms of the update gate and reset gate respectively, b z 、b r Together with the weight matrix, it acts on the input vector and the hidden state of the previous moment to generate the output of the update gate and the reset gate. ⊙ represents the element-level multiplication used to calculate r t For h t-1 The impact of t For h t-1and Since only one layer of GRU is used in codeBERT-GRU / MCSPP, the hidden state h of the last time step is extracted t As features extracted by the GRU module.

[0141] The MCSPP module (see Figure 3 ) The specific steps are:

[0142] Step 3-1, adjust the dimension order of the context representation to meet the requirements of the convolution function, and obtain the data after the dimension order is adjusted;

[0143] In step 3-2, the data after adjusting the dimensional order in step 3-1 is input into three convolutional neural networks of different scales. Among them, the networks with convolution kernels of 2 and 3 can extract the encoding information of %, 28 and %, 3, B as well as fine-grained local features; the network with a larger convolution kernel of 5 can recognize base64 encoded characters with a length multiple of 4 and common Unicode encoded characters, such as the Unicode encoding of a after word segmentation is "&", "#", "97", and ";"; the network with a convolution kernel of 5 can also recognize coarse-grained injected character combinations, such as "or 1=1--";

[0144] In step 3-3, the convolution result is introduced into nonlinearity through the ReLu activation function to enhance the expression and generalization ability of the network; three different convolutional layers will obtain outputs of three different dimensions. In order to make the data dimension input to the fully connected layer consistent and enhance the robustness of the model, a pyramid pooling SPP structure is connected to each convolution layer. The pyramid pooling SPP structure consists of three different maximum pooling layers. The three different maximum pooling layers divide the data into 1, 2, and 4 pooling areas respectively, and select the maximum value from each pooling area. The maximum pooling layer automatically adjusts the pooling window, step size, and padding size according to the size of the input data. For a one-dimensional sequence, its size is set to (b, c, l), where b, c, and l represent the batch size, number of channels, and sequence length, respectively. The number of pooling areas is set to n, and the parameters of the maximum pooling layer are calculated according to formula (5). In the formula, k, s, and p represent the pooling window size, step size, and padding size.

[0145]

[0146] Step 3-4: concatenate the outputs of all the maximum pooling layers to obtain a feature vector with the same dimension;

[0147] For the SPP structure with the default number of pooling regions of 1, 2, and 4, the dimension of the feature vector obtained by the final concatenation is shown in formula (6):

[0148]

[0149] In formula (6), level, n i , noc represent the number of pooling layers, the number of pooling regions of the corresponding layers, and the number of convolutional layers, respectively.

[0150] The feature classifier is composed of two fully connected layers and ReLu and Dropout in between; ReLu is used to introduce nonlinearity to enhance the model's ability to learn complex features, and Dropout prevents overfitting by randomly discarding parameters.

[0151] Example 2 (Verification Example)

[0152] 1. Dataset

[0153] Most existing injection attack payload datasets suffer from a small number of samples, class imbalance, and a limited number of obfuscated encoding categories, making them inadequate for training the task of detecting obfuscated injection attacks. Therefore, we collected several existing public datasets from GitHub and integrated and cleaned them. Ultimately, we constructed a dataset containing 128,205 samples, with 69,860 samples in the Benign, 35,000 in CMDi, and 23,345 in SQLi categories, respectively. This dataset contains a rich collection of samples containing encoding fields. The dataset covers a variety of encoding formats, including URL encoding, base64 encoding, base32 encoding, and unicode encoding, with many samples containing multiple encoding formats simultaneously. The specific number of encoding samples is shown in Table 1.

[0154] Table 1

[0155]

[0156] The data set is divided into training set, validation set and test set in a ratio of 8:1:1. The category ratio of the divided data set is shown in Figure 4 As shown in the figure, the training set is used specifically for model training, the validation set is used to evaluate the model during training and automatically adjust the learning rate accordingly, and the test set is used to evaluate the model's final performance. Of the three datasets, only the training set is used to update the model's parameters. When evaluating the validation and test sets, the model's parameters are frozen, ensuring that the data in both the validation and test sets are new data that the model has never seen, thus ensuring the objectivity and reliability of the evaluation results.

[0157] 2. Training Process

[0158] 1. Experimental Setup

[0159] Experimental Environment: The software environment used in the experiments in this example is the Windows 11 operating system, the PyTorch 2.5 deep learning framework, and Python 3.9. The hardware environment is a 13th Gen Intel(R) Core(TM) i7-13650HX CPU, 16GB RAM, and an NVIDIA RTX 4070 GPU with 8GB VRAM.

[0160] Parameter setting: The epoch number of the training process is set to 4, the hidden layer dimension of codeBERT-GRU / MCSPP is set to 128, and the Adam codeBERT-GRU / MCSPP parameter optimization process is used to update the parameters. The learning rate is automatically adjusted according to the evaluation results of the validation set. The batch size used in both training and testing phases is 32.

[0161] 2. Evaluation Method

[0162] The model is evaluated using four metrics: accuracy, precision, recall, and F1 score. These metrics are calculated based on the model's prediction results for the sample, as shown in Table 2, and are divided into TP, FP, TN, and FN.

[0163] Table 2

[0164]

[0165] The accuracy rate indicates the ratio of the number of samples correctly predicted by the model to the total number of samples. It represents the accuracy of the model's prediction of the overall data. The calculation method is shown in formula (7):

[0166]

[0167] In formula (7), Accuracy represents the accuracy of model prediction, TP represents the number of true positive examples, that is, the number of samples correctly predicted as positive by the model; TN represents the number of true negative examples, that is, the number of samples correctly predicted as negative by the model; FP represents the number of false positive examples, that is, the number of samples incorrectly predicted as positive by the model; FN represents the number of false negative examples, that is, the number of samples incorrectly predicted as positive by the model;

[0168] Precision indicates the accuracy of the model's prediction of the positive class. Its calculation method is shown in formula (8):

[0169]

[0170] In formula (8), Precision represents the accuracy of model prediction;

[0171] The recall rate indicates the proportion of samples that are actually positive that are predicted to be positive. Its calculation method is shown in formula (9):

[0172]

[0173] In formula (9), Recall represents the recall rate of model prediction;

[0174] The F1 score takes into account both precision and recall. It is the weighted average of precision and recall and can measure the overall performance of the model. The larger the F1 score, the better the model performance. Its calculation method is shown in formula (10):

[0175]

[0176] In formula (10), F1Score represents the F1 score of the model;

[0177] 3. Results Analysis

[0178] According to the above experimental settings and evaluation methods, the optimal model was obtained after 4 training sessions. Finally, the accuracy, precision, recall rate, and F1 score of the model evaluated on the test set reached 99.66%, 99.73%, 99.44%, and 99.58%, respectively. Thanks to the high-quality context representation generated by BERT and the effective coordination of various parts of the model, the model can quickly learn the complex features in the injected attack payload. During the training process, the changing trends of the model's accuracy and loss value on the training set and the validation set are shown in Figure 5(a) and Figure 5(b), respectively. During the training process, the accuracy of the model on the training set is always higher than that on the validation set, and both show an upward trend. The loss value of the model on the training set is smaller than that on the validation set, and both show a downward trend. The changing trends of the model's accuracy, precision, recall rate, and F1 score on the validation set are shown in Figure 5(a). Figure 6 As shown in the figure, the accuracy, precision, recall and F1 score of the model on the validation set all show an upward trend.

[0179] 4. Comparative experiment

[0180] This comparative experiment uses the widely used public dataset HTTPParamsDataset. This dataset contains 19,304 normal samples and 11,763 malicious samples. Among the malicious samples, 10,941 samples using SQLi and CMDi attack methods were selected as the malicious samples for testing.

[0181] We selected five recent studies on attack payload detection as comparison benchmark models and divided these five detection methods into two categories: deep learning methods and machine learning methods. For specific indicator comparisons, see Figure 7 shown.

[0182] Mohamed.2023: They proposed using deep learning for intrusion detection and used Bi-LSTM to achieve high-precision attack detection on HTTPParamsDataset, with an F1 score of 99.75%.

[0183] FusionNN.2024: This is a semantic feature fusion model for web anomaly detection, which includes CharCNN and WordCNN models. The FusionNN model ultimately achieved an accuracy of 99.16%.

[0184] CCBA.2024: This is a convolutional channel bidirectional LSTM attention model proposed by Wang et al., who used HTTPParamsDataset in a cross-domain experiment and achieved an accuracy of 99.51%.

[0185] Shaheed.2022: They used four machine learning models and feature engineering to detect network attacks, among which the Naive Bayes algorithm performed best on HTTPParamsDataset, achieving an accuracy of 97.91%.

[0186] Gupta.2024: This study used the XG Boost machine learning model for anomaly detection. They also evaluated the model on the HTTPParamsDataset and achieved an accuracy of 94.2%.

[0187] Deep learning methods significantly outperform machine learning methods when detecting malicious attacks with multiple attack methods. Traditional machine learning methods rely heavily on feature engineering designed by human experts, but the features of attack payloads are often complex and varied, making it difficult for manual selection to cover them comprehensively. In contrast, deep learning methods can automatically learn key feature representations from raw data, thereby demonstrating greater adaptability and accuracy. In addition, the accuracy of the model of the present invention reached 99.84% on the HTTPParamsDataset, which shows that the model of the present invention has excellent performance when processing both obfuscated encoding and plaintext attack payloads.

[0188] 5. Ablation Experiment

[0189] To verify the effectiveness of the GRU and MCSPP modules in the model of this invention, we conducted an ablation experiment. We retrained the BERT-MCSPP, BERT-GRU, and BERT models and finally evaluated them using the test set. The evaluation results and the number of parameters are shown in Table 3. The confusion matrix of the model's prediction results on the test set is shown in Figure 8 shown.

[0190] Table 3

[0191]

[0192] In Table 3, the full model's accuracy, precision, recall, and F1 score are all higher than those of the other cropped models, followed by the BERT-MCSPP model, and the BERT model has the lowest. The full model has the largest number of trainable parameters, while the BERT model has the smallest number of trainable parameters.

[0193] Combining the confusion matrix and the average length of each category in the test set shown in Table 4, we conclude that the BERT-GRU model is sensitive to sequence length, prone to misclassifying some relatively long examples in the generally short Benign as belonging to other categories. SQLi, on the other hand, is closer to the average length of the entire dataset than CMDi, and therefore misclassifies most of the longer Benign examples as SQLi. BERT-MCSPP is better at extracting local features and has a stronger understanding of semantics, resulting in better overall performance than BERT-GRU, but it still struggles with long sequence recognition. Our proposed method effectively combines the advantages of both approaches, achieving optimal recognition results for all three categories.

[0194] Table 4

[0195] category Benign CMDi SQLi Total Average character length 44.62 98.32 88.69 67.31

[0196] In Table 4, the average character lengths for the Benign, CMDi, and SQLi categories are 44.62, 98.32, and 88.69, respectively. The average character length for the entire test dataset is 67.31.

Claims

1. A deep learning-based obfuscated SQL and command injection attack detection method, also known as codeBERT-GRU / MCSPP, is characterized by: The following steps are involved: Step 1: data preprocessing to obtain the preprocessed data set; The pre-trained model CodeBERT is used to encode the payload part of the URL request. The obtained word sequence, mask sequence, and label sequence together constitute the preprocessed dataset; Step 2: Generate context representation Input the dataset obtained in step 1 into the pre-trained model CodeBERT to generate a contextual representation containing contextual information and semantic information; Step 3: Extract dual-stream features The context representation obtained in step 2 is input into the GRU module and MCSPP module in a dual-stream form. By extracting the GRU hidden layer features and concatenating the feature vectors extracted by MCSPP, the GRU module and MCSPP module both produce outputs of the same dimension for feature fusion in step 4. Step 4: Gated feature fusion Using the gated weighted feature fusion mechanism, the feature vectors of size (batch, 128) output by the GRU module and the MCSPP module in step 3 are combined into a tuple and input into the gate unit. The gate unit calculates the fusion coefficient gate in the range of (0, 1) through the trainable weight matrix W and the sigmoid activation function, as shown in formula (1): gate=σ(W·[F gru ||F mcspp ]) (1) In formula (1), || represents the concatenation of features. The weight matrix W is a trainable parameter that can dynamically adjust the size of the fusion coefficient according to the coding features and temporal features of the sequence. Specifically, when the coding content in the sequence is richer, the weight of the features extracted by the MCSPP module will increase. When the temporal features of the sequence are more significant, the weight of the features extracted by the GRU module will increase. Formula (2) is used for feature fusion: F fused =gate·F gru +(1-gate)·F mcspp (2) In formula (2), gate is the fusion coefficient calculated in step 4, F gru and F mcspp They are the features extracted by the GRU module and the features extracted by the MCSPP module, F fused It is the feature after fusion; Step 5: Identify categories The fused features obtained in step 4 are input into the feature classifier for identification and classification, and three results are output, corresponding to the three categories of Benign, CMDi, and SQLi. The probability of the sample in these three categories is obtained through Softmax activation to obtain the final detection result. L2 regularization is introduced in the parameter optimization process of codeBERT-GRU / MCSPP, and L2 regularization is applied to all trainable parameters in codeBERT-GRU / MCSPP. L2 regularization can effectively suppress model complexity, prevent overfitting and improve generalization ability by penalizing excessive weight values in codeBERT-GRU / MCSPP. Its update method is shown in formula (3): In formula (3), w represents the weight parameter of the model, η is the learning rate, and λ is the regularization coefficient, which is used to control the regularization strength.

2. The method for detecting obfuscated SQL and command injection attacks based on deep learning according to claim 1 is characterized in that: The specific steps of step 1 are as follows: In step 1-1, the URL payload is segmented using the RoBERTa tokenizer. This tokenizer uses bytes as its basic unit and can more flexibly handle various input texts. It can segment the URL payload, which alternates between words and encoded characters, into more fine-grained subword units. Step 1-2: Add [CLS] and [SEP] before and after the segmented subword units to mark the beginning and end of the sentence, and obtain the segmented and encoded word sequence; Step 1-3: Map all subword units in the sequence obtained in step 1-2 to corresponding IDs according to the vocabulary; Steps 1-4: Set the maximum length of the word segmentation sequence to 64, pad the sequence that is less than 64, and generate a mask sequence of the same length to identify whether each unit is padded; In steps 1-5, one-hot encode the labels corresponding to the payload to obtain a label sequence of length 3, which is used in the codeBERT-GRU / MCSPP training and evaluation process. Steps 1-7, the word segmentation sequence obtained in step 1-2, the mask sequence obtained in step 1-4, and the label sequence obtained in step 1-5 together constitute the preprocessed data set.

3. The method for detecting obfuscated SQL and command injection attacks based on deep learning according to claim 1 is characterized in that: The step 2, the context representation, is specifically performed as follows: Step 2-1, constructing a data set for detecting injection attacks, using the payload part in the uniform resource locator URL as the original data constituting the data set; Input the segmented and encoded word sequence and mask sequence into the embedding layer of the pre-trained model CodeBERT to generate word embedding vectors and position embedding vectors; Step 2-2: Use the first four Transformer layers in the pre-trained model CodeBERT as encoders. In step 2-3, the output of the encoder in step 2-2 is reduced from 728 dimensions to 128 dimensions to obtain the context representation.

4. The method for detecting obfuscated SQL and command injection attacks based on deep learning according to claim 1 is characterized in that: In step 3, the GRU module is responsible for extracting the temporal information of the word segmentation sequence, and the MCSPP module extracts character encoding and semantic information through multi-scale convolution and pyramid pooling technology.

5. The method for detecting obfuscated SQL and command injection attacks based on deep learning according to claim 4 is characterized in that: The GRU module is specifically implemented as follows: The GRU module is used to further extract the sequence timing information from the context representation, capture the calling order of the eval and base64_decode functions, identify the position of key characters in the text and their influence on subsequent characters, and capture the timing dependency by controlling the update gate and reset gate. The specific process is shown in formula (4): In formula (4), Z t Is the output of the update gate, used to control the hidden state h of the previous moment t-1 The degree of retention, r t Is the output of the reset gate, which is used to determine the previous hidden state to the current candidate hidden state The degree of influence, where σ represents the Sigmoid activation function, W z 、W r , W are the weight matrices of update gate, reset gate and candidate hidden state respectively, h t Represents the hidden state at the current moment, controlled by the update gate h t-1 and The weighted summation is obtained. In addition, x t represents the input vector at the current moment, and are the bias terms of the update gate and reset gate respectively, b z 、b r Together with the weight matrix, it acts on the input vector and the hidden state of the previous moment to generate the output of the update gate and the reset gate. ⊙ represents the element-level multiplication used to calculate r t For h t-1 The impact of t For h t-1 and Since only one layer of GRU is used in codeBERT-GRU / MCSPP, the hidden state h of the last time step is extracted t As features extracted by the GRU module.

6. The method for detecting obfuscated SQL and command injection attacks based on deep learning according to claim 1 is characterized in that: The MCSPP module is specifically implemented as follows: Step 3-1, adjust the dimension order of the context representation to meet the requirements of the convolution function, and obtain the data after the dimension order is adjusted; In step 3-2, the data after adjusting the dimensional order in step 3-1 is input into three convolutional neural networks of different scales. Among them, the networks with convolution kernels of 2 and 3 can extract the encoding information of %, 28 and %, 3, B as well as fine-grained local features; the network with a larger convolution kernel of 5 can recognize base64 encoded characters with a length that is a multiple of 4 and common Unicode encoded characters; the network with a convolution kernel of 5 can also recognize coarse-grained injected character combinations; In step 3-3, the convolution result is introduced into nonlinearity through the ReLu activation function to enhance the expression and generalization ability of the network; three different convolutional layers obtain outputs of three different dimensions. In order to make the data dimension input to the fully connected layer consistent and enhance the robustness of the model, a pyramid pooling SPP structure is connected to each convolution layer. The pyramid pooling SPP structure consists of three different maximum pooling layers. The three different maximum pooling layers divide the data into 1, 2, and 4 pooling areas respectively, and select the maximum value from each pooling area. The maximum pooling layer automatically adjusts the pooling window, step size, and padding size according to the size of the input data. For a one-dimensional sequence, its size is set to (b, c, l), where b, c, and l represent the batch size, number of channels, and sequence length, respectively. The number of pooling areas is set to n, and the parameters of the maximum pooling layer are calculated according to formula (5). In the formula, k, s, and p represent the pooling window size, step size, and padding size. Step 3-4: concatenate the outputs of all the maximum pooling layers to obtain a feature vector with the same dimension; For the SPP structure with the default number of pooling regions of 1, 2, and 4, the dimension of the feature vector obtained by the final concatenation is shown in formula (6): In formula (6), level, n i , noc represent the number of pooling layers, the number of pooling regions of the corresponding layers, and the number of convolutional layers, respectively.

7. The method for detecting obfuscated SQL and command injection attacks based on deep learning according to claim 1 is characterized in that: The feature classifier is composed of two fully connected layers and ReLu and Dropout in between; ReLu is used to introduce nonlinearity to enhance the model's ability to learn complex features, and Dropout prevents overfitting by randomly discarding parameters.

Citation Information

Cited By

  • Dual-channel Web attack detection method based on BERT pre-training model

    CN121567477A