Detailed Description
For the purpose of making the objects, technical solutions and advantages of the present invention more apparent, embodiments of the present invention will be further described with reference to the accompanying drawings.
The related technical concept in the application is as follows:
(1) Kafka is a distributed, partition-supporting and multi-copy (replica) distributed message system based on zookeeper coordination, and has the biggest characteristic of being capable of processing a large amount of data in real time to meet various requirement scenes;
(2) Persistence is a mechanism by which program data transitions between a persistent state and an instantaneous state. Colloquially, instant data (such as data in memory that cannot be permanently stored) persists as persistent data (such as persisted into a database that can be permanently stored);
Referring to fig. 1, fig. 1 is a flow chart of the method of the present invention.
The invention provides an audit log analysis method, audit log analysis equipment and audit log storage equipment, wherein the audit log analysis method specifically comprises the following steps:
S1, acquiring log files and database information:
For the log file, storing various sql databases of the user in the log file of a local disk, reading the local log file, and pushing the local log file to a theme corresponding to the kafka platform;
for database information, directly pulling table information in various sql databases of users, and persisting field information in the table to the local;
It should be noted that, in step S1, the process of persisting the fields in the table to the local is as follows:
Reading a local database field table database_field and loading the database_field to a local FIELDLIST;
reading a local database information table table_info and loading the table_info to a local tableList;
The local database table database_info is read and loaded to the local databaseList.
S2, processing log files and database information:
persistence of the first operation data after the analysis of the local log file to the local;
After field collision detection is carried out on the table information, analyzing the table information to obtain second operation data, and lasting the second operation data to the local;
It should be noted that, the conventional method receives the log collector normative and sends the normative log to the database operation log of kafka, and analyzes sql according to the table field information, the table information and other information stored in the data, performs enhancement operation on the original log data, and then stores the enhanced log data in the local database for later analysis and use.
Different from the conventional scheme, the method converts the related information of the queried database into a Map structure, caches the Map structure in a local cache system, divides sql of a user operation log into individual words, fetches data step by step from the Map according to the words, finally acquires field classes containing all information of the words to perform attribute enhancement and other operations, and the method can greatly reduce time complexity and predict that O (mn) is reduced to O (n) -O (nlogm), n is the number of the sql divided words, and m is the number of database fields.
Referring to fig. 2, fig. 2 is a schematic diagram of stepwise data fetching from the map;
Specifically, the log and database information processing in step S2 is as follows:
constructing database information baseMap according to the field table database_field, the information table table_info and the database table database_info;
Caching database information baseMMap;
dividing sql sentences in the local log into sqlWords lists by taking spaces, ", and";
For example, select id, date_ time from network _match will be segmented into [ "select", "id", "date_time", "from", "networ k _match" ];
traversing sqlWords the list, and obtaining a database dMap corresponding to the database table database_info through a basemap. Get (sqlWord) function;
wherein sqlWord is a specified sql statement;
Obtaining a corresponding information table tMap through a dMap.get () function;
obtaining a corresponding field table fMap through a tmap.get () function;
obtaining a corresponding field class file through an fMap.get () function;
data enhancement is carried out on the field class flied;
Adding enhancement data to the operation table and the inner surface of the association table of the database;
In the invention, a database field table (database_field), an operation table and an association table are respectively shown in tables 1,2 and 3;
Table 1 database field table
Table 2 database operating table (data_ manipulate)
TABLE 3 operation-field association table (manipulate _relation)
And if the enhancement data are sensitive data, directly generating alarm data to push to the kafka platform, and executing corresponding notification or blocking operation.
For example, in the sql collision process, when a sensitive field (such as a password) marked by a user in advance is touched, or a sensitive operation is combined, and an update operation is performed on a field, such as a name, which should not be modified, alarm data is directly generated and pushed to kafka, and the alarm program judges that a corresponding operation (e.g. sending a mail or a short message, or directly blocking the work of a corresponding ip through a firewall according to the operation ip of a log) is performed.
As an embodiment, for example, the log after normalization collected by the present invention:
{
"host": "192.168.184.131",// operations ip
"Data_type": "mysql",// database type
"Manipulation": SELECT id, sql FROM @ mysql @ general_log @ LIMIT 0,1000",// operation statement
}
The enhanced log processed by the steps is as follows:
Step 1, decomposing manipulation into word list wordList ([ 'SELECT', 'id', 'sql' FROM 'mysql', 'general_log', 'LIMIT' ]
Step 2, obtaining baseMap a library list of mysql in the database type field data_type, taking wordList to collide with the library information mysql one by one, and storing the library information mysql in a databases field
Step 3, inquiring a list of table information under the mysql library according to the mysql library, obtaining the table information of general_log by carrying out collision one by using wordList, and storing the table information into tables field
Step 4, inquiring a field list under the table according to the general_log, obtaining field information, and storing the field information in fields
Step 5, judging the sentence operation type according to wordList first words are select, alter, update, delete, and storing in the type field
Step 6, judging whether the field is sensitive or not, storing the sensitive operation into the alert field, and then deciding whether to generate an alarm and a corresponding operation according to the field, and ending the operation
After analysis:
{
"host": "192.168.184.131",// operations ip
"Data_type": "mysql",// database type
"Manipulation": SELECT id, sql FROM @ mysql @ general_log @ LIMIT 0,1000",// operation statement
"Databases" [ "mysql" ],// database
"Tables" [ "general_log" ]// table
"Fields" [ "id", "sql" ]// fields
"Type": "select",// type of operation
"Alert": "false"// whether sensitive data is manipulated
}
And S3, analyzing the operation data, namely performing statistical analysis on the first operation data and the second operation data, and displaying analysis results outwards through unified interface service.
For example, the storage statement database after storage analysis is queried, a certain ip address (192.168.182.131) is counted to perform 20 update operations on a mysql database user information table user_info, 120 password fields password of the table are checked, and because the password fields are sensitive fields, an alarm is generated and a system administrator user is notified.
Referring to fig. 3, fig. 3 is a schematic working diagram of a hardware device according to an embodiment of the present invention, where the hardware device specifically includes an audit log alarm device 401, a processor 402, and a storage device 403.
An audit log alarming device 401, wherein the audit log alarming device 401 implements the audit log analysis method.
Processor 402 the processor 402 loads and executes instructions and data in the storage device 403 for implementing the one audit log analysis method.
The storage device 403 is used for storing instructions and data, and the storage device 403 is used for realizing the audit log analysis method.
The method has the advantages of improving log analysis compatibility, improving processing performance under large-magnitude data processing, timely alarming after collision with sensitive data, and improving overall safety of the system.
The foregoing description of the preferred embodiments of the invention is not intended to limit the invention to the precise form disclosed, and any such modifications, equivalents, and alternatives falling within the spirit and scope of the invention are intended to be included within the scope of the invention.