A method for detecting malicious domain names based on large language models

Through the URL-BERT model based on the large language model, combined with character-level and tag-level embedding features, it solves the problem of limited effectiveness of existing malicious domain name detection methods in the face of the explosive growth of malicious domain names, and improves detection accuracy and generalization capabilities. , adapt to data changes and complexity.

CN118413402BActive Publication Date: 2024-09-06HEFEI CITY COULD DATA CENT
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410875232.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-02
Publication Date
2024-09-06
Estimated Expiration
2044-07-02

AI Technical Summary

Technical Problem

Existing malicious domain name detection methods have limited effectiveness in the face of the explosive growth of malicious domain names. Machine learning-based methods rely heavily on expert knowledge and have limited feature expression capabilities. Deep learning methods ignore the location sensitivity and lack of interpretability of Tokens in domain names. .

Method used

Adopting a malicious domain name detection method based on a large language model, by building a pre-trained and fine-tuned URL-BERT model, combining character-level and tag-level embedding features, using the Transformer layer to capture complex relationships in domain names, and introducing location embedding to detect malicious domain names detection.

Benefits of technology

It improves the accuracy and generalization ability of malicious domain name detection, avoids manual feature design, enhances the model's ability to process sequence data, can better adapt to data changes and complexity, and improves the ability to deal with adversarial attacks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118413402B
    Figure CN118413402B
Patent Text Reader

Abstract

The present invention relates to a malicious domain name detection method based on a large language model, which solves the defect that it is difficult to detect malicious domain names compared with the prior art. The present invention comprises the following steps: construction of a pre-training data set and a fine-tuning training data set; setting a URL-BERT model; pre-training of the URL-BERT model; fine-tuning of the URL-BERT model; obtaining a domain name to be detected; and obtaining a malicious domain name detection result. The present invention adopts a large language model BERT to process malicious domain names, and utilizes the powerful semantic understanding ability of the large language model to better capture the implicit information and context in the domain name, thereby improving the recognition accuracy of malicious domain names.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of cyberspace security and artificial intelligence technology, and in particular to a malicious domain name detection method based on a large language model. Background Art

[0002] With the rapid development of the Internet, network security is threatened, various malicious websites and malware are rampant, and many users and websites are vulnerable to security threats. Among them, malicious domain names are one of the main paths of network attacks. Tens of thousands of new domain names emerge every day. Among these domain names, in addition to a large number of normally registered benign domain names (Benign Domain), there are also a large number of malicious domain names (Malicious Domain) registered maliciously for illegal activities. Malicious domain names have become one of the main attack paths for various illegal network activities.

[0003] Domain names serve as a bridge to connect users with malicious agents such as ransomware, malware, and Trojans. Malicious domain names are often used to illegally steal and store personal sensitive information, illegally control and manage infected hosts, and other malicious behaviors. Almost all network attacks rely on the use of malicious domain names, and the domain name system is abused by attackers. Therefore, how to effectively detect malicious domain names is a hot and difficult issue in the field of network security.

[0004] Existing malicious domain name detection methods are mainly divided into three categories: rule-based, machine learning, and deep learning. The rule-based method detects the legitimacy of the domain name through blacklists and whitelists. This type of method is simple and direct; the machine learning-based method extracts features from the domain name (such as domain name length, number of different IP addresses, etc.), and then builds a machine learning-based classifier to distinguish between benign domain names and malicious domain names; the deep learning-based method encodes and models the text of the domain name through a deep neural network.

[0005] Existing malicious domain name detection methods have achieved good results to a certain extent. However, rule-based methods have limited effectiveness in the face of explosive growth in malicious domain names; machine learning-based methods rely heavily on expert knowledge and are limited by feature expression capabilities, and attackers can easily bypass model detection by adding minimal feature perturbations (changing the length of the domain or modifying network parameters such as TTL); deep learning-based methods have defects such as ignoring the importance of position embedding to domain name vectors and lack of interpretability.

[0006] A domain name usually consists of multiple parts, such as a second-level domain name, a top-level domain name, etc., which are connected by a dot (.), such as Figure 2As shown in the figure. Remove special characters such as "." and "-" in the domain name, and use "." as a separator to segment the domain name to get the domain name token. Deep learning methods usually treat domain names as plain text data, ignoring the sensitivity of the token in the domain name to the position, that is, the same token should have different meanings and representation methods when located in the Domain / Top Level Domain (TLD) / Path.

[0007] Therefore, how to design a malicious domain name detection method based on the special text information of the domain name has become a technical problem that needs to be solved urgently. Summary of the invention

[0008] The purpose of the present invention is to solve the defect that it is difficult to detect malicious domain names in the prior art, and to provide a malicious domain name detection method based on a large language model to solve the above problem.

[0009] In order to achieve the above object, the technical solution of the present invention is as follows:

[0010] A method for detecting malicious domain names based on a large language model comprises the following steps:

[0011] 11) Construction of pre-training dataset and fine-tuning training dataset: Construct pre-training dataset and fine-tuning training dataset, and perform data preprocessing;

[0012] 12) Set up the URL-BERT model;

[0013] 13) Pre-training of URL-BERT model: Pre-train the URL-BERT model using the pre-training dataset;

[0014] 14) Fine-tuning the URL-BERT model: Fine-tune the pre-trained URL-BERT model using the fine-tuning training dataset;

[0015] 15) Obtaining the domain name to be tested: obtaining the domain name to be tested;

[0016] 16) Obtaining malicious domain name detection results: Input the domain name to be detected into the fine-tuned URL-BERT model to obtain malicious domain name detection results.

[0017] The construction of the pre-training dataset and the fine-tuning training dataset includes the following steps:

[0018] 21) Set a pre-training data set, which is unlabeled domain name data. The unlabeled domain name data is obtained from public DNS query logs and WHOIS database sources;

[0019] 22) Set a fine-tuning training data set, which is labeled domain name data. The labeled domain name data is obtained from a network security company or a public malicious domain name database, and the number of positive samples and negative samples is balanced;

[0020] 23) Pre-process the pre-training dataset and fine-tuning training dataset by removing duplicates, removing irrelevant characters, converting to lowercase letters, and standardizing;

[0021] 24) Perform word segmentation on the preprocessed pre-training dataset and fine-tuning training dataset.

[0022] The setting of the URL-BERT model includes the following steps:

[0023] 31) Set the URL-BERT model to include input layer, URL-BERT pre-training layer, character-level embedding feature extraction layer, token-level embedding feature extraction layer, feature fusion layer and fully connected classification layer;

[0024] Set the input layer: The input layer receives the text after word segmentation as the input of the model;

[0025] 32) Setting URL-BERT pre-training layer: In the pre-training stage, the MLM task is set to train a large amount of unlabeled domain name data to learn and capture the rich semantic information and structural features in the domain name text;

[0026] 33) Set the character-level embedding feature extraction layer: The character-level embedding extraction layer extracts the character-level embedding of the domain name text, and uses BiGRU to generate a bidirectional vector representation, which contains the complex correlation information between the characters within the domain name; for the fine-tuning training data set, the bidirectional gated unit BiGRU is used to extract the character-level embedding of the labeled domain name data. BiGRU uses two GRUs in different directions to combine the hidden layer states in the forward and backward directions, thereby integrating the bidirectional information and obtaining the domain name character-level embedding vector ;

[0027] 34) Setting the tag level embedding feature extraction layer to perform tag level embedding;

[0028] 35) Set the feature fusion layer:

[0029] The feature fusion layer concatenates the extracted character-level embedding feature vectors and token-level embedding feature vectors, and then introduces multiple Transformer layers to capture the complex relationship between features;

[0030] A heterogeneous interaction module between Transformer layers, which is used to combine and separate character-level embeddings and token-level embeddings after each Transformer layer. The combination operation enriches the correlation between different representations, and the separation operation preserves the independence of character-level and token-level features, which promotes the model's performance in dual-channel discrimination.

[0031] 36) Set the fully connected classification layer: The fully connected classification layer is used to fine-tune the entire URL-BERT model to adapt to the specific malicious domain name detection task. The feature vector output by the feature fusion layer is input into the fully connected layer, and the loss function is minimized through the back propagation algorithm.

[0032] The pre-training of the URL-BERT model includes the following steps:

[0033] 41) Input the text after word segmentation of the pre-training dataset into the URL-BERT model;

[0034] 42) The URL-BERT pre-training layer performs Masked Language Model pre-training, i.e., MLM pre-training:

[0035] set up is randomly replaced with [MASK] A small part of the token sequence in 15% of the tokens are randomly [MASK], among which Indicates that the i-th token is randomly replaced. The goal of the MLM pre-training process is to predict the content of the [MASK] token based on the context;

[0036] Will Input into the URL-BERT model, The corresponding hidden vector , Depend on Encoded by BERT’s encoder;

[0037] 421) Encoder processing: The input data of the encoding input layer is the embedding vector ;

[0038] 422) Self-Attention Mechanism:

[0039] enter Obtain the query matrix through linear transformation , key matrix K and value matrix ,in , , are the hyperparameters of the encoder:

[0040] ,

[0041] ,

[0042] ,

[0043] The attention weights are then calculated using scaled dot product attention. The output produced by this step contains a representation of the global dependencies within the input sequence.

[0044] in is the dimension of the key vector, used to scale the dot product to prevent the vanishing gradient problem, is the attention weight matrix, is the output of an attention head,

[0045] ,

[0046] Output of multi-head attention:

[0047] The outputs of multiple heads are concatenated and then passed through another linear transformation. The formula is as follows:

[0048] ,

[0049] in, It is The output of the head, is a hyperparameter matrix;

[0050] 423) Feedforward Neural Network:

[0051] The output of the multi-head attention is further processed with a feedforward neural network, which consists of two linear layers and an activation function.

[0052] ,

[0053] in , , , is a learnable parameter;

[0054] Then, residual connection and layer normalization are performed to enhance the training stability and convergence speed of the model:

[0055] ,

[0056] here Representation layer normalization operation;

[0057] Encoder output layer: finally outputs the encoder’s encoded sequence ;

[0058] then, After Sigmoid operation, the corresponding token distribution is obtained;

[0059] The formula for the MLM process is as follows,

[0060] ,

[0061] in Represents the target probability distribution, that is, the entire sequence The probability distribution of represents the predicted probability of the i-th token given all the tokens in the sequence, represents the model parameters, Indicates whether the i-th token is [MASK]. If the i-th token is [MASK], then , otherwise The purpose is to weight the [MASK] tokens, which have an impact on the probability of the entire sequence;

[0062] In MLM pre-training, the goal is to maximize the model's Based on this prediction, the cross entropy loss function is calculated and the model parameters are updated through the back propagation algorithm. , and finally get the pre-trained model ,

[0063] ,

[0064] in, are model parameters, is the cross entropy loss function, is the true label of the ith token. If the token is [MASK], it is the true value of the token. is the predicted probability of the i-th token, that is Minimize the loss function by back-propagation algorithm Update model parameters , and finally get the pre-trained URL-BERT model .

[0065] Fine-tuning the URL-BERT model includes the following steps:

[0066] 51) Training of character-level embedding feature extraction layer and token-level embedding feature extraction layer to perform character-level embedding;

[0067] The fine-tuning dataset is segmented to form a segmentation sequence on the one hand, After embedding at the character level feature extraction layer, we get the embedding vector ;on the other hand After the tag level embedding feature extraction layer embedding, that is Embedding of the pre-trained model, plus the attention mask vector , perform position embedding processing to obtain the tag-level embedding vector with position embedding ;

[0068] Finally, the token level embedding vector With character-level embedding vectors Connected together, that is, Vector end concatenation vector, forming a longer embedding vector ,

[0069] ;

[0070] 52) Set the feature fusion layer: Set the feature fusion layer as the model ,Model Model containing a frozen parameter layer, multiple Transformer layers, multiple heterogeneous interaction layers, a fully connected layer and a Sigmoid layer; through the interaction between modules, the feature fusion layer can capture the complex relationship between the URL character level and the tag level;

[0071] Train the feature fusion layer:

[0072] 521) Setting the model of frozen parameters The layer is the pre-trained URL-BERT model ,

[0073] 522) Set up the Transformer module:

[0074] Transformer consists of an encoder and a decoder. The encoder is used to process input data, and the decoder is responsible for generating output.

[0075] The encoder includes an encoding input layer, self-attention mechanism, multi-head attention, feedforward neural network, residual connection and layer normalization, and encoder output layer;

[0076] The decoder includes a decoding input layer, a self-attention mechanism, an encoder-decoder attention mechanism, a feedforward neural network, residual connections and layer normalization, and a decoder output layer;

[0077] 5221) Encoder processing: The input data of the encoding input layer is the embedding vector ;

[0078] Self-Attention Mechanism:

[0079] For each head , enter Obtain the query matrix through linear transformation , key matrix Sum Matrix ,in , , , are the hyperparameters of the encoder:

[0080] ,

[0081] ,

[0082] ,

[0083] Next, attention weights are calculated for each head using scaled dot product attention. The output produced by this step contains a representation of the global dependencies within the input sequence.

[0084] in is the dimension of the key vector, used to scale the dot product to prevent the vanishing gradient problem, is the attention weight matrix, is the output of the attention mechanism of a head,

[0085] ,

[0086] Output of multi-head attention:

[0087] The outputs of multiple heads are concatenated and then passed through another linear transformation. The formula is as follows:

[0088] ,

[0089] in, is the output of each attention head, is a hyperparameter matrix;

[0090] Feedforward Neural Network:

[0091] The output of the multi-head attention is further processed with a feedforward neural network, which consists of two linear layers and an activation function.

[0092] ,

[0093] in , , , is a learnable parameter;

[0094] Residual connections and layer normalization: used to enhance the training stability and convergence speed of the model.

[0095] ,

[0096] here Representation layer normalization operation;

[0097] Encoder output layer: finally outputs the encoder’s encoded sequence ;

[0098] 5222) Decoder processing:

[0099] The input data of the decoder input layer is an embedded vector

[0100] Self-Attention Mechanism: Obtain the query matrix through linear transformation , key matrix Sum Matrix ,in , , , is the decoder hyperparameter,

[0101] ,

[0102] ,

[0103] ,

[0104] Calculate attention weights for each head, using scaled dot product attention;

[0105] The outputs of multiple heads are concatenated, and the self-attention output of the decoder is obtained through residual connection and layer normalization. ;

[0106] Encoder-decoder attention mechanism: The decoder performs attention calculations on the encoder's output to capture the relationship between the input sequence and the output sequence, allowing the decoder to adjust its own attention based on the encoder's information to generate the target sequence;

[0107] For each position of the decoder , using the decoder output As a query, the encoder output , As keys and values, calculate the attention weights:

[0108] ,

[0109] ,

[0110] Output of multi-head attention: combine the decoder's self-attention output and the encoder-decoder attention output to get the final attention output;

[0111] Add them element-wise weighted, and the expression is as follows:

[0112] ,

[0113] Among them, the final attention output is , is a learnable weight parameter:

[0114] Feedforward neural network: The final attention output is A feed-forward neural network is then processed to further extract and transform feature representations:

[0115] ;

[0116] Residual connections and layer normalization: Residual connections and layer normalization are applied to the output of the feedforward neural network to enhance the training stability and convergence speed of the model:

[0117] ,

[0118] Decoder Output: The output sequence of the decoder is ;

[0119] 523) Set up a heterogeneous interaction module: In the heterogeneous interaction layer, the token-level and character-level representations are treated as two different types of feature representations. After each Transformer conversion layer, these two representations are combined and separated;

[0120] The fully connected network is responsible for mapping the token and character representations into the same feature space to ensure that they have consistent dimensions and semantic representations, which are then connected and integrated through the CNN layer, and finally through residual connections and layer normalization operations;

[0121] 5231) Separation and combination processing:

[0122] The decoder output vector Separate into token-level representations by length and character-level representation , Indicates the mark / character representation of the i-th position, respectively and A dedicated fully connected network is used to convert:

[0123] ,

[0124] ,

[0125] The converted token and character representations are then concatenated to form a fused representation:

[0126] w i x =[ h i ' x ; t i ' x ] ;

[0127] 5232) CNN convolution: representation after fusion Apply CNN operations to integrate features.

[0128] ,

[0129] in, Indicates from arrive Embedded splicing, represents the window size of the jth filter;

[0130] 5233) Separation: The combination after convolution is represented Separated into two different channels of feature representation,

[0131] ,

[0132] ,

[0133] Among them, GELU is an activation function used to separate the fused feature representation;

[0134] 5234) Residual connections and layer normalization: The separated feature representations are added to the initial token and character representations to reconstruct the representations of the two channels:

[0135] ,

[0136] ,

[0137] Finally, the reorganized representation is layer normalized to ensure stability:

[0138] ,

[0139] ,

[0140] The separated features will be connected to get the input of the next layer of Transformer;

[0141] 524) Set up fully connected and Sigmoid classification modules:

[0142] Train the fully connected layer:

[0143] The output of the last layer of Transformer Pass to The fully connected layer of hidden units is mathematically expressed as follows:

[0144] ,

[0145] in, is the input vector, and are the weights and biases of the layer, is the activation function;

[0146] Sigmoid is used to map the output of the fully connected layer to the category probability distribution. The Sigmoid layer maps the output of the fully connected layer to the category probability distribution. Passed to the Sigmoiod function, the Sigmoid function maps the input real value to a probability value between 0 and 1. The output of the fully connected layer is , the output after the Sigmoid function is expressed as:

[0147] ;

[0148] 53) URL-BERT model fine-tuning process:

[0149] Embed the token-level vector of the fine-tuning dataset With character-level embedding vectors The processed embedding vector , using the pre-trained URL-BERT model The fine-tuned model constructed By feeding data into the model , compare the output result with the true label, then calculate the loss function, update the model parameters through the back-propagation algorithm, iteratively train the model until convergence, so that the fine-tuned URL-BERT model can classify malicious domain names.

[0150] The word segmentation processing of the pre-processed pre-training data set and the fine-tuning training data set comprises the following steps:

[0151] 61) For the domain name data in the pre-training dataset and the fine-tuning training dataset, the word segmentation operation splits the entire domain name string according to its structural characteristics, removes special characters in the domain name, and uses " / ", ".", and "-" as separators to segment the domain name:

[0152] Enter a pre-processed domain name , define a word segmentation function f to represent this process:

[0153] ,

[0154] The input of the word segmentation function f() is a preprocessed domain name in string form, and the output is a word segmentation list consisting of the fragments of the domain name after word segmentation. ,in , for The number of words in the expression is as follows:

[0155] T=f url =[ t 1 , t 2 ,…, t i ,…, t len(T) ] ,

[0156] After preliminary word segmentation, BERT word segmenter is used to Perform embedding processing;

[0157] 62) Perform word embedding processing: In order to mark the beginning and end of the input sequence, Add the [CLS] tag at the beginning and the [SEP] tag at the end, and limit the token sequence length to 128. For input sequences that are less than 128 tokens long, use a specific padding tag [PAD] to extend the sequence length until it reaches the limit of 128 tokens. [ CLS , T, SEP , PAD ,…,[PAD]] ;

[0158] 63) Perform segment embedding processing: Set all segment embeddings to 0, that is:

[0159] [ CLS , T, SEP , PAD ,…,[PAD]] Add to [0,0,0,…,0,0] of the same length;

[0160] 64) Perform position embedding processing: Position embedding is based on The different position information of the tokens in the URL-BERT model are encoded into position vectors, and the position relationship of the tokens is introduced into the URL-BERT model. The position embeddings are all set to 0, that is:

[0161] The sequence processed by segment embedding is added to a sequence of the same length with all zeros;

[0162] 65) Generate attention mask vector: Use the attention mask vector to distinguish the actual tokens from the padding tokens in the input sequence.

[0163] For each real token in the sequence, its corresponding attention is set to 1; for each padding token [PAD], its corresponding attention is set to 0; generate the attention mask , where the number of 1s is Right now:

[0164] The sequence processed by position embedding is added to the sequence [1,1,1,…,0,0].

[0165] The character level embedding comprises the following steps:

[0166] 71) Input sequence representation: First, for the input sequence Each of these is the marker for the subword segmentation, is the total number of subwords in the sequence, each token By Character Composition, of which Indicates the length of the subword,

[0167] The total length of the character input is expressed as ;

[0168] 72) Character vector generation: For each character , both generate a character embedding vector ,

[0169] This is done by With the character embedding matrix Multiply to complete, , which maps each character to a vector representation in a high-dimensional space;

[0170] 73) BiGRU processing: generated character embedding vector It is sent to BiGRU for processing. The result of the BiGRU operation is to generate a hidden state vector for each character. ,

[0171] , the hidden state vector Contains contextual information about the characters;

[0172] 74) Construct character-level embeddings: For each token , whose character-level embedding vectors form a sequence , this sequence is processed into a token-level embedding vector ;

[0173] For each tag , concatenate the hidden state vectors of the first and last characters to get the token-level embedding vector By processing the characters of the entire input sequence, we obtain the context character embedding vector of each token, that is, the embedding vector at the domain name character level , which is expressed as follows:

[0174] .

[0175] Beneficial Effects

[0176] The present invention discloses a method for detecting malicious domain names based on a large language model. Compared with the prior art, the large language model BERT is used to process malicious domain names. By utilizing the powerful semantic understanding ability of the large language model, the implicit information and context in the domain name can be better captured, and the recognition accuracy of malicious domain names can be improved. At the same time, the position embedding technology is introduced during pre-training, and the importance of the position information of the token in the domain name for representation is fully considered. By combining the position information with the semantic vector of the token, the meaning of the token at different positions can be expressed more accurately, thereby improving the detection performance of the model for malicious domain names.

[0177] The present invention also uses BiGRU to extract character-level embeddings, making full use of bidirectional information to better capture finer-grained contextual information, thereby more comprehensively understanding URL data and improving the accuracy and expressiveness of embeddings.

[0178] Compared with the traditional feature extraction method based on machine learning, the present invention can avoid manual feature design and can automatically learn higher-level feature representation. This end-to-end training method can better adapt to the changes and complexity of data, thereby improving the generalization performance and transferability of the model and improving the ability to deal with adversarial attacks. Compared with the deep learning method, the present invention introduces position embedding to improve the model's ability to process sequence data. At the same time, pre-training tasks are used to maximize the generalization and transfer capabilities of the model. Even when faced with new malicious domain name classification tasks, the model can quickly adapt and achieve good results.

[0179] In summary, the malicious domain name detection method based on large language models has obvious advantages in accuracy and universality. BRIEF DESCRIPTION OF THE DRAWINGS

[0180] Figure 1 is a method sequence diagram of the present invention;

[0181] Figure 2 It is a URL structure diagram in the prior art;

[0182] Figure 3 This is the structural diagram of the BiGRU network;

[0183] Figure 4 It is a structural diagram of the heterogeneous interaction layer;

[0184] Figure 5 This is the overall architecture diagram of the model. DETAILED DESCRIPTION

[0185] In order to have a further understanding and recognition of the structural features and the effects achieved by the present invention, a preferred embodiment and accompanying drawings are used for detailed description as follows:

[0186] Traditional detection methods based on feature engineering are difficult to achieve good results when facing complex network changes. Secondly, the same token in the domain name should have different meanings and representation methods when located in the Domain / TLD / Path, that is, the token of the domain name is position sensitive. Existing studies regard domain names as plain text sequences and apply language models to characterize domain names. Many studies use the "bag of words" model to model domain name tags and extract lexical features, such as using n-gram features for domain name classification, completely ignoring the position sensitivity of tokens.

[0187] This paper pre-trains BERT with unlabeled domain name data, and then effectively combines the character-level embedding features and tag-level embedding features of the domain name to fine-tune URL-BERT. The context understanding ability and location sensitivity of the BERT model are used to capture the deep semantic information of the domain name, avoiding the heavy reliance on manually defined rules or features in the purely feature-based methods.

[0188] like Figure 1 As shown, the malicious domain name detection method based on a large language model described in the present invention includes the following steps:

[0189] The first step is to build a pre-training dataset and a fine-tuning training dataset: build a pre-training dataset and a fine-tuning training dataset, and perform data preprocessing.

[0190] (1) Set a pre-training dataset, which is unlabeled domain name data. The unlabeled domain name data is obtained from public DNS query logs and WHOIS database sources.

[0191] (2) Set a fine-tuning training dataset. The fine-tuning training dataset is labeled domain name data. The labeled domain name data is obtained from a network security company or a public malicious domain name database, in which the number of positive samples and negative samples is balanced.

[0192] (3) The pre-training dataset and fine-tuning training dataset are preprocessed by removing duplicates, removing irrelevant characters, converting to lowercase letters, and standardizing.

[0193] (4) Perform word segmentation on the pre-processed pre-training dataset and fine-tuning training dataset. This includes the following steps:

[0194] For the domain name data in the pre-training dataset and the fine-tuning training dataset, the word segmentation operation splits the entire domain name string according to its structural characteristics, removes special characters in the domain name, and uses " / ", ".", and "-" as delimiters to segment the domain name:

[0195] Enter a pre-processed domain name , define a word segmentation function f to represent this process:

[0196] ,

[0197] The input of the word segmentation function f() is a preprocessed domain name in string form, and the output is a word segmentation list consisting of the fragments of the domain name after word segmentation. ,in , for The number of words in the expression is as follows:

[0198] T=f url =[ t 1 , t 2 ,…, t i ,…, t len(T) ] ,

[0199] After preliminary word segmentation, BERT word segmenter is used to Perform embedding processing;

[0200] Perform word embedding processing: In order to mark the beginning and end of the input sequence, Add the [CLS] tag at the beginning and the [SEP] tag at the end, and limit the token sequence length to 128. For input sequences that are less than 128 tokens long, use a specific padding tag [PAD] to extend the sequence length until it reaches the limit of 128 tokens. [ CLS , T, SEP , PAD ,…,[PAD]] ;

[0201] Perform segment embedding processing: set all segment embeddings to 0, that is:

[0202] [ CLS , T, SEP , PAD ,…,[PAD]] Add to [0,0,0,…,0,0] of the same length;

[0203] Perform position embedding processing: Position embedding is based on The different position information of the tokens in the URL-BERT model are encoded into position vectors, and the position relationship of the tokens is introduced into the URL-BERT model. The position embeddings are all set to 0, that is:

[0204] The sequence processed by segment embedding is added to a sequence of the same length with all zeros;

[0205] Generate an attention mask vector: Use the attention mask vector to distinguish between actual tokens and padding tokens in the input sequence,

[0206] For each real token in the sequence, its corresponding attention is set to 1; for each padding token [PAD], its corresponding attention is set to 0; generate the attention mask , where the number of 1s is Right now:

[0207] The sequence processed by position embedding is added to the sequence [1,1,1,…,0,0].

[0208] The second step is to set up the URL-BERT model.

[0209] Here, the overall architecture of the model is designed. Taking into account the particularity of domain name text, multiple aspects such as character-level and tag-level feature extraction, feature fusion and classification are comprehensively considered to design a comprehensive model structure.

[0210] In the pre-training stage, the URL-BERT model is pre-trained on large-scale unlabeled domain name data through the MLM task, learning to capture the rich semantic information and structural features in the domain name text; in the feature extraction and fusion stage, a suitable feature extraction method is designed to integrate character-level and tag-level features, and the Transformer layer is used to capture the complex relationship between features to improve the model's representation ability and classification performance.

[0211] The benefit of this design is that it can comprehensively utilize information at different levels, thereby improving the model's representation ability and classification performance. Character-level embedding features can capture fine-grained features of domain name text, such as the semantic information and order relationship of individual characters; while token-level embedding features can capture higher-level semantic information. Through feature fusion, the model can take into account features at both levels at the same time, allowing the model to more comprehensively understand the meaning of domain name text.

[0212] In the URL-BERT architecture design, feature fusion can comprehensively utilize character-level and token-level embedded features, enabling the model to more comprehensively understand the domain name text; while Transformer can handle long-distance dependencies in domain name text and better capture contextual information. These advantages work together to improve the accuracy and generalization ability of the URL-BERT model in malicious domain name detection tasks.

[0213] The specific steps are as follows:

[0214] (1) If Figure 5 As shown, the URL-BERT model is set to include an input layer, a URL-BERT pre-training layer, a character-level embedding feature extraction layer, a token-level embedding feature extraction layer, a feature fusion layer, and a fully connected classification layer;

[0215] Set the input layer: The input layer receives the text after word segmentation as the input of the model.

[0216] (2) Setting the URL-BERT pre-training layer: In the pre-training stage, the MLM task is set to train a large amount of unlabeled domain name data to learn and capture the rich semantic information and structural features in the domain name text.

[0217] (3) Setting the character-level embedding feature extraction layer: The character-level embedding extraction layer extracts the character-level embedding of the domain name text and uses BiGRU to generate a bidirectional vector representation, which contains the complex association information between the characters within the domain name; fine-tuning the training dataset, such as Figure 3 As shown in Figure 1, the bidirectional gating unit BiGRU is used to extract the character-level embedding of the labeled domain name data. BiGRU uses two GRUs in different directions to combine the hidden layer states in the forward and backward directions, thereby integrating the bidirectional information and obtaining the domain name character-level embedding vector. .

[0218] (4) Set the tag level embedding feature extraction layer and perform tag level embedding.

[0219] (5) Setting the feature fusion layer:

[0220] The feature fusion layer concatenates the extracted character-level embedding feature vectors and token-level embedding feature vectors, and then introduces multiple Transformer layers to capture the complex relationship between features;

[0221] The heterogeneous interaction module between Transformer layers is used to combine and separate character-level embeddings and token-level embeddings after each Transformer layer. The combination operation enriches the correlation between different representations, and the separation operation preserves the independence of character-level and token-level features, which promotes the performance of the model in dual-channel distinction.

[0222] (6) Setting the fully connected classification layer: The fully connected classification layer is used to fine-tune the entire URL-BERT model to adapt to the specific malicious domain name detection task. The feature vector output by the feature fusion layer is input into the fully connected layer, and the loss function is minimized through the back propagation algorithm.

[0223] The third step is pre-training of the URL-BERT model: pre-train the URL-BERT model using the pre-training dataset.

[0224] The present invention uses a large amount of unlabeled domain name data to pre-train BERT (Bidirectional Encoder Representations from Transformers) to obtain the URL-BERT model. The URL-BERT model will learn the rich semantic information and structural features in the domain name data through self-supervised learning, understand the semantic relations, lexical rules and structural features in the domain name text, and provide more in-depth and comprehensive language understanding capabilities for subsequent malicious domain name detection tasks.

[0225] The pre-training process involves knowledge in multiple fields such as natural language processing and deep learning. This improves the effect and efficiency of natural language processing applied to URLs, and can greatly improve the accuracy of the model's understanding of URL text and the model's downstream generalization ability. At the same time, pre-training reduces the training cost of the model, shortens the training time, and can effectively utilize the existing URL database to improve data utilization.

[0226] (1) Input the text after word segmentation processing of the pre-training dataset into the URL-BERT model.

[0227] (2) The URL-BERT pre-training layer performs Masked Language Model pre-training, i.e., MLM pre-training:

[0228] set up is randomly replaced with [MASK] A small part of the token sequence in 15% of the tokens are randomly [MASK], among which Indicates that the i-th token is randomly replaced. The goal of the MLM pre-training process is to predict the content of the [MASK] token based on the context;

[0229] Will Input into the URL-BERT model, The corresponding hidden vector , Depend on Encoded by BERT’s encoder;

[0230] A1) Encoder processing: The input data of the encoding input layer is the embedding vector ;

[0231] A2) Self-Attention Mechanism:

[0232] Enter Obtain the query matrix through linear transformation , key matrix K and value matrix ,in , , are the hyperparameters of the encoder:

[0233] ,

[0234] ,

[0235] ,

[0236] The attention weights are then calculated using scaled dot product attention. The output produced by this step contains a representation of the global dependencies within the input sequence.

[0237] in is the dimension of the key vector, used to scale the dot product to prevent the vanishing gradient problem, is the attention weight matrix, is the output of the attention mechanism of a head,

[0238] ,

[0239] Output of multi-head attention:

[0240] The outputs of multiple heads are concatenated and then passed through another linear transformation. The formula is as follows:

[0241] ,

[0242] in, It is The output of the head, is a hyperparameter matrix;

[0243] A3) Feedforward Neural Network:

[0244] The output of the multi-head attention is further processed with a feedforward neural network, which consists of two linear layers and an activation function.

[0245] ,

[0246] in , , , is a learnable parameter;

[0247] Residual connections and layer normalization: used to enhance the training stability and convergence speed of the model.

[0248] ,

[0249] here Representation layer normalization operation;

[0250] Encoder output layer: finally outputs the encoder’s encoded sequence ;

[0251] then, After Sigmoid operation, the corresponding token distribution is obtained;

[0252] The formula for the MLM process is as follows,

[0253] ,

[0254] in Represents the target probability distribution, that is, the entire sequence The probability distribution of represents the predicted probability of the i-th token given all the tokens in the sequence, represents the model parameters, Indicates whether the i-th token is [MASK]. If the i-th token is [MASK], then , otherwise The purpose is to weight the [MASK] tokens, which have an impact on the probability of the entire sequence;

[0255] In MLM pre-training, the goal is to maximize the model's Based on this prediction, the cross entropy loss function is calculated and the model parameters are updated through the back propagation algorithm. , and finally get the pre-trained model ,

[0256] ,

[0257] in, are model parameters, is the cross entropy loss function, is the true label of the ith token. If the token is [MASK], it is the true value of the token. is the predicted probability of the i-th token, that is , minimizing the loss function through the back-propagation algorithm , update the model parameters , and finally get the pre-trained URL-BERT model .

[0258] Step 4: Fine-tune the URL-BERT model: Use the fine-tuning training dataset to fine-tune the pre-trained URL-BERT model.

[0259] The fine-tuning step requires optimization and adjustment of the model, mainly training each module in the feature fusion layer, selecting appropriate hyperparameters, and adjusting the learning ability of the model to achieve the best fine-tuning effect. The fine-tuning process of the model further improves the classification accuracy of malicious domain name detection on the basis of pre-training. Through the application of feature fusion and Transformer, the model has better feature expression and text modeling capabilities, which can accelerate the classification efficiency of malicious domain name detection. At the same time, the fine-tuning process can be applied to multiple fields, such as malicious family classification of URLs, multi-classification of URLs, judgment of URL pair relationships, generation of adversarial samples, etc., and has broad application prospects.

[0260] This method effectively combines the character-level features and token-level features of domain names through fine-tuning. Character features capture the sequential relationship information of domain name text at the level of individual characters, which intuitively reflects the important information of domain name text without relying on semantic understanding; using the contextual understanding ability and position sensitivity of the BERT model, deep semantic information of domain names is captured through token-level features, avoiding the heavy reliance on manually defined rules or features in purely feature-based methods.

[0261] (1) Training the character-level embedding feature extraction layer and the token-level embedding feature extraction layer to perform character-level embedding;

[0262] Performing character-level embedding involves the following steps:

[0263] Input sequence representation: First, for the input sequence , where each is the marker for the subword segmentation, is the total number of subwords in the sequence, each token By Character Composition, of which Indicates the length of the subword,

[0264] The total length of the character input is expressed as ;

[0265] Character vector generation: For each character , both generate a character embedding vector ,

[0266] This is done by With the character embedding matrix Multiply to complete, , which maps each character to a vector representation in a high-dimensional space;

[0267] BiGRU Processing: Generated Character Embedding Vectors It is sent to BiGRU for processing. The result of the BiGRU operation is to generate a hidden state vector for each character. ,

[0268] , the hidden state vector Contains contextual information about the characters;

[0269] Constructing character-level embeddings: For each token , whose character-level embedding vectors form a sequence , this sequence is processed into a token-level embedding vector ;

[0270] For each tag , concatenate the hidden state vectors of the first and last characters to get the token-level embedding vector By processing the characters of the entire input sequence, we obtain the context character embedding vector of each token, that is, the embedding vector at the domain name character level , which is expressed as follows:

[0271] .

[0272] The fine-tuning dataset is segmented to form a segmentation sequence on the one hand, After embedding at the character level feature extraction layer, we get the embedding vector ;on the other hand After the tag level embedding feature extraction layer embedding, that is Embedding of the pre-trained model, plus the attention mask vector , perform position embedding processing to obtain the tag-level embedding vector with position embedding ;

[0273] Finally, the token level embedding vector With character-level embedding vectors Connected together, that is, Vector end concatenation vector, forming a longer embedding vector ,

[0274] .

[0275] (2) Setting the feature fusion layer: Setting the feature fusion layer as the model ,Model Model containing a frozen parameter layer, multiple Transformer layers, multiple heterogeneous interaction layers, a fully connected layer and a Sigmoid layer; through the interaction between modules, the feature fusion layer can capture the complex relationship between the URL character level and the tag level;

[0276] Train the feature fusion layer:

[0277] B1) Model with frozen parameters The layer is the pre-trained URL-BERT model ,

[0278] B2) Set up the Transformer module:

[0279] Transformer consists of an encoder and a decoder. The encoder is used to process input data, and the decoder is responsible for generating output.

[0280] The encoder includes an encoding input layer, self-attention mechanism, multi-head attention, feedforward neural network, residual connection and layer normalization, and encoder output layer;

[0281] The decoder includes a decoding input layer, a self-attention mechanism, an encoder-decoder attention mechanism, a feedforward neural network, residual connections and layer normalization, and a decoder output layer;

[0282] B21) Encoder processing: The input data of the encoding input layer is the embedding vector ;

[0283] Self-Attention Mechanism:

[0284] For each head , enter Obtain the query matrix through linear transformation , key matrix Sum Matrix ,in , , , are the hyperparameters of the encoder:

[0285] ,

[0286] ,

[0287] ,

[0288] Next, attention weights are calculated for each head using scaled dot product attention. The output produced by this step contains a representation of the global dependencies within the input sequence.

[0289] in is the dimension of the key vector, used to scale the dot product to prevent the vanishing gradient problem. is the attention weight matrix, is the output of the attention mechanism of a head,

[0290]

[0291] Output of multi-head attention:

[0292] The outputs of multiple heads are concatenated and then passed through another linear transformation. The formula is as follows:

[0293] ,

[0294] in, is the output of each attention head, is a hyperparameter matrix;

[0295] Feedforward Neural Network:

[0296] The output of the multi-head attention is further processed with a feedforward neural network, which consists of two linear layers and an activation function.

[0297] ,

[0298] in , , , is a learnable parameter;

[0299] Residual connections and layer normalization: used to enhance the training stability and convergence speed of the model.

[0300] ,

[0301] here Representation layer normalization operation;

[0302] Encoder output layer: finally outputs the encoder’s encoded sequence ;

[0303] B22) Decoder processing:

[0304] The input data of the decoder input layer is an embedded vector ;

[0305] Self-Attention Mechanism: Obtain the query matrix through linear transformation , key matrix Sum Matrix ,in , , , is the decoder hyperparameter,

[0306] ,

[0307] ,

[0308] ,

[0309] Calculate attention weights for each head, using scaled dot product attention;

[0310] The outputs of multiple heads are concatenated, and the self-attention output of the decoder is obtained through residual connection and layer normalization. ;

[0311] Encoder-decoder attention mechanism: The decoder performs attention calculations on the encoder's output to capture the relationship between the input sequence and the output sequence, allowing the decoder to adjust its own attention based on the encoder's information to generate the target sequence;

[0312] For each position of the decoder , using the decoder output As a query, the encoder output , As keys and values, calculate the attention weights:

[0313] ,

[0314] ,

[0315] Output of multi-head attention: combine the decoder's self-attention output and the encoder-decoder attention output to get the final attention output;

[0316] Add them element-wise weighted, and the expression is as follows:

[0317] ,

[0318] Among them, the final attention output is , is a learnable weight parameter:

[0319] Feedforward neural network: The final attention output is A feed-forward neural network is then processed to further extract and transform feature representations:

[0320] ;

[0321] Residual connections and layer normalization: Residual connections and layer normalization are applied to the output of the feedforward neural network to enhance the training stability and convergence speed of the model:

[0322] ,

[0323] Decoder Output: The output sequence of the decoder is ;

[0324] B3) Setting up heterogeneous interaction modules: Figure 4 As shown in the figure, the token-level and character-level representations are treated as two different types of feature representations in the heterogeneous interaction layer. After each Transformer conversion layer, the two representations are combined and separated.

[0325] The fully connected network is responsible for mapping the token and character representations into the same feature space to ensure that they have consistent dimensions and semantic representations, which are then connected and integrated through the CNN layer, and finally through residual connections and layer normalization operations;

[0326] B31) Separation and combination processing:

[0327] The decoder output vector Separate into token-level representations by length and character-level representation , Indicates the mark / character representation of the i-th position, respectively and Apply a dedicated fully connected layer for transformation:

[0328] ,

[0329] ,

[0330] The converted token and character representations are then concatenated to form a fused representation:

[0331] w i x =[ h i ' x ; t i ' x ] ;

[0332] B32) CNN convolution: representation of fusion Apply CNN operations to integrate features.

[0333] ,

[0334] in, Indicates from arrive Embedded splicing, represents the window size of the jth filter;

[0335] B33) Separation: The combination after convolution is represented Separated into two different channels of feature representation,

[0336] ,

[0337] ,

[0338] Among them, GELU is an activation function used to separate the fused feature representation;

[0339] B34) Residual connections and layer normalization: The separated feature representations are added to the initial token and character representations to reconstruct the representations of the two channels:

[0340] ,

[0341] ,

[0342] Finally, the reorganized representation is layer normalized to ensure stability:

[0343] ,

[0344] ,

[0345] The separated features will be connected to get the input of the next layer of Transformer;

[0346] B4) Set up fully connected and Sigmoid classification modules:

[0347] Train the fully connected layer:

[0348] The output of the last layer of Transformer Pass to The fully connected layer of hidden units is mathematically expressed as follows

[0349] ,

[0350] in, is the input vector, and are the weights and biases of the layer, is the activation function;

[0351] Sigmoid is used to map the output of the fully connected layer to the category probability distribution. The Sigmoid layer maps the output of the fully connected layer to the category probability distribution. Passed to the Sigmoiod function, the Sigmoid function maps the input real value to a probability value between 0 and 1. The output of the fully connected layer is , the output after the Sigmoid function is expressed as:

[0352] .

[0353] (3) URL-BERT model fine-tuning process:

[0354] Embed the token-level vector of the fine-tuning dataset With character-level embedding vectors The processed embedding vector , using the pre-trained URL-BERT model The fine-tuned model constructed By feeding data into the model , compare the output result with the true label, then calculate the loss function, update the model parameters through the back-propagation algorithm, iteratively train the model until convergence, so that the fine-tuned URL-BERT model can classify malicious domain names.

[0355] Step 5: Obtain the domain name to be tested: obtain the domain name to be tested.

[0356] Step 6: Obtain malicious domain name detection results: Input the domain name to be detected into the fine-tuned URL-BERT model to obtain malicious domain name detection results.

[0357] The present invention proposes a malicious domain name detection method based on the BERT model. Compared with the traditional detection method based on rules and blacklists, the present invention can understand the semantic information and contextual relationship of the domain name at a deeper level, thereby greatly improving the recognition accuracy of malicious domain names. By combining character-level embedding and tag-level embedding, the present method introduces location information and captures the information relationship between different dimensions, further enhancing the model's ability to understand the domain name structure; secondly, the pre-trained BERT model, as a tag-level feature extractor, can utilize the rich language knowledge learned from large-scale pre-training data. By introducing the feature fusion layer, the present invention can flexibly adapt to the specific needs of malicious domain name classification tasks, and provides a malicious domain name detection solution that is both efficient and accurate. In general, the method of the present invention has the advantages of high efficiency, accuracy, and ease of implementation, and has a positive effect on improving the level of network security protection.

[0358] The method described in the present invention takes domain names as the research object. As a special text, domain names can capture the relationship between character-level features and tag-level features of domain names with the help of the powerful representation ability of large language models, and mine the features of domain names from different scales, providing an innovative solution for malicious domain name detection.

[0359] The above shows and describes the basic principles, main features and advantages of the present invention. Those skilled in the art should understand that the present invention is not limited to the above embodiments. The above embodiments and descriptions only describe the principles of the present invention. The present invention may be subject to various changes and improvements without departing from the spirit and scope of the present invention. These changes and improvements fall within the scope of the present invention. The scope of protection claimed by the present invention is defined by the attached claims and their equivalents.

Claims

1. A method for detecting malicious domain names based on a large language model, characterized in that: The following steps are involved: 11) Construction of pre-training dataset and fine-tuning training dataset: Construct pre-training dataset and fine-tuning training dataset, and perform data preprocessing; 12) Set up the URL-BERT model; The setting of the URL-BERT model includes the following steps: 121) The URL-BERT model is set to include an input layer, a URL-BERT pre-training layer, a character-level embedding feature extraction layer, a token-level embedding feature extraction layer, a feature fusion layer, and a fully connected classification layer; Set the input layer: The input layer receives the text after word segmentation as the input of the model; 122) Setting URL-BERT pre-training layer: In the pre-training stage, the MLM task is set to train a large amount of unlabeled domain name data to learn and capture the rich semantic information and structural features in the domain name text; 123) Set the character-level embedding feature extraction layer: The character-level embedding extraction layer extracts the character-level embedding of the domain name text, and uses BiGRU to generate a bidirectional vector representation, which contains the complex correlation information between the characters within the domain name; for the fine-tuning training data set, the bidirectional gated unit BiGRU is used to extract the character-level embedding of the labeled domain name data. BiGRU uses two GRUs in different directions to combine the hidden layer states in the forward and backward directions, thereby integrating the bidirectional information and obtaining the domain name character-level embedding vector ; 124) Setting a tag level embedding feature extraction layer to perform tag level embedding; 125) Set the feature fusion layer: The feature fusion layer concatenates the extracted character-level embedding feature vectors and token-level embedding feature vectors, and then introduces multiple Transformer layers to capture the complex relationship between features; A heterogeneous interaction module between Transformer layers, which is used to combine and separate character-level embeddings and token-level embeddings after each Transformer layer. The combination operation enriches the correlation between different representations, and the separation operation preserves the independence of character-level and token-level features, which promotes the model's performance in dual-channel discrimination. 126) Set the fully connected classification layer: The fully connected classification layer is used to fine-tune the entire URL-BERT model to adapt to the specific malicious domain name detection task. The feature vector output by the feature fusion layer is input into the fully connected layer, and the loss function is minimized through the back propagation algorithm; 13) Pre-training of URL-BERT model: Pre-train the URL-BERT model using the pre-training dataset; The pre-training of the URL-BERT model includes the following steps: 131) Input the text after word segmentation of the pre-training dataset into the URL-BERT model; 132) The URL-BERT pre-training layer performs Masked Language Model pre-training, i.e., MLM pre-training: set up is randomly replaced with [MASK] A small part of the token sequence in 15% of the tokens are randomly [MASK], among which Indicates that the i-th token is randomly replaced. The goal of the MLM pre-training process is to predict the content of the [MASK] token based on the context; Will Input into the URL-BERT model, The corresponding hidden vector , Depend on Encoded by BERT’s encoder; 1321) Encoder processing: The input data of the encoding input layer is the embedding vector ; 1322) Self-attention mechanism: enter Obtain the query matrix through linear transformation , key matrix K and value matrix ,in , , are the hyperparameters of the encoder: , , , The attention weights are then calculated using scaled dot product attention. The output produced by this step contains a representation of the global dependencies within the input sequence. in is the dimension of the key vector, used to scale the dot product to prevent the vanishing gradient problem, is the attention weight matrix, is the output of an attention head, , Output of multi-head attention: The outputs of multiple heads are concatenated and then passed through another linear transformation. The formula is as follows: , in, It is The output of the head, is a hyperparameter matrix; 1323) Feedforward Neural Network: The output of the multi-head attention is further processed with a feedforward neural network, which consists of two linear layers and an activation function. , in , , , is a learnable parameter; Then, residual connection and layer normalization are performed to enhance the training stability and convergence speed of the model: , here Representation layer normalization operation; Encoder output layer: finally outputs the encoder’s encoded sequence ; then, After Sigmoid operation, the corresponding token distribution is obtained; The formula for the MLM process is as follows, , in Represents the target probability distribution, that is, the entire sequence The probability distribution of represents the predicted probability of the i-th token given all the tokens in the sequence, represents the model parameters, Indicates whether the i-th token is [MASK]. If the i-th token is [MASK], then , otherwise The purpose is to weight the [MASK] tokens, which have an impact on the probability of the entire sequence; In MLM pre-training, the goal is to maximize the model's Based on this prediction, the cross entropy loss function is calculated and the model parameters are updated through the back propagation algorithm. , and finally get the pre-trained model , , in, are model parameters, is the cross entropy loss function, is the true label of the ith token. If the token is [MASK], it is the true value of the token. is the predicted probability of the i-th token, that is Minimize the loss function by back-propagation algorithm Update model parameters , and finally obtain the pre-trained URL-BERT model M; 14) Fine-tuning the URL-BERT model: Fine-tune the pre-trained URL-BERT model using the fine-tuning training dataset; 15) Obtaining the domain name to be tested: obtaining the domain name to be tested; 16) Obtaining malicious domain name detection results: Input the domain name to be detected into the fine-tuned URL-BERT model to obtain malicious domain name detection results.

2. According to claim 1, a method for detecting malicious domain names based on a large language model is characterized in that: The construction of the pre-training dataset and the fine-tuning training dataset includes the following steps: 21) Set a pre-training data set, which is unlabeled domain name data. The unlabeled domain name data is obtained from public DNS query logs and WHOIS database sources; 22) Set a fine-tuning training data set, which is labeled domain name data. The labeled domain name data is obtained from a network security company or a public malicious domain name database, where the number of positive samples and negative samples is balanced; 23) Pre-process the pre-training dataset and fine-tuning training dataset by removing duplicates, removing irrelevant characters, converting to lowercase letters, and standardizing; 24) Perform word segmentation on the preprocessed pre-training dataset and fine-tuning training dataset.

3. According to claim 1, a method for detecting malicious domain names based on a large language model is characterized in that: Fine-tuning the URL-BERT model includes the following steps: 31) Training of character-level embedding feature extraction layer and token-level embedding feature extraction layer to perform character-level embedding; The fine-tuning dataset is segmented to form a segmentation sequence on the one hand, After embedding at the character level feature extraction layer, we get the embedding vector ;on the other hand After the tag level embedding feature extraction layer embedding, that is Embedding of the pre-trained model, plus the attention mask vector , perform position embedding processing to obtain the tag-level embedding vector with position embedding ; Finally, the token level embedding vector With character-level embedding vectors Connected together, that is, Vector end concatenation vector, forming a longer embedding vector , ; 32) Set the feature fusion layer: Set the feature fusion layer as the model ,Model Model containing a frozen parameter layer, multiple Transformer layers, multiple heterogeneous interaction layers, a fully connected layer and a Sigmoid layer; through the interaction between modules, the feature fusion layer can capture the complex relationship between the URL character level and the tag level; Train the feature fusion layer: 321) Setting the model of frozen parameters The layer is the pre-trained URL-BERT model , 322) Set up the Transformer module: Transformer consists of an encoder and a decoder. The encoder is used to process input data, and the decoder is responsible for generating output. The encoder includes an encoding input layer, self-attention mechanism, multi-head attention, feedforward neural network, residual connection and layer normalization, and encoder output layer; The decoder includes a decoding input layer, a self-attention mechanism, an encoder-decoder attention mechanism, a feedforward neural network, residual connections and layer normalization, and a decoder output layer; 3221) Encoder processing: The input data of the encoding input layer is the embedding vector ; Self-Attention Mechanism: For each head , enter Obtain the query matrix through linear transformation , key matrix Sum Matrix ,in , , , are the hyperparameters of the encoder: , , , Next, attention weights are calculated for each head using scaled dot product attention. The output produced by this step contains a representation of the global dependencies within the input sequence. in is the dimension of the key vector, used to scale the dot product to prevent the vanishing gradient problem, is the attention weight matrix, is the output of the attention mechanism of a head, , Output of multi-head attention: The outputs of multiple heads are concatenated and then passed through another linear transformation. The formula is as follows: , in, is the output of each attention head, is a hyperparameter matrix; Feedforward Neural Network: The output of the multi-head attention is further processed with a feedforward neural network, which consists of two linear layers and an activation function. , in , , , is a learnable parameter; Residual connections and layer normalization: used to enhance the training stability and convergence speed of the model. , here Representation layer normalization operation; Encoder output layer: finally outputs the encoder’s encoded sequence ; 3222) Decoder processing: The input data of the decoder input layer is an embedded vector ; Self-Attention Mechanism: Obtain the query matrix through linear transformation , key matrix Sum Matrix ,in , , , is the decoder hyperparameter, , , , Calculate attention weights for each head, using scaled dot product attention; The outputs of multiple heads are concatenated, and the self-attention output of the decoder is obtained through residual connection and layer normalization. ; Encoder-decoder attention mechanism: The decoder performs attention calculations on the encoder's output to capture the relationship between the input sequence and the output sequence, allowing the decoder to adjust its own attention based on the encoder's information to generate the target sequence; For each position of the decoder , using the decoder output As a query, the encoder output , As keys and values, calculate the attention weights: , , Output of multi-head attention: combine the decoder's self-attention output and the encoder-decoder attention output to get the final attention output; Add them element-wise weighted, and the expression is as follows: , Among them, the final attention output is , is a learnable weight parameter: Feedforward neural network: The final attention output is A feed-forward neural network is then processed to further extract and transform feature representations: ; Residual connections and layer normalization: Residual connections and layer normalization are applied to the output of the feedforward neural network to enhance the training stability and convergence speed of the model: , Decoder Output: The output sequence of the decoder is ; 323) Set up a heterogeneous interaction module: In the heterogeneous interaction layer, the token-level and character-level representations are treated as two different types of feature representations. After each Transformer conversion layer, these two representations are combined and separated; The fully connected network is responsible for mapping the token and character representations into the same feature space to ensure that they have consistent dimensions and semantic representations, which are then connected and integrated through the CNN layer, and finally through residual connections and layer normalization operations; 3231) Separation and combination processing: The decoder output vector Separate into token-level representations by length and character-level representation , Indicates the mark / character representation of the i-th position, respectively and A dedicated fully connected network is used to convert: , , The converted token and character representations are then concatenated to form a fused representation: ; 3232) CNN convolution: representation after fusion Apply CNN operations to integrate features. , in, Indicates from arrive Embedded splicing, represents the window size of the jth filter; 3233) Separation: The combination after convolution is represented Separated into two different channels of feature representation, , , Among them, GELU is an activation function used to separate the fused feature representation; 3234) Residual connections and layer normalization: The separated feature representations are added to the initial token and character representations to reconstruct the representations of the two channels: , , Finally, the reorganized representation is layer normalized to ensure stability: , , The separated features will be connected to get the input of the next layer of Transformer; 324) Set up fully connected and Sigmoid classification modules: Train the fully connected layer: The output of the last layer of Transformer Pass to The fully connected layer of hidden units is mathematically expressed as follows: , in, is the input vector, and are the weights and biases of the layer, is the activation function; Sigmoid is used to map the output of the fully connected layer to the category probability distribution. The Sigmoid layer maps the output of the fully connected layer to the category probability distribution. Passed to the Sigmoiod function, the Sigmoid function maps the input real value to a probability value between 0 and 1. The output of the fully connected layer is , the output after the Sigmoid function is expressed as: ; 33) URL-BERT model fine-tuning process: Embed the token-level vector of the fine-tuning dataset With character-level embedding vectors The processed embedding vector , using the pre-trained URL-BERT model The fine-tuned model constructed By feeding data into the model , compare the output result with the true label, then calculate the loss function, update the model parameters through the back propagation algorithm, iteratively train the model until convergence, so that the fine-tuned URL-BERT model can classify malicious domain names.

4. According to claim 2, a method for detecting malicious domain names based on a large language model is characterized in that: The word segmentation processing of the pre-processed pre-training data set and the fine-tuning training data set comprises the following steps: 41) For the domain name data in the pre-training dataset and the fine-tuning training dataset, the word segmentation operation splits the entire domain name string according to its structural characteristics, removes special characters in the domain name, and uses " / ", "".", and "-" as delimiters to segment the domain name: Enter a pre-processed domain name , define a word segmentation function f to represent this process: , The input of the word segmentation function f() is a preprocessed domain name in string form, and the output is a word segmentation list consisting of the fragments of the domain name after word segmentation. ,in , for The number of words in the expression is as follows: , After preliminary word segmentation, BERT word segmenter is used to Perform embedding processing; 42) Perform word embedding processing: In order to mark the beginning and end of the input sequence, Add the [CLS] tag at the beginning and the [SEP] tag at the end, and limit the token sequence length to 128. For input sequences that are less than 128 tokens long, use a specific padding tag [PAD] to extend the sequence length until it reaches the limit of 128 tokens. ; 43) Perform segment embedding processing: Set all segment embeddings to 0, that is: Add to [0,0,0,…,0,0] of the same length; 44) Perform position embedding processing: Position embedding is based on The different position information of the tokens in the URL-BERT model are encoded into position vectors, and the position relationship of the tokens is introduced into the URL-BERT model. The position embeddings are all set to 0, that is: The sequence processed by segment embedding is added to a sequence of the same length with all zeros; 45) Generate attention mask vector: Use the attention mask vector to distinguish the actual tokens from the padding tokens in the input sequence. For each real token in the sequence, its corresponding attention is set to 1; for each padding token [PAD], its corresponding attention is set to 0; generate the attention mask , where the number of 1s is Right now: The sequence processed by position embedding is added to the sequence [1,1,1,…,0,0].

5. According to claim 3, a method for detecting malicious domain names based on a large language model is characterized in that: The character level embedding comprises the following steps: 51) Input sequence representation: First, for the input sequence Each of these is the marker for the subword segmentation, is the total number of subwords in the sequence, each token By Character Composition, of which Indicates the length of the subword, The total length of the character input is expressed as ; 52) Character vector generation: For each character , both generate a character embedding vector , This is done by With the character embedding matrix Multiply to complete, , which maps each character to a vector representation in a high-dimensional space; 53) BiGRU processing: generated character embedding vector It is sent to BiGRU for processing. The result of the BiGRU operation is to generate a hidden state vector for each character. , , the hidden state vector Contains contextual information about the characters; 54) Construct character-level embeddings: For each token , whose character-level embedding vectors form a sequence , this sequence is processed into a token-level embedding vector ; For each tag , concatenate the hidden state vectors of the first and last characters to get the token-level embedding vector By processing the characters of the entire input sequence, the context character embedding vector of each token is obtained, that is, the embedding vector at the domain name character level , which is expressed as follows: 。