Database abnormal operation detection method and device and related equipment
Through fine-tuning of the large language model, the interpretability of the database abnormal operation detection method is realized, the causes of abnormal operation are clarified, the problem of lack of explanatory in the existing technology is solved, and the efficiency of abnormal operation detection is improved.
Patent Information
- Application Number
- CN202410915321.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-09
- Publication Date
- 2024-11-05
AI Technical Summary
The existing database abnormality detection methods lack interpretability and cannot clarify the cause of abnormal operations, which requires operators to take a lot of time and effort to check.
The pre-trained large language model (LLM) is used and fine-tuned through Low-Rank Adaptation (LoRA) to design the target model, which can detect the log records of the operation to be tested, output indicator information and exception analysis information, and clarify the cause of the abnormal operation.
This improves the efficiency of database abnormal operation detection, and users can solve problems targeted according to the causes of abnormal operation, which improves the efficiency of problem solving.
Smart Images

Figure CN118897783A_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the field of communication technology, and in particular, relates to a method, device and related equipment for detecting abnormal operation of a database. Background Art
[0002] In recent years, database technology has achieved rapid development and has been able to efficiently process and manage various data types. At the same time, the application scope of databases has continued to expand, and both academic and commercial fields regard it as a powerful tool. However, as more and more critical data is stored in databases, attacks around databases have become more intense, so database abnormal behavior detection has become a current research hotspot. The existing technical means are mainly divided into three categories: syntax-based methods, traffic-based methods, and statistics-based methods. The specific situation and technical solutions are as follows:
[0003] 1. Traffic-based anomaly detection method
[0004] The traffic-based method mainly relies on obtaining the database traffic of the target database and extracting features related to the database type from it. These features are related to database attack behaviors, thereby obtaining corresponding supply features. By analyzing these attack features, it can be determined whether the database is under attack.
[0005] 2. Syntax-based anomaly detection method
[0006] The grammar-based method focuses on studying the grammatical structure of SQL statements and detecting anomalies through pattern matching or machine learning algorithms. It captures SQL statements that access the target database and parses them. This type of detection method mainly detects anomalies in the operation behavior of a single SQL statement.
[0007] 3. Statistical-based anomaly detection methods
[0008] Statistical methods mainly use obvious data changes to perform statistics and anomaly detection. Some methods use frequency-based and statistical algorithms to detect abnormal behavior. When certain data is frequently accessed and exceeds a set threshold, it is marked as an abnormal operation.
[0009] The existing traditional methods are mainly black box models, which lack interpretability and can only give the abnormal operation but cannot explain the reason why the operation behavior is judged as abnormal. This limitation requires operators to invest a lot of time and energy to carefully check the reasons after detecting abnormalities. Summary of the invention
[0010] The embodiments of the present application provide a method, apparatus and related equipment for detecting abnormal operations in a database, which can use a trained target model to judge the abnormal operations included in the operation log records to be tested, and can not only output the judgment results, but also explain the reasons for the abnormal operations, so that users can analyze the reasons based on the explanations and improve the efficiency of resolving abnormal operations.
[0011] In a first aspect, an embodiment of the present application provides a method for detecting abnormal operation of a database, the method comprising:
[0012] Obtaining a log record of the operation to be tested, wherein the log record of the operation to be tested is a log record of an operation performed on a database;
[0013] Inputting the operation log record to be tested into the target model, obtaining a detection result of the operation log record to be tested, wherein the detection result includes indication information and abnormal analysis information, wherein the indication information is used to indicate whether the operation log record to be tested is abnormal, and the abnormal analysis information of the operation log record to be tested is used to explain the reason for the abnormal operation;
[0014] Among them, the target model is obtained by training a large language model LLM through a training data set and fine-tuning the LLM. The training data set includes training sample records, labels corresponding to the training sample records, and abnormal analysis information. The training sample records include multiple operation log records for training, and the labels are used to identify normal or abnormal.
[0015] In a second aspect, an embodiment of the present application provides a database abnormal operation detection device, the device comprising:
[0016] An acquisition module is used to acquire a log record of the operation to be tested, wherein the log record of the operation to be tested is a log record of an operation performed on a database;
[0017] A detection module, used for inputting the operation log record to be tested into the target model to obtain a detection result of the operation log record to be tested, wherein the detection result includes indication information and abnormal analysis information, wherein the indication information is used to indicate whether the operation log record to be tested is abnormal, and the abnormal analysis information of the operation log record to be tested is used to explain the cause of the abnormal operation;
[0018] Among them, the target model is obtained by training a large language model LLM through a training data set and fine-tuning the LLM. The training data set includes training sample records, labels corresponding to the training sample records, and abnormal analysis information. The training sample records include multiple operation log records for training, and the labels are used to identify normal or abnormal.
[0019] In a third aspect, an embodiment of the present application provides an electronic device, comprising: a processor and a memory storing computer program instructions;
[0020] When the processor executes the computer program instructions, the method for detecting abnormal database operations as described in the first aspect is implemented.
[0021] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, on which computer program instructions are stored. When the computer program instructions are executed by a processor, the database abnormal operation detection method described in the first aspect is implemented.
[0022] In a fifth aspect, an embodiment of the present application provides a computer program product. When instructions in the computer program product are executed by a processor of an electronic device, the electronic device executes the database abnormal operation detection method as described in the first aspect.
[0023] The database abnormal operation detection method provided by the embodiment of the present application detects the operation log record to be tested through a pre-trained target model, and outputs the detection result, which includes indication information and abnormal analysis information. The indication information is used to indicate whether the operation log record to be tested is abnormal. According to the detection result, it can be known whether the operation log record to be tested includes abnormal operations, and in the case of including abnormal operations, the reason for being determined as abnormal operation can be known according to the abnormal analysis information. Through the above method, not only can it be determined whether the operation log record to be tested includes abnormal operations, but also the reason for being determined as abnormal operations can be obtained, which is convenient for users to solve problems according to the reasons for abnormal operations, and improves the efficiency of solving problems. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] In order to more clearly illustrate the technical solution of the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0025] Figure 1 It is a flow chart of a method for detecting abnormal database operation provided by an embodiment of the present application;
[0026] Figure 2a It is another flowchart of the method for detecting abnormal database operation provided by an embodiment of the present application;
[0027] Figure 2b It is a structural diagram of a database abnormal operation detection system provided in an embodiment of the present application;
[0028] Figure 3 It is a structural diagram of a database abnormal operation detection device provided in an embodiment of the present application;
[0029] Figure 4 It is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0030] The features and exemplary embodiments of various aspects of the present application will be described in detail below. In order to make the purpose, technical solutions and advantages of the present application clearer, the present application will be further described in detail below in conjunction with the accompanying drawings and specific embodiments. It should be understood that the specific embodiments described herein are only intended to explain the present application, rather than to limit the present application. For those skilled in the art, the present application can be implemented without the need for some of these specific details. The following description of the embodiments is only to provide a better understanding of the present application by illustrating the examples of the present application.
[0031] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the statement "include..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0032] In order to solve the problems in the prior art, the embodiments of the present application provide a method, device and related equipment for detecting abnormal operation of a database. The method for detecting abnormal operation of a database provided by the embodiments of the present application is first introduced below.
[0033] Figure 1 FIG. 1 is a flow chart showing a method for detecting abnormal database operations according to an embodiment of the present application. Figure 1 As shown, the database abnormal operation detection method provided in the embodiment of the present application includes the following steps 101-102, wherein:
[0034] Step 101: Obtain a log record of an operation to be tested, where the log record of the operation to be tested is a log record of an operation on a database.
[0035] Step 102: input the operation log record to be tested into the target model to obtain the detection result of the operation log record to be tested, wherein the detection result includes indication information and exception analysis information, wherein the indication information is used to indicate whether the operation log record to be tested is abnormal, and the exception analysis information of the operation log record to be tested is used to explain the cause of the abnormal operation, wherein the target model is obtained by training a large language model (LLM) using a training data set and fine-tuning the LLM, for example, fine-tuning the model using low-rank adaptation (LoRA), wherein the training data set includes training sample records, labels corresponding to the training sample records and exception analysis information, wherein the training sample records include multiple operation log records for training, and the labels are used to identify normal or abnormal.
[0036] The training sample record includes multiple operation log records for training. A training sample record can also be regarded as a window, which includes multiple operation log records for training. If there is an abnormal record among the multiple operation log records, the label of the training sample record is set as abnormal, and abnormal analysis information is set for the training sample record. The abnormal analysis information can be information used to explain the existing abnormal operation, for example, "this window has low-frequency table deletion behavior, which may be an abnormal operation"; if each record in the multiple operation log records is normal, the label of the training sample record is set as normal. In the case where the training sample record is normal, the abnormal analysis information can be preset information, for example, "this window has no abnormal operation".
[0037] In this embodiment, the operation log record to be tested is tested through a pre-trained target model, and the test result is output. The test result includes indication information and abnormal analysis information. The indication information is used to indicate whether the operation log record to be tested is abnormal. According to the test result, it can be known whether the operation log record to be tested includes abnormal operations, and in the case of including abnormal operations, the reason for being determined as abnormal operation can be known according to the abnormal analysis information. Through the above method, not only can it be determined whether the operation log record to be tested includes abnormal operations, but also the reason for being determined as abnormal operations can be obtained, which is convenient for users to solve problems according to the reasons for abnormal operations, thereby improving the efficiency of solving problems.
[0038] In another embodiment of the present application, before inputting the operation log record to be tested into the target model and obtaining the detection result of the operation log record to be tested, the method further includes:
[0039] Step 201: Acquire multiple operation log records of operations performed on a database.
[0040] This step may specifically include:
[0041] Get multiple log records of database operations, each log record includes SQL statements;
[0042] The SQL (Structured Query Language) statement in each of the log records is word segmented and de-parameterized to obtain the operation log record.
[0043] As shown in Table 1 below, in Table 1, the operation behavior statement is the original operation data, which can also be called a log record, and the template word is the data after word segmentation and de-parameterization processing, and the template word is the operation log record:
[0044] Table 1
[0045]
[0046] In the above, we can use the word segmentation tool NLTK to segment SQL statements, and then use the Drain tool to remove parameters for all operation statements. Since the log records in the database may contain a lot of irrelevant details, the removal of parameters can reduce noise, help simplify the log content, and extract the most important information for anomaly detection. In addition, the removal of parameters can unify the format of log information, facilitate subsequent automated analysis and processing, and reduce analysis errors caused by inconsistent parameter formats.
[0047] Step 202: Group the multiple operation log records to obtain multiple groups of operation log records, each group of operation log records is a training sample record, and each training sample record is provided with a label and abnormal analysis information.
[0048] Taking the window as the unit, every 20 lines of operation behavior sequence (one line has one operation behavior sequence, and the operation behavior sequence can also be called an operation log record) is taken as a window unit, and a window unit can be regarded as a training sample record.
[0049] A label and abnormal analysis information are manually set for each training sample record; if the window includes an abnormal operation behavior statement, the entire window is assigned an abnormal label 1, otherwise it is assigned a normal label 0. Then, the abnormal analysis information corresponding to each manually generated window is given.
[0050] Specifically, setting a label and abnormal analysis information for each training sample record includes:
[0051] If there is at least one operation log record determined to be an abnormal operation in the training sample records, the label corresponding to the training sample record is set as abnormal, and the operation log record determined to be an abnormal operation is analyzed abnormally to obtain abnormal analysis information;
[0052] If there is no operation log record determined to be an abnormal operation in the training sample record, the label corresponding to the training sample record is set to normal, and the abnormal analysis information of the training sample record is set to preset information.
[0053] Abnormal operation refers to an operation that deviates from the preset normal operation.
[0054] Step 203: construct a training data set according to each of the training sample records, the label of each of the training sample records, and the abnormal analysis information.
[0055] Generate a three-part dataset [a training sample record, a label, and anomaly analysis information].
[0056] Step 204: input the training data set into the LLM, and fine-tune the LLM through LoRA to obtain a target model.
[0057] In this embodiment, multiple operation log records are obtained from the database, and training sample records are obtained based on each operation log record, so as to obtain a training data set composed of multiple training sample records, which is used for subsequent model training using the training data set, so that the obtained target model can not only determine whether the operation log record to be tested includes abnormal operations, but also obtain the reasons for determining the abnormal operations, which is convenient for users to solve the problems according to the reasons for the abnormal operations, thereby improving the efficiency of problem solving.
[0058] Specifically, step 204 includes:
[0059] Step 2041, setting an anomaly detection branch and an anomaly analysis branch in the output layer of the LLM, the anomaly detection branch is used to output an anomaly detection result, and the anomaly analysis branch is used to output an anomaly analysis result.
[0060] Specifically, an anomaly detection branch is set in the output layer of the LLM, and an activation function is used to perform binary classification, and a binary classification cross entropy loss function is used to calculate a first loss value;
[0061] An exception analysis branch is set in the output layer of the LLM, and a decoder is added after the encoder of the LLM to generate an exception analysis text, and a cross entropy loss function is used to calculate a second loss value.
[0062] Step 2042, setting a multilayer perceptron (MLP) layer in the LLM to perform loss weight learning.
[0063] Specifically, according to the first loss value and the second loss value, the following weighted loss function is determined:
[0064] loss = a*loss1+b*loss2;
[0065] Among them, loss1 is the first loss value, loss2 is the second loss value, a and b are loss weights, and the values of a and b are obtained by learning the loss weights through the MLP layer. Specifically, the weights are learned through the cross entropy loss function, and the gradient descent optimization algorithm is used to iteratively train the MLP layer so that it can output the optimal loss weights a and b. Loss weight learning is performed by setting an additional MLP layer. For this MLP layer, the accuracy of the model output results can be improved by optimizing the model to reduce the difference between the actual loss value and the target value.
[0066] Step 2043, input the training data set into the LLM, and in the process of fine-tuning the LLM using LoRA, maintain the weight matrix W of the attention module in the LLM q and the weight matrix W v Unchanged, increase the weight matrix W A With the weight matrix W B , get the target model, where W q , W v are matrices with d rows and k columns, W A is a matrix with d rows and r columns, W B is a matrix with r rows and k columns, where the values of d, k, and r are positive integers, and d< <r。
[0067] The attention module of LLM includes three weight matrices: W q , W v and W k , in this step, the weight matrix W q and the weight matrix W v constant.
[0068] In the present embodiment, an anomaly detection branch and an anomaly analysis branch are set in the output layer of the LLM. Compared with the prior art that can only complete anomaly detection or anomaly analysis tasks separately, the present embodiment merges two different but related tasks and designs two different output layers to complete the corresponding tasks. The respective anomaly detection effects and anomaly analysis effects are improved by sharing parameters, so that the anomaly detection accuracy of the obtained target model is higher.
[0069] In another embodiment of the present application, the weight matrix W of the attention module in the LLM is maintained q and the weight matrix W v Unchanged, increase the weight matrix W A With the weight matrix W B , get the target model, including:
[0070] According to the training data set, the weight matrix W A , weight matrix W B , and the weight matrix W q and the weight matrix W v The first parameter included is calculated as follows to obtain the target parameter H;
[0071] H=W0*x+W B W A *x
[0072] Wherein, W0 represents the first parameter, and x represents the data input to the LLM each time in the training data set;
[0073] The weight matrix W in the LLM is adjusted using the target parameters q and the weight matrix W v Update, for example, the weight matrix W q and the weight matrix W v Replaced with the target parameter to obtain the target model. The target parameter H is a merged parameter generated during the LoRA fine-tuning process and is used to update the original weight matrix so that the model can adapt to the new task requirements.
[0074] In this embodiment, the weight matrix W of the attention module in the LLM is maintained q and the weight matrix W v Unchanged, increase the weight matrix W A With the weight matrix W B , get the target model, and fine-tune the model through a more efficient and low-resource consumption method. Freeze the existing weight matrix of the attention module, and add two new weight matrices. By adjusting the two new weight matrices, low-rank decomposition is used to simulate the parameter update amount, achieving low-cost and efficient fine-tuning.
[0075] The above target parameter H is a merged parameter generated during the LoRA fine-tuning process, which is used to replace the original weight matrix so that the model can adapt to the new task requirements.
[0076] The embodiments of the present application are described below by way of example.
[0077] This proposal aims to solve the existing problems of abnormal operation behavior in databases and designs a detection and analysis method for abnormal operation behavior in databases based on fine-tuning of large models. This proposal uses the latest progress of large language models (LLMs) to give full play to their powerful semantic understanding and reasoning capabilities, realize operation statement parsing, abnormal behavior detection and analysis tasks, and complete new log processing in online scenarios with high accuracy.
[0078] The technical solution of this proposal is: a database abnormal behavior detection and analysis method and system based on large model fine-tuning, Figure 2a The flowchart of the abnormal operation detection method of the database provided in the embodiment of the present application is shown in FIG. Figure 2a ,The database abnormal operation detection method includes the following steps:
[0079] Step 1: Data collection: Offline, API endpoints are designed to collect database operation behavior sequences A of large data security platforms;
[0080] Step 2: Data preprocessing: After obtaining the operation behavior sequence A, the data set is cleaned through feature engineering technology to generate a training data set D.
[0081] Specifically, we first use the word segmentation tool NLTK to segment the SQL statements, and then use the Drain tool to de-parameterize all operation statements to generate the final training data set D.
[0082] Step 3: Generate a data set: Match the preprocessed training data set D with its label L. Specifically, take every 20 lines of operation behavior sequence as a window unit. If it contains abnormal operation behavior statements, the entire unit is assigned an abnormal label 1, otherwise it is assigned a normal label 0. Then, the abnormal analysis S corresponding to each manually generated window is given, forming a data with three features in each line: [training data set D, label L, abnormal analysis S].
[0083] Step 4: Input to the pre-trained model: Generate a prompt template instruction Q, and input the data X into the pre-trained model M in the format of [instruction Q, training data set D, label L, exception analysis S].
[0084] This template instruction Q is a template instruction that defines what tasks the large language model needs to perform, such as "Please detect abnormal behaviors in the following database operation behavior logs and provide corresponding abnormal analysis." Because the large language model itself includes too much data and has learned too much knowledge. If the instruction template for this task definition is not added, the large model will randomly process the data due to its own generalization, resulting in poor data processing results. Therefore, it is necessary to tell it what the downstream task is through a template instruction, and activate the representation space of the large language model for processing the task through the template instruction to understand the log data in the database field, and then fine-tune the model to achieve better results.
[0085] Step 5: Model fine-tuning: After inputting the training dataset X, fine-tune the pre-trained model M through LoRA fine-tuning, and finally generate a fine-tuned large language model M that is suitable for downstream tasks.
[0086] Step 5.1: During fine-tuning, due to the addition of W in the weight matrix of the attention module in the pre-trained model M q , W v Freeze and add two new matrices W A With W B , where W q , W v are all matrices with d rows and k columns, W A is a matrix with d rows and r columns, W B is a matrix with r rows and k columns, where the values of d, k, and r are positive integers, and d< <r。
[0087] Step 5.2: Input the training dataset X and fine-tune the pre-trained model, where the matrix W A With W B Contains trainable parameters P, and W q , W v The matrix parameters P' are frozen and not trained. The trained parameters P are then merged with the originally frozen parameters P'. First, the product of the original parameters and the input is calculated, and then merged with the product of matrices A and B and the input.
[0088] Step 5.3: Balancing multiple loss values: Since this model needs to complete two different but related tasks B1 and B2, where B1 is anomaly detection task and B2 is anomaly parsing task. This proposal proposes a pre-trained model M that can complete multiple tasks. In the fine-tuning phase of model M, two different output heads H1 and H2 are designed for two outputs. For two different outputs, the corresponding loss functions are not the same. In order to achieve shared parameter training, this proposal uses a weighted method to assign different weights to the two loss values loss1 and loss2 for training to balance multiple loss values.
[0089] Step 6: Input new data: After the pre-trained model M is fine-tuned, the new data D' to be tested is input into the model M after being pre-processed in step 2;
[0090] Step 7: Output data: The trained model M can give output for new operation behavior log input, including abnormal label L' and abnormal analysis S'.
[0091] Furthermore, after inputting the input data into the pre-trained model, this proposal uses LoRA to fine-tune the model and determine the matrix W in the attention mechanism selected in the pre-trained model. q , W v Make fine adjustments.
[0092] Furthermore, the target layer is replaced by a new LoRA layer. When replacing, the weights and bias values of the original layer are copied to the new LoRA layer. The "target layer" specifically refers to the weight matrix of the attention module in the LLM. By adding LoRA layers to these target layers and fine-tuning them, the model can be adapted to downstream tasks without significantly increasing the training overhead.
[0093] like Figure 2b FIG. 1 is a schematic diagram of a module of a database abnormal operation detection system provided in an embodiment of the present application. Figure 2b As shown, the functional modules included are as follows:
[0094] API interface is a functional module that provides interface calls between modules within the system;
[0095] The data processing module is a functional module that obtains normal operation behavior logs from the database, performs data cleaning and operation statement vectorization on the log data set, and realizes data training.
[0096] The model fine-tuning module is a module that provides the function of fine-tuning the pre-trained model;
[0097] The anomaly detection and anomaly analysis module is a functional module that uses a fine-tuned model to perform anomaly detection and analysis.
[0098] based on Figure 2b The system architecture shown in the figure is implemented, and the system includes 8 functional modules: API interface, data preprocessing module, data set generation module, model training module, anomaly detection module, anomaly analysis module, database, and collection. The specific steps of the method are as follows:
[0099] Step 1: Acquisition and processing of training data. During the offline training phase, the system uses the API to obtain a set A of all operation behavior statement log sequences in the database, and then sends the set A to the data processing module. After receiving data A, the data processing module performs data preprocessing on the operation behavior sequence.
[0100] Step 1.1: Clean the dataset A through feature engineering technology to generate the training dataset D. Specifically, first use the word segmentation tool NLTK to segment the SQL statements, and then use the Drain tool to de-parameterize all operation statements to generate the final dataset D.
[0101] Finally, the preprocessed operation behavior log sequence is obtained and sent to the dataset generation module;
[0102] Step 2: Generate a training data set. After receiving the pre-processed operation behavior log sequence, the data set generation module matches the pre-processed operation behavior log sequence with its label.
[0103] Specifically, this proposal takes every 20 lines of operation behavior sequence as a window unit R i If it includes abnormal operation behavior statements, the entire unit R i Assign an abnormal label 1, otherwise assign a normal label 0. Then give the abnormal analysis S corresponding to each manually generated window i , forming a data set with three features in each line: [preprocessing log D, label L, anomaly analysis S]. Finally, the anomaly analysis text corresponding to each anomaly label is matched, and finally a data set containing three segments [log sequence, label, anomaly analysis] is generated;
[0104] Step 3: Model fine-tuning. Input the processed data set into the pre-trained model and fine-tune the model through LoRA. In order to enable the model to complete multiple tasks, this proposal modifies the output head of the model and the setting of the loss function to balance the performance of each task. The specific steps will be described in step 2 of the specific process.
[0105] Step 4: Abnormal behavior detection and analysis. After the model M is trained, the abnormal behavior detection and analysis task begins. First, the collected new operation behavior data A' is input into the fine-tuned model through the preprocessing module output D', and then the model outputs the abnormal detection label L i Determine whether it is abnormal, analyze the abnormal sequence, determine the cause of the abnormality, and provide an abnormal analysis S i .
[0106] The following is a description of the specific process of this proposal with examples:
[0107] Assuming that there are N databases, each of which records operation behavior logs, the specific implementation process is as follows:
[0108] The specific steps for obtaining and processing training data in step 1 are as follows:
[0109] Step 1.1: In the offline training phase, the data processing module uses the database read call interface provided by the API interface module to read all database normal operation behavior sequences A, and then performs data preprocessing operations on the original data to obtain a usable data set D. Table 1 shows an example of the collected database normal operation behavior sequence.
[0110] Step 1.2: After preprocessing the original data, assign the anomaly detection label L to the operation behavior sequence in units of windows, and input the anomaly analysis reason text set S into the pre-training model M as the training set data. The input format is Input = [preprocessing log D, label L, anomaly analysis S].
[0111] The specific steps of LoRA fine-tuning of the pre-trained model M in step 2 are as follows:
[0112] Step 2.1: Replace the weight matrix W of the attention module in the pre-trained model M with q , W v Freeze and add two new matrices W A With W B , let W q , W v The dimension of the matrix is R d×k , matrix W A With W B The dimensions are R d×r and R r×k , where d< <r。
[0113] Step 2.2: Adjust model output. Since two different but similar tasks, anomaly detection and anomaly analysis, need to be completed simultaneously, this proposal uses one model to achieve multiple tasks. Two different output heads are assigned to the two different tasks, that is, two branches C are set up in the output layer. A With C B .
[0114] Step 2.2.1: Anomaly detection branch: For the anomaly detection task, the vector V generated by the model M after processing the input data D is used for data binary classification through the LeakReLU activation function. The loss function uses the binary cross entropy loss function to calculate the loss value loss1. The final output is O1.
[0115] Step 2.2.2: Anomaly analysis branch: For the anomaly analysis task, for the generated vector V, an additional Decoder layer is added to generate anomaly analysis text, and softmax is used as the activation function. The loss function uses the cross entropy loss function to calculate the loss value loss2. The final output is O2.
[0116] Step 2.2.2: Set the weighted loss function. For the loss function of multiple loss values, loss = a*loss1+b*loss2. For the values of a and b, that is, the weights of each attention, this paper sets an additional MLP layer for loss weight learning. For this MLP layer, the model is optimized to reduce the difference between the actual loss value and the target value. This proposal uses the cross entropy loss function to learn the weights, and finally outputs the values of a and b after the MLP layer is trained.
[0117] Step 2.3: Input the training dataset D and fine-tune the pre-trained model. The matrix W A With W B Contains trainable parameters P, W q , W v The parameters of the matrix P' are frozen and not trained.
[0118] Step 2.3: Merge the trained parameters P with the originally frozen parameters P' by first calculating the product of the original parameters and the input, and then multiplying them with the matrix W A With W B The specific formula is:
[0119] H=W0*x+W B W A *x
[0120] Among them, W0 represents the original pre-trained model parameters, x represents the input of the model, and the final merged parameters H are obtained.
[0121] The specific steps of anomaly detection and analysis in step 3 are as follows:
[0122] Step 3.1: The data preprocessing module in the detection model first preprocesses the read operation behavior log data A to obtain data D, then adds the instruction text to the data prefix and merges it with the original data set, and inputs it together to the fine-tuned large language model M. The specific format is [instruction Q, operation log D]
[0123] Step 3.2: The model finally outputs two parts, namely the anomaly detection result O1 of the operation log sequence and the analysis of the anomaly O2;
[0124] The database abnormal operation detection method provided in the embodiment of the present application has the following beneficial effects:
[0125] For the operation log records to be tested that are judged to be abnormal, the abnormality analysis information makes the abnormality explainable and can analyze the cause of the abnormality;
[0126] A LoRA fine-tuning method is used. Compared with the existing full parameter fine-tuning technology, it uses a more efficient and low-resource consumption method to fine-tune the model. By freezing the original parameters and adding a bypass method, the parameter update amount is determined by low-rank decomposition, achieving low-cost and efficient fine-tuning;
[0127] Compared with the existing technology that can only complete anomaly detection or anomaly analysis tasks separately, this technology merges two different but related tasks, improves their respective effects by sharing parameters, and designs two different output layers to complete the corresponding tasks.
[0128] This paper proposes a method to use MLP layer to complete the problem of allocating weights of multiple loss values in multi-task learning. In order to solve the problem of difficulty in allocating weights to multiple loss functions in multi-task learning, this proposal uses additional MLP layer for learning and training to obtain the most appropriate weight allocation.
[0129] Compared with the existing technical solutions, the designed system solves the problems of lack of explainability of anomaly detection in current methods, huge data set size, and difficulty in coping with new operation log scenarios, and is more in line with actual production needs.
[0130] Figure 3 A structural diagram of a database abnormal operation detection device provided in an embodiment of the present application is shown.
[0131] like Figure 3 As shown, the database abnormal operation detection device 300 includes:
[0132] The first acquisition module 301 is used to acquire a log record of an operation to be tested, where the log record of the operation to be tested is a log record of an operation performed on a database;
[0133] A detection module 302 is used to input the operation log record to be tested into a target model to obtain a detection result of the operation log record to be tested, wherein the detection result includes indication information and abnormal analysis information, wherein the indication information is used to indicate whether the operation log record to be tested is abnormal, and the abnormal analysis information of the operation log record to be tested is used to explain the cause of the abnormal operation;
[0134] Among them, the target model is obtained by training a large language model LLM through a training data set and fine-tuning the LLM. The training data set includes training sample records, labels corresponding to the training sample records, and abnormal analysis information. The training sample records include multiple operation log records for training, and the labels are used to identify normal or abnormal.
[0135] In one embodiment of the present application, the device further includes:
[0136] The second acquisition module is used to acquire multiple operation log records of operating on the database;
[0137] A third acquisition module is used to group the multiple operation log records to obtain multiple groups of operation log records, each group of operation log records is a training sample record, and each training sample record is provided with a label and abnormal analysis information;
[0138] A construction module, used to construct a training data set according to each of the training sample records, the label of each of the training sample records and the abnormal analysis information;
[0139] The training module is used to input the training data set into the LLM and fine-tune the LLM through LoRA to obtain a target model.
[0140] In one embodiment of the present application, the training module includes:
[0141] A third setting submodule is used to set an anomaly detection branch and an anomaly analysis branch in the output layer of the LLM, wherein the anomaly detection branch is used to output an anomaly detection result, and the anomaly analysis branch is used to output an anomaly analysis result;
[0142] A fourth setting submodule is used to set a multi-layer perceptron MLP layer in the LLM to perform loss weight learning;
[0143] A training submodule is used to input the training data set into the LLM, and to maintain the existing weight matrix W of the attention module in the LLM during the fine-tuning of the LLM using LoRA. q and the weight matrix W v No change, additionally add a new weight matrix W A With the weight matrix W B , get the target model, where W q , W v are matrices with d rows and k columns, W A is a matrix with d rows and r columns, W B It is a matrix with r rows and k columns, and the values of d, k, and r are positive integers.
[0144] In one embodiment of the present application, the training submodule includes:
[0145] A calculation unit is used to calculate the training data set and the weight matrix W. A , weight matrix W B , and the weight matrix W q and the weight matrix W v The first parameter included is calculated as follows to obtain the target parameter H;
[0146] H=W0*x+W B W A *x
[0147] Wherein, W0 represents the first parameter, x represents one or more rows of data in the training data set input to the LLM each time, wherein a training sample record, and the label and anomaly analysis information of the training sample record constitute a row of data in the training data set;
[0148] An updating unit, used to replace the weight matrix W in the LLM with the target parameter q and the weight matrix W v , and obtain the target model.
[0149] In an embodiment of the present application, the third setting submodule includes:
[0150] A first calculation unit is used to set an anomaly detection branch in the output layer of the LLM, perform binary classification using an activation function, and calculate a first loss value using a binary classification cross entropy loss function;
[0151] A second calculation unit is used to set an abnormality analysis branch in the output layer of the LLM, and add a decoder after the encoder of the LLM to generate an abnormality analysis text, and calculate a second loss value using a cross entropy loss function;
[0152] Accordingly, the fourth setting submodule includes:
[0153] A determining unit, configured to determine the following weighted loss function according to the first loss value and the second loss value:
[0154] loss = a*loss1+b*loss2;
[0155] Among them, loss1 is the first loss value, loss2 is the second loss value, a and b are loss weights, and the values of a and b are obtained by loss weight learning through the MLP layer.
[0156] In an embodiment of the present application, the first acquisition module includes:
[0157] The first acquisition submodule is used to acquire multiple log records of operations on the database, each log record including an SQL statement;
[0158] The second acquisition submodule is used to perform word segmentation and de-parameterization processing on each SQL statement in the log record to obtain the operation log record.
[0159] The database abnormal operation detection device 300 provided in the embodiment of the present application can implement each process implemented in the aforementioned database abnormal operation detection method embodiment and achieve the same technical effect. To avoid repetition, it will not be described here.
[0160] Figure 4 A schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present application is shown.
[0161] The electronic device may include a processor 401 and a memory 402 storing computer program instructions.
[0162] Specifically, the processor 401 may include a central processing unit (CPU), or an application specific integrated circuit (ASIC), or may be configured to implement one or more integrated circuits of the embodiments of the present application.
[0163] Memory 402 may include a large capacity memory for data or instructions. By way of example and not limitation, memory 402 may include a hard disk drive (HDD), a floppy disk drive, a flash memory, an optical disk, a magneto-optical disk, a magnetic tape, or a universal serial bus (USB) drive or a combination of two or more of these. In appropriate cases, memory 402 may include a removable or non-removable (or fixed) medium. In appropriate cases, memory 402 may be inside or outside of an integrated gateway disaster recovery device. In a specific embodiment, memory 402 is a non-volatile solid-state memory.
[0164] The memory may include a read-only memory (ROM), a random access memory (RAM), a magnetic disk storage medium device, an optical storage medium device, a flash memory device, an electrical, optical or other physical / tangible memory storage device. Thus, typically, the memory includes one or more tangible (non-transitory) computer-readable storage media (e.g., a memory device) encoded with software including computer-executable instructions, and when the software is executed (e.g., by one or more processors), it is operable to perform the operations described with reference to the method according to the first aspect or the second aspect of the present disclosure.
[0165] The processor 401 implements any one of the information auditing methods in the above embodiments by reading and executing computer program instructions stored in the memory 402 .
[0166] In one example, the electronic device may further include a communication interface 403 and a bus 410. Figure 4 As shown, the processor 401, the memory 402, and the communication interface 403 are connected via a bus 410 and communicate with each other.
[0167] The communication interface 403 is mainly used to implement communication between various modules, devices, units and / or equipment in the embodiments of the present application.
[0168] Bus 410 includes hardware, software or both, and the parts of information audit method or verification equipment are coupled to each other. For example, but not limitation, bus may include accelerated graphics port (AGP) or other graphics bus, enhanced industrial standard architecture (EISA) bus, front side bus (FSB), hypertransport (HT) interconnection, industrial standard architecture (ISA) bus, infinite bandwidth interconnection, low pin count (LPC) bus, memory bus, micro channel architecture (MCA) bus, peripheral component interconnection (PCI) bus, PCI-Express (PCI-X) bus, serial advanced technology attachment (SATA) bus, video electronics standard association local (VLB) bus or other suitable bus or two or more of these combinations. In appropriate cases, bus 410 may include one or more buses. Although the present application embodiment describes and shows a specific bus, the application considers any suitable bus or interconnection.
[0169] In addition, in combination with the database abnormal operation detection method in the above embodiment, the embodiment of the present application can provide a computer storage medium for implementation. The computer storage medium stores computer program instructions; when the computer program instructions are executed by the processor, any one of the database abnormal operation detection methods in the above embodiment is implemented.
[0170] It should be clear that the present application is not limited to the specific configuration and processing described above and shown in the figures. For the sake of simplicity, a detailed description of the known method is omitted here. In the above embodiments, several specific steps are described and shown as examples. However, the method process of the present application is not limited to the specific steps described and shown, and those skilled in the art can make various changes, modifications and additions, or change the order between the steps after understanding the spirit of the present application.
[0171] The functional blocks shown in the above-described block diagram can be implemented as hardware, software, firmware or a combination thereof. When implemented in hardware, it can be, for example, an electronic circuit, an application specific integrated circuit (ASIC), appropriate firmware, a plug-in, a function card, etc. When implemented in software, the elements of the present application are programs or code segments that are used to perform the required tasks. The program or code segment can be stored in a machine-readable medium, or transmitted on a transmission medium or a communication link by a data signal carried in a carrier wave. "Machine-readable medium" can include any medium capable of storing or transmitting information. Examples of machine-readable media include electronic circuits, semiconductor memory devices, ROM, flash memory, erasable ROM (EROM), floppy disks, CD-ROMs, optical disks, hard disks, optical fiber media, radio frequency (RF) links, etc. The code segment can be downloaded via a computer network such as the Internet, an intranet, etc.
[0172] It should also be noted that the exemplary embodiments mentioned in this application describe some methods or systems based on a series of steps or devices. However, this application is not limited to the order of the above steps, that is, the steps can be performed in the order mentioned in the embodiment, or in a different order from the embodiment, or several steps can be performed simultaneously.
[0173] In addition, the embodiments of the present application may provide a computer program product for implementation. When the instructions in the computer program product are executed by a processor of an electronic device, the electronic device implements any one of the database abnormal operation detection methods in the above embodiments.
[0174] It should be clear that the present application is not limited to the specific configuration and processing described above and shown in the figures. For the sake of simplicity, a detailed description of the known method is omitted here. In the above embodiments, several specific steps are described and shown as examples. However, the method process of the present application is not limited to the specific steps described and shown, and those skilled in the art can make various changes, modifications and additions, or change the order between the steps after understanding the spirit of the present application.
[0175] The functional blocks shown in the above-described block diagram can be implemented as hardware, software, firmware or a combination thereof. When implemented in hardware, it can be, for example, an electronic circuit, an application specific integrated circuit (ASIC), appropriate firmware, a plug-in, a function card, etc. When implemented in software, the elements of the present application are programs or code segments that are used to perform the required tasks. The program or code segment can be stored in a machine-readable medium, or transmitted on a transmission medium or a communication link by a data signal carried in a carrier wave. "Machine-readable medium" can include any medium capable of storing or transmitting information. Examples of machine-readable media include electronic circuits, semiconductor memory devices, ROM, flash memory, erasable ROM (EROM), floppy disks, CD-ROMs, optical disks, hard disks, optical fiber media, radio frequency (RF) links, etc. The code segment can be downloaded via a computer network such as the Internet, an intranet, etc.
[0176] It should also be noted that the exemplary embodiments mentioned in this application describe some methods or systems based on a series of steps or devices. However, this application is not limited to the order of the above steps, that is, the steps can be performed in the order mentioned in the embodiment, or in a different order from the embodiment, or several steps can be performed simultaneously.
[0177] Aspects of the present disclosure are described above with reference to the flowchart and / or block diagram of the method, device (system) and computer program product according to the embodiment of the present disclosure. It should be understood that each box in the flowchart and / or block diagram and the combination of each box in the flowchart and / or block diagram can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device to produce a machine so that these instructions executed by the processor of the computer or other programmable data processing device enable the implementation of the function / action specified in one or more boxes of the flowchart and / or block diagram. Such a processor can be, but is not limited to, a general-purpose processor, a special-purpose processor, a special application processor, or a field programmable logic circuit. It can also be understood that each box in the block diagram and / or flowchart and the combination of boxes in the block diagram and / or flowchart can also be implemented by dedicated hardware that performs a specified function or action, or can be implemented by a combination of dedicated hardware and computer instructions.
[0178] The above is only a specific implementation of the present application. Those skilled in the art can clearly understand that for the convenience and simplicity of description, the specific working processes of the systems, modules and units described above can refer to the corresponding processes in the aforementioned method embodiments, and will not be repeated here. It should be understood that the protection scope of the present application is not limited to this. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed in this application, and these modifications or replacements should be included in the protection scope of this application.
Claims
1. A method for detecting abnormal database operations. It is characterized in that The method comprises: Obtaining a log record of the operation to be tested, wherein the log record of the operation to be tested is a log record of an operation performed on a database; Inputting the operation log record to be tested into the target model, obtaining a detection result of the operation log record to be tested, wherein the detection result includes indication information and abnormal analysis information, wherein the indication information is used to indicate whether the operation log record to be tested is abnormal, and the abnormal analysis information of the operation log record to be tested is used to explain the reason why the abnormal operation exists in the operation log record to be tested; Among them, the target model is obtained by training a large language model LLM through a training data set and fine-tuning the LLM. The training data set includes training sample records, labels corresponding to the training sample records, and abnormal analysis information. The training sample records include multiple operation log records for training, and the labels are used to identify normal or abnormal.
2. The method according to claim 1, It is characterized in that Before inputting the operation log record to be tested into the target model to obtain the detection result of the operation log record to be tested, the method further includes: Get multiple operation log records for database operations; Grouping the multiple operation log records to obtain multiple groups of operation log records, each group of operation log records is a training sample record, and each of the training sample records is provided with a label and abnormal analysis information; Constructing a training data set according to each of the training sample records, the label of each of the training sample records, and the abnormal analysis information; The training data set is input into the LLM, and the LLM is fine-tuned through low-rank adaptation LoRA to obtain the target model.
3. The method according to claim 2, It is characterized in that The training data set is input into the LLM, and the LLM is fine-tuned through LoRA to obtain a target model, including: An anomaly detection branch and an anomaly analysis branch are set in the output layer of the LLM, the anomaly detection branch is used to output an anomaly detection result, and the anomaly analysis branch is used to output an anomaly analysis result; A multi-layer perceptron MLP layer is set in the LLM to perform loss weight learning; The training data set is input into the LLM. During the fine-tuning of the LLM using LoRA, the existing weight matrix W of the attention module in the LLM is maintained. q and the weight matrix W v No change, additionally add a new weight matrix W A With the weight matrix W B , get the target model, where W q , W v are all matrices with d rows and k columns, W A is a matrix with d rows and r columns, W B It is a matrix with r rows and k columns, and the values of d, k, and r are positive integers.
4. The method according to claim 3, It is characterized in that Maintain the weight matrix W of the attention module in the LLM q and the weight matrix W v Unchanged, increase the weight matrix W A With the weight matrix W B , get the target model, including: According to the training data set, the weight matrix W A , weight matrix W B , and the weight matrix W q and the weight matrix W v The first parameter included is calculated as follows to obtain the target parameter H; H=W 0 *x+W B W A *x Among them, W 0 represents the first parameter, x represents one or more rows of data in the training data set input to the LLM each time, wherein a training sample record, and the label and anomaly analysis information of the training sample record constitute a row of data in the training data set; The target parameters are used to replace the weight matrix W in the LLM q and the weight matrix W v , and obtain the target model.
5. The method according to claim 3, It is characterized in that An anomaly detection branch and an anomaly analysis branch are set in the output layer of the LLM, including: An anomaly detection branch is set in the output layer of the LLM, and an activation function is used to perform binary classification, and a first loss value is calculated using a binary classification cross entropy loss function; An exception analysis branch is set in the output layer of the LLM, and a decoder is added after the encoder of the LLM to generate an exception analysis text, and a second loss value is calculated using a cross entropy loss function; In the LLM, a multi-layer perceptron MLP layer is set to perform loss weight learning, including: According to the first loss value and the second loss value, the following weighted loss function is determined: loss=a*loss 1 +b*loss 2 ; Among them, loss 1 is the first loss value, loss 2 is the second loss value, a and b are loss weights, where the values of a and b are obtained by learning the loss weights through the MLP layer.
6. The method according to claim 2, It is characterized in that Get multiple operation log records for database operations, including: Get multiple log records of database operations, each log record includes SQL statements; The SQL statement in each log record is word segmented and de-parameterized to obtain the operation log record.
7. A database abnormal operation detection device, It is characterized in that The device comprises: An acquisition module is used to acquire a log record of the operation to be tested, wherein the log record of the operation to be tested is a log record of an operation performed on a database; A detection module, used for inputting the operation log record to be tested into a target model to obtain a detection result of the operation log record to be tested, wherein the detection result includes indication information and abnormal analysis information, wherein the indication information is used to indicate whether the operation log record to be tested is abnormal, and the abnormal analysis information of the operation log record to be tested is used to explain the reason for the abnormal operation in the operation log record to be tested; Among them, the target model is obtained by training a large language model LLM through a training data set and fine-tuning the LLM. The training data set includes training sample records, labels corresponding to the training sample records, and abnormal analysis information. The training sample records include multiple operation log records for training, and the labels are used to identify normal or abnormal.
8. An electronic device, It is characterized in that include: a processor and a memory storing computer program instructions; When the processor executes the computer program instructions, the method according to any one of claims 1 to 6 is implemented.
9. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores computer program instructions, and when the computer program instructions are executed by a processor, the method according to any one of claims 1 to 6 is implemented.
10. A computer program product, It is characterized in that When the instructions in the computer program product are executed by a processor of an electronic device, the electronic device executes the method according to any one of claims 1 to 6.
Citation Information
Cited By
Log anomaly detection method and device, equipment and storage medium
CN119806966A
Method and device for detecting abnormal operation behavior of software system and medium
CN121456684A
