A method and system for identifying bad websites based on source code structure and resource links

By extracting and cleaning website source code and network requests, combined with vectorized representation and clustering algorithms, automatic identification of bad websites with the same template but different content is achieved, solving the problem of low identification efficiency and manual reliance in the existing technology. problem, improving the accuracy and efficiency of identifying bad websites.

CN118349756BActive Publication Date: 2024-10-15JIANGSU INTERNET IND MANAGEMENT SERVICE CENT
View PDF 7 Cites 0 Cited by

Patent Information

Application Number
CN202410774673.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-06-17
Publication Date
2024-10-15
Estimated Expiration
2044-06-17

AI Technical Summary

Technical Problem

Existing bad website identification methods have problems such as low identification efficiency, the need to constantly update keywords, great reliance on manual work and batch omissions, and difficulty in discovering new templates. They fail to make full use of the structural characteristics of web pages, resulting in low identification accuracy and efficiency. .

Method used

Using an identification method based on source code structure and resource links, by extracting and cleaning the website source code and network requests, using Doc2Vec and TF-IDF weighted vector representation, combined with the HDBSCAN clustering algorithm, it can automatically identify files with the same template but different content. Bad website.

Benefits of technology

It effectively identifies cloned websites with the same structure but different content, reduces the dependence on specific characters and content, improves the accuracy and efficiency of identification, adapts to the dynamically changing network environment, and reduces the workload of monitoring personnel.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118349756B_ABST
    Figure CN118349756B_ABST
Patent Text Reader

Abstract

The invention discloses a method and system for identifying bad websites based on source code structure and resource links, and relates to the field of information security technology. By extracting and cleaning source code and request links, the interference of invalid data is reduced; by text preprocessing, keywords and feature words that can represent website features are accurately extracted; multiple features are comprehensively represented, and data dimensions are reduced by dimensionality reduction, the number of clusters is automatically determined by the HDBSCAN clustering algorithm, and noise points are effectively identified, stable and accurate clustering results are generated, and normal websites and bad websites can be effectively distinguished; for new website data, existing clustering types are used to mark and infer websites, or batch websites are input for re-clustering, and websites with similar website structures are marked to identify new bad website templates, thereby realizing automatic marking and inference of new websites, adapting to dynamically changing network environments, and improving the accuracy and timeliness of bad website identification.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of information security technology, and in particular to a method and system for identifying bad websites based on source code structure and resource links. Background Art

[0002] With the rapid development of the Internet, the speed and breadth of information dissemination have increased significantly, but at the same time, the problem of bad websites has also emerged, posing a great threat to the network environment and user security. Therefore, identifying and classifying bad websites has become an important issue to ensure the healthy development of the Internet.

[0003] There are two main existing methods for classifying and identifying bad websites: one is a classification technology based on the text content of the website, which classifies the text content of the website, such as patent [CN106599155A] classifies the text content in the website source code, and patent [CN115221376A] identifies bad websites based on the segmentation results of the website to be identified; the other is based on the text and image information of the website, such as patent [CN115374325A], which builds a deep learning classification model based on the merging of text and image features to classify the website. However, the above methods only consider the limited text and image content information of the website, and do not consider the hidden structural characteristics of the web page itself.

[0004] Although patent [CN114363019A] realizes the identification of phishing websites by extracting the URL (uniform resource location) and web page source code of the website, the structure of web pages in reality is very rich, including text, images, audio and video, source code structure and internal links, etc., and the content of bad websites often changes, while the source code templates for batch copying are relatively fixed.

[0005] Therefore, the model for identifying bad websites based on content features has problems such as low recognition efficiency, the need to constantly update keywords, heavy reliance on manual work and batch omissions, and difficulty in discovering new templates. In view of this, it is of great practical significance and application value to study how to make full use of the structural characteristics of web pages, automatically identify bad websites based on the same template with different contents, get rid of the dependence on specific characters and content, and further improve the accuracy and efficiency of recognition. Summary of the invention

[0006] In view of the problems existing in the existing bad website identification methods, such as low recognition efficiency, the need to constantly update keywords, heavy reliance on manual work and batch omissions, and difficulty in discovering new templates, the present invention proposes a bad website identification method and system based on source code structure and resource links, which can automatically identify bad websites with different contents based on the same template.

[0007] In order to achieve the above object, the present invention is implemented by the following technical solutions:

[0008] A method for identifying bad websites based on source code structure and resource links, the method comprising:

[0009] Extract the website source code and clean the extracted source code data;

[0010] Extract website network requests and clean the extracted request link list;

[0011] The cleaned source code data is subjected to text preprocessing based on source code features, and the cleaned request link list is subjected to text preprocessing based on link features;

[0012] The source code data after text preprocessing is vectorized based on Doc2Vec to obtain the source code vector; the request link list after text preprocessing is vectorized based on TF-IDF weighted Doc2Vec to obtain the request link list vector;

[0013] Performing text merging and dimensionality reduction on the source code vector and the request link list vector to generate a new vector;

[0014] The density-based clustering algorithm HDBSCAN is used to perform text clustering on the new vectors generated after dimensionality reduction, and the minimum number of samples in the neighborhood is set to 50-100;

[0015] Type inference: For new website data, use existing clustering types to label and infer websites, or input batches of websites for re-clustering, label websites with similar website structures to identify new bad website templates, and output the final inference results.

[0016] As a preferred solution of the present invention, the method of extracting the website source code and cleaning the extracted source code data specifically includes:

[0017] Download all the source code of the website and extract the source code structure of the website from it;

[0018] Clean the website text content, remove all references and random data information, remove the specific attribute values ​​after the response header, and only keep the tag information and http response header name.

[0019] As a preferred solution of the present invention, the method of extracting website network requests and cleaning the extracted request link list specifically includes:

[0020] Capture the records of website network requests and save them as log files, read and parse the log files, and extract the URLs from them to form a request link list;

[0021] Clean the request link list, remove the request information of internal links, filter out the external network request information, and filter and replace the URL.

[0022] As a preferred solution of the present invention, the method for screening and replacing URLs specifically includes:

[0023] Remove the "http: / / " and "https: / / " marks from URLs;

[0024] Slice the URL and replace the " / " separator with a space separator.

[0025] Replace lowercase or uppercase strings longer than 20 characters with 0;

[0026] Replace a random string of mixed English uppercase and lowercase letters and numbers with 0;

[0027] Replace the long character after the "=" sign with 0;

[0028] Replace ".", "_", "-", "——", "?" or other punctuation marks with spaces to standardize the URL.

[0029] As a preferred embodiment of the present invention, the text preprocessing method specifically includes:

[0030] Perform word segmentation on the source code data and the text that needs to be segmented in the request link list;

[0031] After completing the word segmentation, further remove stop words from the source code data and request link list;

[0032] Remove multiple occurrences of a word in the source data and / or request link list, and keep only the first occurrence of the word.

[0033] As a preferred solution of the present invention, the vectorized representation method specifically includes:

[0034] For the source code data, the Doc2vec algorithm is directly used, and the PV-DM training model is selected for training. The sliding window size is set to 5, and the embedding dimension is 192. After training, the source code data is converted into 192-dimensional source code vectors respectively;

[0035] For the request link list, we first clean the single URL, then perform Doc2vec conversion on the URLs one by one, and then use the TF-IDF weighted average method to obtain the request link list vector; specifically:

[0036] The i-th link The TF-IDF value is calculated as:

[0037] ;

[0038] In the formula, Represents the i-th link TF-IDF value of For Link In the request link list d j The frequency of occurrence in For Link The inverse document frequency of For Link In the request link list d j The frequency of occurrence in is the request link list d j The sum of the corresponding numbers of all links in the training corpus; |D| represents the total number of all links in the training corpus, Indicates that the corpus contains link t i The number of request link lists; j is the index of the request link list;

[0039] The total text vector representation of the request link list corresponding to any website , the calculation formula is:

[0040] ;

[0041] In the formula, is the TF-IDF value of the first link, is the Doc2Vec vector representation of the first link; is the TF-IDF value of the second link, Doc2Vec vector representation of the second link; is the TF-IDF value of the third link, Doc2Vec vector representation of the third link; is the TF-IDF value of the nth link, is the Doc2Vec vector representation of the nth link.

[0042] As a preferred solution of the present invention, text merging and dimension reduction are performed on the source code vector and the request link list vector, and the method specifically includes:

[0043] The source code vector and the request link list vector are accumulated and averaged according to the default ratio to obtain the website feature vector to express the overall characteristics of the website;

[0044] The UMAP algorithm is used to reduce the dimension of the website feature vector, the embedding space dimension is set to 50, and the minimum distance between embedding points is set to 0;

[0045] After dimensionality reduction, a new vector of 50 dimensions is obtained.

[0046] As a preferred solution of the present invention, the implementation steps of the UMAP algorithm include:

[0047] Construct a local neighborhood graph for high-dimensional data, use the k-nearest neighbor algorithm to find the nearest neighbor of each data point, and use the Gaussian kernel function to calculate the similarity between neighboring points;

[0048] Optimize the layout of low-dimensional data, use random initialization or PCA method to generate the initial position of low-dimensional data, and use the cross-entropy loss function to measure the difference between the neighborhood graphs in high-dimensional and low-dimensional space;

[0049] Iteratively update the position of low-dimensional data and use the gradient descent method to minimize the loss function so that the neighborhood graph in the low-dimensional space is maximized to approach the neighborhood graph in the high-dimensional space.

[0050] As a preferred solution of the present invention, the implementation steps of the clustering algorithm HDBSCAN include:

[0051] Calculate the core distance of each data point, that is, the minimum radius that contains at least minPts neighbors;

[0052] Based on the calculated core distance, a minimum spanning tree (MST) is constructed to connect each data point to its nearest neighbor within the core distance. The weight of the edge represents the distance between the two data points.

[0053] The minimum spanning tree MST is divided into layers, starting from the largest edge, to generate clustering results under different density thresholds;

[0054] Stability is calculated for each cluster, and is defined as the sum of the core distances of all points in the cluster minus the sum of the weights of the edges lost when the cluster is cut off;

[0055] The cluster with the highest stability is selected as the final result, and the data points that do not belong to any cluster are marked as noise.

[0056] A bad website identification system based on source code structure and resource links, using the bad website identification method based on source code structure and resource links as described above, the system comprises:

[0057] Source code extraction and cleaning module, used to extract website source code and clean the extracted source code data;

[0058] The network request extraction and cleaning module is used to extract the website network requests and clean the extracted request link list;

[0059] A text preprocessing module is used to perform text preprocessing on the cleaned source code data based on source code features, and to perform text preprocessing on the cleaned request link list based on link features;

[0060] The vectorization representation module is used to vectorize the source code data after text preprocessing based on Doc2Vec to obtain the source code vector; the request link list after text preprocessing is vectorized based on TF-IDF weighted Doc2Vec to obtain the request link list vector;

[0061] A text merging and dimension reduction module, used for performing text merging and dimension reduction on the source code vector and the request link list vector to generate a new vector;

[0062] The text clustering module is used to perform text clustering on the new vectors generated after dimensionality reduction using the density-based clustering algorithm HDBSCAN;

[0063] The type inference module is used to label and infer new website data using existing clustering types, or input batches of websites for re-clustering, and label websites with similar website structures to identify new bad website templates;

[0064] The result output module is used to output the final inference result of a normal website or a bad website.

[0065] The beneficial effects of the present invention are as follows: for bad websites that use a unified template but evade supervision by changing keywords and link images, cluster identification is performed based on website structure and request features, thereby effectively finding cloned websites with the same structure but different contents; by fusing website structure information and request link information, the model can identify similar website structures from massive websites, get rid of dependence on specific characters and content, and identify a large number of bad websites with similar structures and features more accurately and in real time, reducing the workload of monitoring personnel and improving the detection efficiency and accuracy of bad websites.

[0066] By extracting and cleaning the source code and request links, the interference of invalid data is reduced, the availability and processing efficiency of data are improved, and a clean data foundation is provided for subsequent feature extraction and vectorization; the source code data and request link list after cleaning are preprocessed, and word segmentation and stop word removal are performed based on the source code features and link features to extract useful features, which can accurately extract keywords and feature words that can represent the characteristics of the website, reduce redundant information, and improve the effectiveness of feature representation; multiple features are comprehensively represented, and the data dimension is reduced by dimensionality reduction, the main feature information is retained, the calculation complexity is reduced, and the efficiency of subsequent clustering algorithms is improved; the number of clusters is automatically determined by the HDBSCAN clustering algorithm, and noise points are effectively identified to generate stable and accurate clustering results, which can effectively distinguish normal websites from bad websites; for new website data, the existing clustering types are used to mark and infer websites, or batch websites are input for re-clustering, and websites with similar website structures are marked to identify new bad website templates, realizing automatic marking and inference of new websites, adapting to the dynamically changing network environment, and improving the accuracy and timeliness of bad website identification. BRIEF DESCRIPTION OF THE DRAWINGS

[0067] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following briefly introduces the drawings required for describing the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative labor. Among them:

[0068] Figure 1 is a flow chart of the method of the present invention;

[0069] Figure 2 This is a schematic diagram of the PV-DM model structure in an embodiment of the present invention;

[0070] Figure 3 It is a system modular structure diagram of the present invention. DETAILED DESCRIPTION

[0071] In order to make the purpose, technical solution and advantages of the embodiment of the present invention clearer, the technical solution of the embodiment of the present invention will be clearly and completely described below in conjunction with the drawings of the embodiment of the present invention. Obviously, the described embodiment is a part of the embodiment of the present invention, not all of the embodiments. Based on the described embodiment of the present invention, all other embodiments obtained by ordinary technicians in this field belong to the scope of protection of the present invention.

[0072] like Figure 1As shown in FIG. 1 , an embodiment of the present invention is provided, which provides a method for identifying bad websites based on source code structure and resource links, comprising the following steps:

[0073] S1: Extract the website source code and clean the extracted source code data;

[0074] In one embodiment, the method of step S1 specifically includes:

[0075] S11: Download all the source codes of the website and extract the source code structure of the website;

[0076] Use specific tools or scripts to download all the HTML, CSS, JavaScript files and other resource files of the website from the server through network protocols (such as HTTP or HTTPS); after the source code is downloaded, these source code files need to be parsed and processed to extract the source code structure of the website, including the hierarchical relationship of the website, links between pages, organization of the navigation menu, etc. This step usually involves analyzing the DOM tree structure of the HTML file and identifying different tags and their relationships.

[0077] S12: Clean the website text content, remove all references and random data information, remove the specific attribute values ​​after the response header, and only keep the tag information and http response header name;

[0078] After extracting the source code structure of the website, the website text content is cleaned. The main purpose of cleaning is to remove unnecessary information to make the data more concise and useful. The website source code contains a lot of text information, and the text, pictures, and local reference file names often change randomly. Simplifying the source code structure of the website can avoid different framework structure extractions due to different paths of the website.

[0079] Removing all references and random data information means removing redundant information such as reference marks, referenced documents, randomly generated content (such as advertisements, statistical codes, etc.) from the text. Removing specific attribute values ​​can simplify the data structure and reduce interference from irrelevant information. Tag information represents the structure of the web page, and the http response header name represents the basic information of network transmission. Retaining this information can maintain the basic framework of the data while reducing processing and storage costs, reduce complexity, and facilitate subsequent analysis and processing.

[0080] S2: Extract website network requests and clean the extracted request link list;

[0081] In one embodiment, the method of step S2 specifically includes:

[0082] S21: Capture the records of website network requests and save them as log files, read and parse the log files, and extract URLs from them to form a request link list;

[0083] Select a suitable packet capture tool (such as Wireshark, Fiddler, Chrome DevTools) and configure it. Use the packet capture tool to capture the records of the website's network requests and save them as log files (such as HAR file format). The log files contain detailed information about all network requests, including request URL, request method, response status code, request header, response header, request timestamp, response time, request source, etc.

[0084] S22: Clean the request link list, remove the request information of the internal link, filter out the external network request information, and filter and replace the URL;

[0085] The request link list records the http header information of the website's downloaded resources. These request logs include requests for the domain name and external URLs. Internal link information is removed and external network request logs are filtered out. These logs can represent the website's unique resource link requirements and the website's resource structure characteristics. The network module in crawler or developer mode can monitor and extract these request information from the website.

[0086] Furthermore, the method for filtering and replacing URLs specifically includes:

[0087] Remove the "http: / / " and "https: / / " identifiers from URLs; simplify URLs by removing protocol headers for easier processing;

[0088] Slice the URL, replacing the " / " separator with a space separator; split the path part of the URL to make it easier to process and analyze;

[0089] Replace lowercase or uppercase strings longer than 20 characters with 0; continuous strings longer than 20 characters usually have no practical meaning, and those that may be spam or unimportant content are filtered out;

[0090] Replace random strings that mix uppercase and lowercase letters and numbers with 0; mixed random strings are often coded information or tracking identifiers, and replacing them with 0 can avoid interference;

[0091] Replace the long characters after the "=" sign with 0. The content after the "=" sign in the URL is usually a parameter value, which may be randomly generated or encoded information. Replacing it with 0 can simplify processing.

[0092] Replace ".", "_", "-", "——", "?" or other punctuation marks with spaces to standardize the URL.

[0093] S3: Perform text preprocessing on the cleaned source code data based on source code features, and perform text preprocessing on the cleaned request link list based on link features;

[0094] In one embodiment, step S3 specifically includes:

[0095] S31: Perform word segmentation on the source code data and the text that needs word segmentation in the request link list;

[0096] S32: After completing the word segmentation, further remove the stop words in the source code data and the request link list;

[0097] Examples of stop words in source data:

[0098] Special symbols and marks: / , <, >, {,}, [, ], (, ), #, *, &, ^, %, $, @, !, ~;

[0099] Common programming language keywords (depending on the specific programming language): if, else, for, while, return, import, from, def, class, try, except, finally, with, as, and, or, not, is, in;

[0100] HTML / XML tags: html, head, body, div, span, p, a, img, ul, li, table, tr, td, form, input, button, script, style;

[0101] Example of requesting stop words in a linked list:

[0102] Common protocols and subdomains: http, https, www;

[0103] Common domain name suffixes: .com, .net, .org, .gov, .edu, .cn, .uk, .de, .jp;

[0104] Common words in URL structure: index, home, page, default, main, search, login, user, admin, profile, view, content;

[0105] Uncommonly used characters: %20 (space), %3C (<), %3E (>), %2F ( / ), %5C (), %22 ("), %27 ('), %3B (;), %3A (:)

[0106] S33: Remove the words that are repeated multiple times in the source code data and / or request link list, and only keep the first occurrence of the word.

[0107] S4: vectorize the source code data after text preprocessing based on Doc2Vec to obtain a source code vector; vectorize the request link list after text preprocessing based on TF*IDF weighted Doc2Vec to obtain a request link list vector;

[0108] Doc2vec is an unsupervised algorithm that can learn fixed-length feature representations from variable-length texts (e.g., sentences, paragraphs, or documents). It can obtain vector representations of sentences, paragraphs, and documents and is an extension of Word2Vec. It has some advantages, such as not having to fix the length of sentences and accepting sentences of different lengths as training samples. The Doc2vec algorithm is used to predict a vector to represent different documents. The structure of this model potentially overcomes the shortcomings of the bag-of-words model.

[0109] PV-DM (Distributed Memory Model of Paragraph Vectors) is one of the training models of Doc2Vec. The model structure is as follows: Figure 2 As shown in the figure. Each document is regarded as a special "word" with a vector representation (D) and has the same dimension as the word vector in the context. The combined vector is formed by averaging or concatenating these word vectors. In this process, by predicting the target word, document vectors and word vectors are learned at the same time, so as to learn distributed vector representation at the document level.

[0110] To summarize the process of the PV-DM model, there are two main steps:

[0111] Step 1: Train the model to obtain the word vector W, softmax parameters U and b, and paragraph vector or sentence vector from known training data;

[0112] The second step is the inference stage. For the new paragraph, we get its vector representation. Specifically, we add more columns to the matrix D, and use the above method to train with fixed word vectors W, parameters U and b. We use the gradient descent method to get a new D, and thus get the vector representation of the new paragraph.

[0113] Since there is no polysemy problem here and no dependence on the context, the Doc2vec algorithm is directly used on the data of the source code structure. The PV-DM training model is selected for training, the sliding window size is set to 5, and the embedding dimension is 192. After training, the source code data is converted into 192-dimensional source code vectors.

[0114] For the request link list, since it is a collection of unordered URL links and there is no contextual relationship, we first clean the single URL, then perform Doc2vec conversion on the URLs one by one, and then use the TF-IDF weighted average method to obtain the request link list vector;

[0115] The TF-IDF weighted average method requires the use of TF-IDF technology. TF-IDF technology is a commonly used text processing technology. The TF-IDF model is often used to evaluate the importance of a word to a document and is often used in search technology and information retrieval. Because network requests are based on a single URL, the TF-IDF value is calculated using a single link as the minimum unit. The importance of a single link is proportional to its frequency of appearance in the document and inversely proportional to its frequency of appearance in all corpora (i.e., the request link list of all websites).

[0116] TF-IDF is obtained by multiplying TF term frequency and IDF inverse document frequency. , its TF-IDF value The calculation formula is: ;

[0117] In the formula, For Link In the request link list d j The frequency of occurrence in For Link The inverse document frequency of For Link In the request link list d j The frequency of occurrence in is the request link list d j The sum of the corresponding numbers of all links in the training corpus; |D| represents the total number of all links in the training corpus, Indicates that the corpus contains link t i The number of request link lists; j is the index of the request link list; the total number plus one is to prevent the denominator from being zero and the IDF value from being calculated;

[0118] The total text vector representation of the request link list corresponding to any website , the calculation formula is:

[0119] ;

[0120] In the formula, is the TF-IDF value of the first link, is the Doc2Vec vector representation of the first link; is the TF-IDF value of the second link, Doc2Vec vector representation of the second link; is the TF-IDF value of the third link, Doc2Vec vector representation of the third link; is the TF-IDF value of the nth link, is the Doc2Vec vector representation of the nth link.

[0121] S5: Perform text merging and dimensionality reduction on the source code vector and the request link list vector to generate a new vector;

[0122] S51: According to the default ratio (recommended is 1:1, which can also be adjusted according to the specific training situation), the two (source code vector and request link list vector) are accumulated and averaged to obtain the website feature vector to express the overall characteristics of the website;

[0123] S52: The UMAP (Uniform Manifold Approximation and Projection) algorithm is used to reduce the dimension of the website feature vector. The embedding space dimension is set to 50, and the minimum distance between embedded points is set to 0, so that the sample points can be densely packed together, which helps to separate the clusters more clearly. After the dimensionality reduction process, a new vector of 50 dimensions can be obtained;

[0124] Density-based clustering algorithms are easily affected by the curse of dimensionality. Reducing the data dimension can make the density more obvious. For this reason, the UMAP algorithm is used to reduce the dimension of the website feature vector. UMAP is a popular nonlinear dimensionality reduction technology that is very effective for high-dimensional data and can retain the global data structure as much as possible.

[0125] The main steps of the UMAP algorithm are as follows:

[0126] Construct a local neighborhood graph for high-dimensional data, use the k-nearest neighbor algorithm to find the nearest neighbor of each data point, and use the Gaussian kernel function to calculate the similarity between neighboring points;

[0127] Optimize the layout of low-dimensional data, use random initialization or PCA to generate the initial position of low-dimensional data, and use the cross-entropy loss function to measure the difference between the neighborhood graphs in high-dimensional and low-dimensional space;

[0128] Iteratively update the position of low-dimensional data and use the gradient descent method to minimize the loss function so that the neighborhood graph in the low-dimensional space is as close as possible to the neighborhood graph in the high-dimensional space.

[0129] S6: Use the density-based clustering algorithm HDBSCAN to perform text clustering on the new vectors generated after dimensionality reduction, and set the minimum number of samples in the neighborhood to 50-100;

[0130] HDBSCAN (Hierarchical Density-Based Spatial Clustering of Applications with Noise) is an extension of the DBSCAN (Density-Based Spatial Clustering of Applications with Noise) algorithm. It uses the idea of ​​hierarchical clustering to stratify data points according to density, and then selects the most appropriate clustering level based on stability.

[0131] The main steps of HDBSCAN are as follows:

[0132] Calculate the core distance of each data point, that is, the minimum radius that contains at least minPts (minimum points) neighbors;

[0133] Based on the calculated core distance, a minimum spanning tree (MST) is constructed to connect each data point to its nearest neighbor within the core distance. The weight of the edge represents the distance between the two data points.

[0134] The minimum spanning tree MST is divided into layers, starting from the largest edge, to generate clustering results under different density thresholds;

[0135] Stability is calculated for each cluster, and is defined as the sum of the core distances of all points in the cluster minus the sum of the weights of the edges lost when the cluster is cut off;

[0136] The cluster with the highest stability is selected as the final result, and the data points that do not belong to any cluster are marked as noise.

[0137] For each data point, calculate its core distance, that is, the minimum radius containing at least minPts (minimumpoints is an important parameter used to determine the minimum density requirement) neighbors. The core distance reflects the density of the data point in its local area. If a point has fewer than minPts points in its neighborhood, the core distance of the point is usually considered to be infinite, indicating that it cannot be a core point.

[0138] The minimum spanning tree (MST) is constructed based on the core distance. In this way, an undirected graph connecting all data points is constructed. The minimum spanning tree is hierarchically clustered, starting from the largest edge of the tree and gradually cutting it off. Cutting off the largest edge will cause the cluster to split and generate different clustering levels. By continuously cutting off the largest edge, clustering results under different density thresholds can be obtained. The stability of each cluster is calculated. The higher the stability, the more stable the cluster is under different density thresholds, that is, the more reliable the clustering result is.

[0139] S7: Type inference: For new website data, use existing clustering types to label and infer websites, or input batches of websites for re-clustering, label websites with similar website structures to identify new bad website templates, and output the final inference results.

[0140] like Figure 3 As shown, another embodiment of the present invention provides a bad website identification system based on source code structure and resource links, including:

[0141] Source code extraction and cleaning module, used to extract website source code and clean the extracted source code data;

[0142] The network request extraction and cleaning module is used to extract the website network requests and clean the extracted request link list;

[0143] A text preprocessing module is used to perform text preprocessing on the cleaned source code data based on source code features, and to perform text preprocessing on the cleaned request link list based on link features;

[0144] The vectorization representation module is used to vectorize the source code data after text preprocessing based on Doc2Vec to obtain the source code vector; the request link list after text preprocessing is vectorized based on TF-IDF weighted Doc2Vec to obtain the request link list vector;

[0145] The text merging and dimension reduction module is used to merge and reduce the text of the source code vector and the request link list vector to generate a new vector;

[0146] The text clustering module is used to perform text clustering on the new vectors generated after dimensionality reduction using the density-based clustering algorithm HDBSCAN;

[0147] The type inference module is used to label and infer new website data using existing clustering types, or input batches of websites for re-clustering, and label websites with similar website structures to identify new bad website templates;

[0148] The result output module is used to output the final inference result of a normal website or a bad website.

[0149] In summary, the present invention reduces the interference of invalid data, improves the availability and processing efficiency of data, and provides a clean data basis for subsequent feature extraction and vectorization by extracting and cleaning source code and request links; performs text preprocessing on the cleaned source code data and request link list, performs word segmentation and stop word removal based on source code features and link features, extracts useful features, and accurately extracts keywords and feature words that can represent website features, reduces redundant information, and improves the effectiveness of feature representation; comprehensively represents multiple features, reduces data dimensions by dimensionality reduction, retains main feature information, reduces computational complexity, and improves the efficiency of subsequent clustering algorithms; automatically determines the number of clusters through the HDBSCAN clustering algorithm, effectively identifies noise points, generates stable and accurate clustering results, and can effectively distinguish normal websites from bad websites; for new website data, uses existing clustering types to mark and infer websites, or inputs batches of websites for re-clustering, marks websites with similar website structures, and identifies new bad website templates, thereby realizing automatic marking and inference of new websites, adapting to dynamically changing network environments, and improving the accuracy and timeliness of bad website identification.

[0150] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or other arbitrary combinations. When implemented using software, it can be implemented in whole or in part in the form of a computer program product, which includes one or more computer instructions. When loading and executing computer program instructions on a computer, the process or function according to the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium.

[0151] In addition, each functional unit in each embodiment of the present application can be integrated into a processing module, or each unit can exist physically separately, or two or more units can be integrated into one module. The above-mentioned integrated module can be implemented in the form of hardware or in the form of a software functional module. If the above-mentioned integrated module is implemented in the form of a software functional module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. The storage medium can be a read-only memory, a disk or an optical disk, etc.

[0152] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of various changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

Claims

1. A method for identifying bad websites based on source code structure and resource links, characterized in that: The method comprises: Extract the website source code and clean the extracted source code data; Extract website network requests and clean the extracted request link list; The cleaned source code data is subjected to text preprocessing based on source code features, and the cleaned request link list is subjected to text preprocessing based on link features; The source code data after text preprocessing is vectorized based on Doc2Vec to obtain the source code vector; the request link list after text preprocessing is vectorized based on TF-IDF weighted Doc2Vec to obtain the request link list vector; Performing text merging and dimensionality reduction on the source code vector and the request link list vector to generate a new vector; The density-based clustering algorithm HDBSCAN is used to perform text clustering on the new vectors generated after dimensionality reduction, and the minimum number of samples in the neighborhood is set to 50-100; Type inference: For new website data, use existing clustering types to label and infer websites, or input batches of websites for re-clustering, label websites with similar website structures to identify new bad website templates, and output the final inference results; The vectorized representation methods include: For the source code data, the Doc2vec algorithm is directly used, and the PV-DM training model is selected for training. The sliding window size is set to 5, and the embedding dimension is 192. After training, the source code data is converted into 192-dimensional source code vectors respectively; For the request link list, we first clean the single URL, then perform Doc2vec conversion on the URLs one by one, and then use the TF-IDF weighted average method to obtain the request link list vector; specifically: The i-th link The TF-IDF value is calculated as: ; In the formula, Represents the i-th link TF-IDF value of For Link In the request link list d j The frequency of occurrence in For Link The inverse document frequency of For Link In the request link list d j The frequency of occurrence in is the request link list d j The sum of the corresponding numbers of all links in the training corpus; |D| represents the total number of all links in the training corpus, Indicates that the corpus contains link t i The number of request link lists; j is the index of the request link list; The total text vector representation of the request link list corresponding to any website , the calculation formula is: ; In the formula, is the TF-IDF value of the first link, is the Doc2Vec vector representation of the first link; is the TF-IDF value of the second link, Doc2Vec vector representation of the second link; is the TF-IDF value of the third link, Doc2Vec vector representation of the third link; is the TF-IDF value of the nth link, is the Doc2Vec vector representation of the nth link.

2. A method for identifying bad websites based on source code structure and resource links according to claim 1, characterized in that: The method of extracting the website source code and cleaning the extracted source code data specifically includes: Download all the source code of the website and extract the source code structure of the website from it; Clean the website text content, remove all references and random data information, remove the specific attribute values ​​after the response header, and only keep the tag information and http response header name.

3. The method for identifying bad websites based on source code structure and resource links according to claim 1, characterized in that: The method of extracting the website network request and cleaning the extracted request link list specifically includes: Capture the records of website network requests and save them as log files, read and parse the log files, and extract the URLs from them to form a request link list; Clean the request link list, remove the request information of internal links, filter out the external network request information, and filter and replace the URL.

4. A method for identifying bad websites based on source code structure and resource links according to claim 3, characterized in that: The method for filtering and replacing the URL specifically includes: Unify the removal of "http: / / " and "https: / / " marks in URLs; Slice the URL and replace the " / " separator with a space separator. Replace lowercase or uppercase strings longer than 20 characters with 0; Replace a random string of mixed English uppercase and lowercase letters and numbers with 0; Replace the long character after the "=" sign with 0; Replace ".", "_", "-", "——", "?" or other punctuation marks with spaces to standardize the URL.

5. The method for identifying bad websites based on source code structure and resource links according to claim 1, characterized in that: The text preprocessing methods include: Perform word segmentation on the source code data and the text that needs to be segmented in the request link list; After completing the word segmentation, further remove stop words from the source code data and request link list; Remove multiple occurrences of a word in the source data and / or request link list, and keep only the first occurrence of the word.

6. The method for identifying bad websites based on source code structure and resource links according to claim 1, characterized in that: The source code vector and the request link list vector are subjected to text merging and dimension reduction, and the method specifically includes: The source code vector and the request link list vector are accumulated and averaged according to the default ratio to obtain the website feature vector to express the overall characteristics of the website; The UMAP algorithm is used to reduce the dimension of the website feature vector, the embedding space dimension is set to 50, and the minimum distance between embedding points is set to 0; After dimensionality reduction, a new vector of 50 dimensions is obtained.

7. A method for identifying bad websites based on source code structure and resource links according to claim 6, characterized in that: The implementation steps of the UMAP algorithm include: Construct a local neighborhood graph for high-dimensional data, use the k-nearest neighbor algorithm to find the nearest neighbor of each data point, and use the Gaussian kernel function to calculate the similarity between neighboring points; Optimize the layout of low-dimensional data, use random initialization or PCA method to generate the initial position of low-dimensional data, and use the cross-entropy loss function to measure the difference between the neighborhood graphs in high-dimensional and low-dimensional space; Iteratively update the position of low-dimensional data and use the gradient descent method to minimize the loss function so that the neighborhood graph in the low-dimensional space is maximized to approach the neighborhood graph in the high-dimensional space.

8. The method for identifying bad websites based on source code structure and resource links according to claim 1, characterized in that: The implementation steps of the clustering algorithm HDBSCAN include: Calculate the core distance of each data point, that is, the minimum radius that contains at least minPts neighbors; Based on the calculated core distance, a minimum spanning tree (MST) is constructed to connect each data point to its nearest neighbor within the core distance. The weight of the edge represents the distance between the two data points. The minimum spanning tree MST is divided into layers, starting from the largest edge, to generate clustering results under different density thresholds; Stability is calculated for each cluster, and is defined as the sum of the core distances of all points in the cluster minus the sum of the weights of the edges lost when the cluster is cut off; The cluster with the highest stability is selected as the final result, and the data points that do not belong to any cluster are marked as noise.

9. A bad website identification system based on source code structure and resource links, using a bad website identification method based on source code structure and resource links as claimed in any one of claims 1 to 8, characterized in that: The system comprises: Source code extraction and cleaning module, used to extract website source code and clean the extracted source code data; The network request extraction and cleaning module is used to extract the website network requests and clean the extracted request link list; A text preprocessing module is used to perform text preprocessing on the cleaned source code data based on source code features, and to perform text preprocessing on the cleaned request link list based on link features; The vectorization representation module is used to vectorize the source code data after text preprocessing based on Doc2Vec to obtain the source code vector; the request link list after text preprocessing is vectorized based on TF-IDF weighted Doc2Vec to obtain the request link list vector; A text merging and dimension reduction module, used for performing text merging and dimension reduction on the source code vector and the request link list vector to generate a new vector; The text clustering module is used to perform text clustering on the new vectors generated after dimensionality reduction using the density-based clustering algorithm HDBSCAN; The type inference module is used to label and infer new website data using existing clustering types, or input batches of websites for re-clustering, and label websites with similar website structures to identify new bad website templates; The result output module is used to output the final inference result of a normal website or a bad website.

Citation Information

Patent Citations

  • Method and system for classifying web pages

    CN106599155A

  • Phishing website detection model training method and device, equipment and storage medium

    CN114363019A

  • Malicious website identification method and system, electronic device and storage medium

    CN115221376A

  • Website classification method and device, classification equipment and storage medium

    CN115374325A

  • Yellow-related and block-related website detection method based on mixed feature analysis

    CN112347244A