Construction method of attack detection model and attack detection method
By building an attack detection model, using neural networks and attention mechanisms, combining multi-dimensional data feature extraction and time-division strategy, the problem of low accuracy of web attack detection in the existing technology is solved, and efficient identification and prediction of network attacks is achieved. .
Patent Information
- Application Number
- CN202411019557.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-29
- Publication Date
- 2024-11-01
- Estimated Expiration
- 2044-07-29
AI Technical Summary
When detecting Web attacks, the detection accuracy of multi-dimensional anomaly data is low, making it difficult to effectively identify and predict cyber attack behavior, and traditional methods cannot effectively detect zero-day attacks and variant attacks.
Build an attack detection model, by obtaining multiple network sample data, extracting sample features and training neural network models, adopting a time-dividing strategy and attention mechanism, combining a two-way gated recurrent network and a two-way long and short-term memory network, build a capable of targeting different stages. Detection model to improve detection accuracy and efficiency.
It realizes more accurate identification and prediction of network attacks, improves overall detection efficiency and accuracy, and can detect network attacks comprehensively and accurately from multiple dimensions, adapting to different stages of network attacks for effective detection and analysis.
Smart Images

Figure CN118555140B_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the field of network security technology, and specifically relates to a method for constructing an attack detection model and an attack detection method. Background Art
[0002] Web attacks refer to methods used by hackers to attack users' online operations or hardware facilities such as servers, such as implanting malicious attack code segments in the client, dynamically modifying website permissions, embedding and obtaining user privacy information, etc. Web attacks are highly complex and can appear in various fields of http protocol data, such as headers, URIs, parameters, and other dimensions.
[0003] In the prior art, most Web attack detection methods focus on a single or several dimensions. The detection effect of a single dimension is acceptable, but for multi-dimensional abnormal data, the detection accuracy is low and has great limitations. Therefore, there is an urgent need for an efficient and accurate attack detection method in this field. Summary of the invention
[0004] In view of this, the purpose of this application is to provide a method for constructing an attack detection model and an attack detection method to improve the accuracy and efficiency of network attack detection.
[0005] In a first aspect, an embodiment of the present application provides a method for constructing an attack detection model, the method comprising: obtaining multiple network sample data, the multiple network sample data comprising first time period sample data and second time period sample data; extracting sample features of the multiple network sample data; training a first neural network using the sample features of the first time period sample data, and training a second neural network using the sample features of the second time period sample data, wherein the first time period sample data is request time period sample data, and the second time period sample data is response time period sample data; constructing an attack detection model, the attack detection model comprising: an output layer and an intermediate layer, the intermediate layer being composed of the first neural network and the second neural network combined.
[0006] The above attack detection model construction method captures the inherent patterns and dependencies of network attacks by establishing a neural network model to improve the accuracy and efficiency of network attack detection, and adopts a time-division strategy to train the model, ensuring that the attack detection model can effectively detect and analyze different stages of network attacks. This enables the attack detection model to more accurately identify and predict network attack behaviors, further improving the overall detection efficiency and accuracy.
[0007] In an optional embodiment of the present application, sample data in any time period includes network traffic logs, attack attempt data, vulnerability attack data, and attack payload data.
[0008] In the above embodiment, acquiring sample data from multiple dimensions can enable the trained model to perform network attack detection from multiple dimensions, and can detect network attacks more comprehensively and accurately.
[0009] In an optional embodiment of the present application, extracting sample features of the multiple network sample data includes: encoding the multiple network sample data using a specified format to obtain encoded data; denoising and cleaning the encoded data to obtain cleaned data; performing feature extraction on the cleaned data after word segmentation to obtain feature data of each network sample data; performing feature crossover and / or polynomial expansion based on the feature data to obtain sample features of each of the network sample data.
[0010] In the above embodiment, irrelevant and erroneous information in the request data is removed to ensure the quality of the sample data, and continuous text data in the feature data is broken into meaningful phrases, which can help the model better analyze network attacks.
[0011] In an optional embodiment of the present application, the attack detection model also includes an attention layer, which is used to receive the multiple features output by the intermediate layer and assign weights to the multiple features; and transmit the multiple features and the weights to the output layer.
[0012] In the above embodiment, an attention mechanism is introduced into the attack detection model, so that the attack detection model focuses on key features, thereby increasing the sensitivity of the model to specific attack patterns and ensuring higher accuracy and efficiency.
[0013] In an optional embodiment of the present application, the attack detection model further includes a feature extraction layer, and the method further includes: using the multiple network sample data to train the feature extraction layer to extract local spatial features.
[0014] In an optional embodiment of the present application, the first neural network is a bidirectional gated recurrent network, and the second neural network is a bidirectional long short-term memory network. The method of training the first neural network using the sample features of the sample data of the first time period, and training the second neural network using the sample features of the sample data of the second time period, includes: sorting the local spatial features of the sample data of the first time period and the local spatial features of the sample data of the second time period according to a time series to generate first time series data and second time series data, respectively, wherein the time series includes a request time sequence, a time occurrence sequence, and a fixed time sequence; learning the data dependency features in the first time series data based on the bidirectional gated recurrent network to form a first neural network; and learning the time dependency features in the second time series data based on the bidirectional long short-term memory network to form a second neural network.
[0015] In the above embodiment, the discrete feature data are arranged in chronological order so that the attack detection model can learn the dependency of the features over time. Thus, the attack detection model can not only understand the features of a single request, but also learn the time dependency between requests, and can more effectively detect and predict network attack behaviors.
[0016] In a second aspect, an embodiment of the present application provides an attack detection method, comprising: inputting traffic data into a preset attack detection model to obtain a detection result, wherein the attack detection model is obtained by any method described in the first aspect.
[0017] In a third aspect, an embodiment of the present application provides a device for constructing an attack detection model, the device comprising: an acquisition module for acquiring multiple network sample data, the multiple network sample data comprising first time period sample data and second time period sample data; an extraction module for extracting sample features of the multiple network sample data; a training module for training a first neural network using the sample features of the first time period sample data, and training a second neural network using the sample features of the second time period sample data, wherein the first time period sample data is request time period sample data, and the second time period sample data is response time period sample data; a construction module for constructing an attack detection model, the attack detection model comprising: an output layer and an intermediate layer, the intermediate layer being composed of the first neural network and the second neural network combined.
[0018] In a fourth aspect, an embodiment of the present application provides an electronic device, comprising: a memory and a processor, the processor being connected to the memory; the memory being used to store programs; and the processor being used to call the programs stored in the memory to execute any of the methods described in the first aspect.
[0019] In a fifth aspect, an embodiment of the present application provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, executes any one of the methods in the first aspect.
[0020] Other features and advantages of the present application will be described in the following description. The purpose and other advantages of the present application can be realized and obtained through the structures specifically pointed out in the written description and the drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments are briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work. The above and other purposes, features and advantages of the present application will be more clear as shown in the drawings.
[0022] Figure 1 A schematic diagram of a process for constructing an attack detection model provided in an embodiment of the present application is shown;
[0023] Figure 2 A schematic block diagram of a device for constructing an attack detection model provided in an embodiment of the present application is shown;
[0024] Figure 3 A schematic block diagram of an electronic device provided in an embodiment of the present application is shown. DETAILED DESCRIPTION
[0025] Hereinafter, embodiments of the present application are described in detail with reference to the accompanying drawings. It should be noted that although the same elements are shown in different drawings, they will be represented by the same reference numerals. In the following description, specific details such as detailed configuration and components are provided to only help fully understand the embodiments of the present application. Therefore, it should be clear to those skilled in the art that various changes and modifications to the embodiments described herein can be made without departing from the scope of the present application. In addition, for clarity and conciseness, the description of well-known functions and configurations is omitted. The terms described below are defined in consideration of the functions in the present application, and may be different according to the user, the user's intention or custom. Therefore, the definition of the term should be determined based on the content throughout this specification.
[0026] The present application may have various modifications and various embodiments, in which the embodiments are described in detail below with reference to the accompanying drawings. However, it should be understood that the present application is not limited to the embodiments, but includes all modifications, equivalents and substitutes within the scope of the present application.
[0027] The terms used herein are only used to describe various embodiments of the present application and are not intended to limit the present application. Unless the context clearly indicates otherwise, the singular form is intended to include the plural form. In the present application, it should be understood that the term "including" or "having" indicates the presence of features, quantities, steps, operations, structural elements, parts or combinations thereof, and does not exclude the presence of one or more other features, quantities, steps, operations, structural elements, parts or combinations thereof, or the possibility of adding one or more other features, quantities, steps, operations, structural elements, parts or combinations thereof.
[0028] Unless defined differently, all terms used herein have the same meaning as understood by a person skilled in the art to which the present application belongs. Unless explicitly defined in the present application, terms (such as those defined in a general dictionary) should be interpreted as having the same meaning as the contextual meaning in the relevant art, and should not be interpreted as having an idealized or overly formal meaning.
[0029] The electronic device according to one embodiment may be one of various types of electronic devices. The electronic device may include, for example, a portable communication device (e.g., a smart phone), a computer, a portable multimedia device, a portable medical device, a camera, a wearable device, or a household appliance. According to one embodiment disclosed, the electronic device is not limited to those described above.
[0030] The terms used in this application are not intended to limit the application, but are intended to include various changes, equivalents or alternatives of corresponding embodiments. Regarding the description of the accompanying drawings, similar reference numerals may be used to represent similar elements or related elements. Unless the relevant context clearly indicates otherwise, the singular form of the noun corresponding to the item may include one or more things. As used herein, each of the phrases such as "A or B", "at least one of A and B", "at least one of A or B", "A, B or C", "at least one of A, B and C" and "at least one of A, B or C" may include all possible combinations of the items listed together in the corresponding one in the phrase. As used herein, terms such as "the 1st", "the 2nd", "the first" and "the second" may be used to distinguish the corresponding component from another component, and are not intended to limit the component in other aspects (e.g., importance or order). It is intended that if an element (e.g., a first element) is referred to as being “coupled with,” “coupled to,” “connected to,” or “connected to” another element (e.g., a second element), with or without the term “operably” or “communicatively,” it indicates that the element may be coupled with the other element directly (e.g., wired), wirelessly, or via a third element.
[0031] As used herein, the term "module" may include a unit implemented in hardware, software, or firmware, and may be used interchangeably with other terms (e.g., "logic," "logic block," "component," and "circuit"). A module may be a single integrated component or its smallest unit or component suitable for performing one or more functions. For example, according to one embodiment, a module may be implemented in the form of an application specific integrated circuit (ASIC).
[0032] To facilitate understanding, the relevant terms and concepts involved in the embodiments of the present application are first introduced below.
[0033] With the rapid development of Web (World Wide Web) technology and the widespread popularity of Internet applications, network security issues have become increasingly prominent. Web applications have become one of the main targets of attackers, and various Web attacks have emerged one after another, including cross-site scripting (XSS), SQL injection (SQLi), distributed denial of service (DDoS) attacks, etc. These attacks not only endanger the data security of individuals and enterprises, but may also pose a serious threat to the stability and security of the entire network.
[0034] Traditional Web attack detection methods mostly rely on signature matching technology, which is to identify potential attacks by comparing specific patterns in network traffic with entries in a known attack signature database.
[0035] However, this method has obvious limitations. First, it cannot effectively detect zero-day attacks (i.e., attacks for which there is no known signature) and variant attacks. Second, as Web applications become increasingly complex, signature matching technology requires constant updating and maintenance of a large number of rule sets, which is time-consuming and error-prone in actual operations.
[0036] To overcome these limitations, existing technologies have proposed some methods based on anomaly detection. These methods detect attacks by building a model of normal behavior and then monitoring activities that deviate from the model. However, defining "normal behavior" is not an easy task, especially in the Web environment, where user behaviors are diverse and attack methods are constantly evolving, making it difficult to cover all normal or abnormal behaviors with a simple statistical model.
[0037] Based on the above problems, this application proposes a method for constructing an attack detection model and an attack detection method to improve the accuracy and efficiency of network attack detection.
[0038] The embodiment of the present application provides a method for constructing an attack detection model, which captures the inherent patterns and dependencies of network attacks through a neural network to improve the accuracy and efficiency of network attack detection, and adopts a time-division strategy to train the model, ensuring that the attack detection model can effectively detect and analyze different stages of network attacks. This enables the attack detection model to more accurately identify and predict network attack behaviors, further improving the overall detection efficiency and accuracy.
[0039] like Figure 1 As shown, Figure 1 FIG. 1 is a flow chart of a method for constructing an attack detection model provided in an embodiment of the present application. Figure 1 As shown, the method includes steps 110 to 140:
[0040] Step 110: Acquire a plurality of network sample data, wherein the plurality of network sample data includes sample data of a first time period and sample data of a second time period.
[0041] Obtain sample data, each sample data includes feature data and label data. When the model constructed in the present application is used to detect network attacks, the sample data includes samples related to network attacks. The feature data in a sample related to a network attack is network data, and the label data is whether the feature data is data of a network attack.
[0042] For example, data including HTTP (HyperText Transfer Protocol) request header, request method, URL (Uniform Resource Locator), user agent and request body are extracted from the network traffic log, and the extracted data is used as feature data to identify whether the network traffic log is data when a Web attack occurs. If so, the label data is set to yes.
[0043] In the present application, when constructing sample data, samples of the first time period and samples of the second time period are constructed, so that the model is trained using a time-division strategy.
[0044] The time segmentation strategy is a training method that divides the entire data set into different time segments based on the order of time or event occurrence. Each time segment contains data collected within a specific time range. The purpose of this strategy is to allow the model to focus on learning data patterns and behaviors that appear in a specific time segment, thereby improving the model's recognition accuracy of these specific behaviors. For example, for a model that detects Web attacks, the time segmentation strategy allows the model to focus on data in a specific time segment, thereby better capturing the complex patterns of XSS attacks and better handling the complexity of Web attack detection.
[0045] In this application, the time period can be set according to the needs. For example, the first time period is set to sample data between 9 am and 12 pm, and the second time period is set to sample data between 6 pm and 8 pm, or the first time period is set to sample data during the peak period, and the second time period is set to sample data during the off-peak period.
[0046] In one embodiment of the present application, the first time period sample data is request time period sample data, and the second time period sample data is response time period sample data.
[0047] The first period may also be set as sample data in a user request phase, and the second period may be set as sample data in a server response phase.
[0048] In one embodiment of the present application, sample data in any time period includes network traffic logs, attack attempt data, vulnerability attack data, and attack payload data.
[0049] Get data from two time periods related to the request: user request phase data and server response phase data. User request phase data includes: user input, click behavior, form submission, etc. Server response phase data includes: HTTP status code returned by the server, response content, etc.
[0050] The request data for each period will be collected from multiple dimensions, including:
[0051] Extract data from network traffic logs, including HTTP request headers, request methods, URLs, user agents, and request bodies.
[0052] Get potential attack attempts from the Web Application Firewall (WAF) logs.
[0053] Collect public datasets, such as OWASP (Open Web Application Security Project) XSS testing data.
[0054] The latest attack payloads are legally collected from the dark web and forums through web crawler technology.
[0055] Perform preliminary classification of the collected data to distinguish between normal requests and attack requests. The classification method can be: use multiple machine learning algorithms for cross-validation to improve the accuracy of classification, and combine expert manual labeling to process samples. For samples with high uncertainty, use semi-supervised learning technology to further optimize the data set to ensure the quality of training samples.
[0056] The data is divided into normal requests and attack requests, that is, positive samples and negative samples in supervised learning are obtained, and sample data is obtained.
[0057] In the above embodiment, acquiring sample data from multiple dimensions can enable the trained model to perform network attack detection from multiple dimensions, and can detect network attacks more comprehensively and accurately.
[0058] Step 120: extracting sample features of the plurality of network sample data.
[0059] The sample data directly extracted from network data cannot ensure data quality, and there are irrelevant and erroneous information in it. Therefore, after dividing the data into normal requests and attack requests, the data can be further cleaned. Feature data is extracted from the cleaned data.
[0060] In one embodiment of the present application, extracting sample features of the plurality of network sample data includes: encoding the plurality of network sample data using a specified format to obtain encoded data; denoising and cleaning the encoded data to obtain cleaned data; performing feature extraction on the cleaned data after word segmentation to obtain feature data of each network sample data; performing feature crossover and / or polynomial expansion based on the feature data to obtain sample features of each network sample data. .
[0061] First, data cleaning and denoising are performed, including:
[0062] After the data is divided into normal requests and attack requests, the normal requests and attack requests are encoded using a specified format, and the data is uniformly encoded into a specified format such as UTF-8. Since Web attack data may contain a variety of different encoding formats, encoding into a specified format ensures that data from different sources can be processed consistently.
[0063] After encoding, remove all non-printing and / or control characters from the encoded data, as these tend not to contribute useful information for attack detection.
[0064] Convert all HTML (HyperText Markup Language) entities to equivalent characters. HTML entities refer to characters such as <, which have special meanings to HTML, so these characters are not allowed to be used in text. To display the character < in HTML, you must use entity characters. Attackers often use HTML entities to evade detection, and converting them to equivalent characters can better extract feature information.
[0065] Decode the URL, because the attack payload may hide its attack characteristics through URL encoding. URL encoding, also known as percent encoding, is a process of converting non-alphanumeric characters in a URL into a special encoding. URL decoding is to restore the encoded URL fragment to its original character form.
[0066] Finally, duplicate request samples are removed to reduce data redundancy and improve the efficiency of subsequent processing.
[0067] After the above denoising and cleaning, cleaned data is obtained. The cleaned data is segmented and embedded. Segmentation is to break continuous text data into meaningful units (such as words, phrases or symbols). Segmentation and embedding of cleaned data can help the model better understand and analyze attack data. For example, advanced segmentation algorithms in natural language processing can be used. These algorithms can identify and correctly process highly technical Web attack data for word segmentation. These algorithms map each character or word in the above processed data to a vector in a high-dimensional space, the so-called word embedding, and then output the vector to a segmentation model such as random forest for word segmentation.
[0068] For example, models such as Word2Vec or GloVe are used to convert word segmentation into fixed-length vectors that can capture the semantic relationship between words. The BiLSTM model is then used to identify the contextual information of each point in the converted text, so as to predict the boundary of each character or word based on the context, and achieve word segmentation and word embedding.
[0069] For the request data after word segmentation, features are extracted from it to further remove redundant data. For example, features can be extracted through regular expressions, through built-in string methods, str type methods to perform basic string operations to extract features, and through NLP technology to extract features.
[0070] For example, regular expressions are used to match and extract data with specific patterns such as URLs, user agent strings, session IDs, attack payloads, etc.
[0071] Through operations such as string segmentation, indexing, and searching, specific information can be extracted from HTTP headers, request bodies, etc.
[0072] Since Web attacks may include injection attacks (such as SQL injection), NLP technology is used to understand and extract semantic information in attack commands or malicious scripts as features.
[0073] In order to make the extracted features suitable for machine learning models, they also need to be encoded. Common encoding methods include One-Hot Encoding: First, determine how many unique categories there are, each of which corresponds to a new feature; for each observation, create a zero vector with a length equal to the number of categories. In this zero vector, set the position representing the category of the observation to 1, and the rest to 0. This achieves the encoding of the feature value.
[0074] After the request data is encoded, for a request data, the encoded form of the request data is used as the feature data in the sample, and label information is added according to the attack information (normal request / attack request) of the request data, thereby generating a sample data.
[0075] In the above embodiment, irrelevant and erroneous information in the request data is removed to ensure the quality of the sample data, and continuous text data in the feature data is broken into meaningful phrases, which can help the model better analyze network attacks.
[0076] Furthermore, feature crossover and / or polynomial expansion are performed on the encoded features to obtain the multiple sample data.
[0077] For each encoded request data, different features can be combined to create new features through programming or using data processing tools (such as Python's pandas library, SQL query, etc.). For example, the HTTP request method and specific parts of the URL can be combined to capture potential attack patterns.
[0078] And / or, using libraries such as scikit-learn's PolynomialFeatures, a new set of features can be generated from existing features, which are polynomial combinations of the original features. This helps the model capture more complex relationships between features, thereby improving the accuracy of attack detection.
[0079] For a request data, the encoding features and original features of the request data are used as feature data in the sample, and label information is added according to the attack information (normal request / attack request) of the request data to generate a sample data.
[0080] In the above embodiments, feature crossover and / or polynomial expansion are performed on the request data so that the trained model can capture potential attack patterns, capture the relationship between input features, and improve the accuracy of attack detection.
[0081] An attack detection model is constructed, wherein the attack detection model includes a first neural network layer and a second neural network layer.
[0082] Step 130, using the sample features of the sample data of the first time period to train the first neural network, and using the sample features of the sample data of the second time period to train the second neural network, wherein the sample data of the first time period is the sample data of the request period, and the sample data of the second time period is the sample data of the response period.
[0083] In order to ensure that the model can effectively detect different stages of network attacks, this application uses data from different stages to train two different neural network layers. After training, the structure and function of the two neural network layers are integrated into the attack detection model, ensuring that the attack detection model can effectively detect and analyze different stages of network attacks.
[0084] For example, the training of the neural network layer may be: training the basic model in which the neural network layer is located, thereby training the neural network layer.
[0085] The structure of the basic model in this application is input layer-neural network layer-output layer, where the input layer is a neural network for extracting features. The neural network layer is a neural network that further processes the input layer data, and the output layer is a neural network that can implement the classifier function, which is used for final attack detection. The output layer can be a fully connected network or a softmax layer, which identifies the existence of Web attacks based on enhanced key features and classifies them.
[0086] In order to further utilize the time series characteristics in the data, the neural network layer of the model is a recurrent neural network (RNN) to further process the data extracted by the input layer. For example, a bidirectional gated recurrent unit (Bi-GRU) or a bidirectional long short-term memory network (Bi-LSTM) can be used. Bidirectional gated recurrent unit (Bi-GRU) or bidirectional long short-term memory network (Bi-LSTM) are two variants of recurrent neural networks. By scanning forward and backward on the time series of data, they can capture dependencies in the time dimension, which is particularly important for detecting attack patterns that require understanding request sequences or session contexts. By using these two neural network layers, the attack detection model can comprehensively consider the position of a request in the session and the information of its previous and subsequent requests, providing dynamic feature analysis capabilities for detecting more complex cross-site scripting attacks.
[0087] For example, suppose the network attack is a file inclusion attack.
[0088] The sample data of the request period may include: data in the user request, such as URL parameters, POST data, Headers, etc. The features extracted from the sample data of the request period include: file path and file name features in the request (such as .. / , absolute path, file extension, etc.). File path structure features and path traversal features included in the request. Data distribution features that conform to regular expressions and pattern matching.
[0089] The sample data of the response period includes: data in the server response, such as returned file content, error information, etc. Feature extraction from the response period data includes: whether the file content and system information in the response (such as system files, configuration files, etc.) contain error information, and abnormal file output. Abnormal data contained in the response (such as sensitive information leakage). Abnormal patterns in the response content.
[0090] The first neural network is placed in the first basic model, such as the first neural network is a bidirectional long short-term memory network, and the first basic model is a convolutional neural network-bidirectional long short-term memory network-fully connected neural network. The first basic model trained with the request period data can detect user requests and determine whether there are file inclusion attack features in the request.
[0091] The second neural network is placed in the second basic model, such as the second neural network is a bidirectional gated recurrent unit, and the first basic model is a convolutional neural network-bidirectional gated recurrent unit-fully connected neural network. The second basic model trained with the response period data can detect the server response and determine whether the response contains the result of the file inclusion attack.
[0092] The detection results of these two models comprehensively evaluate whether there is a file inclusion attack.
[0093] In one embodiment of the present application, the first neural network is a bidirectional gated recurrent network, and the second neural network is a bidirectional long short-term memory network. The method of training the first neural network using the sample features of the sample data of the first time period, and training the second neural network using the sample features of the sample data of the second time period, includes: sorting the local spatial features of the sample data of the first time period and the local spatial features of the sample data of the second time period according to a time series to generate first time series data and second time series data respectively, wherein the time series includes a request time sequence, a time occurrence sequence, and a fixed time sequence; learning the data dependency features in the first time series data based on the bidirectional gated recurrent network to form a first neural network; and learning the time dependency features in the second time series data based on the bidirectional long short-term memory network to form a second neural network.
[0094] The first neural network layer is a bidirectional long short-term memory network (Bi-LSTM). The second neural network layer is a bidirectional gated recurrent unit (Bi-GRU).
[0095] Since a time-series-based recurrent neural network is used, the data input into the recurrent neural network needs to be converted into time series data. Time series data is a collection of data points arranged in chronological order, where each data point is associated with a specific timestamp. For example, in the context of Web attack detection, time series data may include: User request logs, which record the time sequence of requests made by users to Web servers, such as form data submitted by users at a specific time, links clicked, etc. Server response logs, which record the time sequence of the server's response to user requests, including the response status code, returned content, etc. Network traffic data, which records the time record of data packet transmission in the network, may include the size of the data packet, the time of sending and receiving, etc.
[0096] For example, the security of an e-commerce website is being monitored. In the user request phase, a normal user may log in to the website at 9 am, browse products, add items to the shopping cart at 10 am, and then check out at 10:30 am. These operations will be recorded in the user request log and form a time series: [login, browse, add to shopping cart, check out], with timestamps of [09:00, 09:30, 10:00, 10:30]. In the server response phase, the server will respond to each user operation. For example, the login request may return a successful status code 200, and the add to shopping cart operation may return a confirmation message. These responses and corresponding timestamps also form a time series. Based on the time series of the request data, the extracted features can be arranged to generate time series data for input into the recurrent neural network.
[0097] The first basic model is trained using samples from the first period, such as samples from the user request phase, to train the first neural network layer, so that the trained first neural network layer focuses on analyzing data from the user request phase. This includes user input, click behavior, form submission, etc. The first basic model uses a convolutional neural network to extract key features from user request data, such as URL patterns, request parameters, header information, etc. The extracted features are then organized into time series data so that the model can understand the order and frequency of requests. The first basic model uses a Bi-LSTM layer to process time series data to capture the temporal dependency of request patterns.
[0098] The second basic model is trained using samples from the second period, such as samples from the server response phase, to form the second neural network layer. The trained second neural network layer focuses on analyzing data from the server response phase, including the HTTP status code and response content returned by the server. The second basic model also uses CNN to extract key features from the server response data, such as response delay, content size, error messages, etc. The second basic model also organizes the features of the extracted response data into a time series so that the model can analyze changes in server behavior over time. The second basic model uses the Bi-GRU layer to process time series data and identify abnormal patterns in server responses.
[0099] During the training process, closely monitor the performance indicators of the first and second neural network layers, especially the accuracy on the validation dataset. At the same time, check whether the model is overfitting to ensure the effectiveness of the training process and the generalization ability of the model.
[0100] Step 130, constructing an attack detection model, wherein the attack detection model includes: an output layer and an intermediate layer, wherein the intermediate layer is formed by combining the first neural network and the second neural network.
[0101] The structure and function of the trained first and second neural network layers are integrated into the final attack detection model, ensuring that the attack detection model can effectively detect and analyze different stages of network attacks. This combination enables the attack detection model to more accurately identify and predict network attack behaviors, improving overall detection efficiency and accuracy.
[0102] In this application, the first neural network layer and the second neural network layer in the basic model are obtained respectively, and the outputs of the two neural networks are integrated together. The two neural networks serve as the middle layer of the attack detection model. The attack detection model structure is feature extraction layer-middle layer-output layer. In one embodiment of the present application, the feature extraction layer, the middle layer and the output layer in the attack detection model are connected in sequence, the feature extraction layer is used to extract feature data from the input data, the first neural network and the second neural network in the middle layer both receive the feature data transmitted by the feature extraction layer, and the output layer is used to make attack judgments based on the data input by the middle layer.
[0103] The feature extraction layer of the attack detection model is used to extract features from the input data using a neural network, which can be a convolutional neural network, etc. For example, a convolutional neural network (CNN) is selected as the network for feature extraction. Convolutional neural networks perform convolution operations on input data through filters, which can effectively capture local spatial features in the data. For example, this is particularly useful for understanding complex patterns in web logs. Alternatively, by identifying the structural patterns of HTTP requests, convolutional neural networks can help the model identify potential signs of attacks at a preliminary stage.
[0104] The attack detection model also includes a time series construction layer, which is located between the feature extraction layer and the middle layer; the time series construction layer is used to sort the features output by the feature extraction layer according to the time series, generate time series data and input it into the middle layer, and the time series includes request time sequence, time occurrence sequence, and fixed time sequence.
[0105] Converting the features extracted by the feature extraction layer into a time series format can further exploit the time dependency of the recurrent neural network. By analyzing these time series data, the deep learning model can learn the patterns of normal user behavior and identify abnormal behaviors, such as frequent login attempts or large requests for specific URLs in a short period of time, which may be automated attack behaviors such as brute force or DDoS attacks.
[0106] For example, for features extracted from input data by a convolutional neural network, such as request frequency, request patterns of a specific type, request duration, etc., these features are sorted in chronological order. The chronological order can be the order of user requests, the order of events, or any other logical order related to time. Then, the sorted features are constructed into a sequence. The features at each time point become an element in a sequence. For example, if the features are extracted at 10 consecutive time points, the features at each time point will constitute an element in a time series.
[0107] In some embodiments of the present application, in order to capture time dependency, a sliding window method can be used. This means that at each time point, not only the features of the point are considered, but also the features within a certain time window before and after are considered. For example, the data of the past 5 minutes and the data of the next 1 minute can be used to predict the attack status at the current time point.
[0108] The time basis for time series conversion depends on the time attributes of the data itself and the goal of the analysis. In the context of network attack detection, time can be: Request timestamp: The timestamp of each HTTP request can be used as the basis for the time series. Order of events: If the attack events (such as login attempts, form submissions, etc.) have a clear order of occurrence, the order of these events can be used as the basis for the time series. Fixed time intervals: Data can be organized according to fixed time intervals (such as every minute, every hour) to form a time series.
[0109] For example, the input data is HTTP request data, each request has a timestamp and some features extracted by convolution, such as request type, URL, request size, etc. Follow the steps below to convert these features into a time series: Sort all requests according to the timestamp of the request. For each time point, extract the features of that time point and put them into a sequence. If a time window is set, a sliding window can be applied to include the features of the previous and next time windows. Input these sequences into a recurrent neural network or LSTM or GRU network to let the model learn the relationship between features over time.
[0110] In the above embodiment, the discrete feature data are arranged in chronological order so that the attack detection model can learn the dependency of the features over time. Thus, the attack detection model can not only understand the features of a single request, but also learn the time dependency between requests, and can more effectively detect and predict network attack behaviors.
[0111] The data extracted by the extraction layer, or, in the case of a time series construction layer, the time series data is fed into the intermediate layer.
[0112] The input data of the intermediate layer will be input into the Bi-GRU layer and the Bi-LSTM layer respectively.
[0113] The Bi-GRU layer processes time series (i.e., time series features) through a bidirectional GRU layer, which can simultaneously consider the dependencies between each data point in the sequence and capture potential attack behavior patterns. The Bi-LSTM layer passes the time series data to the bidirectional LSTM layer, which further analyzes the long-term dependencies in time (i.e., state features) and enhances the model's ability to capture complex attack strategies.
[0114] The concatenated recurrent neural network layer combines the outputs of Bi-GRU and Bi-LSTM to form a complete feature representation, which provides a basis for subsequent classification or anomaly detection. For example, the outputs of different layers are concatenated and then passed through one or more layers of fully connected networks, which allows the model to learn the nonlinear relationship between different representations.
[0115] In one embodiment of the present application, the attack detection model also includes an attention layer, which is used to receive multiple features output by the intermediate layer and assign weights to the multiple features; and transmit the multiple features and the weights to the output layer.
[0116] Assign a weight (or attention score) to each feature of the input feature sequence. These weights indicate which parts the model should focus on at the current moment. Use the calculated attention weights to weight the features and emphasize those that the model considers important. For example, applying attention weights to the output of Bi-LSTM can make the model pay more attention to attack-related sequence features, such as specific parameter orders or patterns.
[0117] Furthermore, the weighted features can be combined with the original features or features of other layers for further processing. This can be achieved by simple concatenation or complex feature fusion methods, such as merging features through one or more fully connected layers.
[0118] Introducing the attention mechanism into the attack detection model can further enhance the model's ability to focus on key features. The attention mechanism assigns different weights to different parts of the model, allowing the model to automatically identify and focus on the information that is most critical to classification judgment. In the context of Web attack detection, this means that the model can distinguish and focus on request features that are most relevant to attack behavior, such as abnormal request parameters or unusual access patterns. It can also maintain high accuracy and efficiency when processing large and diverse Web request data. Especially when detecting attacks that require fine-grained analysis, such as cross-site scripting (XSS) attacks, the application of the attention mechanism can significantly improve detection performance.
[0119] In the above embodiment, an attention mechanism is introduced into the attack detection model, so that the attack detection model focuses on key features, thereby increasing the sensitivity of the model to specific attack patterns and ensuring higher accuracy and efficiency.
[0120] The features integrated with the attention mechanism are input into the output layer, which can be a fully connected network, softmax layer, etc., for the final attack behavior classification or anomaly detection. The output layer will determine whether there is a Web attack based on the enhanced key features and perform corresponding classification.
[0121] The above attack detection model construction method captures the inherent patterns and dependencies of network attacks through neural networks to improve the accuracy and efficiency of network attack detection, and adopts a time-division strategy to train the model, ensuring that the attack detection model can effectively detect and analyze different stages of network attacks. This enables the attack detection model to more accurately identify and predict network attack behaviors, further improving the overall detection efficiency and accuracy.
[0122] In one embodiment of the present application, the attack detection model further includes a feature extraction layer, and the method further includes: using the multiple network sample data to train the feature extraction layer to extract local spatial features.
[0123] The feature extraction layer in this application is also trained, using preprocessed and encoded feature data to train deep learning models, such as convolutional neural networks (CNN) or recurrent neural networks (RNN). These models can capture high-level features and patterns in the data, providing higher accuracy and efficiency than traditional machine learning methods. Furthermore, when there is a time series in the input data, a model architecture suitable for processing time series data (such as LSTM or GRU) is used to better understand and predict sequence-based attack activities and enhance the model's ability to detect complex attack behaviors.
[0124] like Figure 2 As shown, Figure 2 An attack detection model construction device 200 provided in an embodiment of the present application is shown, and the device 200 includes: an acquisition module 210, an extraction module 220, a training module 230 and a construction module 240;
[0125] An acquisition module 210 is used to acquire a plurality of network sample data, wherein the plurality of network sample data includes a first period sample data and a second period sample data;
[0126] An extraction module 220, configured to extract sample features of the plurality of network sample data;
[0127] A training module 230, configured to train a first neural network using sample features of the sample data of the first period, and train a second neural network using sample features of the sample data of the second period, wherein the sample data of the first period is sample data of the request period, and the sample data of the second period is sample data of the response period;
[0128] The construction module 240 is used to construct an attack detection model, wherein the attack detection model includes: an output layer and an intermediate layer, wherein the intermediate layer is formed by combining the first neural network and the second neural network.
[0129] The attack detection model construction device provided in the embodiment of the present application has the same implementation principle and technical effects as those in the aforementioned method embodiment. For the sake of brief description, for matters not mentioned in the device embodiment, reference can be made to the corresponding contents in the aforementioned method embodiment.
[0130] An embodiment of the present application also provides an attack detection method, including: inputting traffic data into a preset attack detection model to obtain a detection result, wherein the attack detection model is obtained by any one of the above-mentioned attack detection model construction methods.
[0131] like Figure 3 As shown, Figure 3 FIG. 1 is a schematic block diagram of an electronic device 300 provided in an embodiment of the present application. The electronic device 300 includes: a processor 310 and a memory 320;
[0132] The processor 310, the memory 320 and each component are directly or indirectly electrically connected to each other to achieve data transmission or interaction. For example, these components can be electrically connected to each other via one or more communication buses or signal lines. The memory 320 is used to store computer programs, such as storing Figure 1 The method corresponds to the software function modules shown. These software function modules include at least one software function module that can be stored in the memory 320 in the form of software or firmware or fixed in the operating system (OS) of the electronic device 300. The processor 310 is used to execute the executable modules stored in the memory 320, such as Figure 1 The software function module or computer program corresponding to the method.
[0133] Among them, the memory 320 can be, but is not limited to, random access memory (Random Access Memory, RAM), read only memory (Read Only Memory, ROM), programmable read-only memory (Programmable Read-Only Memory, PROM), erasable programmable read-only memory (Erasable Programmable Read-Only Memory, EPROM), electrically erasable read-only memory (Electric Erasable Programmable Read-Only Memory, EEPROM), etc.
[0134] The processor 310 may be an integrated circuit chip with signal processing capabilities. The above-mentioned processor may be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), a microprocessor, etc.; it may also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The methods, steps and logic block diagrams disclosed in the embodiments of the present application may be implemented or executed. Alternatively, the processor 310 may also be any conventional processor, etc.
[0135] The embodiment of the present application also provides a non-volatile computer-readable storage medium (hereinafter referred to as storage medium), on which a computer program is stored. When the computer program is run by a computer such as the above-mentioned electronic device 300, the method for constructing the attack detection model shown above is executed.
[0136] It should be noted that the various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.
[0137] In several embodiments provided in the present application, it should be understood that the disclosed devices and methods can also be implemented in other ways. The device embodiments described above are merely schematic. For example, the flowcharts and block diagrams in the accompanying drawings show the possible architecture, functions and operations of the devices, methods and computer program products according to multiple embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of a code, and the module, a program segment or a part of a code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, and the combination of boxes in the block diagram and / or flowchart can be implemented with a dedicated hardware-based system that performs a specified function or action, or can be implemented with a combination of dedicated hardware and computer instructions.
[0138] In addition, the functional modules in the various embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.
[0139] If the functions are implemented in the form of software function modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product is stored in a computer-readable storage medium, including several instructions to enable a computer device (which can be a personal computer, a laptop, a server, or an electronic device, etc.) to perform all or part of the steps of the methods described in each embodiment of the present application. The aforementioned computer-readable storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0140] 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 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 constructing an attack detection model, characterized in that: The method comprises: Acquire a plurality of network sample data, wherein the plurality of network sample data includes first period sample data and second period sample data; Extracting sample features of the plurality of network sample data; Using sample features of the sample data of the first time period to train a first neural network, and using sample features of the sample data of the second time period to train a second neural network, wherein the sample data of the first time period is sample data of a request period, and the sample data of the second time period is sample data of a response period; An attack detection model is constructed, wherein the attack detection model includes: an output layer and an intermediate layer, wherein the intermediate layer is composed of the first neural network and the second neural network, the first neural network is used to analyze potential attack behavior patterns of input data of the intermediate layer, the second neural network is used to analyze potential attack strategies of input data of the intermediate layer, and the output layer is used to perform network attack detection based on the analysis results of the first neural network and the second neural network.
2. The method according to claim 1, characterized in that Sample data for any period of time includes network traffic logs and vulnerability attack data.
3. The method according to claim 1, characterized in that The extracting sample features of the plurality of network sample data comprises: Encode the plurality of network sample data using a specified format to obtain encoded data; De-noising and cleaning the encoded data to obtain cleaned data; Perform feature extraction on the cleaned data after word segmentation to obtain feature data for each network sample data; Feature crossover and / or polynomial expansion is performed based on the feature data to obtain sample features of each of the network sample data.
4. The method according to claim 1, characterized in that The attack detection model also includes an attention layer, which is used to receive multiple features output by the intermediate layer and assign weights to the multiple features; and transmit the multiple features and the weights to the output layer.
5. The method according to claim 1, characterized in that: The attack detection model also includes a feature extraction layer, and the method further includes: The ability of the feature extraction layer to extract local spatial features is trained using the multiple network sample data.
6. The method according to claim 5, characterized in that The first neural network is a bidirectional gated recurrent network, the second neural network is a bidirectional long short-term memory network, and the first neural network is trained using the sample features of the sample data of the first period, and the second neural network is trained using the sample features of the sample data of the second period, including: Sorting the local spatial features of the sample data in the first time period and the local spatial features of the sample data in the second time period according to a time series to generate first time series data and second time series data respectively, wherein the time series includes a request time sequence, a time occurrence sequence, and a fixed time sequence; Learning data-dependent features in the first time series data based on the bidirectional gated recurrent network to form a first neural network; Based on the bidirectional long short-term memory network, the time-dependent features in the second time series data are learned to form a second neural network.
7. An attack detection method, characterized in that: include: Get the network data to be detected; The network data is input into a preset attack detection model to obtain a detection result, wherein the attack detection model is obtained by any method as claimed in claim 1 to claim 6.
8. A device for constructing an attack detection model, characterized in that: The device comprises: An acquisition module, used for acquiring a plurality of network sample data, wherein the plurality of network sample data includes a first period sample data and a second period sample data; An extraction module, used to extract sample features of the plurality of network sample data; A training module, configured to train a first neural network using sample features of sample data of the first time period, and train a second neural network using sample features of sample data of the second time period, wherein the sample data of the first time period is sample data of a request time period, and the sample data of the second time period is sample data of a response time period; A construction module is used to construct an attack detection model, wherein the attack detection model includes: an output layer and an intermediate layer, wherein the intermediate layer is composed of the first neural network and the second neural network, the first neural network is used to analyze the potential attack behavior pattern of the input data of the intermediate layer, the second neural network is used to analyze the potential attack strategy of the input data of the intermediate layer, and the output layer is used to perform network attack detection based on the analysis results of the first neural network and the second neural network.
9. An electronic device, characterized in that: include: A memory and a processor, wherein the processor is connected to the memory; The memory is used to store programs; The processor is used to call the program stored in the memory to execute the method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: A computer program is stored thereon, and when the computer program is executed by a processor, the method according to any one of claims 1 to 7 is executed.
