Website sensitive word detection method and device
Through the Horspool algorithm and thread pool technology, efficient detection of sensitive words on website pages is achieved, solving the problem of low detection efficiency in the existing technology, improving network management efficiency and accuracy, and reducing resource waste.
Patent Information
- Application Number
- CN202310334120.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-31
- Publication Date
- 2024-10-01
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Existing technology is difficult to quickly and accurately detect sensitive words on web pages, resulting in inefficient network management and the inability to intercept and filter bad information in a timely manner.
Using the Horspool algorithm combined with thread pool technology, the response content of the links to be detected is obtained in batches and matched through the sensitive word database. If a sensitive word is triggered, an alarm will be issued. It also supports the detection and response of simplified Chinese characters, traditional Chinese characters, pinyin and two simplified characters. When the content is too long, it will be split and detected in parallel, and expired links will be requested again.
It improves the efficiency of sensitive word detection, reduces invalid alarms, prevents waste of resources, can more accurately identify and filter out bad information, and improves network management efficiency.
Smart Images

Figure FT_1 
Figure FT_2
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of website security, and in particular relates to a method for detecting sensitive words on pages of links on a website and a device applying the method. Background Art
[0002] With the development of mobile Internet, users can publish information on various online platforms, comment on media resources on various online platforms, interact with the authors of media resources, and communicate online, such as making phone calls. However, all good interactions are based on high-quality media resources and a good network atmosphere. To build a good network atmosphere, it mainly depends on various online platforms to search and verify the content, and intercept and filter the bad information after determining it to be bad information.
[0003] Therefore, how to quickly and accurately detect sensitive words on website pages and issue timely warnings has positive significance for maintaining network cleanliness and improving network management efficiency. Summary of the invention
[0004] Based on the above background, the present invention aims to propose a method for realizing efficient detection of sensitive words on a website and a sensitive word detection device of a website security detection system applying the method.
[0005] In the first aspect, a method for detecting sensitive words on a website is proposed, comprising: according to the configuration parameters of the detection task, batches of links to be detected are obtained and added to a thread pool; requests are periodically initiated to the links in the thread pool to obtain response content; a sensitive word library is loaded, and the response content is detected using the Horspool algorithm, and if a sensitive word is triggered, an alarm is issued according to a preset configuration.
[0006] The above-mentioned sensitive word database also includes the categories to which the sensitive words belong and the corresponding levels. When a sensitive word of a preset category and / or preset level is triggered, an alarm of a preset level is issued.
[0007] After the above detection task is completed, the detection results including the link address, the triggered keywords and their positions are output; when the sensitive word library is triggered, if the detection result successfully matches the ignored word library, the alarm is cancelled.
[0008] Preferably, if the length of the response header or response content string is greater than 10,000, it is segmented by rounding up the string length / 10,000, and a corresponding number of threads are started according to the number of segments to perform detection in parallel.
[0009] Also, when obtaining the link to be detected, the number of directory levels of each link is less than the task configuration, and the number of pages of each link is less than the task configuration; and, before the detection, if the link data has expired, the request information is carried to re-request the response content.
[0010] Preferably, the sensitive word database includes simplified Chinese characters, traditional Chinese characters, pinyin and simplified Chinese characters.
[0011] In the second aspect, a sensitive word detection device of a website security detection system is proposed, comprising: Pre-crawling module, used to periodically crawl link data to be detected from the target website; Task scheduling module, used to create sensitive word detection tasks and configure task parameters; The word library module includes a preset sensitive word library and an ignored word library, wherein the sensitive word library includes simplified Chinese characters, traditional Chinese characters, pinyin and two simplified Chinese characters; The detection module performs the detection task, requests the response content from the link to be detected, and performs sensitive word detection on the response content; The alarm module will issue an alarm according to the preset task configuration if the link to be detected triggers sensitive words.
[0012] Preferably, the sensitive word library of the above-mentioned word library module further includes the categories to which the sensitive words belong and the corresponding levels. When a sensitive word of a preset category and / or preset level is triggered, an alarm of a preset level is issued.
[0013] Preferably, the above-mentioned sensitive word detection module obtains links to be detected in batches and adds them to a thread pool according to the configuration parameters of the detection task; regularly initiates requests to the links in the thread pool to obtain response content, and uses the Horspool algorithm to detect the response content.
[0014] Furthermore, if the length of the response header or response content string is greater than 10,000, it is split according to the string length / 10,000 and rounded up, and a corresponding number of threads are started according to the number of splits to perform detection in parallel; Also, when obtaining the link to be detected, the number of directory levels of each link is less than the task configuration, and the number of pages of each link is less than the task configuration; and, before the detection, if the link data has expired, the request information is carried to re-request the response content.
[0015] The present invention adopting the above technical solution has at least the following beneficial effects: crawling the link to be detected from the target website, requesting the link to be detected to obtain the response content, loading the sensitive word library according to the detection task configuration, matching the response content with the word library using a preset algorithm, and issuing an alarm when a sensitive keyword is triggered. Among them, the Horspool algorithm detection is more efficient; when the length of the response content string is greater than 10,000, it is segmented and matched in parallel by multiple threads, which is conducive to improving the matching efficiency; when a sensitive word is triggered, it is further matched with the ignored word library, which can screen out special websites and reduce invalid alarms; before matching, it is judged whether the link is expired to prevent the processing of expired data, which is conducive to reducing resource waste. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] Figure 1 This is a schematic diagram of the working process of an embodiment of a method for detecting sensitive words on a website according to the present invention; Figure 2 This is a schematic diagram of the module composition of an embodiment of the website sensitive word detection device of the present invention. Implementation
[0017] To make the purpose, technical solution and advantages of the embodiments of the present invention more clear, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of the present invention.
[0018] First, the technical terms involved in the embodiments of the present invention are explained: Horspool algorithm: The pattern starts matching from the last character on the right (the pattern is a slider sliding along the text, if the pattern does not match, it slides n string lengths, and the sliding length is determined by the alphabet): If the character at the end of the pattern is inconsistent with the character x corresponding to the current text, determine whether x is in the pattern. If not, move the pattern forward n positions; If the text character x matches a character in the pattern, the pattern is aligned to the right; If the last character is exactly the same as the corresponding character x in the current text, but x is not included in the other m-1 characters of the pattern, the shift is the length of the pattern; If the last character is exactly the same as the corresponding character x in the current text, and x is included in the other m-1 characters of the pattern, align the x in the first m-1 characters of the pattern with the x in the text when moving.
[0019] The specific process includes: (1) For a given pattern of length m, construct the alphabet used in the pattern and text by yourself; (2) align the pattern with the text; (3) Starting from the last character of the pattern, compare the pattern with the corresponding characters in the text until: (1) all m characters are matched; or (2) a pair of unmatched characters is encountered. In the latter case, if c is a character in the current text that aligns with the last character of the pattern, take the cell t(c) away from column c of the shift alphabet and shift the pattern right along the text by t(c) characters. Sensitive word monitoring task input parameters: {user_id, task_id}. The monitoring task process is as follows: 1. Call the MySQL database operation method to obtain configuration parameters from the sensitiv_confe library; 2. Call the sqlite3 database operation method to obtain monitoring keywords from the key_words library; 3. Start monitoring, determine whether an alarm is generated, and store the alarm information in the database; 4. Alarms are not called by the monitoring engine, but vulnerability alarms are collected periodically by the scheduling engine. An embodiment of a method for detecting sensitive words on a website, the overall process includes: (1) Task scheduling engine - issuing tasks; (2) Receive and determine whether the parameters are correct; (3) Load the vocabulary (sensitive words, ignored words); (4) Obtain configuration information; (5) Sensitive word monitoring; (6) The alarm information is sent to the alarm engine.
[0020] like Figure 1 The specific process shown is to obtain the links to be detected in batches and add them to the thread pool according to the configuration parameters of the detection task; to initiate requests to the links in the thread pool at regular intervals to obtain response content; to load the sensitive word library, and to use the Horspool algorithm to detect the response content. If a sensitive word is triggered, an alarm is issued according to the preset configuration.
[0021] The above-mentioned sensitive word database also includes the categories to which the sensitive words belong and the corresponding levels. When a sensitive word of a preset category and / or preset level is triggered, an alarm of a preset level is issued.
[0022] After the above detection task is completed, the detection results including the link address, the triggered keywords and their positions are output; when the sensitive word library is triggered, if the detection result successfully matches the ignored word library, the alarm is cancelled.
[0023] Preferably, if the length of the response header or response content string is greater than 10,000, it is segmented by rounding up the string length / 10,000, and a corresponding number of threads are started according to the number of segments to perform detection in parallel.
[0024] Also, when obtaining the link to be detected, the number of directory levels of each link is less than the task configuration, and the number of pages of each link is less than the task configuration; and, before the detection, if the link data has expired, the request information is carried to re-request the response content.
[0025] Preferably, the above sensitive word database includes simplified Chinese characters, traditional Chinese characters, pinyin and two simplified Chinese characters. Specifically: Based on the above sensitive word monitoring method, the implementation method of traditional Chinese character monitoring is: convert the sensitive words in the sensitive word library into traditional Chinese characters by converting simplified Chinese characters into traditional Chinese characters. The sensitive words processed by traditional Chinese characters are monitored by the monitoring engine, thereby realizing the monitoring of sensitive words in traditional Chinese characters. By comparison, the zhconv library is simpler to use, and the traditional Chinese word library in the zhconv library is richer, providing the maximum positive matching simplified and traditional Chinese conversion based on the MediaWiki vocabulary, and supporting multiple regions.
[0026] The implementation principle of sensitive word monitoring in pinyin is similar to that of traditional Chinese characters, which is to convert sensitive words in the sensitive word library into pinyin, and then perform sensitive word monitoring, so as to realize sensitive word monitoring in pinyin. The xpinyin library is a third-party library that converts Chinese characters into pinyin. Compared with xpinyin, pypinyin is more powerful. Pypinyin provides three functions, 'slug, pinyin' and 'lazy_pinyin'. The difference lies in whether the result is returned with tone by default, whether the result is a string or a list, and the separator. xpinyin has the function 'get_pinyin'.
[0027] The PyPinyin library is a Python third-party library that supports Chinese to Pinyin output. It can intelligently match the most correct Pinyin according to the phrase, and supports polyphonetic characters, simple traditional Chinese, Zhuyin, and conversion of multiple different Pinyin / Zhuyin styles.
[0028] By consulting the relevant information on the second simplified characters, the official second simplified characters table currently released is a full table of 268 characters, and most of the characters cannot be typed now. The second simplified characters that can be typed are all simplified characters that are typed into simple simplified characters. Therefore, the current method is to sort out the second simplified characters that can be typed, select the more prominent second simplified characters from them, and compare them with the obtained web page content, so as to realize the second simplified character detection.
[0029] like Figure 2 As shown, an embodiment of a sensitive word detection device of a website security detection system includes: Pre-crawling module, used to periodically crawl link data to be detected from the target website; Task scheduling module, used to create sensitive word detection tasks and configure task parameters; The word library module includes a preset sensitive word library and an ignored word library, wherein the sensitive word library includes simplified Chinese characters, traditional Chinese characters, pinyin and two simplified Chinese characters; The detection module performs the detection task, requests the response content from the link to be detected, and performs sensitive word detection on the response content; The alarm module will issue an alarm according to the preset task configuration if the link to be detected triggers sensitive words.
[0030] Preferably, the sensitive word library of the above-mentioned word library module further includes the categories to which the sensitive words belong and the corresponding levels. When a sensitive word of a preset category and / or preset level is triggered, an alarm of a preset level is issued.
[0031] Preferably, the above-mentioned sensitive word detection module obtains links to be detected in batches and adds them to a thread pool according to the configuration parameters of the detection task; regularly initiates requests to the links in the thread pool to obtain response content, and uses the Horspool algorithm to detect the response content.
[0032] Furthermore, if the length of the response header or response content string is greater than 10,000, it is split according to the string length / 10,000 and rounded up, and a corresponding number of threads are started according to the number of splits to perform detection in parallel; When obtaining the link to be detected, the number of directory levels of each link is less than the task configuration, and the number of pages of each link is less than the task configuration; and, before the detection, if the link data has expired, the request information is carried to re-request the response content.
[0033] In the technical solution of the embodiment of the present invention as described above, the link to be detected is crawled from the target website, the response content is obtained from the request to the link to be detected, the sensitive word library is loaded according to the detection task configuration, the response content is matched with the library using a preset algorithm, and an alarm is issued when a sensitive keyword is triggered. Among them, the Horspool algorithm detection is more efficient; when the length of the response content string is greater than 10,000, it is segmented and matched in parallel with multiple threads, which is conducive to improving the matching efficiency; when a sensitive word is triggered, it is further matched with the ignored word library, which can screen out special websites and reduce invalid alarms; before matching, it is judged whether the link is expired to prevent the processing of expired data, which is conducive to reducing resource waste.
[0034] A person skilled in the art can understand that all or part of the steps in the above embodiments can be implemented by instructing related hardware through a program, and the program can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc.
[0035] The above description of the above disclosed embodiments enables those skilled in the art to implement or use the present invention. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but will conform to the broadest scope consistent with the principles disclosed herein.
Claims
1. A method for detecting sensitive words on a website, characterized in that: include: According to the configuration parameters of the detection task, batches of links to be detected are obtained and added to the thread pool; Initiate a request to the link in the thread pool at a regular interval to obtain the response content; The sensitive word library is loaded, and the Horspool algorithm is used to detect the response content. If a sensitive word is triggered, an alarm is issued according to the preset configuration.
2. The sensitive word detection method according to claim 1, characterized in that: The sensitive word database also includes the categories to which the sensitive words belong and the corresponding levels. When a sensitive word of a preset category and / or preset level is triggered, an alarm of a preset level is issued.
3. The sensitive word detection method according to claim 1 or 2, characterized in that: After the detection task is completed, the detection result including the link address, the triggered keywords and their positions is output; when the sensitive word library is triggered, if the detection result successfully matches the ignored word library, the alarm is cancelled.
4. The sensitive word detection method according to claim 1, characterized in that: If the length of the response header or response content string is greater than 10,000, it is split into parts according to the string length / 10,000, and the corresponding number of threads are started for parallel detection according to the number of parts.
5. The sensitive word detection method according to claim 1, characterized in that: When obtaining the link to be detected, the number of directory levels of each link is less than the task configuration, and the number of pages of each link is less than the task configuration; and, before the detection, if the link data has expired, the request information is carried to re-request the response content.
6. The sensitive word detection method according to claim 1, characterized in that: The sensitive word database includes simplified Chinese characters, traditional Chinese characters, pinyin and two simplified Chinese characters.
7. A sensitive word detection device for a website security detection system, characterized in that: The device includes: Pre-crawling module, used to periodically crawl link data to be detected from the target website; Task scheduling module, used to create sensitive word detection tasks and configure task parameters; The word library module includes a preset sensitive word library and an ignored word library, wherein the sensitive word library includes simplified Chinese characters, traditional Chinese characters, pinyin and two simplified Chinese characters; The detection module performs the detection task, requests the response content from the link to be detected, and performs sensitive word detection on the response content; The alarm module will issue an alarm according to the preset task configuration if the link to be detected triggers sensitive words.
8. The device according to claim 7, characterized in that The sensitive word library of the word library module also includes the categories to which the sensitive words belong and the corresponding levels. When a sensitive word of a preset category and / or preset level is triggered, an alarm of a preset level is issued.
9. The device according to claim 7, characterized in that The sensitive word detection module, according to the configuration parameters of the detection task, batches the links to be detected and adds them to the thread pool; regularly initiates requests to the links in the thread pool, obtains response content, and uses the Horspool algorithm to detect the response content.
10. The device according to claim 9, characterized in that If the length of the response header or response content string is greater than 10,000, it will be split into parts according to the string length / 10,000, and the corresponding number of threads will be started for parallel detection according to the number of parts. When obtaining the link to be detected, the number of directory levels of each link is less than the task configuration, and the number of pages of each link is less than the task configuration; and, before the detection, if the link data has expired, the request information is carried to re-request the response content.
