A method, device, and medium for training a URL detection model

By employing an iterative cross-supervised training method using unlabeled sample URLs during the training process of the URL detection model, and by adjusting the model parameters using pseudo-labels and probabilities, the problem of low training efficiency is solved, and the training speed and accuracy of the model are improved.

CN117614672BActive Publication Date: 2026-11-24CHINA TELECOM NETWORK SECURITY TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311575506.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-11-23
Publication Date
2026-11-24
Estimated Expiration
2043-11-23

AI Technical Summary

Technical Problem

The training efficiency of existing URL detection models is low because the collection and labeling of training data takes a long time.

Method used

By iteratively training using unlabeled sample URLs in the training set, cross-pseudo-supervised training using the first and second sub-models, determining the loss value based on pseudo-labels and probabilities, and adjusting model parameters, training efficiency is improved.

Benefits of technology

This achievement improves the training efficiency of URL detection models under unlabeled data conditions, thereby enhancing the training speed and accuracy of the models.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117614672B_ABST
    Figure CN117614672B_ABST
Patent Text Reader

Abstract

This application relates to the field of network security technology, and in particular to a training method, apparatus, device, and medium for a URL detection model. During each iteration of training, a first preset number of sample URLs are obtained from the training set. A first sub-model of the initial detection model determines a first probability, and a second sub-model determines a second probability. A first pseudo-label is determined based on the first probability and a preset threshold, and a first loss value is determined based on the first pseudo-label and the second probability. A second pseudo-label is determined based on the second probability and the preset threshold, and a second loss value is determined based on the second pseudo-label and the first probability. The parameters of the first sub-model are adjusted based on the first and second loss values ​​corresponding to the first sample URLs, and the parameters of the second sub-model are adjusted based on the adjusted parameters of the first sub-model. This enables training of the initial URL detection model using unlabeled sample data, effectively improving the efficiency of model training.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of network security technology, and in particular to a training method, apparatus, device and medium for a URL detection model. Background Technology

[0002] With the rapid development of information technology, all industries are facing the challenge of cybersecurity vulnerabilities. When users access the network and visit unknown Uniform Resource Locators (URLs) or URLs disguised as legitimate but malicious ones, they may fall into the trap of cyber attackers, leading to the leakage of personal information or even financial losses. Therefore, how to efficiently and accurately detect whether the URLs accessed by users are safe and prevent users from accessing malicious URLs has become a hot research topic.

[0003] In related technologies, a pre-trained URL detection model is typically used to detect URLs and determine whether they are malicious. The traditional training process for URL detection models usually involves pre-labeling a large amount of training data and then using this large amount of training data to train the initial URL detection model. However, malicious URLs are generated very quickly, which means that the URL detection model needs to be retrained frequently to ensure that it can accurately identify malicious URLs. Collecting and labeling training data is very time-consuming, resulting in extremely low efficiency in retraining the URL detection model each time.

[0004] Therefore, improving the training efficiency of URL detection models has become an urgent problem to be solved. Summary of the Invention

[0005] This application provides a training method, apparatus, device, and medium for a URL detection model, which solves the problem of low training efficiency of URL detection models in the prior art due to the long time required for collecting and labeling training data.

[0006] Firstly, this application provides a method for training a URL detection model, the method comprising:

[0007] Obtain a training set, which includes the URLs of the first samples;

[0008] The initial detection model is trained iteratively for a predetermined number of rounds to obtain the URL detection model. Each iteration of training involves the following steps:

[0009] Obtain a first preset number of first sample URLs from the training set;

[0010] For each first sample URL, the first sample URL is input into the initial detection model, which extracts a first feature vector from the first sample URL. This first feature vector is then input into a first sub-model and a second sub-model to obtain a first probability output by the first sub-model and a second probability output by the second sub-model. Based on the first probability and a preset threshold, a first pseudo-label is determined, and based on the first pseudo-label and the recognition result corresponding to the second probability, a first loss value is determined. Based on the second probability and the preset threshold, a second pseudo-label is determined, and based on the second pseudo-label and the recognition result corresponding to the first probability, a second loss value is determined.

[0011] Based on the first loss value and the second loss value corresponding to the first sample URL of the first preset number, the parameters in the first sub-model are adjusted; and based on the adjusted parameters in the first sub-model and the preset weights, the parameters in the second sub-model are adjusted.

[0012] Furthermore, before inputting the first sample URL into the initial detection model, the method further includes:

[0013] Based on the pre-saved symbol identifiers, the first sample URL is segmented, each resulting string is treated as a word, and the word vector corresponding to each word is determined.

[0014] Based on the word vectors corresponding to each word, construct the first feature matrix corresponding to the first sample URL;

[0015] The step of inputting the first sample URL into the initial detection model includes:

[0016] The first feature matrix of the first sample URL is input into the initial detection model.

[0017] Furthermore, before inputting the first sample URL into the initial detection model, the method further includes:

[0018] Based on web crawling technology, obtain the running code of the webpage corresponding to the first sample URL;

[0019] The number of times each preset function is called in the running code is counted, and a corresponding first risk value is determined based on each number. The preset functions include at least one of the following: functions that inject content into the webpage, functions that do not need to be detected, text matching functions, and functions used to store sensitive user information.

[0020] The number of times a preset keyword appears in the running code is counted, and a corresponding second risk value is determined based on each occurrence. The preset keywords include at least one of the following: reserved keywords, standard keywords corresponding to preset language types, keywords corresponding to triggering events, and keywords corresponding to modifying Hypertext Markup Language (HTML).

[0021] The number of strings directly assigned in the running code is determined as the third risk value, and the entropy value of the running code is determined as the fourth risk value;

[0022] Based on each statistical risk value, construct the second feature vector corresponding to the first sample URL;

[0023] The step of inputting the first sample URL into the initial detection model includes:

[0024] The second feature vector is used as the URL of the first sample and input into the initial detection model.

[0025] Further, adjusting the parameters in the first sub-model based on the first loss value and the second loss value corresponding to the first preset number of first sample URLs includes:

[0026] The first detection error of the first sample URL is determined based on the difference between the first probability and the second probability corresponding to each first sample URL;

[0027] Based on the first detection error and the first loss value and the second loss value corresponding to the first sample URL of the first preset number, respectively, a first target loss value is determined, and the parameters in the first sub-model are adjusted based on the first target loss value.

[0028] Furthermore, the training set also includes a second sample URL and its corresponding label, the label being used to identify the probability that the corresponding second sample URL is a malicious URL; the following steps are also performed during each training iteration:

[0029] Obtain a second preset number of second sample URLs from the training set;

[0030] For each second sample URL, the second sample URL and its corresponding label are input into the initial detection model, and the initial detection model extracts the third feature vector of the second sample URL; the third feature vector is then input into the first sub-model to obtain the third probability output by the first sub-model; and the third loss value of the first sub-model is determined based on the label and the third probability.

[0031] The step of adjusting the parameters in the first sub-model according to the first loss value and the second loss value corresponding to the first sample URL of the first preset number of samples includes:

[0032] Based on the first loss value and the second loss value corresponding to the first sample URL of the first preset number of samples, and the third loss value corresponding to the second sample URL of the second preset number of samples, a second target loss value is determined, and the parameters in the first sub-model are adjusted based on the second target loss value.

[0033] Furthermore, after determining the third loss value of the first sub-model, and before adjusting the parameters in the first sub-model according to the first loss value and the second loss value corresponding to the first sample URL of the first preset number, the method further includes:

[0034] The third feature vector is input into the second sub-model to obtain the fourth probability output by the second sub-model;

[0035] The second detection error of the second preset number of second sample URLs is determined based on the difference between the third probability and the fourth probability corresponding to each second sample URL.

[0036] Based on the first loss value and the second loss value corresponding to the first sample URL of the first preset number of samples, and the third loss value corresponding to the second sample URL of the second preset number of samples, a second target loss value is determined, and the parameters in the first sub-model are adjusted based on the second target loss value, including:

[0037] Based on the second detection error, the first loss value and the second loss value corresponding to the first preset number of first sample URLs, and the third loss value corresponding to the second preset number of second sample URLs, a third target loss value is determined, and the parameters in the first sub-model are adjusted based on the third target loss value.

[0038] Furthermore, the first sub-model and the second sub-model have the same structure, and the adjustment of the parameters in the second sub-model based on the adjusted parameters in the first sub-model and the preset weights includes:

[0039] For each parameter to be adjusted in the second sub-model, a third parameter value is determined based on the first parameter value corresponding to the parameter to be adjusted in the second sub-model, the second parameter value corresponding to the parameter to be adjusted in the adjusted first sub-model, and the corresponding preset weight, and the first parameter value is updated using the third parameter value.

[0040] Secondly, this application provides a training apparatus for a URL detection model, the apparatus comprising:

[0041] The acquisition module is used to acquire a training set, which includes a first sample URL.

[0042] The training module is used to iterate the initial detection model for a preset number of rounds to obtain the URL detection model;

[0043] The training module is specifically configured to: acquire a first preset number of first sample URLs in the training set; input each first sample URL into the initial detection model, whereby the initial detection model extracts a first feature vector from the first sample URL; input the first feature vector into a first sub-model and a second sub-model respectively to obtain a first probability output by the first sub-model and a second probability output by the second sub-model; determine a first pseudo-label based on the first probability and a preset threshold, and determine a first loss value based on the recognition result corresponding to the first pseudo-label and the second probability; determine a second pseudo-label based on the second probability and the preset threshold, and determine a second loss value based on the recognition result corresponding to the second pseudo-label and the first probability; adjust the parameters in the first sub-model based on the first loss value and the second loss value corresponding to the first preset number of first sample URLs; and adjust the parameters in the second sub-model based on the adjusted parameters in the first sub-model and preset weights.

[0044] Furthermore, the device also includes:

[0045] The preprocessing module is used to segment the first sample URL according to the pre-saved symbol identifiers, treat each string as a word, and determine the word vector corresponding to each word; construct a first feature matrix corresponding to the first sample URL based on the word vector corresponding to each word; and input the first feature matrix of the first sample URL into the initial detection model.

[0046] Furthermore, the preprocessing module is also used to obtain the running code of the webpage corresponding to the first sample URL based on crawling technology; count the number of times each preset function is called in the running code, and determine the corresponding first risk value based on each count. The preset functions include at least one of the following: functions for injecting content into the webpage, functions that do not need to be detected, text matching functions, and functions for storing sensitive user information; count the number of times preset keywords appear in the running code, and determine the corresponding second risk value based on each count. The preset keywords include at least one of the following: reserved keywords, standard keywords corresponding to preset language types, keywords corresponding to triggering events, and keywords corresponding to modifying Hypertext Markup Language (HTML); determine the number of times strings are directly assigned in the running code as a third risk value, and determine the entropy value of the running code as a fourth risk value; construct a second feature vector corresponding to the first sample URL based on each statistical risk value; and input the second feature vector as the first sample URL into the initial detection model.

[0047] Furthermore, the training module is specifically used to determine the first detection error of the first preset number of first sample URLs based on the difference between the first probability and the second probability corresponding to each first sample URL; determine the first target loss value based on the first detection error and the first loss value and the second loss value corresponding to the first preset number of first sample URLs respectively; and adjust the parameters in the first sub-model based on the first target loss value.

[0048] Further, the training module is specifically used to obtain a second preset number of second sample URLs in the training set; for each second sample URL, input the second sample URL and its corresponding label into the initial detection model, and the initial detection model extracts the third feature vector of the second sample URL; input the third feature vector into the first sub-model to obtain the third probability output by the first sub-model; determine the third loss value of the first sub-model based on the label and the third probability; determine the second target loss value based on the first loss value and the second loss value corresponding to the first preset number of first sample URLs, and the third loss value corresponding to the second preset number of second sample URLs; and adjust the parameters in the first sub-model based on the second target loss value.

[0049] Further, the training module is specifically used to input the third feature vector into the second sub-model to obtain the fourth probability output by the second sub-model; determine the second detection error of the second preset number of second sample URLs based on the difference between the third probability and the fourth probability corresponding to each second sample URL; determine the third target loss value based on the second detection error, the first loss value and the second loss value corresponding to the first preset number of first sample URLs respectively, and the third loss value corresponding to the second preset number of second sample URLs respectively; and adjust the parameters in the first sub-model based on the third target loss value.

[0050] Furthermore, the training module is specifically used to determine a third parameter value for each parameter to be adjusted in the second sub-model, based on the first parameter value corresponding to the parameter to be adjusted in the second sub-model, the second parameter value corresponding to the parameter to be adjusted in the adjusted first sub-model, and the corresponding preset weight, and to update the first parameter value using the third parameter value.

[0051] Thirdly, this application also provides an electronic device including a processor, the processor being configured to execute a computer program stored in a memory to implement the steps of a training method for any of the URL detection models described above.

[0052] Fourthly, this application also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps of the training method for any of the URL detection models described above.

[0053] In this embodiment, the training set used to train the initial URL detection model only includes first sample URLs. During each iteration of training, a first preset number of first sample URLs are obtained from the training set. For each sample URL, the first sample URL is input into the initial detection model, which extracts a first feature vector from the first sample URL. The first feature vector is then input into the first sub-model and the second sub-model to obtain a first probability output by the first sub-model and a second probability output by the second sub-model. Based on the first probability and a preset threshold, a first pseudo-label is determined, and based on the recognition result corresponding to the first pseudo-label and the second probability, a first loss value is determined. Based on the second probability and the preset threshold, a second pseudo-label is determined, and based on the recognition result corresponding to the second pseudo-label and the first probability, a second loss value is determined. Based on the first loss value and the second loss value corresponding to the first preset number of first sample URLs, the parameters in the first sub-model are adjusted. Based on the adjusted parameters in the first sub-model and the preset weights, the parameters in the second sub-model are adjusted. This achieves training the initial URL detection model using unlabeled sample data, effectively improving the efficiency of model training. Attached Figure Description

[0054] To more clearly illustrate the technical solutions of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0055] Figure 1 A flowchart illustrating the training process of a URL detection model provided in this application embodiment;

[0056] Figure 2 A URL segmentation diagram provided for an embodiment of this application;

[0057] Figure 3 A schematic diagram of a training process provided in an embodiment of this application;

[0058] Figure 4 This is a schematic diagram of a sample URL processing procedure provided in an embodiment of this application;

[0059] Figure 5 A schematic diagram of a training device for a URL detection model provided in an embodiment of this application;

[0060] Figure 6 This is a schematic diagram of an electronic device structure provided in an embodiment of this application. Detailed Implementation

[0061] To make the objectives, technical solutions, and advantages of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art are within the scope of protection of this application.

[0062] This application provides a training method, apparatus, device, and medium for a URL detection model. The method involves acquiring a training set, which includes first sample URLs; performing a preset number of iterative training iterations on an initial detection model to obtain a URL detection model. Each iteration executes the following steps: acquiring a first preset number of first sample URLs in the training set; for each first sample URL, inputting the first sample URL into the initial detection model, whereby the initial detection model extracts a first feature vector from the first sample URL; inputting the first feature vector into a first sub-model and a second sub-model respectively to obtain a first probability output by the first sub-model and a second probability output by the second sub-model; determining a first pseudo-label based on the first probability and a preset threshold, and determining a first loss value based on the recognition result corresponding to the first pseudo-label and the second probability; determining a second pseudo-label based on the second probability and the preset threshold, and determining a second loss value based on the recognition result corresponding to the second pseudo-label and the first probability; adjusting the parameters in the first sub-model based on the first loss value and the second loss value corresponding to the first preset number of first sample URLs; and adjusting the parameters in the second sub-model based on the adjusted parameters in the first sub-model and preset weights.

[0063] Example 1:

[0064] Figure 1 This is a flowchart illustrating the training process of a URL detection model provided in an embodiment of this application, as shown below. Figure 1 As shown, the process includes the following steps:

[0065] S101: Obtain a training set, which includes a first sample URL; perform a preset number of iterations to train the initial detection model to obtain a URL detection model.

[0066] The training method for the URL detection model provided in this application is applied to electronic devices, such as servers and PCs.

[0067] To train a URL detection model with higher accuracy, a training set is configured in this embodiment. The training set includes multiple sample data, which can be referred to as the first sample URLs for ease of description. To avoid the problem of the long time required to collect sample data affecting the training efficiency of the URL detection model, each first sample URL in the training set does not have a corresponding label. That is, after collecting each first sample URL, no corresponding label is assigned to each first sample URL. The first sample URL can be any type of URL link randomly collected from the Internet; that is, the first sample URL may be a malicious URL or a non-malicious URL.

[0068] To train the initial detection model, in this embodiment, after obtaining the training set, the sample data included in the training set can be used to perform a preset number of iterative training iterations on the initial detection model to obtain the URL detection model. The preset number of iterations can be configured by those skilled in the art as needed. When the number of training iterations reaches the preset number of iterations, the model training is considered to have met the convergence condition. Of course, those skilled in the art can configure other convergence conditions, and this embodiment does not limit this.

[0069] S102: During each iteration of training, obtain a first preset number of first sample URLs from the training set.

[0070] During each iteration of training, a first preset number of first sample URLs can be obtained from the training set. The first preset number can be any positive integer, but it should be less than the number of first sample URLs included in the training set. Those skilled in the art can configure the value of the first preset number as needed.

[0071] S103: For each first sample URL, input the first sample URL into the initial detection model, and the initial detection model extracts the first feature vector of the first sample URL.

[0072] After obtaining a first preset number of first sample URLs, each of these URLs can be input into an initial detection model. The initial detection model then classifies the first sample URL, determining whether it is a malicious or non-malicious URL. Based on this classification result, the initial detection model is trained. In this embodiment, after receiving the first sample URL, the initial detection model can extract a first feature vector from it.

[0073] For example, the convolutional and pooling layers of the initial detection model can be used to extract features from the first sample URL. After the first sample URL is input into the initial detection model, the convolutional layer of the initial detection model can perform convolution processing on the first sample URL to obtain a convolutional feature vector. This convolutional feature vector is then input into the pooling layer, which performs pooling processing on the convolutional feature vector to obtain a pooled feature vector. This pooled feature vector can then be used as the first feature vector of the first sample URL.

[0074] Because the feature vector after convolution loses a significant amount of information during max pooling, thus affecting the model training effect, in this embodiment, the pooling layer of the initial detection model can be composed of multiple Long Short-Term Memory (LSTM) networks connected together. That is, the output of the first LSTM network can be used as the input of the second LSTM network, the output of the second LSTM network can be used as the input of the third LSTM network, and so on, until the output of the last LSTM network becomes the first feature vector of the corresponding first sample URL. This embodiment does not limit the number of LSTMs included in the pooling layer; those skilled in the art can configure them as needed. In this embodiment, concatenating multiple LSTMs enables feature extraction and dimensionality reduction of the feature vector, reduces the dimensionality of intermediate hidden layers, decreases the computational load of subsequent layers, and provides rotation invariance.

[0075] S104: Input the first feature vector into the first sub-model and the second sub-model respectively to obtain the first probability output by the first sub-model and the second probability output by the second sub-model; determine the first pseudo-label based on the first probability and a preset threshold, and determine the first loss value based on the recognition result corresponding to the first pseudo-label and the second probability; determine the second pseudo-label based on the second probability and the preset threshold, and determine the second loss value based on the recognition result corresponding to the second pseudo-label and the first probability.

[0076] After extracting the first feature vector of the first sample URL, the first feature vector can be input into the first sub-model and the second sub-model respectively to obtain the first probability output by the first sub-model and the second probability output by the second sub-model. The first and second sub-models can be any classification models, and the selected classification models can be trained or untrained. This application embodiment does not restrict the selection of the first and second sub-models.

[0077] For example, both the first sub-model and the second sub-model may include a three-layer fully connected network and an activation function. The structures of the first sub-model and the second sub-model may be the same, but their initialization parameters may be the same or different.

[0078] After obtaining the first probability and the second probability, the tag corresponding to the first sample URL can be determined based on the first probability, the second probability and the preset threshold. For ease of description, the determined tag can be called a pseudo tag.

[0079] In this embodiment, a first sub-model and a second sub-model can be used for cross-pseudo-supervised training. That is, the first and second sub-models use each other's generated pseudo-labels to determine the loss value. Specifically, the first pseudo-label can be determined based on a first probability and a preset threshold. In other words, whether the first sample URL identified by the first sub-model is a malicious URL or a non-malicious URL is determined by whether the first probability output by the first sub-model is greater than the preset threshold. For example, if the preset threshold for malicious URLs in the pre-saved sample data is 0.7, and the first probability that the first sample URL1 output by the first sub-model is a malicious URL is 0.75, since 0.75 > 0.7, the first pseudo-label corresponding to the first sample URL1 can be determined as a malicious URL. After obtaining the first pseudo-label, the recognition result corresponding to the second probability output by the second sub-model is determined, and the first loss value is determined based on the first pseudo-label and the recognition result. Similarly, the second pseudo-label can be determined based on the second probability and the preset threshold, and the second loss value is determined based on the second pseudo-label and the recognition result corresponding to the first probability output by the first sub-model. The principle for determining the second loss value is the same as the principle for determining the first loss value, and the process for determining the second loss value will not be repeated here.

[0080] S105: Adjust the parameters in the first sub-model according to the first loss value and the second loss value corresponding to the first sample URL of the first preset number; and adjust the parameters in the second sub-model according to the adjusted parameters in the first sub-model and the preset weights.

[0081] After determining the first loss value and the second loss value corresponding to each of the first sample URLs of the first preset number, the parameters in the first sub-model can be adjusted according to the first loss value and the second loss value. For example, the sum of the first loss value and the second loss value can be determined as the final loss value, and the parameters in the first sub-model can be adjusted based on the final loss value. How to adjust the parameters in the model based on the loss value is existing technology and will not be described in detail in this embodiment.

[0082] Furthermore, after adjusting the parameters in the first sub-model, the parameters in the second sub-model can be adjusted based on the adjusted parameters in the first sub-model and the preset weights. For example, for each adjusted parameter in the first sub-model, the product of the parameter value corresponding to that parameter in the adjusted first sub-model and the preset weight is determined, and this product is used to update the parameter value corresponding to that parameter in the second sub-model.

[0083] Through continuous iteration until the initial detection model converges, the first sub-model can accurately classify URLs under the guidance of the second sub-model.

[0084] In this embodiment, the training set used to train the initial URL detection model only includes first sample URLs. During each iteration of training, a first preset number of first sample URLs are obtained from the training set. For each sample URL, the first sample URL is input into the initial detection model, which extracts a first feature vector from the first sample URL. The first feature vector is then input into the first sub-model and the second sub-model to obtain a first probability output by the first sub-model and a second probability output by the second sub-model. Based on the first probability and a preset threshold, a first pseudo-label is determined, and based on the recognition result corresponding to the first pseudo-label and the second probability, a first loss value is determined. Based on the second probability and the preset threshold, a second pseudo-label is determined, and based on the recognition result corresponding to the second pseudo-label and the first probability, a second loss value is determined. Based on the first loss value and the second loss value corresponding to the first preset number of first sample URLs, the parameters in the first sub-model are adjusted. Based on the adjusted parameters in the first sub-model and the preset weights, the parameters in the second sub-model are adjusted. This achieves training the initial URL detection model using unlabeled sample data, effectively improving the efficiency of model training.

[0085] Example 2:

[0086] To improve the accuracy of the URL detection model, based on the above embodiments, in this embodiment, before inputting the first sample URL into the initial detection model, the method further includes:

[0087] Based on the pre-saved symbol identifiers, the string between any two symbol identifiers in the first sample URL is taken as a word, and the word vector corresponding to each word is determined;

[0088] Based on the word vectors corresponding to each word, construct the first feature matrix corresponding to the first sample URL;

[0089] The step of inputting the first sample URL into the initial detection model includes:

[0090] The first feature matrix of the first sample URL is input into the initial detection model.

[0091] To improve the accuracy of the URL detection model, the first sample URL can be preprocessed before being input into the initial detection model. In this embodiment, the first sample URL can be segmented from a string into several words according to heuristic rules. Heuristic rules refer to the fact that when humans analyze URLs, they segment them using "." and " / " to divide them into domain names, top-level domains, paths, file extensions, etc., and then parse the segmented characters into several familiar words.

[0092] In this embodiment, segmentation symbols can be pre-stored in an electronic device. Before inputting the first sample URL into the initial detection model, the first sample URL can be segmented into multiple strings based on the pre-stored symbol identifiers. Each string can be considered a word, and the word vector corresponding to each word can be determined. This method of segmenting the first sample URL into multiple words allows for better feature extraction than treating the entire first sample URL as a single long string. After determining the word vector corresponding to each word, a first feature matrix corresponding to the first sample URL can be constructed based on the word vectors corresponding to each word.

[0093] Specifically, assuming the first sample URL is www.ABC / / DEF.com, and the pre-saved symbols are "." and " / ", before inputting this first sample URL into the initial detection model, it can be segmented into multiple strings based on the pre-saved symbols. Each string is "www", "ABC", "DEF", or "com", and each string can be considered a word. After determining each word, it can be mapped to a word vector using Word2Vec (word to vector). The dimension of each word vector can be 128 or other dimensions, which can be configured as needed by those skilled in the art. After obtaining the word vector corresponding to each word, the first feature vector corresponding to the first sample URL can be constructed based on the word vector corresponding to each word. Assuming that the number of words corresponding to a certain first sample URL is n, and the word vector corresponding to each word is 128-dimensional, then an n*128 first feature matrix can be constructed, that is, the number of rows of the constructed first feature vector is n and the number of columns is 128.

[0094] Furthermore, to ensure the uniformity of the input data for the initial detection model, in this embodiment, the number of words that a large number of URLs can be segmented can be pre-counted, and the maximum number of words is determined as the quantity threshold. This quantity threshold can be understood as the maximum number of words that a URL can contain. When determining the first feature matrix corresponding to the first sample URL, if the number of words included in the first sample URL is less than the quantity threshold, zeros can be used to supplement the first feature matrix to ensure that the number of rows in each determined first feature matrix is ​​the pre-configured quantity threshold.

[0095] Specifically, assuming a URL is pre-configured to include a maximum of 10 words, and after segmenting the first sample URL, 8 words can be identified. Since the number of identified words is less than the threshold of 10, they can be padded with 0. Therefore, rows 1 to 8 of the resulting first feature vector are the word vectors corresponding to each word, and rows 9 and 10 of the first feature vector are padded with 0.

[0096] After determining the first feature matrix corresponding to the first sample URL, the first feature matrix of the first sample URL can be input into the initial detection model, and the initial detection model will process the first feature matrix.

[0097] The preprocessing process is described below with reference to a specific embodiment. Figure 2 A URL segmentation diagram provided for an embodiment of this application, such as... Figure 2 As shown, the first sample URL is http: / / AC.BE.com / userfiles / aaa / bbbb / 123.html. Using pre-saved symbol identifiers, this first sample URL can be segmented, resulting in the words: http, AC, BE, com, userfiles, aaa, bbbb, 123, html. After obtaining each word, the corresponding word vector is determined, and each word vector is concatenated row-wise to obtain an m*n first feature matrix. Here, m represents the maximum number of words included in the URL; if the number of words in the first sample URL is less than this maximum, it is padded with 0s; n represents the dimension of each word vector.

[0098] Example 3:

[0099] To further improve the accuracy of the URL detection model, based on the above embodiments, in this embodiment, before inputting the first sample URL into the initial detection model, the method further includes:

[0100] Based on web crawling technology, obtain the running code of the webpage corresponding to the first sample URL;

[0101] The number of times each preset function is called in the running code is counted, and a corresponding first risk value is determined based on each number. The preset functions include at least one of the following: functions that inject content into the webpage, functions that do not need to be detected, text matching functions, and functions used to store sensitive user information.

[0102] The number of times a preset keyword appears in the running code is counted, and a corresponding second risk value is determined based on each occurrence. The preset keywords include at least one of the following: reserved keywords, standard keywords corresponding to preset language types, keywords corresponding to triggering events, and keywords corresponding to modifying Hypertext Markup Language (HTML).

[0103] The number of strings directly assigned in the running code is determined as the third risk value, and the entropy value of the running code is determined as the fourth risk value;

[0104] Based on each statistical risk value, construct the second feature vector corresponding to the first sample URL;

[0105] The step of inputting the first sample URL into the initial detection model includes:

[0106] The second feature vector is used as the URL of the first sample and input into the initial detection model.

[0107] To further improve the accuracy of the URL detection model, features of the webpage corresponding to the first sample URL can be extracted. In this embodiment, the running code of the webpage corresponding to the first sample URL can be obtained based on web crawling technology. How to obtain the running code is existing technology and will not be described in detail in this embodiment.

[0108] To determine whether there is a risk in the running code, in this embodiment, the number of times each preset function is called in the running code can be counted, and a first risk value can be determined based on the number of calls. Specifically, the preset function can be a function that injects content into a webpage, such as the `eval()` function or the `document.write()` function; the preset function can also be a function that does not need to be detected, such as the `unescape()` function or the `exec()` function; the preset function can also be a text matching function, such as the `search()` function; the preset function can also be a function used to store sensitive user information, such as the `cookie()` function. That is to say, in this embodiment, the number of times one or more of the above preset functions are called in the running code can be counted, and the number of calls for each preset function can be used as the first risk value for the corresponding preset function.

[0109] The system can also count the occurrences of preset keywords in the running code and determine a corresponding second risk value based on each occurrence. Specifically, preset keywords can be reserved keywords; standard keywords corresponding to preset language types, such as standard keywords for shell code; keywords corresponding to triggering events, i.e., counting the number of triggered events, such as the number of JS events; or keywords corresponding to modifications to the Hypertext Markup Language (HTML), i.e., counting the number of times JS modifies the HTML DOM. In this embodiment, one or more of the above preset keywords can be counted, and the occurrences of each preset keyword can be used as the second risk value for that keyword.

[0110] It can also count the number of strings directly assigned in the running code, and determine this number as the third risk value. The entropy value of the running code can be determined, and this entropy value can be determined as the fourth risk value. How to determine the entropy value of the running code is a current technology.

[0111] It should be noted that the content of the runtime code statistics is not limited to the above examples. Those skilled in the art can also collect statistics on content that may pose risks as needed.

[0112] After obtaining the first risk value, the second risk value, the third risk value, and the fourth risk value, a second feature vector corresponding to the first sample URL can be constructed based on each statistical risk value.

[0113] Specifically, assuming the determined risk values ​​are 1, 2, 3, 4, and 5, then the determined second feature vector is [1, 2, 3, 4, 5].

[0114] After obtaining the second feature vector, it can be used as the URL of the first sample and input into the initial detection model, which will then process the second feature vector.

[0115] It should be noted that if both the first feature matrix and the second feature vector are determined, they can be fused. The fused feature matrix can then be used as the input to the initial detection model for the first sample URL. During the fusion process, a new row can be added to the first feature matrix; this row contains the second feature vector. That is, if the first feature matrix has 10 rows, the fused feature matrix will have 11 rows. When the dimensions of the second feature vector differ from those of the columns in the first feature matrix, zeros can be used to supplement the second feature vector.

[0116] Example 4:

[0117] To further improve the accuracy of the URL detection model, based on the above embodiments, in this embodiment, adjusting the parameters in the first sub-model according to the first loss value and the second loss value corresponding to the first sample URLs of the first preset number includes:

[0118] The first detection error of the first sample URL is determined based on the difference between the first probability and the second probability corresponding to each first sample URL;

[0119] Based on the first detection error and the first loss value and the second loss value corresponding to the first sample URL of the first preset number, respectively, a first target loss value is determined, and the parameters in the first sub-model are adjusted based on the first target loss value.

[0120] To further improve the accuracy of the URL detection model, when adjusting the parameters in the first sub-model, in this embodiment of the application, a compatibility loss value can also be determined, that is, the deviation between the first sub-model and the second sub-model in processing each first sample URL.

[0121] In this embodiment of the application, for each first sample URL, the first probability of the first sample URL output by the first sub-model and the second probability of the first sample URL output by the second sub-model can be obtained, and the difference between the first probability and the second probability corresponding to the first sample URL can be determined.

[0122] After determining the difference corresponding to each first sample URL, the first detection error of the first preset number of first sample URLs can be determined based on the difference corresponding to each first sample URL.

[0123] Specifically, the first detection error can be calculated based on the following formula:

[0124]

[0125] Among them, L CL Let S(x) represent the first detection error; n represents the first preset quantity; S(x) represents the first probability; and T(x) represents the second probability.

[0126] After obtaining the first detection error, the first target loss value can be determined based on the first detection error, the first loss value, and the second loss value corresponding to the first preset number of first sample URLs, respectively. The parameters in the first sub-model can then be adjusted based on this first target loss value. When determining the first target loss value, the first loss value and the second loss value corresponding to each first sample URL can be summed, and the sum of the sums and the first detection error can be used to determine the first target loss value.

[0127] Specifically, assuming the first preset number of sample URLs obtained are first sample URL-1, first sample URL-2, and first sample URL-3, and the first detection error is C. Wherein, the first loss value corresponding to first sample URL-1 is A1, and the second loss value is B1; the first loss value corresponding to first sample URL-2 is A2, and the second loss value is B2; and the first loss value corresponding to first sample URL-3 is A3, and the second loss value is B3. Then, the first target loss value can be determined as A1 + A2 + A3 + B1 + B2 + B3 + C.

[0128] Example 5:

[0129] To further improve the accuracy of the URL detection model, based on the above embodiments, in this embodiment, the training set also includes a second sample URL and its corresponding label, wherein the label is used to identify the probability that the corresponding second sample URL is a malicious URL; the following steps are also performed during each training iteration:

[0130] Obtain a second preset number of second sample URLs from the training set;

[0131] For each second sample URL, the second sample URL and its corresponding label are input into the initial detection model, and the initial detection model extracts the third feature vector of the second sample URL; the third feature vector is then input into the first sub-model to obtain the third probability output by the first sub-model; and the third loss value of the first sub-model is determined based on the label and the third probability.

[0132] The step of adjusting the parameters in the first sub-model according to the first loss value and the second loss value corresponding to the first sample URL of the first preset number of samples includes:

[0133] Based on the first loss value and the second loss value corresponding to the first sample URL of the first preset number of samples, and the third loss value corresponding to the second sample URL of the second preset number of samples, a second target loss value is determined, and the parameters in the first sub-model are adjusted based on the second target loss value.

[0134] To further improve the accuracy of the URL detection model, the training set can also include labeled sample data during model training. In this embodiment, the training set also includes second sample URLs and their corresponding labels, where the labels indicate the probability of whether the corresponding second sample URL is a malicious URL. The probability for a malicious URL can be 1, indicating that the corresponding second sample URL is 100% malicious, and the probability for a non-malicious URL can be 0, indicating that the corresponding second sample URL is 100% non-malicious. In this embodiment, URL links can be obtained from publicly available datasets of URLs used for multiple malicious attacks and used as the second sample URLs.

[0135] During each training iteration, a second preset number of second sample URLs can be obtained from the training set. This second preset number can be the same as, smaller than, or larger than the first preset number. For example, during each training iteration, the number of first and second sample URLs can be obtained in a 1:5 ratio. This application embodiment does not limit the number of second sample URLs obtained.

[0136] After obtaining the second preset number of second sample URLs, for each second sample URL, the second sample URL and its corresponding tag can be input into the initial detection model. Upon receiving the second sample URL, the initial detection model can extract the third feature vector of the second sample URL and input this third feature vector into the first sub-model to obtain the third probability output by the first sub-model. The principle of extracting the third feature vector and determining the third probability is consistent with the principle of extracting the first feature vector and determining the first probability, and has been explained in detail in the above embodiments, and will not be repeated in this application embodiment.

[0137] Since the second sample URL has a corresponding tag, after obtaining the third probability output by the first sub-model, the third loss value of the first sub-model can be determined based on the tag and the third probability.

[0138] Specifically, the third loss value can be determined based on the following formula:

[0139] L CE =-∑Q(c)logP(c)

[0140] Among them, L CE denoted by , Q(c) represents the probability that the corresponding second sample URL is a malicious URL, i.e., 0 or 1 as indicated in the label; P(c) represents the third probability of the corresponding second sample URL.

[0141] After obtaining the third loss value corresponding to each second sample URL in the second preset number, a second target loss value can be determined based on the first and second loss values ​​corresponding to the first sample URLs in the first preset number, and the third loss values ​​corresponding to the second sample URLs in the second preset number. In this embodiment, the sum of all first, second, and third loss values ​​can be determined and used as the second target loss value; alternatively, the average of all first, second, and third loss values ​​can be determined and used as the second target loss value. The parameters in the first sub-model are then adjusted based on this second target loss value.

[0142] Example 6:

[0143] To further improve the accuracy of the URL detection model, based on the above embodiments, in this embodiment, after determining the third loss value of the first sub-model and before adjusting the parameters in the first sub-model according to the first loss value and the second loss value corresponding to the first sample URLs of the first preset number, the method further includes:

[0144] The third feature vector is input into the second sub-model to obtain the fourth probability output by the second sub-model;

[0145] The second detection error of the second preset number of second sample URLs is determined based on the difference between the third probability and the fourth probability corresponding to each second sample URL.

[0146] Based on the first loss value and the second loss value corresponding to the first sample URL of the first preset number of samples, and the third loss value corresponding to the second sample URL of the second preset number of samples, a second target loss value is determined, and the parameters in the first sub-model are adjusted based on the second target loss value, including:

[0147] Based on the second detection error, the first loss value and the second loss value corresponding to the first preset number of first sample URLs, and the third loss value corresponding to the second preset number of second sample URLs, a third target loss value is determined, and the parameters in the first sub-model are adjusted based on the third target loss value.

[0148] To further improve the accuracy of the URL detection model, after determining the third loss value, the third feature vector corresponding to the second sample URL can be input into the second sub-model to obtain the fourth probability output by the second sub-model. Based on the difference between the third and fourth probabilities corresponding to each second sample URL, the second detection error for a second preset number of second sample URLs is determined. The principle for determining the second detection error is similar to that for determining the first detection error, and will not be elaborated further in this embodiment.

[0149] After determining the second detection error, when adjusting the parameters in the first sub-model based on the second target loss value, a third target loss value can be determined according to the second detection error, the first loss value corresponding to a first preset number of first sample URLs, the second loss value corresponding to a first preset number of first sample URLs, and the third loss value corresponding to a second preset number of second sample URLs. The parameters in the first sub-model are then adjusted based on this third target loss value. In this embodiment, the second detection error, the sum of all first loss values, second loss values, and third loss values ​​can be determined, and this sum can be used as the third target loss value; alternatively, the average value of the second detection error, all first loss values, second loss values, and third loss values ​​can be determined, and this average value can be used as the third target loss value. Thus, the parameters in the first sub-model are adjusted based on this third target loss value.

[0150] Example 7:

[0151] To further improve the accuracy of the URL detection model, based on the above embodiments, in this embodiment, the first sub-model and the second sub-model have the same structure. The adjustment of the parameters in the second sub-model according to the adjusted parameters in the first sub-model and the preset weights includes:

[0152] For each parameter to be adjusted in the second sub-model, a third parameter value is determined based on the first parameter value corresponding to the parameter to be adjusted in the second sub-model, the second parameter value corresponding to the parameter to be adjusted in the adjusted first sub-model, and the corresponding preset weight, and the first parameter value is updated using the third parameter value.

[0153] To adjust the parameters in the second sub-model and improve the accuracy of the URL detection model, in this embodiment, the parameters in the second sub-model can be updated based on the updated parameters of the first sub-model and the Exponential Moving Average (EMA) method. When updating the parameters in the second sub-model, for each parameter to be adjusted in the second sub-model, the corresponding second parameter value in the first sub-model can be obtained. Then, based on the corresponding first parameter value, the second parameter value, and a preset weight in the second sub-model, a third parameter value is determined, and this third parameter value is used to update the first parameter value.

[0154] Specifically, the value of the third parameter can be determined based on the following formula:

[0155]

[0156] in, This represents the value of the third parameter; α represents the preset weight. Indicates the value of the first parameter; θ t This indicates the value of the second parameter.

[0157] In this embodiment, the preset weights can be pre-configured. For example, if the number of iterations for model training is known, then the preset weights for the first 50% of iterations can be pre-configured as A1, and the preset weights for the last 50% of iterations can be pre-configured as A2. These preset weights can also be determined based on a Gaussian warm-up function. This embodiment does not limit the configuration of the preset weights; those skilled in the art can configure them as needed.

[0158] In the embodiments of this application, the preset weight is typically a constant close to 1, used to control the update speed of the second sub-model. The larger the preset weight, the more the second sub-model retains previous information and the smoother it is; the smaller the preset weight, the faster the second sub-model follows the changes of the first sub-model and the more sensitive it is.

[0159] This application employs a teacher-student mentoring approach to learn from a large number of unlabeled samples. Through the consistency principle, the teacher model (the second sub-model) supervises and guides the student model (the first sub-model) on the unlabeled dataset. Pseudo-labeling technology is then used to allow the teacher and student models to share pseudo-labels, improving the model's generalization ability. The student model is trained by minimizing the classification loss of labeled data and the consistency loss of unlabeled data, learning better generalization ability from the teacher model's guidance. The teacher model's parameters are updated using a preset weight α, ensuring it maintains a long-term average state rather than fluctuating with the student model's performance. This method effectively utilizes unlabeled data to improve detection performance and generalization ability. Compared to traditional methods that only use labeled data for training, this approach obtains malicious URLs from publicly available malicious attack URL datasets as labeled data and randomly collects a large number of URLs of unknown categories from the internet as unlabeled data. This covers more novel malicious URLs as well as normal URLs. This makes the teacher model more stable and robust, avoiding the influence of noise or overfitting from the student model. At the same time, the teacher model can serve as a better target generator, providing more accurate and consistent output results for the student model.

[0160] Example 8:

[0161] The training process of the URL detection model will be explained below with reference to a specific example. Figure 3 This is a schematic diagram of a training process provided in an embodiment of this application. First, in the training set, a first sample URL and a second sample URL are obtained according to a certain ratio. For ease of description in this embodiment of the application, the first sample URL and the second sample URL are collectively referred to as target samples.

[0162] For each target sample, preprocessing is performed to obtain a first feature matrix and a second feature vector. The first feature matrix and the second feature vector are then fused to obtain a fused first feature matrix. This fused feature matrix is ​​then input into the first sub-model and the second sub-model to obtain the probabilities output by the first sub-model and the second sub-model, respectively. In this embodiment, the first sub-model can be figuratively called the student model, and the second sub-model can be figuratively called the teacher model. During training, a teacher-student guidance approach is used to learn from a large number of unlabeled samples.

[0163] After obtaining the probabilities output by the first sub-model and the second sub-model, it is determined whether the corresponding target sample is the first sample URL. If so, the first and second sub-models are cross-supervised for training to determine the first and second loss values. If not, the third loss value is determined based on the corresponding label and the probability output by the first sub-model.

[0164] After determining the first loss value, second loss value, or third loss value for each target sample, the parameters in the first sub-model can be adjusted based on each of the first, second, and third loss values. The parameters in the second sub-model are then updated based on the EMA method.

[0165] Example 9:

[0166] The following example illustrates the process of the initial detection model processing sample URLs. Figure 4 This is a schematic diagram of a sample URL processing procedure provided in an embodiment of this application, such as... Figure 4 As shown, the first feature matrix corresponding to a sample URL is input into the initial detection model. Convolutional windows of different sizes in the initial detection model perform convolution processing on this first feature matrix to obtain a feature vector. This feature vector is then input into a pooling layer to obtain a pooled feature vector. This pooling layer includes multiple LSTMs, each sequentially connected. The pooled feature vector is then input into the first and second sub-models, which use the same structure for convenient parameter transfer. Both the first and second sub-models include three connection layers and an activation (sigmoid) layer. The activation function of the activation layer determines whether the corresponding sample URL is malicious.

[0167] Building upon the aforementioned embodiments, the URL detection model training method proposed in this application incorporates heuristic rules during URL feature extraction. It parses the URL from a simple string into several words and leverages the advantage of LSTM in capturing contextual information and bidirectional dependencies within the text, fully extracting the dependencies between words. Furthermore, it extracts webpage information from the URL, such as JavaScript information, as feature vectors, and fuses these with word vector matrices to generate a new feature matrix. This generated feature matrix is ​​then input into an initial detection model, which consists of convolutional layers and pooling layers. The pooling layers are composed of multiple cascaded LSTM networks, and the output of the final LSTM is the final feature vector. This approach better captures the semantic and structural information within the URL.

[0168] It should be noted that the URL detection model obtained based on the training method of the URL detection model provided in this application can be used in a variety of URL security detection scenarios.

[0169] In one possible implementation, the URL detection model can be applied to personal information protection scenarios to ensure that individual users securely access network links. Individual users can install malicious URL detection software or plugins to verify and filter links received through emails, SMS messages, social media, and other channels, preventing the leakage of personal information or property. The installed malicious URL detection software or plugins may include a URL detection model.

[0170] In one possible implementation, the URL detection model can be applied to network security monitoring scenarios to provide convenient support for downstream business operations. Network security organizations or enterprises can deploy malicious URL detection systems to periodically or dynamically collect and analyze URLs on the Internet, discover and remove malicious URLs, and maintain network order and user trust. The deployed malicious URL detection system may include a URL detection model.

[0171] In one possible implementation, the URL detection model can be applied to browser protection scenarios to prevent users from browsing malicious websites. Browsers can use their built-in malicious URL detection module to scan and block URLs visited by users in real time, preventing attacks such as XSS, phishing, and fraud. This malicious URL detection module may include a URL detection model.

[0172] Example 10:

[0173] Based on the above embodiments, Figure 5 This application provides a schematic diagram of a training device for a URL detection model, which includes:

[0174] Acquisition module 501 is used to acquire a training set, wherein the training set includes a first sample URL;

[0175] Training module 502 is used to perform a preset number of iterations of training on the initial detection model to obtain the URL detection model;

[0176] The training module 502 is specifically configured to: acquire a first preset number of first sample URLs in the training set; input each first sample URL into the initial detection model, whereby the initial detection model extracts a first feature vector from the first sample URL; input the first feature vector into a first sub-model and a second sub-model respectively to obtain a first probability output by the first sub-model and a second probability output by the second sub-model; determine a first pseudo-label based on the first probability and a preset threshold, and determine a first loss value based on the recognition result corresponding to the first pseudo-label and the second probability; determine a second pseudo-label based on the second probability and the preset threshold, and determine a second loss value based on the recognition result corresponding to the second pseudo-label and the first probability; adjust the parameters in the first sub-model based on the first loss value and the second loss value corresponding to the first preset number of first sample URLs; and adjust the parameters in the second sub-model based on the adjusted parameters in the first sub-model and preset weights.

[0177] In one possible implementation, the device further includes:

[0178] The preprocessing module 503 is used to segment the first sample URL according to the pre-saved symbol identifiers, treat each string as a word, and determine the word vector corresponding to each word; construct a first feature matrix corresponding to the first sample URL based on the word vector corresponding to each word; and input the first feature matrix of the first sample URL into the initial detection model.

[0179] In one possible implementation, the preprocessing module 503 is further configured to: obtain the running code of the webpage corresponding to the first sample URL based on web crawling technology; count the number of times each preset function is called in the running code, and determine a corresponding first risk value based on each count, wherein the preset functions include at least one of the following: functions for injecting content into the webpage, functions that do not need to be detected, text matching functions, and functions for storing sensitive user information; count the number of times preset keywords appear in the running code, and determine a corresponding second risk value based on each count, wherein the preset keywords include at least one of the following: reserved keywords, standard keywords corresponding to preset language types, keywords corresponding to triggering events, and keywords corresponding to modifying Hypertext Markup Language (HTML); determine the number of times strings are directly assigned in the running code as a third risk value, and determine the entropy value of the running code as a fourth risk value; construct a second feature vector corresponding to the first sample URL based on each statistical risk value; and input the second feature vector as the first sample URL into the initial detection model.

[0180] In one possible implementation, the training module 502 is specifically configured to determine a first detection error of the first preset number of first sample URLs based on the difference between the first probability and the second probability corresponding to each first sample URL; determine a first target loss value based on the first detection error and the first loss value and the second loss value corresponding to the first preset number of first sample URLs respectively; and adjust the parameters in the first sub-model based on the first target loss value.

[0181] In one possible implementation, the training module 502 is specifically configured to: acquire a second preset number of second sample URLs in the training set; for each second sample URL, input the second sample URL and its corresponding label into the initial detection model, the initial detection model extracting a third feature vector of the second sample URL; input the third feature vector into the first sub-model to obtain a third probability output by the first sub-model; determine a third loss value of the first sub-model based on the label and the third probability; determine a second target loss value based on the first loss value and the second loss value corresponding to the first preset number of first sample URLs, and the third loss value corresponding to the second preset number of second sample URLs; and adjust the parameters in the first sub-model based on the second target loss value.

[0182] In one possible implementation, the training module 502 is specifically used to input the third feature vector into the second sub-model to obtain the fourth probability output by the second sub-model; determine the second detection error of the second preset number of second sample URLs based on the difference between the third probability and the fourth probability corresponding to each second sample URL; determine the third target loss value based on the second detection error, the first loss value and the second loss value corresponding to the first preset number of first sample URLs respectively, and the third loss value corresponding to the second preset number of second sample URLs respectively, and adjust the parameters in the first sub-model based on the third target loss value.

[0183] In one possible implementation, the training module 502 is specifically used to determine a third parameter value for each parameter to be adjusted in the second sub-model, based on the first parameter value corresponding to the parameter to be adjusted in the second sub-model, the second parameter value corresponding to the parameter to be adjusted in the adjusted first sub-model, and the corresponding preset weight, and to update the first parameter value using the third parameter value.

[0184] Example 11:

[0185] Based on the above embodiments, this application also provides an electronic device. Figure 6This application provides a schematic diagram of an electronic device structure, such as... Figure 6 As shown, it includes: processor 601, communication interface 602, memory 603 and communication bus 604, wherein processor 601, communication interface 602 and memory 603 communicate with each other through communication bus 604.

[0186] The memory 603 stores a computer program, which, when executed by the processor 601, causes the processor 601 to perform the following steps:

[0187] Obtain a training set, which includes the URLs of the first samples;

[0188] The initial detection model is trained iteratively for a predetermined number of rounds to obtain the URL detection model. Each iteration of training involves the following steps:

[0189] Obtain a first preset number of first sample URLs from the training set;

[0190] For each first sample URL, the first sample URL is input into the initial detection model, which extracts a first feature vector from the first sample URL. This first feature vector is then input into a first sub-model and a second sub-model to obtain a first probability output by the first sub-model and a second probability output by the second sub-model. Based on the first probability and a preset threshold, a first pseudo-label is determined, and based on the first pseudo-label and the recognition result corresponding to the second probability, a first loss value is determined. Based on the second probability and the preset threshold, a second pseudo-label is determined, and based on the second pseudo-label and the recognition result corresponding to the first probability, a second loss value is determined.

[0191] Based on the first loss value and the second loss value corresponding to the first sample URL of the first preset number, the parameters in the first sub-model are adjusted; and based on the adjusted parameters in the first sub-model and the preset weights, the parameters in the second sub-model are adjusted.

[0192] In one possible implementation, the processor 601 is further configured to: segment the first sample URL according to a pre-saved symbol identifier, treat each string as a word, and determine the word vector corresponding to each word;

[0193] Based on the word vectors corresponding to each word, construct the first feature matrix corresponding to the first sample URL;

[0194] The step of inputting the first sample URL into the initial detection model includes:

[0195] The first feature matrix of the first sample URL is input into the initial detection model.

[0196] In one possible implementation, the processor 601 is further configured to: obtain the running code of the webpage corresponding to the first sample URL based on crawler technology;

[0197] The number of times each preset function is called in the running code is counted, and a corresponding first risk value is determined based on each number. The preset functions include at least one of the following: functions that inject content into the webpage, functions that do not need to be detected, text matching functions, and functions used to store sensitive user information.

[0198] The number of times a preset keyword appears in the running code is counted, and a corresponding second risk value is determined based on each occurrence. The preset keywords include at least one of the following: reserved keywords, standard keywords corresponding to preset language types, keywords corresponding to triggering events, and keywords corresponding to modifying Hypertext Markup Language (HTML).

[0199] The number of strings directly assigned in the running code is determined as the third risk value, and the entropy value of the running code is determined as the fourth risk value;

[0200] Based on each statistical risk value, construct the second feature vector corresponding to the first sample URL;

[0201] The step of inputting the first sample URL into the initial detection model includes:

[0202] The second feature vector is used as the URL of the first sample and input into the initial detection model.

[0203] In one possible implementation, the processor 601 is further configured to: determine a first detection error of the first preset number of first sample URLs based on the difference between the first probability and the second probability corresponding to each first sample URL;

[0204] Based on the first detection error and the first loss value and the second loss value corresponding to the first sample URL of the first preset number, respectively, a first target loss value is determined, and the parameters in the first sub-model are adjusted based on the first target loss value.

[0205] In one possible implementation, the processor 601 is further configured to: acquire a second preset number of second sample URLs in the training set;

[0206] For each second sample URL, the second sample URL and its corresponding label are input into the initial detection model, and the initial detection model extracts the third feature vector of the second sample URL; the third feature vector is then input into the first sub-model to obtain the third probability output by the first sub-model; and the third loss value of the first sub-model is determined based on the label and the third probability.

[0207] The step of adjusting the parameters in the first sub-model according to the first loss value and the second loss value corresponding to the first sample URL of the first preset number of samples includes:

[0208] Based on the first loss value and the second loss value corresponding to the first sample URL of the first preset number of samples, and the third loss value corresponding to the second sample URL of the second preset number of samples, a second target loss value is determined, and the parameters in the first sub-model are adjusted based on the second target loss value.

[0209] In one possible implementation, the processor 601 is further configured to: input the third feature vector into the second sub-model to obtain the fourth probability output by the second sub-model;

[0210] The second detection error of the second preset number of second sample URLs is determined based on the difference between the third probability and the fourth probability corresponding to each second sample URL.

[0211] Based on the first loss value and the second loss value corresponding to the first sample URL of the first preset number of samples, and the third loss value corresponding to the second sample URL of the second preset number of samples, a second target loss value is determined, and the parameters in the first sub-model are adjusted based on the second target loss value, including:

[0212] Based on the second detection error, the first loss value and the second loss value corresponding to the first preset number of first sample URLs, and the third loss value corresponding to the second preset number of second sample URLs, a third target loss value is determined, and the parameters in the first sub-model are adjusted based on the third target loss value.

[0213] In one possible implementation, the processor 601 is further configured to: for each parameter to be adjusted in the second sub-model, determine a third parameter value based on a first parameter value corresponding to the parameter to be adjusted in the second sub-model, a second parameter value corresponding to the parameter to be adjusted in the adjusted first sub-model, and a corresponding preset weight, and update the first parameter value using the third parameter value.

[0214] Since the principle of the above-mentioned electronic device in solving the problem is similar to the training method of the URL detection model, the implementation of the above-mentioned electronic device can be found in the embodiments of the method, and the repeated parts will not be described again.

[0215] The communication bus mentioned in the aforementioned electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. This communication bus can be divided into address bus, data bus, control bus, etc. For ease of illustration, only one thick line is used in the figure, but this does not indicate that there is only one bus or one type of bus. Communication interface 602 is used for communication between the aforementioned electronic device and other devices. The memory can include random access memory (RAM) or non-volatile memory (NVM), such as at least one disk storage device. Optionally, the memory can also be at least one storage device located remotely from the aforementioned processor.

[0216] The processors mentioned above can be general-purpose processors, including central processing units, network processors (NPs), etc.; they can also be digital signal processors (DSPs), application-specific integrated circuits, field-programmable gate arrays or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc.

[0217] Example 12:

[0218] Based on the above embodiments, this invention also provides a computer-readable storage medium storing a computer program executable by a processor. When the program runs on the processor, it causes the processor to perform the following steps:

[0219] Obtain a training set, which includes the URLs of the first samples;

[0220] The initial detection model is trained iteratively for a predetermined number of rounds to obtain the URL detection model. Each iteration of training involves the following steps:

[0221] Obtain a first preset number of first sample URLs from the training set;

[0222] For each first sample URL, the first sample URL is input into the initial detection model, which extracts a first feature vector from the first sample URL. This first feature vector is then input into a first sub-model and a second sub-model to obtain a first probability output by the first sub-model and a second probability output by the second sub-model. Based on the first probability and a preset threshold, a first pseudo-label is determined, and based on the first pseudo-label and the recognition result corresponding to the second probability, a first loss value is determined. Based on the second probability and the preset threshold, a second pseudo-label is determined, and based on the second pseudo-label and the recognition result corresponding to the first probability, a second loss value is determined.

[0223] Based on the first loss value and the second loss value corresponding to the first sample URL of the first preset number, the parameters in the first sub-model are adjusted; and based on the adjusted parameters in the first sub-model and the preset weights, the parameters in the second sub-model are adjusted.

[0224] In one possible implementation, before inputting the first sample URL into the initial detection model, the method further includes:

[0225] Based on the pre-saved symbol identifiers, the first sample URL is segmented, each resulting string is treated as a word, and the word vector corresponding to each word is determined.

[0226] Based on the word vectors corresponding to each word, construct the first feature matrix corresponding to the first sample URL;

[0227] The step of inputting the first sample URL into the initial detection model includes:

[0228] The first feature matrix of the first sample URL is input into the initial detection model.

[0229] In one possible implementation, before inputting the first sample URL into the initial detection model, the method further includes:

[0230] Based on web crawling technology, obtain the running code of the webpage corresponding to the first sample URL;

[0231] The number of times each preset function is called in the running code is counted, and a corresponding first risk value is determined based on each number. The preset functions include at least one of the following: functions that inject content into the webpage, functions that do not need to be detected, text matching functions, and functions used to store sensitive user information.

[0232] The number of times a preset keyword appears in the running code is counted, and a corresponding second risk value is determined based on each occurrence. The preset keywords include at least one of the following: reserved keywords, standard keywords corresponding to preset language types, keywords corresponding to triggering events, and keywords corresponding to modifying Hypertext Markup Language (HTML).

[0233] The number of strings directly assigned in the running code is determined as the third risk value, and the entropy value of the running code is determined as the fourth risk value;

[0234] Based on each statistical risk value, construct the second feature vector corresponding to the first sample URL;

[0235] The step of inputting the first sample URL into the initial detection model includes:

[0236] The second feature vector is used as the URL of the first sample and input into the initial detection model.

[0237] In one possible implementation, adjusting the parameters in the first sub-model based on the first loss value and the second loss value corresponding to the first preset number of first sample URLs respectively includes:

[0238] The first detection error of the first sample URL is determined based on the difference between the first probability and the second probability corresponding to each first sample URL;

[0239] Based on the first detection error and the first loss value and the second loss value corresponding to the first sample URL of the first preset number, respectively, a first target loss value is determined, and the parameters in the first sub-model are adjusted based on the first target loss value.

[0240] In one possible implementation, the training set also includes a second sample URL and its corresponding label, the label being used to identify the probability that the corresponding second sample URL is a malicious URL; the following steps are also performed during each training iteration:

[0241] Obtain a second preset number of second sample URLs from the training set;

[0242] For each second sample URL, the second sample URL and its corresponding label are input into the initial detection model, and the initial detection model extracts the third feature vector of the second sample URL; the third feature vector is then input into the first sub-model to obtain the third probability output by the first sub-model; and the third loss value of the first sub-model is determined based on the label and the third probability.

[0243] The step of adjusting the parameters in the first sub-model according to the first loss value and the second loss value corresponding to the first sample URL of the first preset number of samples includes:

[0244] Based on the first loss value and the second loss value corresponding to the first sample URL of the first preset number of samples, and the third loss value corresponding to the second sample URL of the second preset number of samples, a second target loss value is determined, and the parameters in the first sub-model are adjusted based on the second target loss value.

[0245] In one possible implementation, after determining the third loss value of the first sub-model and before adjusting the parameters in the first sub-model according to the first loss value and the second loss value corresponding to the first sample URL of the first preset number, the method further includes:

[0246] The third feature vector is input into the second sub-model to obtain the fourth probability output by the second sub-model;

[0247] The second detection error of the second preset number of second sample URLs is determined based on the difference between the third probability and the fourth probability corresponding to each second sample URL.

[0248] Based on the first loss value and the second loss value corresponding to the first sample URL of the first preset number of samples, and the third loss value corresponding to the second sample URL of the second preset number of samples, a second target loss value is determined, and the parameters in the first sub-model are adjusted based on the second target loss value, including:

[0249] Based on the second detection error, the first loss value and the second loss value corresponding to the first preset number of first sample URLs, and the third loss value corresponding to the second preset number of second sample URLs, a third target loss value is determined, and the parameters in the first sub-model are adjusted based on the third target loss value.

[0250] In one possible implementation, the first sub-model and the second sub-model have the same structure, and the adjustment of the parameters of the second sub-model based on the parameters in the adjusted first sub-model and the preset weights includes:

[0251] For each parameter to be adjusted in the second sub-model, a third parameter value is determined based on the first parameter value corresponding to the parameter to be adjusted in the second sub-model, the second parameter value corresponding to the parameter to be adjusted in the adjusted first sub-model, and the corresponding preset weight, and the first parameter value is updated using the third parameter value.

[0252] Since the principle of the computer-readable storage medium in solving the problem is similar to the training method of the URL detection model, the implementation of the computer-readable storage medium can be found in the embodiments of the method, and repeated details will not be repeated.

[0253] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0254] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to this application. It should be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0255] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0256] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0257] Obviously, those skilled in the art can make various modifications and variations to this application without departing from the spirit and scope of this application. Therefore, if such modifications and variations fall within the scope of the claims of this application and their equivalents, this application also intends to include such modifications and variations.

Claims

1. A training method for a URL detection model, characterized in that, The method includes: Obtain a training set, which includes a first sample URL, wherein the first sample URL is a URL that does not contain a label; The initial detection model is trained iteratively for a predetermined number of rounds to obtain the URL detection model. Each iteration of training involves the following steps: Obtain a first preset number of first sample URLs from the training set; For each first sample URL, the first sample URL is input into the initial detection model, which extracts a first feature vector from the first sample URL. This first feature vector is then input into a first sub-model and a second sub-model to obtain a first probability output by the first sub-model and a second probability output by the second sub-model. Based on the first probability and a preset threshold, a first pseudo-label is determined, and based on the first pseudo-label and the recognition result corresponding to the second probability, a first loss value is determined. Based on the second probability and the preset threshold, a second pseudo-label is determined, and based on the second pseudo-label and the recognition result corresponding to the first probability, a second loss value is determined. Based on the first loss value and the second loss value corresponding to the first sample URL of the first preset number, the parameters in the first sub-model are adjusted; and based on the adjusted parameters in the first sub-model and the preset weights, the parameters in the second sub-model are adjusted. The step of adjusting the parameters in the first sub-model according to the first loss value and the second loss value corresponding to the first sample URL of the first preset number of samples includes: The first detection error of the first sample URL is determined based on the difference between the first probability and the second probability corresponding to each first sample URL; The first loss value and the second loss value corresponding to each first sample URL are summed, and the sum of the sum and the first detection error is determined as the first target loss value. The parameters in the first sub-model are then adjusted based on the first target loss value.

2. The method according to claim 1, characterized in that, Before inputting the first sample URL into the initial detection model, the method further includes: Based on the pre-saved symbol identifiers, the first sample URL is segmented, each resulting string is treated as a word, and the word vector corresponding to each word is determined. Based on the word vectors corresponding to each word, construct the first feature matrix corresponding to the first sample URL; The step of inputting the first sample URL into the initial detection model includes: The first feature matrix of the first sample URL is input into the initial detection model.

3. The method according to claim 1 or 2, characterized in that, Before inputting the first sample URL into the initial detection model, the method further includes: Based on web crawling technology, obtain the running code of the webpage corresponding to the first sample URL; The number of times each preset function is called in the running code is counted, and a corresponding first risk value is determined based on each number. The preset functions include at least one of the following: functions that inject content into the webpage, functions that do not need to be detected, text matching functions, and functions used to store sensitive user information. The number of times a preset keyword appears in the running code is counted, and a corresponding second risk value is determined based on each occurrence. The preset keywords include at least one of the following: reserved keywords, standard keywords corresponding to preset language types, keywords corresponding to triggering events, and keywords corresponding to modifying Hypertext Markup Language (HTML). The number of strings directly assigned in the running code is determined as the third risk value, and the entropy value of the running code is determined as the fourth risk value; Based on each statistical risk value, construct the second feature vector corresponding to the first sample URL; The step of inputting the first sample URL into the initial detection model includes: The second feature vector is used as the URL of the first sample and input into the initial detection model.

4. The method according to claim 1, characterized in that, The training set also includes a second sample URL and its corresponding label, the label being used to identify the probability that the corresponding second sample URL is a malicious URL; the following steps are also performed during each training iteration: Obtain a second preset number of second sample URLs from the training set; For each second sample URL, the second sample URL and its corresponding label are input into the initial detection model, and the initial detection model extracts the third feature vector of the second sample URL; the third feature vector is then input into the first sub-model to obtain the third probability output by the first sub-model; and the third loss value of the first sub-model is determined based on the label and the third probability. The step of adjusting the parameters in the first sub-model according to the first loss value and the second loss value corresponding to the first sample URL of the first preset number of samples includes: Based on the first loss value and the second loss value corresponding to the first sample URL of the first preset number of samples, and the third loss value corresponding to the second sample URL of the second preset number of samples, a second target loss value is determined, and the parameters in the first sub-model are adjusted based on the second target loss value.

5. The method according to claim 4, characterized in that, After determining the third loss value of the first sub-model, and before adjusting the parameters in the first sub-model according to the first loss value and the second loss value corresponding to the first sample URL of the first preset number, the method further includes: The third feature vector is input into the second sub-model to obtain the fourth probability output by the second sub-model; The second detection error of the second preset number of second sample URLs is determined based on the difference between the third probability and the fourth probability corresponding to each second sample URL. Based on the first loss value and the second loss value corresponding to the first sample URL of the first preset number of samples, and the third loss value corresponding to the second sample URL of the second preset number of samples, a second target loss value is determined, and the parameters in the first sub-model are adjusted based on the second target loss value, including: Based on the second detection error, the first loss value and the second loss value corresponding to the first preset number of first sample URLs, and the third loss value corresponding to the second preset number of second sample URLs, a third target loss value is determined, and the parameters in the first sub-model are adjusted based on the third target loss value.

6. The method according to claim 1, characterized in that, The first sub-model and the second sub-model have the same structure. Adjusting the parameters of the second sub-model based on the adjusted parameters of the first sub-model and preset weights includes: For each parameter to be adjusted in the second sub-model, a third parameter value is determined based on the first parameter value corresponding to the parameter to be adjusted in the second sub-model, the second parameter value corresponding to the parameter to be adjusted in the adjusted first sub-model, and the corresponding preset weight, and the first parameter value is updated using the third parameter value.

7. A training device for a URL detection model, characterized in that, The device includes: The acquisition module is used to acquire a training set, which includes a first sample URL, wherein the first sample URL is a URL that does not contain a label; The training module is used to iterate the initial detection model for a preset number of rounds to obtain the URL detection model; The training module is specifically configured to: acquire a first preset number of first sample URLs in the training set; input each first sample URL into the initial detection model, whereby the initial detection model extracts a first feature vector from the first sample URL; input the first feature vector into a first sub-model and a second sub-model respectively to obtain a first probability output by the first sub-model and a second probability output by the second sub-model; determine a first pseudo-label based on the first probability and a preset threshold, and determine a first loss value based on the recognition result corresponding to the first pseudo-label and the second probability; determine a second pseudo-label based on the second probability and the preset threshold, and determine a second loss value based on the recognition result corresponding to the second pseudo-label and the first probability; adjust the parameters in the first sub-model based on the first loss value and the second loss value corresponding to the first preset number of first sample URLs; and adjust the parameters in the second sub-model based on the adjusted parameters in the first sub-model and preset weights. The training module is specifically used to determine the first detection error of the first preset number of first sample URLs based on the difference between the first probability and the second probability corresponding to each first sample URL; to accumulate the first loss value and the second loss value corresponding to each first sample URL, to determine the sum of the accumulated value and the first detection error as the first target loss value, and to adjust the parameters in the first sub-model based on the first target loss value.

8. An electronic device, characterized in that, The electronic device includes a processor that executes a computer program stored in a memory to implement the steps of the training method for the URL detection model as described in any one of claims 1-6.

9. A computer-readable storage medium, characterized in that, It stores a computer program that, when executed by a processor, implements the steps of the training method for the URL detection model as described in any one of claims 1-6.

Citation Information

Patent Citations

  • Steel cold rolling annealing furnace component detection method based on semi-supervised learning

    CN114943689A

  • Aero-engine damage detection method based on semi-supervised semantic segmentation

    CN115115608A