Malicious URL detection method based on EMO-GAN
EMO-GAN combines semi-supervised learning and generative adversarial networks to solve the problem of insufficient data acquisition and feature representation in malicious URL detection, achieve real-time update of the model and efficient detection, overcome concept drift, and improve the accuracy of malicious URL detection. Accuracy and adaptability.
Patent Information
- Application Number
- CN202410960330.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-17
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2044-07-17
AI Technical Summary
Existing malicious URL detection methods have challenges in data acquisition difficulties, insufficient feature representation, and model concept drift, resulting in insufficient detection accuracy and real-time performance.
Adopting a malicious URL detection method based on EMO-GAN, combined with semi-supervised learning and generative adversarial network, through multi-channel feature fusion and online learning, it overcomes the problems of data imbalance and label scarcity, and updates the model in real time to adapt to changes in the data environment.
It improves the generalization ability and accuracy of the model, provides a more comprehensive feature representation, enhances the accuracy and reliability of detection, and maintains efficient detection performance in the face of concept drift.
Smart Images

Figure CN118861818A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of network security, and specifically relates to a malicious URL detection method based on EMO-GAN. The malicious URL detection method aims to solve the challenges of data acquisition, insufficient feature representation, and model concept drift encountered in malicious URL detection. Background Art
[0002] With the accelerated advancement of the digital age, the World Wide Web has become the core of the daily life and work of organizations and individuals. However, it is accompanied by a sharp increase in cyber threats. According to the information security vulnerability report released by the National Information Security Vulnerability Database (CNNVD), cross-site scripting (XSS), SQL injection, and phishing have long been at the top of the threat list. In these attack methods, attackers carefully construct malicious URLs, disguise them as normal requests, induce users or bypass security mechanisms, thereby achieving illegal purposes. Malicious URLs refer to URL links used to carry out network attacks. In the field of network security, malicious URLs have become a serious threat, with diverse attack types and far-reaching harm. Common malicious URL attack behaviors, including phishing, SQL injection, and cross-site scripting attacks, have frequently occurred, which has caused many serious consequences. Timely and effective detection of malicious URLs is crucial to responding to network security threats.
[0003] At present, malicious URL detection mainly relies on two methods: blacklist and machine learning. Although blacklist technology can effectively defend against known malicious URLs, it is limited by its update speed and attackers' bypass technology, and there are lags and incomplete detection, and the results achieved are often unsatisfactory. Machine learning-based methods can accurately identify complex and subtle abnormal patterns and show higher generalization and accuracy by extracting features and using algorithms to train models under the training of a large amount of data. However, most of these methods are based on balanced and well-labeled data sets. In practical applications, the uneven distribution of data and the scarcity of labels have become bottlenecks that restrict their performance. Secondly, the feature extraction strategies used in many methods often have limitations. Although some methods perform well on specific models, they have weak generalization capabilities and are difficult to adapt to different scenarios; while some methods have relatively limited extracted feature information, resulting in room for improvement in the detection effect of the final model. In addition, most methods are designed and applied based on offline mode. This offline mode means that the model is trained on a fixed data set and is only applicable to static malicious URL detection scenarios. However, in actual network environments, the distribution of malicious URLs will change with the emergence of new attack methods. Therefore, when faced with the dynamic changes in the distribution of original samples, the detection performance of the model that only relies on the training of the previous data set will tend to gradually decrease, and it will be difficult to maintain a high accuracy rate.
[0004] With the development of machine learning, semi-supervised learning and generative adversarial networks have become effective means to solve the problem of unbalanced source data and scarce labels. The idea of semi-supervised learning aims to use unlabeled data to improve learning performance and reduce the model's dependence on labeled data. Generative adversarial networks (GANs) are often used to expand original data sets in malicious URL detection because of their ability to generate highly realistic data. In addition, the generative characteristics of GANs and the semi-supervised idea can work together to further improve model performance.
[0005] Currently, many detection models rely mainly on a single channel for feature extraction, which results in relatively limited information they can express. Although features based on human selection perform well in terms of accuracy and efficiency, improper feature selection may have a negative impact on overall detection accuracy. In contrast, features automatically derived from the URL string itself through algorithms can provide a beneficial supplement to the model without relying on third-party intervention or prior knowledge. These automatically generated features show positive effects on data representation, helping the model to more accurately identify data categories, thereby improving detection accuracy and reliability.
[0006] Most of the existing malicious URL detection models are based on offline mode, which means that they are trained on fixed data sets and applied to static malicious URL detection scenarios. However, in practical applications, the distribution of malicious URLs will continue to change with the emergence of new attack methods. Therefore, the performance of the model trained with the previous data set will gradually decrease when the distribution of the original samples changes. In order to solve this kind of concept drift problem, scalable online learning has been introduced and studied in depth. Online learning emphasizes the real-time and accuracy of the model. It allows the model to receive new data in real time and update itself to adapt to the rapidly changing data environment. In addition, it also solves the cost problem caused by retraining. Summary of the invention
[0007] The present invention is committed to addressing the three core challenges in the field of malicious URL detection: the difficulty of data acquisition, the challenge of feature representation, and the concept drift problem faced by the model. In order to effectively solve these problems, the present invention proposes a malicious URL detection method based on EMO-GAN. The framework adopts a combination of semi-supervised learning and generative adversarial networks to effectively overcome the problem of data acquisition difficulties; by integrating features from different channels, the data representation ability is greatly enriched; at the same time, using online learning strategies, the framework can adapt to and respond to the concept drift phenomenon of the model in real time, ensuring the accuracy and real-time performance of detection.
[0008] In order to achieve the above object, the present invention adopts the following technical solution: a malicious URL detection method based on EMO-GAN, which includes the following steps: Step 1: Data preprocessing: Use crawler tools to obtain URL data from web pages, clean, decode, and standardize them to obtain sample data; Step 2, feature engineering: Use Python tools to build a feature extraction module, which includes a statistical feature extraction submodule, a character feature extraction submodule, a vocabulary feature extraction submodule and a fusion feature submodule. Input the sample data obtained in step 1 into the statistical feature extraction submodule, the character feature extraction submodule and the vocabulary feature extraction submodule respectively to obtain 128-dimensional statistical features, 64-dimensional character features and 64-dimensional vocabulary features. Input the three features into the fusion feature submodule to combine and output 256-dimensional features, where the 256-dimensional features include labeled sample features and unlabeled sample features. Step 3, construction and training of the detection model: Step 3.1, construction of the model, the detection model includes an extreme random tree classifier module, a generator module, a discriminator module and a classifier module, wherein the Scikit-learn library is used to build the extreme random tree classifier module, and the PyTorch framework is used to build the generator module, the discriminator module and the classifier module; Step 3.2, model training, set the training rounds of the model in advance, input the 256-dimensional features obtained in step 2 into the detection model for training, use the labeled features to train the extreme random tree classifier module, input the random distribution into the generator module to output the 256-dimensional generated sample features, input the generated sample features and the unlabeled sample features into the trained extreme random tree classifier module to label them, input all labeled features into the discriminator module and the classifier module for training, and the generator module is trained against the discriminator module and the classifier module respectively; Step 4: Model performance evaluation: Use the macro average of precision, recall, and F1 score as the evaluation index of the model. If the accuracy is greater than 99% and the F1 score is greater than 80%, execute step 5. Otherwise, execute step 3.2 to continue model training. Step 5, detection of malicious URLs: Collect URL data from real web pages as test data, process the test data using steps 1 and 2 to obtain output 256-dimensional features, and then input them into the trained classifier module for classification prediction, obtain corresponding labels, and complete the detection; Step 6: Online update of the detection model: The predicted labels obtained in step 5 are verified by manual feedback to obtain the true labels of the test data. The 256-dimensional features of the test data obtained in step 5 and the true labels of manual feedback are input into the classifier module for online learning and updating.
[0009] As a further illustration of this embodiment, in step 1, the specific steps of data preprocessing are as follows: Step 1.1, data acquisition: use a crawler tool to obtain URL data from the web page as input for step 1.2; Step 1.2, data cleaning: Use Python programming language to write a script to delete URL strings that belong to both malicious and benign categories. The obtained data is used as input for step 1.3; Step 1.3: Data decoding: Use Python programming language to write a script to decode the encoded special characters and hexadecimal numbers in the URL data into their original form. The obtained data is used as input for step 1.4. Step 1.4: Data standardization: Use Python programming language to write a script to uniformly replace non-ASCII characters in URL data with a fixed string str to obtain clean and standard sample data.
[0010] As a further illustration of this embodiment, in step 2, the specific steps of feature engineering are as follows: Step 2.1, statistical feature extraction: In the statistical feature extraction submodule, the sample data obtained in step 1.4 is used as input, and a script is written in Python programming language to calculate a total of 128 statistical indicators of the URL as statistical features, where the statistical indicators include domain name length, the number of decimal points in the domain name, whether the domain name contains -, top-level domain name length, path length, the number of / , whether the protocol is https, the number of &, the total length of the URL, whether it contains redirection, whether it contains short links, character frequency, and keyword frequency; Step 2.2, character feature extraction: In the character feature extraction submodule, the sample data obtained in step 1.4 is used as input, and a script is written in Python programming language to convert each character of the URL into ASCII code and use it as a character feature. The character feature dimension of each URL is set to 64. For URLs with less than 64 characters, a zero-filling strategy is adopted; for URLs with more than 64 characters, truncation is performed; Step 2.3, lexical feature extraction: In the lexical feature extraction submodule, the sample data obtained in step 1.4 is used as input, and a script is written in Python programming language. First, word segmentation is performed based on regular expressions; second, the word frequency-inverse file frequency of each word is calculated, and the first 500 words are selected as the filter standard to form a dictionary; then, the dictionary is used to train the Word2Vec model to generate lexical features; finally, the mean of all word vectors in the URL is calculated to obtain a 64-dimensional vector as the lexical feature representation of the URL; Step 2.4, feature fusion: In the fusion feature submodule, the three character features obtained in steps 2.1, 2.2 and 2.3 are combined to obtain a total of 256-dimensional sample feature representation.
[0011] As a further illustration of this embodiment, in step 3, the specific steps of constructing and training the detection model are as follows: Step 3.1, Building and training the extremely randomized tree classifier module: Use the Scikit-learn library to build the extremely randomized tree classifier module, select the labeled part of the sample features obtained in step 2.4 as the input of the extremely randomized tree classifier, set the parameters of the extremely randomized tree, and then train it; Step 3.2, labeling: Use the trained extreme random tree classifier obtained in step 3.1 to predict the unlabeled sample features in the sample features obtained in step 2.4, and use the predicted results as pseudo labels; Step 3.3, construction and training of the generator module: Based on the PyTorch framework, several linear layers and convolutional layers are constructed as generators. A 62-dimensional random distribution is selected as input, and the output is a 256-dimensional feature. The output features are obtained by the trained extreme random tree classifier obtained in step 3.1 to obtain pseudo labels. The adversarial training with the classifier module is achieved by minimizing the cross entropy loss between the pseudo labels and the predicted labels of the classifier module. The adversarial training with the discriminator module is achieved by minimizing the cross entropy loss between the predicted labels of the discriminator module and the true labels. Step 3.4, construction and training of the discriminator module: Based on the PyTorch framework, several linear layers and convolutional layers are constructed as the discriminator. The input includes the real samples obtained in step 2.4, the generated samples obtained in step 3.3, and the labels of the two data obtained in step 3.2. The adversarial training with the generator module is achieved by minimizing the cross entropy loss between the real samples and the real labels and minimizing the cross entropy loss between the generated samples and the generated labels. Step 3.5, construction and training of the classifier module: Based on the PyTorch framework, several linear layers are constructed as classifiers. The input includes the real samples obtained in step 2.4, the generated samples obtained in step 3.3, and the labels of the two data obtained in step 3.2. For labeled samples, the classifier module is trained by minimizing the cross entropy loss between the real label and the predicted label; for unlabeled samples, the classifier module is trained by minimizing the cross entropy loss between the pseudo label and the predicted label; for generated samples, the classifier module is trained by maximizing the cross entropy between the pseudo label and the predicted label.
[0012] As a further illustration of this embodiment, in step 3.5, the classifier is a multi-layer perceptron structure, which includes five linear layers and one output layer. After each linear layer, a separate linear layer is introduced as the output layer network, and its output result is weighted as the final prediction result; the classifier uses a hedging algorithm to learn weighted parameters, and in the initial iteration, the weights are evenly distributed to each output layer; in subsequent iterations, the loss is calculated based on the classifier's prediction and the true label, and the weights are updated accordingly. The classifier module can automatically assign appropriate weights to each hidden layer, automatically adapt to different network depths, and be compatible with online scenarios.
[0013] As a further illustration of this embodiment, in step 5, the specific steps of malicious URL detection are as follows: Step 5.1, data preprocessing: The URL data to be tested is cleaned in step 1.2, decoded in step 1.3, and standardized in step 1.4 to obtain clean and standard sample data; Step 5.2, feature engineering: The sample data obtained in step 5.1 is processed through steps 2.1 to 2.4 to obtain 256-dimensional features; Step 5.3, anomaly detection: Input the 256-dimensional features obtained in step 5.2 into the classifier module trained in step 3.5 for prediction, and obtain label 1 for malicious prediction and label 0 for benign prediction.
[0014] As a further illustration of this embodiment, in step 6, the specific steps of online updating of the detection model are as follows: Step 6.1, manual feedback: Step 5.3 obtains the prediction result of the URL to be tested, and manually reviews it, and feedbacks the true label of the URL data to be tested based on the review result; Step 6.2, online update: Input the 256-dimensional features obtained in step 5.2 and the true labels obtained in step 6.1 into the classifier module and perform training updates according to step 3.5.
[0015] As a further illustration of this embodiment, in step 4, the performance evaluation index is calculated as follows: Precision Macro Average , Where: ; Recall Macro Average , Where: ; F1 score macro average , Where: ; Accuracy: ; Among them, TP means that the malicious URL is correctly identified as malicious, TN means that the legal URL is correctly identified as legal, FP means that the legal URL is incorrectly identified as malicious; FN means that the malicious URL is incorrectly identified as legal; n represents the number of categories.
[0016] Compared with the prior art, the present invention proposes a malicious URL detection method based on EMO-GAN, and its beneficial effects are mainly reflected in the following four aspects: 1. This invention combines Extremely Random Trees (ET) with Margin Generative Adversarial Networks (MarginGAN) to achieve efficient data processing and model training under the conditions of data imbalance and label scarcity. This innovative solution effectively overcomes the problem of data acquisition difficulties and improves the generalization ability and accuracy of the model.
[0017] 2. The present invention proposes a feature extraction module that integrates statistical features, character features, lexical features and fusion features. This module can fully capture the key information in the URL and effectively improve the feature information, providing a more accurate feature representation for malicious URL detection. This comprehensive feature extraction method enables the model to more accurately identify malicious URLs.
[0018] 3. This paper improves the MarginGAN model by introducing a semi-supervised learning mechanism and applies it to the malicious URL detection task. This mechanism can make full use of limited labeled and unlabeled data and achieve efficient learning in unbalanced and insufficiently labeled data scenarios. This not only improves the training efficiency of the model, but also enhances the robustness of the model.
[0019] 4. The present invention proposes a malicious URL classifier that supports online learning, which has good scalability and adaptability. It can update the model in real time to adapt to new attack methods and effectively deal with the continuous changes and evolution of malicious URLs. This online learning capability makes the malicious URL detection system of the present invention more flexible and reliable in practical applications. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] Figure 1 This is a schematic diagram of the malicious URL detection method of the present invention; Figure 2 A detailed diagram of the statistical features of the present invention; Figure 3 The character frequency part in the statistical feature of the present invention; Figure 4 The part involving keyword frequency in the statistical features of the present invention; Figure 5 It is a structural diagram of EMO-GAN in the present invention; Figure 6 This is a comparative experimental result diagram of the feature extraction method under 100% label evaluation in the present invention; Figure 7 This is a comparative experimental result diagram of the feature extraction method under 10% label in the present invention; Figure 8 This is a comparative experimental result diagram of the feature extraction method under 5% label evaluation in the present invention; Fig. 9This is a performance comparison experimental result diagram of the model in the present invention and other models; Fig.10 This is a graph of experimental results for evaluating the online learning performance of the classifier in the present invention; Fig.11 This is a graph of experimental results of evaluating the performance of the model in the present invention on different data sets; Fig.12 This is a graph showing the experimental results of the comparison between the model in the present invention and other mainstream models. DETAILED DESCRIPTION
[0021] In order to better understand the present invention, Figures 1 to 12 The present invention is further illustrated by the following examples, but the present invention is not limited thereto.
[0022] As attached Figure 1 As shown, the malicious URL detection method used in the present invention is mainly composed of two modules, namely: a feature engineering module, whose main function is to provide richer and more comprehensive data information representation by integrating the features collected through three channels of statistical features, character features and vocabulary features, so as to facilitate the use of subsequent models; a detection model module, whose main functions are to use the EMO-GAN model to complete the training of the classifier; and to use the classifier to complete the detection of malicious URLs. The overall process is: first, the pre-processed sample enters the feature engineering module, and three features are obtained and fused respectively, and then the features are input into the detection model module. At this time, there will be three types of data, one is the real data feature with labels, one is the real data feature without labels, and the other is the generated sample feature generated by the generative adversarial network. The labels of the latter two are obtained through extremely random trees trained with labeled data. Finally, the three types of data obtain an efficient classifier under the adversarial training of the EMO-GAN model. After this series of operations, the classifier obtained at this time can achieve higher detection accuracy in an unbalanced and sample-scarce data environment. At the same time, it can perform online learning based on human feedback or newly arrived URL data, update and improve the model, and make the model more adaptable and detectable to the ever-changing malicious URLs.
[0023] A malicious URL detection method based on EMO-GAN, characterized by comprising the following steps: Step 1: Data preprocessing: Use crawler tools to obtain URL data from web pages, clean, decode, and standardize them to obtain sample data; Step 2, feature engineering: Use Python tools to build a feature extraction module, which includes a statistical feature extraction submodule, a character feature extraction submodule, a vocabulary feature extraction submodule and a fusion feature submodule. Input the sample data obtained in step 1 into the statistical feature extraction submodule, the character feature extraction submodule and the vocabulary feature extraction submodule respectively to obtain 128-dimensional statistical features, 64-dimensional character features and 64-dimensional vocabulary features. Input the three features into the fusion feature submodule to combine and output 256-dimensional features, where the 256-dimensional features include labeled sample features and unlabeled sample features. Step 3, construction and training of the detection model: Step 3.1, construction of the model, the detection model includes an extreme random tree classifier module, a generator module, a discriminator module and a classifier module, wherein the Scikit-learn library is used to build the extreme random tree classifier module, and the PyTorch framework is used to build the generator module, the discriminator module and the classifier module; Step 3.2, model training, set the training rounds of the model in advance, input the 256-dimensional features obtained in step 2 into the detection model for training, use the labeled features to train the extreme random tree classifier module, input the random distribution into the generator module to output the 256-dimensional generated sample features, input the generated sample features and the unlabeled sample features into the trained extreme random tree classifier module to label them, input all labeled features into the discriminator module and the classifier module for training, and the generator module is trained against the discriminator module and the classifier module respectively; Step 4: Model performance evaluation: Use the macro average of precision, recall, and F1 score as the evaluation index of the model. If the accuracy is greater than 99% and the F1 score is greater than 80%, execute step 5. Otherwise, execute step 3.2 to continue model training. Step 5, detection of malicious URLs: Collect URL data from real web pages as test data, process the test data using steps 1 and 2 to obtain output 256-dimensional features, and then input them into the trained classifier module for classification prediction, obtain corresponding labels, and complete the detection; Step 6: Online update of the detection model: The predicted labels obtained in step 5 are verified by manual feedback to obtain the true labels of the test data. The 256-dimensional features of the test data obtained in step 5 and the true labels of manual feedback are input into the classifier module for online learning and updating.
[0024] In the above embodiment, in step 1, the specific steps of data preprocessing are as follows: Step 1.1, data acquisition: use a crawler tool to obtain URL data from the web page as input for step 1.2; Step 1.2, data cleaning: Use Python programming language to write a script to delete URL strings that belong to both malicious and benign categories. The obtained data is used as input for step 1.3; Step 1.3: Data decoding: Use Python programming language to write a script to decode the encoded special characters and hexadecimal numbers in the URL data into their original form. The obtained data is used as input for step 1.4. Step 1.4: Data standardization: Use Python programming language to write a script to uniformly replace non-ASCII characters in URL data with a fixed string str to obtain clean and standard sample data.
[0025] In the above embodiment, in step 2, the specific steps of feature engineering are as follows: Step 2.1, statistical feature extraction: In the statistical feature extraction submodule, the sample data obtained in step 1.4 is used as input, and a script is written in Python programming language to calculate a total of 128 statistical indicators of the URL as statistical features, where the statistical indicators include domain name length, the number of decimal points in the domain name, whether the domain name contains -, top-level domain name length, path length, the number of / , whether the protocol is https, the number of &, the total length of the URL, whether it contains redirection, whether it contains short links, character frequency, and keyword frequency; as shown in the attached Figure 2 The features shown are Figure 3 Indicates attachment Figure 2 Specific items of character frequency in the text, attached Figure 4 Indicates attachment Figure 2 According to the specific items of keyword frequency in the URL, a total of 128-dimensional features are extracted from the URL string as statistical features. The pseudo code is as follows: Algorithm 1: Algorithm 1 Extracting statistical features of URLs ; Step 2.2, character feature extraction: In the character feature extraction submodule, the sample data obtained in step 1.4 is used as input, and a script is written in Python programming language to convert each character of the URL into ASCII encoding and use it as a character feature. The character feature dimension of each URL is set to 64. For URLs with less than 64 characters, a zero-filling strategy is adopted; for URLs with more than 64 characters, truncation is performed; after encoding, the feature vector is normalized to obtain the final character feature representation. The pseudo code is as follows: Algorithm 2: Algorithm 2 Extracting URL character features ; Step 2.3, lexical feature extraction: Take the sample data obtained in step 1.4 as input, and write a script in Python programming language. First, perform word segmentation on the URL according to regular expressions to extract the payload from the URL. Secondly, use the term frequency-inverse file frequency (TF-IDF) algorithm to build a dictionary of the payload, use this algorithm to calculate the TF-IDF value of each word, and use this as the filtering criterion to screen out the top 500 relatively important words to form a dictionary. Finally, use the constructed dictionary to train the word embedding model to generate lexical features. The present invention selects the Skip-gram architecture of Word2Vec for training to obtain the word vector for each word. In order to represent the lexical features of the entire URL, the mean of all word vectors in each URL is calculated to obtain a 64-dimensional vector as the lexical feature representation of the URL, and the pseudo code is implemented as follows: Algorithm 3: Algorithm 3 Extracting lexical features of URL ;
[0026] Step 2.4, feature fusion: In the fusion feature submodule, the three character features obtained in steps 2.1, 2.2 and 2.3 are combined to obtain a total of 256-dimensional sample feature representation.
[0027] In the above embodiment, in step 3, the specific steps of constructing and training the detection model are as follows: Step 3.1, Building and training the extremely randomized tree classifier module: Use the Scikit-learn library to build the extremely randomized tree classifier module, select the labeled part of the sample features obtained in step 2.4 as the input of the extremely randomized tree classifier, set the parameters of the extremely randomized tree, and then train it; Step 3.2, labeling: Use the trained extreme random tree classifier obtained in step 3.1 to predict the unlabeled sample features in the sample features obtained in step 2.4, and use the predicted results as pseudo labels; Step 3.3, construction and training of the generator module: Based on the PyTorch framework, several linear layers and convolutional layers are constructed as generators. A 62-dimensional random distribution is selected as input, and the output is a 256-dimensional feature. The output feature is obtained by the trained extreme random tree classifier obtained in step 3.1 to obtain a pseudo-label. One of the training goals of the generator is to generate samples that are close to the real ones to challenge the discriminator's discrimination ability, which is achieved by minimizing the cross entropy loss between the discriminator output label and label 1 (representing the real sample). At the same time, samples that help the classifier make accurate decisions are generated, and the generated samples are optimized by minimizing the cross entropy loss between the pseudo-label and the classifier's predicted label, while the classifier attempts to reduce the impact of these generated samples on its decision-making process. The confrontation between the generator and the classifier aims to enhance the robustness of the classifier to incorrect labels; Step 3.4, construction and training of the discriminator module: Based on the PyTorch framework, several linear layers and convolutional layers are constructed as the discriminator. The input includes real data (including labels and unlabeled data), generated data and their labels, which come from steps 2.4, 3.2 and 3.3 respectively. The output is the data label, which aims to distinguish whether the input data is a real sample or a fake sample generated by the generator. The training task of the discriminator is to distinguish whether the input data is a real sample or a fake sample generated by the generator. This is achieved by minimizing the cross entropy loss between real samples (including labels and unlabeled data) and label 1 (indicating real samples) and minimizing the cross entropy loss between generated samples and label 0 (indicating generated samples). This is similar to a binary classification task. Through continuous confrontation with the generator, the discriminator continuously improves its discrimination ability, thereby improving the decision-making performance and generalization ability of the overall model. Step 3.5, construction and training of the classifier module: Based on the PyTorch framework, several linear layers are constructed, and the hedging algorithm is added to its back propagation as a classifier. The input is the same as the discriminator module in step 3.4, and the output is the data label, which aims to distinguish whether the input data is malicious or benign. For labeled samples, the classifier is trained by minimizing the cross entropy loss between the true label and the predicted label; for unlabeled samples, the classifier is trained by minimizing the cross entropy loss between the pseudo label and the predicted label; for generated samples, the classifier is trained by maximizing the cross entropy between the pseudo label and the predicted label.
[0028] In this embodiment, in step 5, the specific steps of malicious URL detection are as follows: Step 5.1, data preprocessing: for the URL to be tested, clean, decode, and standardize it through steps 1.2, 1.3, and 1.4 to obtain a clean and standard sample; Step 5.2, feature engineering: The samples obtained in step 5.1 are processed through steps 2.1 to 2.4 to obtain a 256-dimensional feature sequence; Step 5.3, anomaly detection: input the feature sequence obtained in step 5.2 into the classifier trained in step 3.5 for prediction, and obtain label 1 for malicious prediction and label 0 for benign prediction.
[0029] In this embodiment, in step 6, the specific steps of updating the detection model online are as follows: Step 6.1, manual feedback: Step 5.3 obtains the predicted result of the URL to be tested, and manually reviews it, and feedbacks the real label of the URL to be tested based on the review result; Step 6.2, online update: Input the features of the sample to be tested obtained in step 5.2 and the true label obtained in step 6.1 into the classifier and perform training update according to step 3.5.
[0030] In step 4, the performance evaluation index is calculated as follows: Precision Macro Average , Where: ; Recall Macro Average , Where: ; F1 score macro average , Where: ; Accuracy: ; Among them, TP means that the malicious URL is correctly identified as malicious, TN means that the legal URL is correctly identified as legal, FP means that the legal URL is incorrectly identified as malicious; FN means that the malicious URL is incorrectly identified as legal; n represents the number of categories.
[0031] As attached Figure 5 As shown in the figure, the classifier is a multi-layer perceptron (MLP) structure, which contains five linear layers and one output layer. A separate linear layer is introduced after each linear layer as the output layer network, and its output result is weighted as the final prediction result. In order to make full use of the information of each hidden layer. In addition, the classifier uses the hedge algorithm to learn the weighting parameters. In the initial iteration, the weights are evenly distributed to each output layer. In subsequent iterations, the loss is calculated based on the classifier's prediction and the true label, and the weights are updated accordingly. The classifier module can automatically assign appropriate weights to each hidden layer, automatically adapt to different network depths, and be compatible with online scenarios.
[0032] In order to verify the effectiveness of the detection method proposed in the present invention, a large number of experiments were conducted to evaluate it. The data set used is shown in Table 1 below, the data set division method is shown in Table 2 below, the experimental environment is shown in Table 3 below, and the EMO-GAN model parameters are shown in Table 4 below: Table 1 Dataset ; Table 2 Dataset segmentation ; Table 3 Experimental environment ; Table 4 EMO-GAN model parameters .
[0033] The comparative experimental evaluation results of the feature engineering mentioned in this invention and other feature engineering in the malicious URL detection task are shown in the attached figure. Figure 6 , 7 , 8. The experiment uses the Malicious URL public dataset in Table 1, and obtains nine sub-datasets as shown in Table 2. A variety of machine learning algorithms are selected, including basic machine learning algorithms (such as support vector machine SVM and logistic regression LR), ensemble learning algorithms (such as extremely random tree ET) and deep learning algorithms (such as convolutional neural network CNN and multi-layer perceptron MLP), and combined with four feature engineering methods of statistical features, character features, lexical features and hybrid features, to build and train the corresponding models, and perform statistics on performance indicators.
[0034] The comparative experimental evaluation results of the EMO-GAN model mentioned in this invention and other detection models are shown in the attached figure. Fig. 9 As shown. The experiment aims to evaluate the performance of the model in scenarios with unbalanced and label-scarce data. To be closer to the real scene, a URL dataset with a positive-negative sample ratio of 1:99 and a label ratio of only 5% was used, and hybrid features were selected as the feature extraction method. During the experiment, seven different models were tested, including two semi-supervised models (Co-training, Self-training), two generative adversarial network models (SGAN, MarginGAN), an ensemble learning model (RandomForest), a deep learning model (CNN), and the EMO-GAN model proposed in this invention.
[0035] The experimental results of the online learning ability evaluation of the EMO-GAN model mentioned in the present invention are shown in the attached figure. Fig.10As shown. The experiment aims to evaluate the ability of the EMO-GAN model to better adapt to the new data environment by fine-tuning its own parameters after receiving new data. In the experiment, the pre-trained EMO-GAN classifier was used as the basic model, and different numbers of new samples were introduced for fine-tuning. These new samples came from a dataset with a positive-to-negative sample ratio of 1:1. In order to comprehensively evaluate the online learning performance of EMO-GAN, the accuracy, precision, recall and F1 score indicators were used. These indicators are cumulative, that is, when each new sample arrives, the classifier first predicts, then adds the true label for training, and accumulates the predicted label and the true label each time to calculate the indicators.
[0036] The generalization ability evaluation experimental results of the EMO-GAN model mentioned in the present invention are shown in the attached Fig.11 The experiment was comprehensively evaluated on four different public datasets shown in Table 1. To ensure the fairness and effectiveness of the evaluation, each dataset was randomly sampled with a positive-negative sample ratio of 1:99 and a label ratio of 5%, and 100,000 samples were extracted from each dataset. There are six models involved in the comparison, covering supervised learning (ET), semi-supervised learning (self-training ET, self-training MLP), and deep learning (MLP, SGAN, MarginGAN).
[0037] The comparative experimental evaluation results of the EMO-GAN model mentioned in this invention and other mainstream detection methods are shown in the attached Fig.12 The experiment aims to verify the advancedness of the detection model of the present invention, and to illustrate that the proposed method can provide effective solutions to the data acquisition, feature acquisition and concept drift processing problems faced by the malicious URL detection task. The experimental data set uses the Malicious URL public data set in Table 1.
[0038] In summary, the present invention proposes a malicious URL detection method based on EMO-GAN to address the three major problems currently faced by malicious URL detection: difficulty in data acquisition, difficulty in feature representation, and model concept drift. The framework integrates the ideas of semi-supervised learning and generative adversarial networks (GAN) to solve the problem of data acquisition difficulties caused by imbalance and label scarcity. Semi-supervised learning is achieved by introducing extremely random trees (ET), which effectively utilizes unlabeled data and reduces the dependence on labeled data. At the same time, combined with the characteristics of MarginGAN, samples are generated and the influence of erroneous pseudo-labels is reduced, further improving the performance of the model. In addition, the present invention proposes a feature representation scheme that integrates statistical features, character features, and lexical features, effectively improves feature information, and proposes a solution for efficient feature representation of URLs. Finally, the present invention also introduces online learning technology to solve the concept drift problem in malicious URL detection. Online learning allows the model to receive new data in real time and update itself, thereby adapting to the rapidly changing data environment.
[0039] Experimental results show that the EMO-GAN proposed in this paper has achieved higher results in terms of accuracy and F1 score, and has obvious advantages over classical methods.
[0040] The above shows and describes the main features and advantages of the present invention. For those skilled in the art, it is obvious that the specific implementation of the present invention is not limited to the details of the above exemplary embodiments, and the creative ideas and design ideas of the present invention can be realized in other specific forms without departing from the spirit or basic features of the present invention, which should be equivalent to the protection scope disclosed in the technical solution of the present invention. Therefore, no matter from which point of view, the embodiments should be regarded as exemplary and non-restrictive. The scope of the present invention is defined by the attached claims rather than the above description, and it is intended to include all changes within the meaning and scope of the equivalent elements of the claims in the present invention.
[0041] In addition, it should be understood that although the present specification is described according to implementation modes, not every implementation mode contains only one independent technical solution. This description of the specification is only for the sake of clarity. Those skilled in the art should regard the specification as a whole. The technical solutions in each embodiment may also be appropriately combined to form other implementation modes that can be understood by those skilled in the art.
Claims
1. A malicious URL detection method based on EMO-GAN, characterized by: It includes the following steps: Step 1: Data preprocessing: Use crawler tools to obtain URL data from web pages, clean, decode, and standardize them to obtain sample data; Step 2, feature engineering: Use Python tools to build a feature extraction module, which includes a statistical feature extraction submodule, a character feature extraction submodule, a vocabulary feature extraction submodule and a fusion feature submodule. Input the sample data obtained in step 1 into the statistical feature extraction submodule, the character feature extraction submodule and the vocabulary feature extraction submodule respectively to obtain 128-dimensional statistical features, 64-dimensional character features and 64-dimensional vocabulary features. Input the three features into the fusion feature submodule to combine and output 256-dimensional features, where the 256-dimensional features include labeled sample features and unlabeled sample features. Step 3, construction and training of the detection model: Step 3.1, construction of the model, the detection model includes an extreme random tree classifier module, a generator module, a discriminator module and a classifier module, wherein the Scikit-learn library is used to build the extreme random tree classifier module, and the PyTorch framework is used to build the generator module, the discriminator module and the classifier module; Step 3.2, model training, set the training rounds of the model in advance, input the 256-dimensional features obtained in step 2 into the detection model for training, use the labeled features to train the extreme random tree classifier module, input the random distribution into the generator module to output the 256-dimensional generated sample features, input the generated sample features and the unlabeled sample features into the trained extreme random tree classifier module to label them, input all labeled features into the discriminator module and the classifier module for training, and the generator module is trained against the discriminator module and the classifier module respectively; Step 4: Model performance evaluation: Use the macro average of precision, recall, and F1 score as the evaluation index of the model. If the accuracy is greater than 99% and the F1 score is greater than 80%, execute step 5. Otherwise, execute step 3.2 to continue model training. Step 5, detection of malicious URLs: Collect URL data from real web pages as test data, process the test data using steps 1 and 2 to obtain output 256-dimensional features, and then input them into the trained classifier module for classification prediction, obtain corresponding labels, and complete the detection; Step 6: Online update of the detection model: The predicted labels obtained in step 5 are verified by manual feedback to obtain the true labels of the test data. The 256-dimensional features of the test data obtained in step 5 and the true labels of manual feedback are input into the classifier module for online learning and updating.
2. The malicious URL detection method based on EMO-GAN according to claim 1, characterized in that: In step 1, the specific steps of data preprocessing are as follows: Step 1.1, data acquisition: use a crawler tool to obtain URL data from the web page as input for step 1.2; Step 1.2, data cleaning: Use Python programming language to write a script to delete URL strings that belong to both malicious and benign categories. The obtained data is used as input for step 1.3; Step 1.3: Data decoding: Use Python programming language to write a script to decode the encoded special characters and hexadecimal numbers in the URL data into their original form. The obtained data is used as the input of step 1.
4. Step 1.4: Data standardization: Use Python programming language to write a script to uniformly replace non-ASCII characters in URL data with a fixed string str to obtain clean and standard sample data.
3. The malicious URL detection method based on EMO-GAN according to claim 2 is characterized in that: In step 2, the specific steps of feature engineering are as follows: Step 2.1, statistical feature extraction: In the statistical feature extraction submodule, the sample data obtained in step 1.4 is used as input, and a script is written in Python programming language to calculate a total of 128 statistical indicators of the URL as statistical features, where the statistical indicators include domain name length, the number of decimal points in the domain name, whether the domain name contains -, top-level domain name length, path length, the number of / , whether the protocol is https, the number of &, the total length of the URL, whether it contains redirection, whether it contains short links, character frequency, and keyword frequency; Step 2.2, character feature extraction: In the character feature extraction submodule, the sample data obtained in step 1.4 is used as input, and a script is written in Python programming language to convert each character of the URL into ASCII code and use it as a character feature. The character feature dimension of each URL is set to 64. For URLs with less than 64 characters, a zero-filling strategy is adopted; for URLs with more than 64 characters, truncation is performed; Step 2.3, vocabulary feature extraction: In the vocabulary feature extraction submodule, the sample data obtained in step 1.4 is used as input, and a script is written in Python programming language. First, word segmentation is performed based on regular expressions; Secondly, the word frequency-inverse file frequency of each word is calculated, and the top 500 words are selected as the filtering criteria to form a dictionary. Then, the Word2Vec model is trained using the dictionary to generate lexical features. Finally, the mean of all word vectors in the URL is calculated to obtain a 64-dimensional vector as the lexical feature representation of the URL. Step 2.4, feature fusion: In the fusion feature submodule, the three character features obtained in steps 2.1, 2.2 and 2.3 are combined to obtain a total of 256-dimensional sample feature representation.
4. The malicious URL detection method based on EMO-GAN according to claim 3 is characterized in that: In step 3, the specific steps of building and training the detection model are as follows: Step 3.1, Building and training the extremely randomized tree classifier module: Use the Scikit-learn library to build the extremely randomized tree classifier module, select the labeled part of the sample features obtained in step 2.4 as the input of the extremely randomized tree classifier, set the parameters of the extremely randomized tree, and then train it; Step 3.2, labeling: Use the trained extreme random tree classifier obtained in step 3.1 to predict the unlabeled sample features in the sample features obtained in step 2.4, and use the predicted results as pseudo labels; Step 3.3, construction and training of the generator module: Based on the PyTorch framework, several linear layers and convolutional layers are constructed as generators. A 62-dimensional random distribution is selected as input, and the output is a 256-dimensional feature. The output features are obtained by the trained extreme random tree classifier obtained in step 3.1 to obtain pseudo labels. The adversarial training with the classifier module is achieved by minimizing the cross entropy loss between the pseudo labels and the predicted labels of the classifier module. The adversarial training with the discriminator module is achieved by minimizing the cross entropy loss between the predicted labels of the discriminator module and the true labels. Step 3.4, construction and training of the discriminator module: Based on the PyTorch framework, several linear layers and convolutional layers are constructed as the discriminator. The input includes the real samples obtained in step 2.4, the generated samples obtained in step 3.3, and the labels of the two data obtained in step 3.
2. The adversarial training with the generator module is achieved by minimizing the cross entropy loss between the real samples and the real labels and minimizing the cross entropy loss between the generated samples and the generated labels. Step 3.5, building and training the classifier module: Based on the PyTorch framework, several linear layers are constructed as classifiers. The input includes the real samples obtained in step 2.4, the generated samples obtained in step 3.3, and the labels of the two data obtained in step 3.
2. For the labeled samples, the classifier module is trained by minimizing the cross entropy loss between the real label and the predicted label. For unlabeled samples, the classifier module is trained by minimizing the cross entropy loss between pseudo labels and predicted labels; For generated samples, the classifier module is trained by maximizing the cross entropy between pseudo labels and predicted labels.
5. The malicious URL detection method based on EMO-GAN according to claim 4 is characterized in that: In step 3.5, the classifier is a multi-layer perceptron structure, which contains five linear layers and one output layer. A separate linear layer is introduced after each linear layer as the output layer network, and its output result is weighted as the final prediction result; the classifier uses a hedging algorithm to learn the weighted parameters. In the initial iteration, the weights are evenly distributed to each output layer; in subsequent iterations, the loss is calculated based on the classifier's prediction and the true label, and the weight is updated accordingly.
6. A malicious URL detection method based on EMO-GAN according to any one of claims 1 to 5, characterized in that: In step 5, the specific steps of malicious URL detection are as follows: Step 5.1, data preprocessing: The URL data to be tested is cleaned in step 1.2, decoded in step 1.3, and standardized in step 1.4 to obtain clean and standard sample data; Step 5.2, feature engineering: the sample data obtained in step 5.1 is processed through steps 2.1 to 2.4 to obtain 256-dimensional features; Step 5.3, anomaly detection: Input the 256-dimensional features obtained in step 5.2 into the classifier module trained in step 3.5 for prediction, and obtain label 1 for malicious prediction and label 0 for benign prediction.
7. The method for detecting malicious URLs based on EMO-GAN according to claim 6, characterized in that: In step 6, the specific steps of online updating of the detection model are as follows: Step 6.1, manual feedback: Step 5.3 obtains the prediction result of the URL to be tested, and manually reviews it, and feedbacks the true label of the URL data to be tested based on the review result; Step 6.2, online update: Input the 256-dimensional features obtained in step 5.2 and the true labels obtained in step 6.1 into the classifier module and perform training updates according to step 3.
5.
8. A malicious URL detection method based on EMO-GAN according to any one of claims 1 to 5 or 7, characterized in that: In step 4, the performance evaluation index is calculated as follows: Precision Macro Average , Where: ; Recall Macro Average , Where: ; F1 score macro average , Where: ; Accuracy: ; Among them, TP means that the malicious URL is correctly identified as malicious, TN means that the legal URL is correctly identified as legal, FP means that the legal URL is incorrectly identified as malicious; FN means that the malicious URL is incorrectly identified as legal; n represents the number of categories.
Citation Information
Patent Citations
Semi-supervised malicious traffic detection method based on improved WGAN-GP
CN115314254A
Malicious account detection method and device based on active learning
CN115422511A
Security assessment method and system for malicious detector of Internet of Things
CN115643198A
Phishing URL detection using transformers
US20220279014A1
