Training and detection method of malicious URL detection classification model based on CNN+BERT
Through the malicious website detection and classification model based on CNN+BERT, combined with the feature extraction of URL and web page text, the problems of high misjudgment rate and high resource consumption in malicious website detection in the existing technology are solved, achieving high accuracy and low cost. Resource-consuming malicious website identification.
Patent Information
- Application Number
- CN202410905401.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-08
- Publication Date
- 2024-09-03
- Estimated Expiration
- 2044-07-08
AI Technical Summary
Malicious website detection in the existing technology has the defects of static detection with high misjudgment rate and dynamic detection with high resource consumption, which makes it difficult to effectively apply in large-scale web page identification.
A malicious website detection and classification model based on CNN+BERT is used to accurately identify malicious websites by extracting and encoding features of URLs and web page texts, and classifying them using a fully connected layer.
It improves the accuracy of website detection, reduces resource consumption, enhances the comprehensiveness and accuracy of feature extraction, and is suitable for large-scale web page recognition.
Smart Images

Figure CN118445802B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of Internet network security technology, and in particular to a training and detection method for a malicious website detection classification model based on CNN+BERT. Background Art
[0002] With the popularization of computers and smart phones, China's Internet has developed rapidly. When people browse different websites to get what they need, they can easily mistakenly enter malicious websites, which seriously threatens people's property safety and personal information security. Therefore, how to quickly and accurately identify and classify malicious websites has become an urgent problem to be solved in the current anti-fraud work.
[0003] In the current work of detecting malicious websites, two main methods are used: static detection and dynamic detection.
[0004] The static detection method mainly collects static information of the website, such as URL, web page text, web page source code, etc., and then classifies normal websites and malicious websites by designing a rule or extracting similar features from malicious website information. Existing static detection methods include feature code matching, heuristic rule-based detection methods, code behavior-based detection methods, etc. Static detection consumes less resources and has a fast recognition speed, but it has high requirements for rule design. When identifying deliberately disguised malicious websites, there is a greater possibility of misjudgment.
[0005] Dynamic detection usually builds a virtual machine or virtual browser environment first, dynamically loads web pages in the environment, and detects and analyzes the real-time behavior characteristics of web pages to see if they are malicious, thereby identifying malicious websites. Compared with static detection, dynamic detection has a higher accuracy rate, but at the same time, the resource consumption brought by running a virtual environment is also very huge, and the detection cycle will be longer, making it difficult to apply to large-scale web page recognition. Summary of the invention
[0006] In order to overcome the defects of the above-mentioned prior art that static detection has a high misjudgment rate for website identification and dynamic detection consumes too many resources, the present invention proposes a training and detection method for a malicious website detection classification model based on CNN+BERT.
[0007] To achieve the above object, the present invention adopts the following technical solutions, including:
[0008] The training method of the malicious URL detection classification model based on CNN+BERT includes:
[0009] S1: Collect web page data, which includes URLs and web page texts, and annotate web pages to obtain web page tags for representing classification categories; construct a data set, which includes URLs, web page texts, and corresponding web page tags; wherein URLs are web addresses;
[0010] S2: Perform word segmentation on each URL in the dataset to obtain the word units in each URL; use the word vector model to process the word units of all URLs to obtain the word vectors of each word unit, and build a character dictionary of the URL, and obtain the word index of each word unit in the character dictionary, and build an embedding matrix based on the character dictionary and the word vectors of each word unit; encode each URL according to the word index of each word unit in the character dictionary to obtain the encoding vector of each URL, that is, the sentence vector;
[0011] S3: The URL sentence vector is adaptively extracted through the CNN network to obtain the URL feature vector;
[0012] S4: Encode the webpage text in the dataset using the encoder of the text preprocessing model to obtain the text vector, and then use the text vector through the BERT model to obtain the webpage text feature vector;
[0013] S5: Concatenate the URL feature vector and the web page text feature vector, pass through the fully connected layer, and classify to obtain the predicted output.
[0014] Preferably, in step S2, during the word segmentation process for each URL in the data set, characters are used as the smallest word element for word segmentation.
[0015] Preferably, in step S2, the word vector model is used to process the word elements of all URLs, obtain the character dictionary size of the URL, that is, the number of characters contained in the character dictionary words is M, the word vector dimension is N, and an M×N embedding matrix is constructed, wherein the first M-1 characters in the character dictionary are characters obtained after word segmentation processing of the word elements of all URLs, and the Mth character in the character dictionary is a null character, representing an unknown word that may appear.
[0016] Preferably, in step S2, each URL is encoded according to the word index of each word in the character dictionary. In the process of obtaining each URL sentence vector, the URL length, that is, the number of characters contained in the URL, is set to K. For URL sentence vectors with a length less than K, they are filled with 0, and for URL sentence vectors with a length exceeding K, the excess part is truncated.
[0017] Preferably, in step S3, the URL sentence vector is subjected to adaptive feature extraction through a CNN network to obtain a URL feature vector, including:
[0018] In the embedding layer, a K×N URL word vector matrix is constructed based on the word index in the URL sentence vector and the corresponding word vector in the embedding matrix;
[0019] In the convolution layer, H convolution kernels with different sliding window sizes are used to extract features from the word vector matrix, respectively, to obtain H feature vectors with different dimensions; the number of each convolution kernel is P, and finally P feature vectors are obtained in each dimension;
[0020] In the maximum pooling layer, for the P feature vectors of each dimension, a maximum value is extracted from each feature vector, and the P maximum values extracted from the P feature vectors are combined into a P-dimensional feature vector; finally, H P-dimensional feature vectors are obtained, and the H P-dimensional feature vectors are concatenated to obtain an H×P-dimensional URL feature vector.
[0021] Preferably, in step S4, the webpage text in the data set is encoded using an encoder of a text preprocessing model to obtain a text vector, and the text vector is passed through a BERT model to obtain a webpage text feature vector, including:
[0022] Adjust the length of the webpage text to K, that is, the webpage text contains K words;
[0023] The webpage text in the dataset is encoded using the encoder of the text preprocessing model, and the webpage text is represented as three text vectors: Token_tensor, Segment_tensor, and Mask_tensor. The lengths of the three text vectors are all K.
[0024] Input the three text vectors into the BERT model, fuse the three text vectors, and obtain a K×F text matrix through the BERT model last_hidden_state, where F is the vector dimension of the word in the webpage text;
[0025] The last_hidden_state of the BERT model is average pooled along the dimension of the text sentence length to obtain a web page text feature vector of length F.
[0026] Preferably, in step S5, the URL feature vector and the webpage text feature vector are concatenated and classified through a fully connected layer to obtain a prediction output, including:
[0027] Extracting H×P dimensional URL feature vector and F dimensional web page text feature vector;
[0028] Through the fully connected layer concatenation, we get the H×P+F dimensional feature vector;
[0029] The H×P+F dimensional feature vector is transformed through the softmax function to obtain the probability of belonging to each type of web page label;
[0030] The category corresponding to the maximum probability is selected as the predicted output.
[0031] Preferably, the classification categories include normal websites, fake order websites, credit and financial management websites and other websites.
[0032] Preferably, during the training process of the model, the parameters of the CNN network and the BERT model are set to be adjustable, the difference between the predicted output and the actual label is calculated using the multivariate cross entropy loss function, and the parameters are updated through the back propagation mechanism.
[0033] The present invention also provides a detection method for a malicious website detection classification model based on CNN+BERT, which is characterized by comprising:
[0034] The training method of the malicious website detection classification model based on CNN+BERT of the present invention is adopted to obtain the malicious website detection classification model based on CNN+BERT;
[0035] For the URLs that need to be detected, extract the URL and webpage text and input them into the model;
[0036] The URL detection results are obtained through the malicious URL detection classification model based on CNN+BERT.
[0037] The advantages of the present invention are:
[0038] (1) The present invention uses CNN to capture the features of URLs, namely local features, and uses BERT to understand web page text, thereby extracting global context information features. By combining the advantages of the CNN and BERT models, a richer and more effective feature representation is extracted, and the URL feature vector and the web page text feature vector are fused and spliced through a fully connected layer. The model is then trained to finally obtain the classification result of the URL. Compared with other models, the accuracy of URL detection is greatly improved, and a static detection method is adopted to avoid excessive resource consumption.
[0039] (2) The present invention extracts features by treating URLs as text information rather than simple sequence information. This approach not only enables the identification of key words in the URL structure, but also enables the recognition and understanding of the context and role of these keywords in a specific Web environment. This in-depth exploration of the intrinsic semantics of URLs greatly improves the comprehensiveness and accuracy of feature extraction, and provides a more powerful information basis for subsequent malicious website identification.
[0040] (3) The present invention enhances the ability of the present invention in learning the semantic relationship between URL characters by introducing the Word2vec model to process URL words and learning word vectors through the CNN network embedding layer, thereby improving the learning efficiency and model accuracy and enabling the model to converge more quickly.
[0041] (4) The present invention focuses on the static information of the web page by obtaining the URL and text content of the web page, avoiding the need for dynamic content or executing complex JavaScript (a literal programming language), which often requires additional processing time and computing resources. Therefore, the present invention greatly reduces the requirements for environmental resources, reduces operating costs, and improves the processing speed of the model.
[0042] (5) When constructing a character dictionary, the present invention segments URLs based on characters rather than word segments, uses characters as the smallest word element for segmentation, and also includes special characters of URLs in the dictionary instead of simply removing them as separators. Therefore, the information features in the URL are fully utilized, and the size of the URL character dictionary is greatly reduced, effectively avoiding the situation where the URL cannot be correctly represented due to too many unknown words.
[0043] (6) The final result of the present invention is to further classify URLs in detail, rather than just binary classification, which is closer to the needs of actual URL classification, thereby effectively proving the superiority of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] Figure 1 This is a flowchart of the training method for the malicious URL detection classification model based on CNN+BERT;
[0045] Figure 2 This is a framework diagram of the malicious URL detection and classification model based on CNN+BERT;
[0046] Figure 3 This is a comparison chart of malicious URL detection and classification accuracy of different models. DETAILED DESCRIPTION
[0047] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0048] like Figure 1-2 As shown, the present invention proposes a training method for a malicious website detection classification model based on CNN+BERT, including:
[0049] S1: Collect web page data, which includes URLs and web page texts, and annotate web pages to obtain web page tags used to represent classification categories; construct a data set, which includes URLs, web page texts, and corresponding web page tags;
[0050] In this embodiment, the data set includes manually collected data and open source data obtained from the Internet, with the ratio of the two being 1:5. The web page labels are 0, 1, 2, and 3, which respectively represent normal URLs, fake order URLs, credit and financial management URLs, and other URLs.
[0051] S2: Perform word segmentation on each URL in the dataset to obtain the word units in each URL; use the word vector model (Word2vec model) to process the word units of all URLs to obtain the word vector of each word unit, and build a character dictionary for the URL, as well as the word index of each word unit in the character dictionary, and build an embedding matrix based on the character dictionary and the word vector of each word unit; encode each URL according to the word index of each word unit in the character dictionary to obtain the encoding vector of each URL, i.e., the sentence vector.
[0052] In this embodiment, the meaningless segments are first removed from the URLs in the data set. The format of the URL is generally fixed, which is: <protocol name>: / / <user name>:<password>@<host domain name>:<port number> / <path>; <parameter>?<query>. In most URLs, the protocol uses the https protocol or the http protocol, and the path name mostly starts with www.. Therefore, the present invention believes that the protocol part and the beginning part are basically ineffective in distinguishing malicious and benign websites, and these two parts are removed in actual processing. In addition, the query part in the URL is generally the user name information or the user query field, which varies for different user names. The query also has no effect on distinguishing websites, so it is removed together.
[0053] Then, the word segmentation process is performed. In this embodiment, characters are used as the smallest word unit to obtain characters in each URL. The Word2vec model is used to pre-train the characters in a large number of URLs to obtain a character dictionary of size 93 and the word vectors corresponding to each character, that is, the character dictionary contains 93 different characters, and each character is represented by a 32-dimensional word vector. In order to avoid the situation where there is no word vector to match due to unknown characters in the new sample, the 93rd character is an additional empty character to represent the unknown words that may appear. The 32-dimensional vector corresponding to the empty character is represented by a random number in the range of (-0.5, 0.5). After obtaining the character dictionary and word vector, a 93×32 embedding matrix can be constructed.
[0054] The Word2vec model is a related model used to generate word vectors. Word vectors are a method of representing words, or word units, into real vectors in a high-dimensional space. Each word is represented as a vector of a fixed length, so that the semantic relationship between words can be preserved and expressed in the vector space. Sentence vectors are a method of representing sentences into vector space, which can capture the semantic information and grammatical structure of sentences. Sentence vectors can be constructed by knowing each word unit and word index in the sentence. The character dictionary consists of different characters and different numbers (indexes) that represent these different characters.
[0055] Obviously, the length of each URL is different. After counting a large number of URL lengths, the present invention found that more than 97% of URL lengths are within 100 characters, and 100 characters are sufficient to represent the characteristics of most URLs. Therefore, in this embodiment, the length of the encoded URL sentence vector is unified to 100, and the URL sentence vectors with a length of less than 100 are padded with zeros, and the URL sentence vectors with a length of more than 100 are truncated. Figure 2 middle <pad>This means filling.
[0056] In many past studies, the extraction of URL features often relies on artificially designed features, such as URL length, number of special symbols, information carried by IP segments, etc. However, in the present invention, the present invention regards URL as a special form of text, and uses the Word2vec pre-trained model to obtain the unique character dictionary and character corresponding word vectors in the URL data set, thereby constructing the URL word vector matrix, which facilitates the CNN feature extraction work in the subsequent steps. In addition, when constructing the unique character dictionary, the present invention uses the URL segmentation method based on characters rather than segments, uses characters as the smallest word element for segmentation, and also includes the special characters of the URL in the dictionary scope, rather than simply removing them as separators. The above method greatly reduces the size of the URL unique character dictionary, and effectively avoids the situation where the URL cannot be correctly represented due to too many unknown words, and fully utilizes the information features in the URL.
[0057] For example, taking the URL [https: / / www.baidu.com] as an example, after deleting meaningless segments and word segmentation, we can split the URL into the format of [b, a, i, d, u, ., c, o, m]. We encode it with the index in the character dictionary, and the URL can be represented as a sentence vector of [20 3 5 15 18 9 6 1 12].
[0058] S3: The URL sentence vector is adaptively extracted through the CNN network to obtain the URL feature vector.
[0059] include:
[0060] In the embedding layer, the word vector matrix of the URL is constructed based on the word index in the URL sentence vector and the corresponding word vector in the embedding matrix.
[0061] In the convolutional layer, a sliding window is used to extract features from the above word vector matrix to obtain multiple multi-dimensional feature vectors;
[0062] In the maximum pooling layer, multiple multi-dimensional feature vectors are reduced in dimension and concatenated to obtain the URL feature vector.
[0063] In the CNN network, the first layer is the Embedding layer. In the present invention, since the present invention has pre-trained the embedding matrix using Word2vec, there is no need to use the embedding layer to increase or decrease the dimension of the text vector. Here, the present invention can simply understand the embedding layer as "looking up a dictionary". In the above steps, the present invention performs word index encoding and zero padding on the URL, thereby obtaining a URL sentence vector of size 100. The role of the embedding layer is to find the corresponding word vector in the embedding matrix according to the word index in the URL sentence vector, thereby converting the URL sentence vector into a word vector matrix of size 100×32. Obviously, in the present invention, the present invention can use a pre-trained embedding matrix to define the weight of the embedding layer, rather than simply randomly initializing it, so that the model of the present invention can converge faster and the extracted features can be more accurate. During the training process, the weight of the embedding layer will also be continuously adjusted until the word vector of each unique word can best express the semantic information of the word in the URL.
[0064] The second layer is the convolution layer. In the convolution layer, the convolution kernel convolves the URL word vector matrix in a top-down direction (i.e., the direction of the text sequence), focusing on the relationship between character combinations rather than the connection between different dimensions. In this embodiment, three types of convolution kernels with sliding window sizes of 3, 4, and 5 are used to extract features of the URL word vector matrix, and feature vectors of 98, 97, and 96 dimensions are obtained respectively. This method can effectively extract feature vectors between different character combinations, and at the same time, the number of each convolution kernel is set to 256, and finally 256 feature vectors are obtained in each dimension. The use of multiple convolution kernels of the same size is to learn complementary features from the same character combination, so as to better characterize the word vector matrix.
[0065] The third layer is the maximum pooling layer. The maximum pooling layer is essentially a dimensionality reduction operation, which focuses on how to characterize the entire feature vector with the maximum value. After convolution of a single URL, the present invention obtains 256 feature vectors in three dimensions of 98, 97, and 96 dimensions, respectively, and before the feature vector enters the pooling layer, the present invention first processes it with the RELU activation function, and then inputs it into the maximum pooling layer. In the maximum pooling layer, the model extracts the maximum value of each 256 feature vectors of the same dimension. Taking the 98-dimensional feature vector as an example, there are a total of 256 98-dimensional feature vectors, and then find the maximum value of each 98-dimensional feature vector, a total of 256 maximum values are obtained, and then combined into a 256-dimensional feature vector. Since there are 256 97-dimensional and 256 96-dimensional feature vectors, 3 feature vectors with a dimension of 256 are finally obtained. Then the present invention splices it to obtain a 768-dimensional URL feature vector.
[0066] In actual operation, multiple convolution kernels of the same size are used to convolve the word vector matrix. The purpose of this is to learn complementary features from the same window. Each convolution operation extracts features from the word vector matrix. By defining windows of different sizes and setting the number of convolution kernels, different features can be extracted.
[0067] S4: Encode the webpage text in the dataset using the encoder of the text preprocessing model (bert base chinese model) to obtain the text vector, and then use the text vector through the BERT model to obtain the text feature vector. Including:
[0068] The length of the webpage text is adjusted to K, that is, the webpage text contains K words; the insufficient length is filled with 0, and the excessive length is truncated;
[0069] The webpage text in the dataset is encoded using the encoder of the bert-chinese-base model, and the webpage text is represented as three text vectors: Token_tensor, Segment_tensor, and Mask_tensor. The lengths of the three text vectors are all K.
[0070] Input the three text vectors into the BERT model, fuse the three text vectors, set the text word vector dimension to F, and obtain the K×F text matrix through the last_hidden_state of the BERT model. Last_hidden_state is the hidden state of the last layer of the BERT model.
[0071] The last_hidden_state of the BERT model is average pooled along the dimension of the text sentence length to obtain a web page text feature vector of length F.
[0072] First, for the input webpage text, the present invention needs to perform uniform length processing and encoding. The present invention uses 100 words as the threshold and deletes texts longer than 100 words to avoid unnecessary resource consumption in the subsequent training process due to overly long texts. For texts shorter than 100 words, the present invention uses zero padding to modulate the length of the text to be the same.
[0073] Then, the present invention uses the encoder that comes with the BERT model to encode the text, and represents a single text as three equal-length vectors: Token_tensor, Segment_tensor (Seg tensor), and Mask_tensor. Token_tensor represents the word index of each word in the text in the BERT Chinese dictionary, which is used to obtain the corresponding word vector during the BERT pre-training process. Segment_tensor is used to distinguish different sentences. Since the present invention uses the BERT model based on the Chinese corpus, the separation of sentences is marked by periods, question marks, ellipsis, etc. The encoding method is that in a long text, the Segment_tensor of the first sentence is all 0, and the Segment_tensor of the second sentence is all 1, and so on, to complete the encoding of the entire text. The main function of Mask_tensor is to make the model pay more attention to the words marked as 1; because the present invention uses zero padding in the above steps to adjust the length of all texts to the same, in order to make the model pay more attention to the non-zero-filled words, BERT uses Mask_tensor to set all the word vectors of non-zero-filled words to 1, so that the model can accurately focus on the meaningful words in the text sequence, thereby better extracting information. The BERT Chinese dictionary can be found in the prior art.
[0074] After obtaining the three text vectors, the present invention inputs the three text vectors into the BERT model and sets the parameters of the BERT model to be adjustable so as to make it more suitable for the classification task of malicious texts through fine-tuning.
[0075] The output of the BERT model consists of four parts, namely last_hidden_state (hidden state of the last layer), pooler_output (pooling output), hidden_state (hidden state), and attentions (attention weights). In the present invention, only last_hidden_state is used as a text feature vector. In the present invention, the word vector dimension of the word in the web page text is set to 768. For each word in the web page text, the features in the three text vectors are fused and represented as a 768-dimensional vector. Finally, the size of BERT's last_hidden_state is 100×768 (i.e., sentence length×word vector dimension). Then, BERT's last_hidden_state is averagely pooled along the dimension of the text sentence length to obtain the mean of each word vector. The result obtained in this way will be a single text feature vector with a length of 768, representing the average word vector of the entire sentence.
[0076] S5: The URL feature vector is concatenated with the web page text vector, and is classified through the fully connected layer FC to obtain the prediction output, i.e., the prediction result label of the URL.
[0077] In this embodiment, a 768-dimensional URL feature vector and a 768-dimensional text feature vector are first extracted;
[0078] Then, a 768+768=1586-dimensional mixed feature vector is obtained through the fully connected layer; four category probabilities are obtained through softmax function conversion; and the category corresponding to the maximum value of the four category probabilities is selected as the prediction output.
[0079] Before entering the fully connected layer, a Dropout layer is used to discard 50% of the neurons each time to prevent possible overfitting.
[0080] During the model training process, the parameters of the embedding layer of the CNN network model and the BERT model are set to be adjustable, and the multivariate cross entropy loss function is used to calculate the difference between the predicted output and the actual label. The parameters are updated through the back propagation mechanism so that the model can continuously learn in the back propagation and optimize the model performance.
[0081] The present invention adopts a static detection method, which collects two types of static information, namely the URL and web page text of the website, and performs data preprocessing such as encoding and word vector conversion. Finally, the CNN+BERT model is used to adaptively extract features of the data to obtain recognition outputs of different categories of URLs, such as normal URLs, fake order URLs, credit and financial management URLs, and other URLs, thereby improving the accuracy of the model.
[0082] In summary, the malicious URL detection and classification model based on CNN+BERT proposed in the present invention includes a URL preprocessing module, a CNN convolution module, a text preprocessing module, a BERT training module and a classification module. The URL preprocessing module obtains a URL sentence vector by processing the URL, the CNN convolution module performs adaptive feature extraction on the URL sentence vector to obtain a URL feature vector, and at the same time, the text preprocessing module encodes the web page text to obtain a text vector, the BERT training module obtains a web page text feature vector through the text vector, and the classification module splices and fuses the URL feature vector with the web page text feature vector to obtain a prediction output.
[0083] like Figure 3 As shown in the figure, in order to demonstrate the superiority of the model of the present invention, we compared the model of the present invention with some malicious URL research in recent years (Embedding-CNN, Mix-VGG-BL, RNN, stacked-LSTM, CNN-SVM, eXpose), and used the accuracy as the evaluation index. Figure 3 It can be seen that, except for the RNN model, the classification accuracy of the other models based on URL can reach more than 90%. Except for the model of the present invention, the highest accuracy of the other models is the Mix-VGG-BL model, with an accuracy of 96.16%, while the accuracy of the model of the present invention is as high as 98.02%. Compared with the other six models, our model has the highest accuracy, and the structure of the model in the present invention is more flexible, because the model of the present invention can further classify web pages in more detail based on information, rather than just binary classification, and is closer to the actual needs of URL classification, thereby effectively proving the superiority of the present invention.
[0084] At the same time, the present invention regards URL as text information for feature extraction, and adopts Word2vec pre-training and embedding layer weights to continuously update learning to make the model converge faster. In order to prove the effectiveness of Word2vec pre-training and embedding layer, the present invention designs an ablation experiment to verify it.
[0085] In the experiment, four groups of experiments were set up, namely: ① Only the word vector obtained by Word2vec pre-training is used to represent the URL, and the embedding layer parameters are frozen so that they will not be changed in subsequent training. ② Without using Word2vec pre-training, only the embedding layer Embedding is used for word vector learning, and its weight is obtained by random initialization. ③ The word vector is adjusted by both Word2vec pre-training and embedding layer Embedding learning. The above are all URL classification based only on URL. In addition, ④ we also add the complete model of the present invention, namely CNN+BERT, to compare and analyze it from the perspectives of classification accuracy and recall rate. The ablation experiment results are as follows:
[0086] Table 1 Ablation verification - classification accuracy
[0087] ;
[0088] Table 2 Ablation Verification - Recall Rate
[0089] ;
[0090] From the analysis of Table 1 and Table 2, we can see that the recognition accuracy of the four methods for normal URLs can reach more than 99.50%. In the case of only extracting features from URLs, the three methods have similar detection and classification accuracy and recall rates for URLs, but the addition of Word2vec pre-training and embedding layers can make the model converge faster while improving accuracy.
[0091] When we extract features from URLs and web page texts at the same time, the classification accuracy and recall rate are higher than when we only extract features from URLs. The trained model also has better generalization performance and robustness, which proves that our algorithm is reasonable and effective.
[0092] Of course, it is obvious to those skilled in the art that the present invention is not limited to the details of the exemplary embodiments described above, but also includes the same or similar structures that can be implemented in other specific forms without departing from the spirit or essential features of the present invention. Therefore, no matter from which point of view, the embodiments should be regarded as exemplary and non-limiting, and the scope of the present invention is defined by the appended claims rather than the above description, and it is intended that all changes falling within the meaning and scope of the equivalent elements of the claims are included in the present invention. Any reference numerals in the claims should not be regarded as limiting the claims involved.
[0093] In addition, it should be understood that although the present specification is described according to implementation modes, not every implementation mode contains only one independent technical solution. This description of the specification is only for the sake of clarity. Those skilled in the art should regard the specification as a whole. The technical solutions in each embodiment may also be appropriately combined to form other implementation modes that can be understood by those skilled in the art.
[0094] The techniques, shapes, and structural parts not described in detail in the present invention are all well-known techniques.< / pad>
Claims
1. The training method of the malicious URL detection classification model based on CNN+BERT is characterized by: include: S1: Collect web page data, including URLs and web page texts, and annotate web pages to obtain web page tags for indicating classification categories; Construct a data set, which includes URL, web page text and corresponding web page tags; URL is the website address; S2: Perform word segmentation on each URL in the dataset to obtain the word units in each URL; use the word vector model to process the word units of all URLs to obtain the word vectors of each word unit, and build a character dictionary of the URL, and obtain the word index of each word unit in the character dictionary, and build an embedding matrix based on the character dictionary and the word vectors of each word unit; encode each URL according to the word index of each word unit in the character dictionary to obtain the encoding vector of each URL, that is, the sentence vector; S3: The URL sentence vector is adaptively extracted through the CNN network to obtain the URL feature vector; S4: Encode the webpage text in the dataset using the encoder of the text preprocessing model to obtain the text vector, and then use the text vector through the BERT model to obtain the webpage text feature vector; S5: Concatenate the URL feature vector and the web page text feature vector, pass through the fully connected layer, and classify to obtain the predicted output.
2. The training method for the malicious URL detection classification model based on CNN+BERT as claimed in claim 1, characterized in that: In step S2, in the process of segmenting each URL in the data set, characters are used as the smallest word element for segmentation.
3. The training method of the malicious website detection classification model based on CNN+BERT as claimed in claim 2, characterized in that: In step S2, the word vector model is used to process the word elements of all URLs, and the character dictionary size of the URL is obtained, that is, the number of characters contained in the character dictionary words is M, the word vector dimension is N, and an M×N embedding matrix is constructed, wherein the first M-1 characters in the character dictionary are the characters obtained after word segmentation processing of the word elements of all URLs, and the Mth character in the character dictionary is a null character, representing an unknown word that may appear.
4. The training method of the malicious website detection classification model based on CNN+BERT as claimed in claim 3 is characterized in that: In step S2, each URL is encoded according to the word index of each word in the character dictionary. In the process of obtaining each URL sentence vector, the URL length, that is, the number of characters contained in the URL, is set to K. For URL sentence vectors with a length less than K, they are filled with 0, and for URL sentence vectors with a length exceeding K, the excess part is truncated.
5. The training method of the malicious website detection classification model based on CNN+BERT as claimed in claim 4, characterized in that: In step S3, the URL sentence vector is subjected to adaptive feature extraction through a CNN network to obtain a URL feature vector, including: In the embedding layer, a K×N URL word vector matrix is constructed based on the word index in the URL sentence vector and the corresponding word vector in the embedding matrix; In the convolution layer, H convolution kernels with different sliding window sizes are used to extract features from the word vector matrix, respectively, to obtain H feature vectors with different dimensions; the number of each convolution kernel is P, and finally P feature vectors are obtained in each dimension; In the maximum pooling layer, for the P feature vectors of each dimension, a maximum value is extracted from each feature vector, and the P maximum values extracted from the P feature vectors are combined into a P-dimensional feature vector; finally, H P-dimensional feature vectors are obtained, and the H P-dimensional feature vectors are concatenated to obtain an H×P-dimensional URL feature vector.
6. The training method of the malicious website detection classification model based on CNN+BERT as claimed in claim 5, characterized in that: In step S4, the webpage text in the data set is encoded using the encoder of the text preprocessing model to obtain a text vector, and the text vector is passed through the BERT model to obtain a webpage text feature vector, including: Adjust the length of the webpage text to K, that is, the webpage text contains K words; The webpage text in the dataset is encoded using the encoder of the text preprocessing model, and the webpage text is represented as three text vectors: Token_tensor, Segment_tensor, and Mask_tensor. The lengths of the three text vectors are all K. Input the three text vectors into the BERT model, fuse the three text vectors, and obtain a K×F text matrix through the BERT model last_hidden_state, where F is the vector dimension of the word in the webpage text; The last_hidden_state of the BERT model is average pooled along the dimension of the text sentence length to obtain a web page text feature vector of length F.
7. The training method of the malicious website detection classification model based on CNN+BERT as claimed in claim 6, characterized in that: In step S5, the URL feature vector is concatenated with the webpage text feature vector, and is classified through a fully connected layer to obtain a prediction output, including: Extracting H×P dimensional URL feature vector and F dimensional web page text feature vector; Through the fully connected layer concatenation, we get the H×P+F dimensional feature vector; The H×P+F dimensional feature vector is transformed through the softmax function to obtain the probability of belonging to each type of web page label; The category corresponding to the maximum probability is selected as the predicted output.
8. The training method for the malicious website detection classification model based on CNN+BERT as claimed in claim 1, characterized in that: The classification categories include normal websites, fake order websites, credit and financial management websites and other websites.
9. The training method of the malicious website detection classification model based on CNN+BERT as claimed in claim 1, characterized in that: During the training process of the model, the parameters of the CNN network and the BERT model are set to be adjustable, and the multivariate cross entropy loss function is used to calculate the difference between the predicted output and the actual label, and the parameters are updated through the back-propagation mechanism.
10. The detection method of malicious website detection classification model based on CNN+BERT is characterized by: include: Adopting the training method of the malicious website detection classification model based on CNN+BERT as described in any one of claims 1 to 9, obtaining a malicious website detection classification model based on CNN+BERT; For the URLs that need to be detected, extract the URL and webpage text and input them into the model; The URL detection results are obtained through the malicious URL detection classification model based on CNN+BERT.
