Malicious URL detection method and system based on semantic feature fusion and enhancement

CN122528913APending Publication Date: 2026-08-07CHANGSHU INSTITUTE OF TECHNOLOGY
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
CHANGSHU INSTITUTE OF TECHNOLOGY
Filing Date
2026-07-13
Publication Date
2026-08-07

AI Technical Summary

Technical Problem

[0006]针对现有恶意URL检测方法在短URL、字符变体、局部扰动和噪声片段较多场景下存在的上下文表征不稳定、局部模式提取不足以及关键片段聚合不准确的问题,本发明的目的在于提供一种基于语义特征融合与增强的恶意URL检测方法及系统,能够融合多层上下文语义特征、增强多尺度局部结构建模能力,并对关键URL片段进行自适应聚合,以提高恶意URL检测的准确性、稳定性和泛化能力

Benefits of technology

1、本发明通过层级表征融合模块对多层上下文语义特征进行自适应融合,能够充分利用不同隐藏层中的局部形态信息、结构模式信息和高层语义信息,提高短URL场景下序列表征的稳定性。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122528913A_ABST
    Figure CN122528913A_ABST
Patent Text Reader

Abstract

The application discloses a malicious URL detection method and system based on semantic feature fusion and enhancement, and comprises the following steps: obtaining a URL text to be detected to obtain a URL input sequence; extracting a multi-layer context semantic feature from the URL input sequence, fusing the multi-layer context semantic feature, and obtaining a robust URL sequence representation; extracting a character-level local pattern, a cross-fragment dependency and a disturbance feature from the robust URL sequence representation, and obtaining an enhanced URL sequence representation; obtaining a pooling representation corresponding to multiple attention heads through a multi-head attention pooling unit from the enhanced URL sequence representation, fusing the pooling representations corresponding to the multiple attention heads, generating a URL-level global representation, and outputting a malicious URL judgment result through a classifier. The application can enhance the representation ability of URL local patterns and key fragments, and improve the accuracy and stability of the malicious URL detection result.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of malicious URL detection technology. It relates to a method and system for detecting malicious URLs based on semantic feature fusion and enhancement. Background Technology

[0002] Malicious URLs are a significant vector in cyberattacks. Attackers often use phishing links, malicious download addresses, fake login pages, shortened link redirects, and abnormal parameter injection to lure users to dangerous websites or perform high-risk operations, leading to account leaks, financial losses, or device infections. Therefore, accurate identification and timely blocking of malicious URLs are crucial components of a cybersecurity protection system.

[0003] Currently, malicious URL detection methods mainly include blacklist matching, rule matching, traditional machine learning, and deep learning. Blacklisting and rule matching methods are simple to implement, but rely on manual maintenance and struggle to promptly cover newly generated malicious URLs, variant URLs, and zero-day attack links. Traditional machine learning methods typically require manual extraction of features such as URL length, number of special characters, domain hierarchy, path depth, and query parameters, combined with a classifier for judgment. However, their detection effectiveness is significantly affected by manual feature design and has limited generalization ability in cross-dataset or complex URL variations scenarios.

[0004] In recent years, detection methods based on pre-trained language models have been increasingly applied to malicious URL identification tasks. These methods can automatically learn contextual semantic features from URL sequences, reducing reliance on manual feature engineering. However, URL text differs from ordinary natural language text, typically exhibiting characteristics such as short sequences, loose structure, dense symbols, frequent character variations, and sensitivity to local fragments. Directly employing general pre-trained encoders can easily lead to problems such as insufficient perception of local character patterns, inadequate capture of cross-fragment dependencies, and instability in short sequence representations.

[0005] Furthermore, existing methods typically generate URL-level representations directly using the last hidden state, [CLS] vectors, or simple pooling, which makes it difficult to effectively distinguish noisy segments such as the domain body, suspicious substrings, and random parameters. When the URL contains prefix and suffix perturbations, abnormal paths, encoding obfuscation, or random strings, the model output is easily affected by irrelevant segments, impacting the accuracy and stability of the detection results. Summary of the Invention

[0006] To address the problems of unstable contextual representation, insufficient local pattern extraction, and inaccurate key fragment aggregation in existing malicious URL detection methods in scenarios with short URLs, character variations, local perturbations, and numerous noisy fragments, the present invention aims to provide a malicious URL detection method and system based on semantic feature fusion and enhancement. This method can fuse multi-layer contextual semantic features, enhance multi-scale local structure modeling capabilities, and adaptively aggregate key URL fragments to improve the accuracy, stability, and generalization ability of malicious URL detection.

[0007] The technical solution to achieve the purpose of this invention is as follows: A malicious URL detection method based on semantic feature fusion and enhancement includes the following steps: S01: Obtain the URL text to be detected, and get the URL input sequence; S02: Extract multi-layer contextual semantic features from the URL input sequence, and fuse the multi-layer contextual semantic features to obtain a robust URL sequence representation; S03: Extract local structural patterns and cross-fragment dependencies from the robust URL sequence representation to obtain an enhanced URL sequence representation; S04: The enhanced URL sequence representation is obtained by passing the multi-head attention pooling unit to obtain pooled representations corresponding to multiple attention heads. The pooled representations corresponding to multiple attention heads are fused to generate a URL-level global representation. The malicious URL judgment result is output by the classifier.

[0008] In the preferred technical solution, step S01, obtaining the URL input sequence, includes: The URL text to be detected is standardized. The URL text is segmented into sub-words to obtain a sub-word sequence, and the sub-word sequence is mapped to an integer index sequence; When the URL text length exceeds the preset maximum length, it is truncated; when the URL text length is less than the preset maximum length, it is padded. Attention masks are generated simultaneously to distinguish between valid and padded positions, so that the padded positions are masked in subsequent semantic encoding and feature aggregation processes.

[0009] In the preferred technical solution, step S02, extracting multi-layer contextual semantic features, includes: The URL input sequence is modeled using the DeBERTa encoder to output the sequence hidden states corresponding to multiple hidden layers. The sequence hidden states are used to represent the domain name, path, parameters, symbol fragments, abnormal character combinations and their contextual relationships in the URL text.

[0010] In the preferred technical solution, the robust URL sequence representation includes: Obtain the hidden states of the last K layers of the DeBERTa encoder output. Generate fusion weights for each hidden layer using learnable layer weight parameters and temperature parameter τ. Perform a linear combination of the hidden states of the last K layers of the sequence based on the fusion weights to obtain a robust URL sequence representation.

[0011] In the preferred technical solution, the hidden states of the last K-layer sequence output by the DeBERTa encoder are obtained as follows: ; Set a set of learnable hierarchical weight parameters The fusion weights for each hidden layer are calculated using a softmax function with a temperature parameter τ. The calculation method is as follows:

[0012] According to the fusion weight A robust URL sequence representation is obtained by linearly combining the hidden states of the last K layers of the DeBERTa encoder. The calculation method is as follows:

[0013] in, L This indicates the total number of hidden layers in the DeBERTa encoder. K This indicates the number of hidden layers participating in the fusion. Indicates the first k Each learnable layer weight parameter corresponds to a hidden layer involved in the fusion process, where τ represents the temperature parameter. This represents the robust URL sequence representation obtained after hierarchical fusion.

[0014] In the preferred technical solution, step S03, extracting local structural patterns and cross-fragment dependencies from the URL, includes: Normalize the robust URL sequence representation; Multiple one-dimensional depthwise convolutional kernels with different dilation rates are used to convolve the normalized robust URL sequence representation to obtain multi-scale convolutional features Z. The multi-scale convolutional feature Z is divided into channels and nonlinear gated activation to obtain the gated convolutional feature Y. Gating coefficients G are generated based on robust URL sequence representations, and the gated convolutional features Y are adjusted position by position. The adjusted convolutional features are fused with the robust URL sequence representation to obtain the enhanced URL sequence representation. .

[0015] In the preferred technical solution, the scale-based convolutional features obtained include: Multi-scale convolution is performed using a dilation rate set D={1,2,4,8}, and the convolutional features obtained under different dilation rates are fused to obtain the multi-scale convolutional feature Z. The calculation method is as follows:

[0016] in, This represents a one-dimensional depthwise convolution operation with an inflation rate of d.

[0017] In the preferred technical solution, generating a URL-level global representation in step S04 includes: The enhanced URL sequence representation is divided according to attention heads. Different attention heads are linearly scored and mask-aware softmax calculated in their respective subspaces. The attention mask is applied to the mask-aware softmax in each attention head so that the filling position does not participate in attention normalization, thus obtaining the attention weights at different positions. The enhanced features at each sequence position are weighted and summed according to the attention weights to obtain pooled representations corresponding to multiple attention heads; The pooled representations of multiple attention heads are passed through the inter-head weight generation module to obtain the corresponding inter-head gating weights, and then the URL-level global representation is obtained by concatenating the gating weights.

[0018] This invention also discloses a malicious URL detection system based on semantic feature fusion and enhancement, used to implement the aforementioned malicious URL detection method based on semantic feature fusion and enhancement, comprising: The URL preprocessing module obtains the URL text to be detected, resulting in the URL input sequence; The semantic encoding module extracts multi-layer contextual semantic features from the URL input sequence; The hierarchical representation fusion module fuses the multi-layered contextual semantic features to obtain a robust URL sequence representation; The multi-scale gated convolutional enhancement module extracts local structural patterns and cross-segment dependencies from the robust URL sequence representation to obtain an enhanced URL sequence representation. The multi-head gating pooling module obtains pooled representations corresponding to multiple attention heads by passing the enhanced URL sequence representation through the multi-head attention pooling unit, fuses the pooled representations corresponding to multiple attention heads to generate a URL-level global representation, and outputs the malicious URL judgment result through the classifier.

[0019] The present invention also discloses a computer storage medium storing a computer program thereon, which, when executed, implements the above-mentioned malicious URL detection method based on semantic feature fusion and enhancement.

[0020] Compared with the prior art, the significant advantages of this invention are: 1. This invention adaptively fuses multi-layer contextual semantic features through a hierarchical representation fusion module, which can make full use of local morphological information, structural pattern information and high-level semantic information in different hidden layers, thereby improving the stability of sequence representation in short URL scenarios.

[0021] 2. This invention introduces one-dimensional deep convolutions with different dilation rates through a multi-scale gated convolution enhancement module, which can capture character-level n-grams, prefix and suffix perturbations, path segment associations and cross-parameter dependencies under different receptive fields, thereby enhancing the model's ability to perceive the local abnormal structure of malicious URLs.

[0022] 3. This invention uses channel gating, position-by-position gating, residual scaling, and multi-head gating pooling mechanisms to adaptively adjust and fuse multi-scale convolutional features and pooling results of different attention heads. This can highlight key segments such as domain name body, suspicious substrings, and abnormal paths, and reduce the impact of random parameters, padding positions, and irrelevant segments on the detection results.

[0023] 4. This invention can be implemented in various forms such as methods, systems, and computer-readable storage media, and can be applied to application scenarios such as browser security detection, gateway filtering, email security detection, terminal protection, and network content review, and has good deployment adaptability and practical application value. Attached Figure Description

[0024] Figure 1 This is a flowchart of the malicious URL detection method based on semantic feature fusion and enhancement in this embodiment; Figure 2 This is a diagram illustrating the overall structure of the malicious URL detection method based on semantic feature fusion and enhancement in this embodiment. Figure 3 This is a flowchart illustrating the malicious URL detection method based on semantic feature fusion and enhancement in this embodiment. Figure 4 This is a schematic diagram of the hierarchical representation fusion module structure in this embodiment; Figure 5 This is a schematic diagram of the multi-scale gated convolution enhancement module structure in this embodiment; Figure 6 This is a schematic diagram of the multi-head gating pooling module structure in this embodiment. Detailed Implementation

[0025] Invention principle: This invention can integrate multi-layer contextual semantic features, enhance multi-scale local structure modeling capabilities, and adaptively aggregate key URL fragments to extract character-level local patterns, cross-fragment dependencies, and perturbation features, thereby improving the accuracy, stability, and generalization ability of malicious URL detection.

[0026] Example 1: like Figure 1 , Figure 2 As shown, a malicious URL detection method based on semantic feature fusion and enhancement includes the following steps: S01: Obtain the URL text to be detected, and get the URL input sequence; S02: Extract multi-layer contextual semantic features from the URL input sequence, and fuse the multi-layer contextual semantic features to obtain a robust URL sequence representation; S03: Extract local structural patterns and cross-fragment dependencies from the robust URL sequence representation to obtain an enhanced URL sequence representation; S04: The enhanced URL sequence representation is obtained by passing the multi-head attention pooling unit to obtain pooled representations corresponding to multiple attention heads. The pooled representations corresponding to multiple attention heads are fused to generate a URL-level global representation. The malicious URL judgment result is output by the classifier.

[0027] Another embodiment, a malicious URL detection system based on semantic feature fusion and enhancement, includes: The URL preprocessing module obtains the URL text to be detected, resulting in the URL input sequence; The semantic encoding module extracts multi-layer contextual semantic features from the URL input sequence; The hierarchical representation fusion module fuses the multi-layered contextual semantic features to obtain a robust URL sequence representation; The multi-scale gated convolutional enhancement module extracts character-level local patterns, cross-segment dependencies, and perturbation features from the robust URL sequence representation to obtain an enhanced URL sequence representation. The multi-head gating pooling module obtains pooled representations corresponding to multiple attention heads by passing the enhanced URL sequence representation through the multi-head attention pooling unit, fuses the pooled representations corresponding to multiple attention heads to generate a URL-level global representation, and outputs the malicious URL judgment result through the classifier.

[0028] like Figure 3 As shown, the model flow in this embodiment includes URL input, URL preprocessing, SentencePiece segmentation and encoding, DeBERTa-v3 encoding, hierarchical representation fusion module, multi-scale gated convolution enhancement module, multi-head gated pooling module, fully connected layer, and classification output layer. After the URL text to be detected goes through the above process, the classification output layer finally provides the judgment result of whether it is a benign or malicious URL. Figure 3 This is used to illustrate the processing order and data transfer relationship between the various functional modules in this application.

[0029] In the URL preprocessing stage, the URL text to be detected is first obtained and then normalized. Normalization includes removing leading and trailing whitespace characters from the URL text, standardizing character formats, and preserving or standardizing protocol fields, domain fields, path fields, query parameters, special symbols, and abnormal characters in the URL.

[0030] Since malicious URLs often conceal their attack intent through special characters, encoding obfuscation, abnormal paths, random parameters, or short link redirects, this embodiment does not simply remove special structures from the URLs during preprocessing. Instead, it retains character fragments with discriminative significance as much as possible while ensuring a consistent input format. This approach avoids the removal of suspicious markers from malicious URLs due to over-cleaning, thereby improving the subsequent model's ability to detect abnormal structures.

[0031] During the training phase, for labeled URL samples, the original labels from different data sources are mapped to a unified benign and malicious category. For example, labels such as "normal access links" and "legitimate webpage links" can be mapped to the benign category, while labels such as "phishing links," "malicious download links," "fraudulent links," or "abnormal attack links" can be mapped to the malicious category. Through label normalization, URL samples from different data sources and labeling systems can be trained and detected within the same binary classification framework.

[0032] In the SentencePiece segmentation and encoding stage, a segmenter matched with the DeBERTa encoder is used to segment the URL text into sub-words, obtaining a sub-word sequence, which is then mapped to an integer index sequence. Compared with traditional character-level encoding methods, the SentencePiece segmentation method can reduce the sparsity of the input representation by utilizing the existing vocabulary representation capabilities of the pre-trained model while preserving fine-grained character information of the URL.

[0033] When the URL text length exceeds the preset maximum length, the system truncates it; when the URL text length is less than the preset maximum length, the system pads it and simultaneously generates an attention mask. The attention mask is used to distinguish between valid positions and padding positions, so that the padding positions are masked in subsequent semantic encoding, attention calculation, and pooling aggregation processes, avoiding interference from padding information on the URL-level representation.

[0034] In a preferred embodiment, the URL text to be detected is segmented and encoded to form a URL input sequence, which is then input into the subsequent DeBERTa-v3 encoder along with an attention mask. The URL input sequence represents sub-word fragments, symbol fragments, and path fragments in the URL, while the attention mask marks which positions in the sequence belong to the actual URL content and which belong to filler content.

[0035] In the DeBERTa semantic encoding stage, the URL input sequence is fed into the DeBERTa-v3 encoder to extract contextual semantic features corresponding to multiple hidden layers. The DeBERTa-v3 encoder is used to model the domain name, path, parameters, symbol fragments, abnormal character combinations and their contextual relationships in the URL, thereby obtaining a sequence of hidden states with context-aware capabilities. The sequence of hidden states is used to represent the domain name, path, parameters, symbol fragments, abnormal character combinations and their contextual relationships in the URL text.

[0036] It should be noted that this application may use other DeBERTa encoders or other models, as long as they can extract the contextual semantic features corresponding to multiple hidden layers.

[0037] Because URL text typically has characteristics such as short sequences, dense symbols, obvious local perturbations, and weak natural semantics, using only the last layer of hidden states can easily lead to unstable representations of short sequences. Especially in malicious URLs, a small number of character substitutions, path concatenations, or parameter perturbations can change the risk attributes of the URL. If the model relies on only a single layer of output, it is easily affected by local noise or individual abnormal segments.

[0038] Based on the above characteristics, this embodiment further introduces a hierarchical representation fusion module to adaptively fuse the multi-layer hidden states output by the DeBERTa-v3 encoder. By fusing the contextual representations of multiple hidden layers, the model can not only retain the character morphology and local fragment information in the earlier layers, but also utilize the structural relationship information in the middle layers and the high-level semantic information in the later layers, thereby obtaining a more robust URL sequence representation.

[0039] like Figure 4 As shown, the hierarchical representation fusion module takes the last K hidden states output by the DeBERTa-v3 encoder as input, generates fusion weights corresponding to each hidden layer through learnable hierarchical weight parameters and temperature parameters τ, and then performs linear combination of the last K hidden states according to the fusion weights to obtain the fused URL sequence representation.

[0040] Figure 4 In this process, the URL term sequence is encoded by a DeBERTa-v3 encoder, which outputs multiple hidden layer representations, including the hidden states of the last few layers. Learnable scores and temperature parameters are input to the layer weights Softmax, used to generate the layer weights corresponding to different hidden layers. Subsequently, these layer weights are applied to multiple hidden layer representations, and the resulting fused sequence features are obtained through layer-weighted fusion.

[0041] In a preferred embodiment, the hierarchical representation fusion module sets a set of learnable hierarchical weight parameters. The fusion weights corresponding to the k-th layer are calculated using a softmax function with a temperature parameter τ. The temperature parameter τ is used to adjust the smoothness of the weight distribution in different layers, enabling the model to automatically select the more contributing hidden layer information based on the URL detection task.

[0042] Specifically, the last K hidden states output by the DeBERTa encoder are: Set a set of learnable hierarchical weight parameters The fusion weights for each hidden layer are calculated using a softmax function with a temperature parameter τ. The calculation method is as follows:

[0043] According to the fusion weight The hierarchical representation fusion module performs a linear combination of the last K hidden states of the DeBERTa-v3 encoder to obtain a robust URL sequence representation. This robust URL sequence representation serves as input to subsequent multi-scale gated convolutional enhancement modules, used to further extract local structural patterns and cross-segment dependencies from the URLs.

[0044] Specifically, the calculation method is as follows:

[0045] in, L This indicates the total number of hidden layers in the DeBERTa encoder. K This represents the number of hidden layers participating in the fusion, and τ represents the temperature parameter. This represents the URL sequence after hierarchical fusion.

[0046] Obtaining robust URL sequence representations Subsequently, the system inputs it into a multi-scale gated convolutional enhancement module. Malicious URLs often contain local structural features such as prefix and suffix perturbations, character substitutions, abnormal paths, random strings, encoding obfuscation, and cross-parameter dependencies. Relying solely on the Transformer self-attention mechanism may be insufficient to fully capture these fine-grained patterns. Therefore, this embodiment explicitly enhances the local character-level patterns and cross-segment structural information in the URL sequence through multi-scale dilated deep convolutions.

[0047] like Figure 5 As shown, the multi-scale gated convolution enhancement module includes a pre-normalization unit, a multi-scale dilated depthwise separable convolution unit, a multi-scale feature accumulation unit, a gated activation unit, a position-wise gated unit, a residual scaling unit, and a residual fusion unit. These units work together to enable the model to enhance the modeling of local anomalies in URLs without compromising the semantic representation of DeBERTa-v3.

[0048] Specifically, after the robust URL sequence representation enters the multi-scale gated convolutional enhancement module, it first undergoes pre-normalization processing via Pre-LN. Pre-normalization can make the distribution of input features more stable, reduce the sensitivity of subsequent convolution and gating operations to feature scale, and facilitate the convergence of the model training process.

[0049] Subsequently, the pre-normalized sequence representation is transformed into a feature shape suitable for one-dimensional convolution processing through a transpose operation. Since one-dimensional convolution typically extracts local patterns along the sequence direction, transpose processing allows the convolution kernel to more easily operate on adjacent term segments and cross-segment positions in the URL sequence.

[0050] In a preferred embodiment, the multi-scale dilated depthwise convolutional unit uses a dilation rate set D={1,2,4,8} for convolution processing. Different dilation rates correspond to different receptive field sizes, capable of covering local character segments of different scales such as 3-gram, 5-gram, 9-gram, and 17-gram. Smaller receptive fields are beneficial for capturing short, suspicious character combinations, while larger receptive fields are beneficial for capturing path segments, parameter fields, and cross-segment dependencies.

[0051] The multi-scale dilated depthwise convolutional unit accumulates the convolutional features obtained under different dilation rates to obtain the multi-scale convolutional feature Z, which is calculated as follows:

[0052] in, This represents a one-dimensional depthwise convolution operation with an inflation rate of d.

[0053] This processing method can simultaneously preserve short-range local patterns and long-span structural dependencies in the same representation space, thereby enhancing the model's ability to identify deformed malicious URLs and abnormal fragments.

[0054] The channel gating unit divides the multi-scale convolutional feature Z into channels and obtains the gated convolutional feature Y through nonlinear gating activation. This process can adaptively control the degree of passage of convolutional features in different channels, so that the model retains local patterns that contribute to the identification of malicious URLs, while suppressing invalid responses caused by random parameters, irrelevant characters or noise fragments.

[0055] Furthermore, the position-wise gating unit generates gating coefficients G based on the robust URL sequence representation and adjusts the gated convolutional features Y position-wise. Since different positions in the URL sequence have different importance—for example, the domain body, login fields, abnormal paths, and suspicious parameters often have strong discriminative power, while partially padded positions, random numbers, or tracking parameters may contribute less—position-wise gating allows the model to focus more on key segments and reduce the impact of irrelevant positions on the detection results.

[0056] The residual scaling unit controls the degree to which convolutional branches affect the original robust URL sequence representation. In a preferred embodiment, the residual scaling unit introduces a learnable residual scaling parameter λ, and constrains the learnable residual scaling parameter λ to a stable range using a sigmoid function. This residual scaling setting avoids excessive perturbation of the pre-trained semantic representation by the convolutional branches in the early stages of training, thereby improving the model training stability.

[0057] The residual fusion unit fuses the gated convolutional features with robust URL sequence representations to obtain enhanced URL sequence representations. The calculation method is as follows:

[0058] in, This represents the Sigmoid activation function. λ represents the random deactivation operation, λ represents the learnable residual scaling parameter, and ⊙ represents element-wise multiplication.

[0059] The enhanced URL sequence representation incorporates both contextual semantic information extracted by DeBERTa-v3 and local structural information enhanced by multi-scale convolution, enabling a more comprehensive characterization of suspicious character combinations, abnormal paths, and cross-parameter dependencies in URLs.

[0060] In obtaining enhanced URL sequence representation The system then inputs it into the multi-head gating pooling module. For malicious URL detection tasks, different URL fragments contribute differently to the final classification result. Domain body, sensitive keywords, abnormal paths, suspicious parameters, and encoded obfuscated fragments usually contain strong discriminative information, while random parameters, padding positions, or irrelevant fragments may introduce noise.

[0061] Based on the above characteristics, this embodiment employs a multi-head attention pooling and inter-head gating fusion mechanism to compress the enhanced URL sequence representation into a stable URL-level global representation. This mechanism can distinguish the importance of different positions at the sequence position level and the contribution degree of different subspace features at the attention head level.

[0062] like Figure 6As shown, the multi-head gating pooling module includes a multi-head attention pooling unit and an inter-head gating fusion unit. The multi-head attention pooling unit divides the enhanced URL sequence representation according to attention heads and masks the padding positions according to the attention mask, assigning attention weights to different effective positions in the URL sequence; the inter-head gating fusion unit adaptively weights and fuses the pooled representations corresponding to multiple attention heads to generate a URL-level global representation.

[0063] The multi-head gating pooling module's processing includes multi-head partitioning, multi-head attention pooling units, attention mask input, head outputs, inter-head weight generation, gating weighted concatenation, and global URL representation generation. The enhanced URL sequence representation is first partitioned according to attention heads. Different attention heads perform linear scoring and mask-aware softmax calculations within their respective subspaces to obtain attention weights at different positions.

[0064] Before the softmax normalization of each attention head, the attention mask masks the attention scores corresponding to the filling position, making the attention weight of the filling position close to 0, thereby preventing the filling position from participating in URL-level feature aggregation.

[0065] In one specific implementation, for the m-th sample, the h-th attention head, and the i-th sequence position, the attention weights are... Pooling representation The calculation method is as follows:

[0066] in, This represents the attention score for the m-th sample, the h-th attention head, and the i-th sequence position. This represents the feature representation of the m-th sample and the i-th position in the enhanced URL sequence representation.

[0067] Different attention heads can focus on different suspicious segments in the URL. For example, some attention heads can focus more on the domain body, some on the path field, and others on abnormal parameters, random strings, or character perturbations. Through this multi-head mechanism, the model can extract complementary URL risk features from multiple subspaces.

[0068] After obtaining the pooled representations corresponding to multiple attention heads, the inter-head gating fusion unit further performs adaptive weighted fusion on the outputs of each head. Since the contribution of different attention heads to the final detection result is not exactly the same, some attention heads may extract effective malicious patterns, while others may be affected by dataset noise or random fragments. Therefore, inter-head gating fusion can enhance the contribution of effective attention heads and suppress the influence of redundant or noisy attention heads.

[0069] In a preferred embodiment, the inter-head weight generation module includes an inter-head scoring layer, a softmax normalization layer, and a gated weighted concatenation layer. This module first scores the pooled representation of each attention head to obtain an importance score for each attention head; then, it uses softmax normalization to obtain the inter-head gating weights for each attention head; finally, it weights and concatenates the pooled representations of multiple attention heads according to the inter-head gating weights to obtain a URL-level global representation. This approach can adaptively allocate weights based on the contribution of different attention heads to the detection results, thereby enhancing the role of effective attention heads and suppressing the influence of redundant or noisy attention heads.

[0070] The classification output module outputs the probability distribution of benign or malicious URLs based on the URL-level global representation. Specifically, the URL-level global representation is input into the fully connected layer and the classification output layer, and the class probability is obtained through the softmax function. The calculation method is as follows:

[0071] in, This represents the URL-level global representation of the m-th URL to be detected. and These represent the weight matrix and bias term of the classifier, respectively. p This represents the probability distribution of categories.

[0072] When the probability of a malicious URL category is greater than a preset threshold, output the malicious URL detection result; otherwise, output the benign URL detection result.

[0073] The preset threshold can be adjusted based on the false positive rate, false negative rate, and security protection requirements in the actual deployment scenario. For example, in scenarios such as real-time browser interception, gateway security filtering, or email security detection, the threshold can be appropriately adjusted according to the security policy to balance the needs of false positive control and malicious URL recall.

[0074] As described above, this embodiment extracts contextual semantic features using a DeBERTa-v3 encoder, improves the stability of sequence representations in short URL scenarios through a hierarchical representation fusion module, captures character-level local patterns, path fragment associations, and cross-parameter dependencies through a multi-scale gated convolution enhancement module, and highlights key URL fragments through a multi-head gated pooling module, ultimately obtaining a stable URL-level global representation. This method can reduce the interference of random parameters, padding positions, and irrelevant fragments on the detection results, improving the accuracy and stability of malicious URL detection.

[0075] The method and system described in this embodiment can be applied to scenarios such as browser security detection, gateway filtering, email security detection, endpoint protection, network content review, and enterprise secure access control. In actual deployment, the URL to be accessed can be input into the detection system in real time. The classification output module provides a judgment result indicating whether the URL is benign or malicious, and executes processing strategies such as allowing access, issuing alarms, blocking, or further manual review based on the detection results. The above application methods are merely examples and do not constitute a limitation on the application scenarios of this application.

[0076] Experiment and effect verification

[0077] To verify the effectiveness of the malicious URL detection method based on DeBERTa and multi-scale gating described in the embodiments of this application, experimental verification was conducted based on a publicly available malicious URL detection dataset.

[0078] The experiment mainly evaluates the method of this application from the aspects of detection accuracy, malicious sample identification ability, stability under different datasets, and the contribution of each functional module.

[0079] This embodiment selects the GramBeddings dataset and the Phishing URL dataset as evaluation objects. Both datasets contain benign and malicious URL samples, which can be used to verify the detection effect of this method on URL samples from different sources and of different sizes.

[0080] To ensure consistency in experimental evaluation, labels from different sources were uniformly mapped to benign and malicious categories during the experiment, and training and testing were conducted within a binary classification task framework.

[0081] In one specific experimental setup, the GramBeddings dataset contained 200,000 benign samples and 200,000 malicious samples, totaling 400,000 URL samples; the Phishing URL dataset contained 104,438 benign samples and 104,438 malicious samples, totaling 208,876 URL samples. The statistics for these datasets are shown in Table 1.

[0082] Table 1 Dataset Statistics

[0083] The above samples were normalized, segmented and encoded, truncated and padded, and attention masked before being input into the model to verify the applicability of the method in this application under different URL sample distributions.

[0084] In the experimental environment, the model uses DeBERTa-v3 as the backbone semantic encoder, and then builds a hierarchical representation fusion module, a multi-scale gated convolution enhancement module, and a multi-head gated pooling module on top of it.

[0085] The AdamW optimizer was used during training, with an initial learning rate of 2e-5, weight decay of 1e-4, Dropout coefficient of 0.10, batch size of 16, and training epochs of 3.

[0086] The training set is used for model parameter updates, the validation set is used for hyperparameter selection and model state assessment, and the test set is used only for final performance evaluation.

[0087] The main hyperparameter settings for the experiment are shown in Table 2.

[0088] Table 2. Main hyperparameter settings for the experiment

[0089] To comprehensively evaluate the model's detection capabilities, this embodiment uses accuracy, precision, recall, and F1 score as evaluation metrics.

[0090] Accuracy rate reflects the proportion of times the model correctly identifies benign and malicious URLs overall.

[0091] Precision is used to reflect the proportion of truly malicious URLs among the samples that are judged as malicious URLs by the model.

[0092] Recall rate reflects the proportion of genuine malicious URLs that are successfully identified by the model.

[0093] The F1 score is used to comprehensively measure the balance between precision and recall.

[0094] To verify the performance advantages of the method in this application, it was compared with several typical malicious URL detection methods.

[0095] The comparison methods include GramBeddings based on n-gram embeddings, DomURLS_BERT, TransUrl, URLBERT, and PMANet based on pre-trained language models. The method in this application is named GateMix-URLNet.

[0096] The results of the main control experiment are shown in Table 3.

[0097] Table 3 Results of the main comparison experiment

[0098] As shown in Table 3, on the GramBeddings dataset, the accuracy, precision, recall and F1 score of the method in this application reached 0.9849, 0.9860, 0.9838 and 0.9849, respectively.

[0099] Compared with the GramBeddings method, the accuracy of the method in this application is improved from 0.9650 to 0.9849, and the F1 score is improved from 0.9647 to 0.9849.

[0100] Compared with the PMANet method, the accuracy of the method in this application is improved from 0.9669 to 0.9849, and the F1 value is improved from 0.9667 to 0.9849.

[0101] The above results demonstrate that, in URL samples with complex structures and obvious local perturbations, the method of this application can better distinguish between benign and malicious URLs, and can maintain a good malicious sample recall capability while maintaining a high accuracy rate.

[0102] On the Phishing URL dataset, the accuracy, precision, recall, and F1 score of the proposed method reached 0.9980, 0.9994, 0.9966, and 0.9980, respectively.

[0103] Compared with the TransUrl method, the accuracy of the method in this application is improved from 0.9947 to 0.9980, and the F1 score is improved from 0.9947 to 0.9980.

[0104] Compared with the PMANet method, the accuracy of the method in this application is improved from 0.9950 to 0.9980, and the F1 value is improved from 0.9949 to 0.9980.

[0105] The results show that the proposed method can still maintain high detection accuracy on datasets where the overall classification performance is close to saturation, and it performs stably in terms of false alarm control and malicious sample identification.

[0106] The experimental results from the two datasets show that the method proposed in this application achieved good detection results under different data sources and sample sizes.

[0107] The comparative experimental results above demonstrate that the performance improvement of the method in this application does not come from the adjustment of a single classifier, but from the synergistic effect between multiple functional modules.

[0108] Among them, the hierarchical representation fusion module can improve the stability of context representation in short URL scenarios.

[0109] The multi-scale gated convolution enhancement module can enhance the ability to perceive character-level local patterns and cross-fragment dependencies.

[0110] The multi-head gating pooling module can highlight key segments such as the domain body, suspicious substrings, and abnormal paths, thereby jointly improving the detection effect of malicious URLs.

[0111] To further verify the contribution of each functional module to the overall performance, ablation experiments were conducted on the GramBeddings dataset.

[0112] Ablation experiments were conducted to remove or replace some functional modules, and changes in model accuracy, precision, recall, and F1 score were observed.

[0113] The ablation experiment setup includes removing all enhancement modules, removing hierarchical representation fusion modules, removing multi-scale convolutional enhancement modules, retaining only some convolutional branches, removing multi-head gating pooling modules, and randomly disabling some attention heads.

[0114] The results of the ablation experiment are shown in Table 4.

[0115] Table 4 Ablation Experiment Results

[0116] As shown in Table 4, when all enhancement modules are removed, the model accuracy, precision, recall and F1 score are 0.9786, 0.9813, 0.9755 and 0.9784, respectively.

[0117] When the hierarchical representation fusion module is removed, the model accuracy, precision, recall, and F1 score are 0.9824, 0.9840, 0.9789, and 0.9814, respectively.

[0118] When the multi-scale convolutional enhancement module was removed, the model accuracy, precision, recall, and F1 score were 0.9801, 0.9820, 0.9764, and 0.9792, respectively.

[0119] When using two-way 3 and 9 convolution branches, the model accuracy, precision, recall, and F1 score are 0.9820, 0.9835, 0.9787, and 0.9811, respectively.

[0120] When the multi-head gating pooling module is removed, the model accuracy, precision, recall, and F1 score are 0.9806, 0.9824, 0.9778, and 0.9801, respectively.

[0121] When 30% of the attention heads were randomly turned off, the model's accuracy, precision, recall, and F1 score were 0.9818, 0.9831, 0.9795, and 0.9813, respectively.

[0122] In comparison, the full model achieved accuracy, precision, recall, and F1 score of 0.9849, 0.9860, 0.9838, and 0.9849 on the GramBeddings dataset, respectively, all of which were higher than the ablation version mentioned above.

[0123] The results show that the hierarchical representation fusion module, the multi-scale gated convolution enhancement module, and the multi-head gated pooling module all make positive contributions to the model performance.

[0124] The ablation experiment results show that the model performance drops significantly after removing the multi-scale convolution enhancement module, indicating that structural features such as character-level n-grams, local perturbations, and cross-fragment dependencies play an important role in malicious URL identification.

[0125] After removing the multi-head gating pooling module, the model's ability to aggregate key URL segments during the readout phase weakens, indicating that relying solely on simple pooling methods is insufficient to fully distinguish the importance of different segments such as domain body, abnormal paths, and random parameters.

[0126] After removing the hierarchical representation fusion module, the model performance also decreased, indicating that using only a single hidden layer output is not sufficient to adapt to scenarios with short URLs and many character perturbations.

[0127] By fusing the multi-layered hidden states of the DeBERTa-v3 encoder, the model can integrate the local morphological information, structural pattern information, and contextual semantic information of the URL at different levels of abstraction, thereby obtaining a more stable sequence representation.

[0128] Based on the main comparison experiment and ablation experiment, it can be seen that the method described in the embodiments of this application can achieve stable results on multiple publicly available malicious URL detection datasets.

[0129] Compared with conventional detection methods based on single-layer hidden states, simple convolution, or ordinary pooling, the method in this application can more fully integrate multi-layer contextual semantic information, enhance the ability to perceive multi-scale local structures and character perturbations, and adaptively aggregate key URL fragments.

[0130] Therefore, the method of this application can improve the accuracy and stability of malicious URL detection results.

[0131] The above experimental results further demonstrate that the method described in the embodiments of this application has good practical application value.

[0132] This method can maintain high detection performance in datasets with complex structures and obvious local perturbations, and can further improve fine-grained metrics in datasets where classification performance is close to saturation.

[0133] The method described in this application can be applied to practical scenarios such as browser security detection, gateway filtering, email security detection, endpoint protection, and network content review.

[0134] It should be noted that the above experimental results are only used to illustrate the effectiveness of the methods described in the embodiments of this application, and do not constitute a limitation on the scope of protection of this application.

[0135] Those skilled in the art may adjust the number of training samples, network parameters, threshold settings, deployment methods, or post-processing strategies according to the actual application scenario, data scale, hardware conditions, and security strategies. Such adjustments shall still fall within the reasonable scope of implementation of the technical solution of this application.

[0136] In another embodiment, a computer storage medium stores a computer program that, when executed, is the malicious URL detection method based on semantic feature fusion and enhancement described in any of the preceding embodiments.

[0137] The above embodiments are preferred embodiments of the present invention, but the embodiments of the present invention are not limited to the above embodiments. Any changes, modifications, substitutions, combinations, or simplifications made without departing from the spirit and principle of the present invention shall be considered equivalent substitutions and shall be included within the protection scope of the present invention.

Claims

1. A malicious URL detection method based on semantic feature fusion and enhancement, characterized in that, Includes the following steps: S01: Obtain the URL text to be detected, and get the URL input sequence; S02: Extract multi-layer contextual semantic features from the URL input sequence, and fuse the multi-layer contextual semantic features to obtain a robust URL sequence representation; S03: Extract local structural patterns and cross-fragment dependencies from the robust URL sequence representation to obtain an enhanced URL sequence representation; S04: The enhanced URL sequence representation is obtained by passing the multi-head attention pooling unit to obtain pooled representations corresponding to multiple attention heads. The pooled representations corresponding to multiple attention heads are fused to generate a URL-level global representation. The malicious URL judgment result is output by the classifier.

2. The malicious URL detection method based on semantic feature fusion and enhancement according to claim 1, characterized in that, Step S01 yields the following URL input sequence: The URL text to be detected is standardized. The URL text is segmented into sub-words to obtain a sub-word sequence, and the sub-word sequence is mapped to an integer index sequence; When the URL text length exceeds the preset maximum length, it is truncated; when the URL text length is less than the preset maximum length, it is padded. Attention masks are generated simultaneously to distinguish between valid and padded positions, so that the padded positions are masked in subsequent semantic encoding and feature aggregation processes.

3. The malicious URL detection method based on semantic feature fusion and enhancement according to claim 1, characterized in that, Step S02 involves extracting multi-layer contextual semantic features, including: The URL input sequence is modeled using the DeBERTa encoder to output the sequence hidden states corresponding to multiple hidden layers. The sequence hidden states are used to represent the domain name, path, parameters, symbol fragments, abnormal character combinations and their contextual relationships in the URL text.

4. The malicious URL detection method based on semantic feature fusion and enhancement according to claim 3, characterized in that, The robust URL sequence representation includes: Obtain the hidden states of the last K layers of the DeBERTa encoder output. Generate fusion weights for each hidden layer using learnable layer weight parameters and temperature parameter τ. Perform a linear combination of the hidden states of the last K layers of the sequence based on the fusion weights to obtain a robust URL sequence representation.

5. The malicious URL detection method based on semantic feature fusion and enhancement according to claim 4, characterized in that, The hidden states of the last K layers of the DeBERTa encoder output are obtained as follows: ; Set a set of learnable hierarchical weight parameters The fusion weights for each hidden layer are calculated using a softmax function with a temperature parameter τ. The calculation method is as follows: According to the fusion weight A robust URL sequence representation is obtained by linearly combining the hidden states of the last K layers of the DeBERTa encoder. The calculation method is as follows: in, L This indicates the total number of hidden layers in the DeBERTa encoder. K This indicates the number of hidden layers participating in the fusion. Indicates the first k The learnable layer weight parameters corresponding to the hidden layers involved in the fusion, where τ represents the temperature parameter. This represents the robust URL sequence representation obtained after hierarchical fusion.

6. The malicious URL detection method based on semantic feature fusion and enhancement according to claim 1, characterized in that, Step S03, extracting local structural patterns and cross-fragment dependencies from the URL, includes: Normalize the robust URL sequence representation; Multiple one-dimensional depthwise convolutional kernels with different dilation rates are used to convolve the normalized robust URL sequence representation to obtain multi-scale convolutional features Z. The multi-scale convolutional feature Z is divided into channels and nonlinear gated activation to obtain the gated convolutional feature Y. Gating coefficients G are generated based on robust URL sequence representations, and the gated convolutional features Y are adjusted position by position. The adjusted convolutional features are fused with the robust URL sequence representation to obtain the enhanced URL sequence representation. .

7. The malicious URL detection method based on semantic feature fusion and enhancement according to claim 6, characterized in that, The scaled convolutional features obtained include: Multi-scale convolution is performed using a dilation rate set D={1,2,4,8}, and the convolutional features obtained under different dilation rates are fused to obtain the multi-scale convolutional feature Z. The calculation method is as follows: in, This represents a one-dimensional depthwise convolution operation with an inflation rate of d.

8. The malicious URL detection method based on semantic feature fusion and enhancement according to claim 1, characterized in that, Step S04, generating a URL-level global representation, includes: The enhanced URL sequence representation is divided according to attention heads. Different attention heads are linearly scored and mask-aware softmax calculated in their respective subspaces. The attention mask is applied to the mask-aware softmax layer in each attention head so that the filling position does not participate in attention normalization, thus obtaining the attention weights at different positions. The enhanced features at each sequence position are weighted and summed according to the attention weights to obtain pooled representations corresponding to multiple attention heads; The pooled representations of multiple attention heads are passed through the inter-head weight generation module to obtain the corresponding inter-head gating weights, and then the URL-level global representation is obtained by concatenating the gating weights.

9. A malicious URL detection system based on semantic feature fusion and enhancement, used to implement the malicious URL detection method based on semantic feature fusion and enhancement as described in any one of claims 1-8, characterized in that, include: The URL preprocessing module obtains the URL text to be detected, resulting in the URL input sequence; The semantic encoding module extracts multi-layer contextual semantic features from the URL input sequence; The hierarchical representation fusion module fuses the multi-layered contextual semantic features to obtain a robust URL sequence representation; The multi-scale gated convolutional enhancement module extracts local structural patterns and cross-segment dependencies from the robust URL sequence representation to obtain an enhanced URL sequence representation. The multi-head gating pooling module obtains pooled representations corresponding to multiple attention heads by passing the enhanced URL sequence representation through the multi-head attention pooling unit, fuses the pooled representations corresponding to multiple attention heads to generate a URL-level global representation, and outputs the malicious URL judgment result through the classifier.

10. A computer storage medium having a computer program stored thereon, characterized in that, When the computer program is executed, it implements the malicious URL detection method based on semantic feature fusion and enhancement as described in any one of claims 1-8.