A method and system for auditing high-risk instructions of a database for a bastion host
By running the MySQL Agent program and monitoring and forwarding program on the bastion machine, the security and real-time issues of the approval operation of high-risk instructions in the database are solved, and real-time interactive processing of customized configuration and operation and maintenance instructions of high-risk instruction sets of different database servers is realized, improving Improve the security and monitoring capabilities of the database server.
Patent Information
- Application Number
- CN202210811101.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-07-11
- Publication Date
- 2024-10-11
- Estimated Expiration
- 2042-07-11
AI Technical Summary
The existing database high-risk instruction approval operation has problems such as insufficient security, inability to realize real-time high-risk instruction setting and approval operations, and inability to realize real-time interaction between the client and the bastion machine.
By running the MySQL Agent program and the monitoring and forwarding program on the bastion machine, the client interacts with the bastion machine to send high-risk command sets. The bastion machine establishes a configuration file and intercepts operation and maintenance instructions. It intercepts and approves the instructions based on the type, achieving real-time interaction and auditing.
It improves the security of the database server, realizes the customized configuration of high-risk instruction sets for different database servers, and realizes real-time interactive processing and monitoring of the operation and maintenance instruction level between the client, the bastion host and the database server.
Smart Images

Figure CN115242473B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical fields of database, information security and network security, and more specifically, to a method and system for auditing high-risk instructions of a database for a bastion host. Background Art
[0002] The bastion host is used to protect specific internal networks and data from intrusion and destruction from external and internal users, and uses various technical means to monitor and record the operation behaviors of operation and maintenance personnel on servers, network devices, security devices, databases and other devices in the network, so as to realize alarm, timely processing and auditing and accountability. The working principle of the bastion host is mainly to block direct access to the database by the network and client devices, and analyze and filter all schemes and operation behaviors through protocol proxy, so as to ensure that reliable data access and operations are released, and untrusted or suspected operations will be filtered and intercepted.
[0003] A database is a collection of large amounts of data that is stored in a computer for a long time, organized, shareable, and uniformly managed. In the information age, databases are strategic assets of the information systems of enterprises and institutions. As the saying goes, "equipment has value, but data is priceless", it is necessary to strictly prevent and monitor databases to prevent illegal and malicious operations. With the continuous development of informatization, the threat of information security is also growing. According to statistics: 100% of enterprises are currently facing data security threats. 82% of enterprises are at risk of data leakage. 75% of enterprises have system and application vulnerabilities. Many enterprises have not yet audited and monitored data access behaviors, and are unable to respond to operational behaviors in a timely manner. Therefore, there is a high urgency to approve and audit high-risk database instructions.
[0004] The current methods for approving high-risk database instructions are mainly: 1. Installing an access control terminal on a remote desktop server, loading the Windows File Protection (WFP) driver, intercepting database traffic to the audit server, and marking the traffic with corresponding account information. After the traffic reaches the audit server, the account information is parsed to check whether there is corresponding authority; 2. Configuring the corresponding high-risk instruction file on the data client, the user operation will access the configuration file to query whether it has the corresponding operation authority; 3. Using the relevant agent program, configure a fixed rule file on the agent program, and use fixed rules to implement whether the client-related operations have the corresponding operation authority.
[0005] However, the existing database high-risk instruction approval operations all have some defects that cannot be ignored: first, installing the corresponding control terminal on the remote server is itself unsafe and is likely to cause the entire server to be damaged; second, the method of writing in the client's fixed configuration file cannot realize real-time high-risk instruction setting and approval operations according to specific operation requirements; third, the method of writing in the configuration file of the intermediate agent program basically cannot realize the operation processing flow of real-time interaction and approval with the client. Summary of the invention
[0006] In response to the above defects or improvement needs of the prior art, the present invention provides a database high-risk instruction review method and system for real-time interaction with a bastion host, which aims to solve the technical problems that the existing database high-risk instruction approval operation is unsafe due to the installation of the corresponding control terminal on the remote server, and will cause the entire server to be destroyed, as well as the technical problem that real-time high-risk instruction setting and approval operations cannot be implemented according to specific operation requirements due to the use of a fixed configuration file written in the client, and the technical problem that the operation processing flow of real-time interaction and approval with the client cannot be implemented due to the use of a configuration file written in an intermediate agent program.
[0007] To achieve the above object, according to one aspect of the present invention, a method and system for auditing high-risk instructions of a database of a bastion host is provided, comprising the following steps:
[0008] (1) The client configures a high-risk instruction set for operating and maintaining the database server and sends a connection request to the bastion host;
[0009] (2) After receiving the connection request from the client, the bastion host allocates a listening port number for the client, sends the port number to the client, and starts the MySQL Agent program to listen for the connection request from the client;
[0010] (3) The client sends a high-risk instruction set to the bastion host;
[0011] (4) After receiving the high-risk instruction set from the client, the bastion host creates and saves the corresponding configuration file.
[0012] (5) After receiving the MySQL login command entered by the user, the client initiates a connection request to the bastion host;
[0013] (6) The bastion host establishes a connection with the database server after listening to the connection request from the client;
[0014] (7) The client enters operation and maintenance instructions to perform operation and maintenance operations on the database server through the bastion host;
[0015] (8) The bastion host intercepts the operation and maintenance instructions input by the client and determines the type of the operation and maintenance instructions based on the configuration file established in step (4);
[0016] (9) The bastion host performs corresponding operations on the operation and maintenance instruction according to the type of operation and maintenance instruction determined in step (8).
[0017] (10) When the maintenance operation on the database server is completed, the bastion host shuts down the MySQL Agent program and the monitoring forwarding program, establishes the maintenance end time information of the MySQL client, and sends the maintenance end time information to the bastion host.
[0018] Preferably, the client is connected to the database server via a bastion host;
[0019] The client includes the operation and maintenance client system and the MySQL client;
[0020] The bastion host includes Python forwarding program, monitoring forwarding program, MySQL Agent program, and log database;
[0021] A MySQL server is set on the database server.
[0022] Preferably, step (2) comprises the following sub-steps:
[0023] (2-1) After the Python forwarding program in the bastion host monitors the connection request from the client, it establishes a connection with the monitoring forwarding program in the bastion host and forwards the connection request to the monitoring forwarding program;
[0024] (2-2) After receiving the connection request, the monitoring forwarding program in the bastion host dynamically allocates a listening port number (such as 4006) for the MySQL Agent program in the bastion host, sends the listening port number to the Python forwarding program in the bastion host, and starts a process to run the MySQL Agent program in the bastion host;
[0025] (2-3) The MySQL Agent program in the bastion host starts listening for connection requests from the MySQL client in the client.
[0026] Preferably, the types of instructions include warning instructions, blocking instructions after timeout or rejection, session disconnection instructions after timeout or rejection, blocking instructions, and session disconnection instructions.
[0027] Preferably, step (5) comprises the following sub-steps:
[0028] (5-1) The operation and maintenance client system in the client calls and starts the MySQL client;
[0029] (5-2) After receiving the MySQL login command entered by the user, the MySQL client in the client initiates a connection request to the MySQL Agent program in the bastion host.
[0030] Step (6) includes the following sub-steps:
[0031] (6-1) The MySQL Agent program in the bastion host establishes a connection with the MySQL client in the client after listening to the connection request from the client;
[0032] (6-2) The MySQL Agent program in the bastion host establishes a connection with the operation and maintenance database server based on the connection request of the MySQL client in the client, so as to forward the instructions from the MySQL client and the response information of the database server.
[0033] Preferably, if the operation and maintenance instruction is an alarm-type instruction, step (9) is specifically as follows: the MySQL Agent program in the bastion host forwards the operation and maintenance instruction to the MySQL server in the database server, and the MySQL server executes the operation and maintenance instruction and returns the execution result to the MySQL Agent program in the bastion host; the MySQL Agent program in the bastion host intercepts the response result of the MySQL server in the database server, and adds an alarm message after the execution result, forwards the execution result with the added alarm message to the MySQL client in the client, and constructs log information at the same time, and writes it back to the Python forwarding program in the bastion host. Finally, after receiving and parsing the log information, the Python forwarding program in the bastion host writes it into the log database for storage.
[0034] If the operation and maintenance instruction is a blocking instruction, step (9) is specifically as follows: the MySQL Agent program in the bastion host directly blocks the forwarding operation of the operation and maintenance instruction, and then forges a warning message information according to the MySQL protocol message format from the MySQL server to the MySQL client, and then forwards the forged warning message information to the MySQL client for display, and at the same time constructs a log message and writes it back to the Python forwarding program in the bastion host. After receiving and parsing the log information, the Python forwarding program in the bastion host writes it into the log database for storage;
[0035] Preferably, if the operation and maintenance instruction is an instruction to disconnect the session after timeout or rejection, step (9) is specifically as follows: the MySQL Agent program in the bastion host constructs a data packet with a quit command according to the MySQL protocol message format from the MySQL client to the MySQL server, and then uses a forged data packet with a quit command to replace the data packet containing the operation and maintenance instruction, and forwards it to the MySQL server in the database server, so as to disconnect the session connection between the MySQL client in the client and the MySQL server in the database server. Finally, a log message is constructed and written back to the Python forwarding program in the bastion host. After receiving and parsing the log message, the Python forwarding program in the bastion host writes it into the log database for storage.
[0036] Preferably, if the operation and maintenance instruction is a blocking instruction after timeout or rejection, step (9) is specifically as follows: if the operation and maintenance instruction is an approval-type (blocking) instruction, the MySQL Agent program in the bastion host constructs instruction approval request information, sends it to the operation and maintenance client system through the Python forwarding program for real-time approval operation, and waits for receiving the approval result from the operation and maintenance client system; if the approval result is passed, the MySQL Agent program in the bastion host forwards the operation and maintenance instruction to the MySQL server in the database server, the MySQL server executes the operation and maintenance instruction and returns the instruction execution result, and after receiving the instruction execution result, the MySQL Agent program in the bastion host forwards it to the MySQL client in the client for display;
[0037] If the approval result is failure or approval times out, the MySQL Agent program in the bastion host forwards the operation and maintenance instruction to the MySQL server. At the same time, the MySQL Agent program in the bastion host forges a warning message according to the MySQL protocol message format from the MySQL server to the MySQL client, and then forwards the forged warning message to the MySQL client in the client for display. At the same time, a log message is constructed and written back to the Python forwarding program in the bastion host. After receiving and parsing the log message, the Python forwarding program in the bastion host writes it into the log database for storage.
[0038] If the operation and maintenance instruction is an instruction to disconnect the session after timeout or rejection, step (9) is specifically as follows: the MySQL Agent program in the bastion host constructs instruction approval request information, sends it to the operation and maintenance client system through the Python forwarding program for real-time approval operation, and waits to receive the approval result from the operation and maintenance client system; if the approval result is passed, the MySQL Agent program in the bastion host passes the operation and maintenance instruction to the MySQL server in the database server, the MySQL server executes the operation and maintenance instruction and returns the instruction execution result, the MySQL Agent program in the bastion host receives the instruction execution result and forwards it to the MySQL client in the client for display;
[0039] If the approval result is failure or approval times out, the MySQL Agent program in the bastion host blocks the forwarding of the operation and maintenance instruction, and constructs a data packet with a quit command according to the message format of the MySQL protocol from the MySQL client to the MySQL server. Then, the forged data packet with the quit command is used to replace the data packet containing the original operation and maintenance instruction, and forwarded to the MySQL server in the database server to disconnect the session connection with the MySQL server. Finally, the MySQL Agent program in the bastion host constructs a log message and forwards it to the Python forwarding program in the bastion host. After receiving and parsing the log message, the Python forwarding program in the bastion host writes it into the log database for storage.
[0040] Preferably, if the operation and maintenance instruction is a pass-class instruction, the MySQLAgent program in the bastion host forwards the operation and maintenance instruction to the MySQL server on the database server, waits for the execution result generated after the MySQL server executes the operation and maintenance instruction, and then forwards the execution result to the MySQL client in the client for display.
[0041] According to another aspect of the present invention, a database high-risk instruction audit system for a bastion host is provided, comprising:
[0042] The first module is set in the client and is used to configure a high-risk instruction set for operating and maintaining the database server and send a connection request to the bastion host;
[0043] The second module is set in the bastion host and is used to allocate a listening port number to the client after receiving a connection request from the client, send the port number to the client, and start the MySQL Agent program to listen for the connection request from the client;
[0044] The third module is set in the client and is used to send a high-risk instruction set to the bastion host;
[0045] The fourth module is arranged in the bastion host, and is used for establishing and saving a corresponding configuration file after receiving a high-risk instruction set from a client.
[0046] The fifth module is set in the client and is used to initiate a connection request with the bastion host after receiving the MySQL login instruction input by the user;
[0047] The sixth module is provided in the bastion host and is used to establish a connection with the database server after monitoring a connection request from a client;
[0048] The seventh module is provided in the client and is used to input operation and maintenance instructions so as to perform operation and maintenance operations on the database server through the bastion host;
[0049] The eighth module is set in the bastion host and is used to intercept the operation and maintenance instructions input by the client and determine the type of the operation and maintenance instructions according to the configuration file established by the fourth module;
[0050] The ninth module is arranged in the bastion host, and is used to perform corresponding operations on the operation and maintenance instruction according to the type of the operation and maintenance instruction determined by the eighth module.
[0051] The tenth module is set in the bastion host and is used to close the MySQLAgent program and the monitoring forwarding program when the operation and maintenance operation of the database server is completed, establish the operation and maintenance end time information of the MySQL client, and send the operation and maintenance end time information to the bastion host.
[0052] In general, the above technical solutions conceived by the present invention can achieve the following beneficial effects compared with the prior art:
[0053] 1. Since the present invention separates the client, the bastion host, and the database server, and the database proxy program and configuration files run on the bastion host, the remote database server can be truly protected from misoperation and attack, and one end can be protected from being damaged without affecting the service of the other end, making the service safer;
[0054] 2. Since the present invention adopts step (1), step (3), and step (4), when the MySQL server in the operation and maintenance database server starts, the client interacts with the bastion host, the client sends the high-risk instruction set category of the current operation and maintenance MySQL server, and the MySQL Agent program in the bastion host establishes a corresponding configuration file record. The bastion host can customize the configuration file filtering rules in real time according to the requirements of the MySQL server being operated and maintained, so as to achieve the effect of customizing different high-risk instruction sets for MySQL servers in different database servers;
[0055] 3. Since the present invention adopts step (7), step (8), and step (9), in the process of operating and maintaining the MySQL server in the database server, the MySQLAgent program in the bastion host will intercept and forward the client's operation command request according to the high-risk instruction rules in the previous configuration file. If it is an approval-type instruction, the MySQLAgent program in the bastion host will establish a connection with the operation and maintenance client system in the client in real time and interact with the audit command. The operation and maintenance client system in the client can review the operation and maintenance instructions of the MySQL client in real time, and whether the approval is passed or blocked. The MySQLAgent program in the bastion host forwards or blocks the operation and maintenance instructions according to the audit result of the operation and maintenance client system of the client, thereby realizing real-time interactive processing of operation and maintenance instruction level review and blocking between the client, the bastion host and the database server;
[0056] 4. Since the present invention adopts step (9) and step (10), during the operation and maintenance of the MySQL server in the database server, the MySQLAgent program in the bastion host will send the instruction approval process of the operation and maintenance operation in the format of a log to the Python forwarding program in the bastion host in real time for saving in the log database. This can realize full monitoring and tracking of the operation process of the MySQL server in the operation and maintenance database server, thereby achieving traceability. BRIEF DESCRIPTION OF THE DRAWINGS
[0057] Figure 1 It is a flow chart of a method for auditing high-risk instructions of a database of a bastion host according to the present invention;
[0058] Figure 2 It is a schematic diagram of the positional relationship of the client, bastion host, and database server of the present invention and the software programs running thereon;
[0059] Figure 3 It is a detailed flow chart of the method for auditing high-risk instructions of a database of a bastion host according to the present invention. DETAILED DESCRIPTION
[0060] In order to make the purpose, technical solutions and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention. In addition, the technical features involved in the various embodiments of the present invention described below can be combined with each other as long as they do not conflict with each other.
[0061] In view of the current problems of insufficient real-time, configurability and interactivity of the approval operation of high-risk instructions in the bastion host database, the present invention proposes a method that can configure different unique high-risk instruction sets for different operation and maintenance database servers, and a method for the bastion host to interact with the client in real time to approve the high-risk instruction set during the operation and maintenance process. When the user starts the operation and maintenance, the operation and maintenance client system in the client establishes a connection with the monitoring forwarding program in the bastion host to send the high-risk instruction set, and the monitoring forwarding program in the bastion host saves the corresponding configuration file to achieve real-time configurability; and when the MySQL Agent program in the bastion host detects a high-risk instruction during the operation and maintenance process, the approval-type instruction can be interacted with the operation and maintenance client system in the client in real time for real-time approval, so as to achieve real-time blocking or execution of the instruction according to the approval result, so that the approval process has better real-time and interactivity.
[0062] like Figure 1 and Figure 3 As shown, the present invention provides a method for auditing high-risk instructions of a database of a bastion host, comprising the following steps:
[0063] (1) The client configures a high-risk instruction set for operating and maintaining the database server and sends a connection request to the bastion host;
[0064] (2) After receiving the connection request from the client, the bastion host allocates a listening port number for the client, sends the port number to the client, and starts the MySQL Agent program to listen for the connection request from the client;
[0065] The advantage of this step is that the bastion host can monitor multiple MySQL clients communicating with the MySQL server at the same time.
[0066] Specifically, this step includes the following sub-steps:
[0067] (2-1) After the Python forwarding program in the bastion host monitors the connection request from the client, it establishes a connection with the monitoring forwarding program in the bastion host and forwards the connection request to the monitoring forwarding program;
[0068] (2-2) After receiving the connection request, the monitoring forwarding program in the bastion host dynamically allocates a listening port number (such as 4006) for the MySQL Agent program in the bastion host, sends the listening port number to the Python forwarding program in the bastion host, and starts a process to run the MySQL Agent program in the bastion host;
[0069] (2-3) The MySQL Agent program in the bastion host starts listening for connection requests from the MySQL client in the client.
[0070] The location relationship of the client, bastion host, and database server of the present invention is as follows: Figure 2 As shown in the figure. The client includes the operation and maintenance client system and the MySQL client. The bastion host includes: Python forwarding program, monitoring forwarding program, MySQL Agent program and log database. The database server is equipped with a MySQL server.
[0071] (3) The client sends a high-risk instruction set to the bastion host;
[0072] (4) After receiving the high-risk instruction set from the client, the bastion host creates and saves the corresponding configuration file.
[0073] The advantage of this step is that different high-risk instruction set configuration files can be established in real time for different MySQL servers according to their specific needs to implement the filtering and auditing operations of step (9).
[0074] Specifically, this step first parses the high-risk instruction set to obtain multiple different types, and then writes all types of high-risk instruction sets into corresponding configuration files and saves them.
[0075] More specifically, the format of the high-risk instruction set received by the bastion host is as follows:
[0076] {"method":"highrisk_set","session_id":"1E971CB109","data":{"time_out":60,"risk_list":{"insert":1,"update":3,"delete":2,"drop":5,"truncate":4}}}
[0077] risk_list corresponds to the following high-risk instruction set types: 1: Alarm type (i.e. insert instruction); 2: Approval type (i.e. delete, instruction that blocks after timeout or rejection); 3: Approval type (i.e. update, instruction that disconnects the session after timeout or rejection); 4: Blocking type (i.e. truncate); 5: Disconnecting the session (i.e. drop);
[0078] (5) After receiving the MySQL login command entered by the user, the client initiates a connection request to the bastion host;
[0079] Specifically, this step includes the following sub-steps:
[0080] (5-1) The operation and maintenance client system in the client calls and starts the MySQL client;
[0081] (5-2) After receiving the MySQL login command input by the user, the MySQL client in the client initiates a connection request with the MySQL Agent program in the bastion host;
[0082] Login command format: mysql–uroot–h10.200.102.197–P4006–p123456
[0083] Where u indicates the specified user, –h indicates the bastion host IP, –P indicates the specified port number, and –p indicates the specified user password;
[0084] (6) The bastion host establishes a connection with the database server after listening to the connection request from the client;
[0085] Specifically, this step includes the following sub-steps:
[0086] (6-1) The MySQL Agent program in the bastion host establishes a connection with the MySQL client in the client after listening to the connection request from the client;
[0087] (6-2) The MySQL Agent program in the bastion host establishes a connection with the operation and maintenance database server based on the connection request of the MySQL client in the client, so as to forward the instructions from the MySQL client and the response information of the database server.
[0088] (7) The client enters operation and maintenance instructions to perform operation and maintenance operations on the database server through the bastion host;
[0089] Specifically, the MySQL client in the client inputs the corresponding operation instruction and starts the operation and maintenance operation on the database server;
[0090] (8) The bastion host intercepts the operation and maintenance instructions input by the client and determines the type of the operation and maintenance instructions based on the configuration file established in step (4);
[0091] (9) The bastion host performs corresponding operations on the operation and maintenance instruction according to the type of the operation and maintenance instruction determined in step (8);
[0092] The advantage of this step is that the bastion host can intercept and filter the client's operation and maintenance instructions in real time according to the high-risk instruction configuration file in step (4), and interact with the client in real time according to the category of the high-risk instruction set to achieve real-time review and blocking of the operation and maintenance instructions.
[0093] Specifically, if the operation and maintenance instruction is an alarm-type instruction, the MySQL Agent program in the bastion host forwards the operation and maintenance instruction to the MySQL server in the database server. The MySQL server executes the operation and maintenance instruction and returns the execution result to the MySQL Agent program in the bastion host. The MySQL Agent program in the bastion host intercepts the response result of the MySQL server in the database server, and adds an alarm message (###Alert command###) after the execution result. The execution result with the added alarm message is forwarded to the MySQL client in the client, and log information is constructed at the same time, and written back to the Python forwarding program in the bastion host. Finally, after receiving and parsing the log information, the Python forwarding program in the bastion host writes it to the log database for storage.
[0094] Log information uses JSON format:
[0095] {"url":" / rpc / log","sid":"1E971CB109","action":1,"cmd":"001","approvers":"Approved by","dst_ip":"127.0.0.1","src_ip":"10.200.102.130"}action:1Sensitive command execution2Command blocking3Session blocking5Application approved6Application rejected7Application timeout (command blocking)8Application timeout (session blocking)9Cancel
[0096] Adding alarm information is done according to the MySQL protocol message format. The MySQL protocol message format from the MySQL server to the MySQL client is:
[0097]
[0098] If the operation and maintenance instruction is a blocking instruction, the MySQL Agent program in the bastion host directly blocks the forwarding operation of the operation and maintenance instruction, and then forges a warning message information according to the MySQL protocol message format from the MySQL server to the MySQL client, and then forwards the forged warning message information to the MySQL client for display, and at the same time constructs a log message and writes it back to the Python forwarding program in the bastion host. After receiving and parsing the log information, the Python forwarding program in the bastion host writes it into the log database for storage.
[0099] If the operation and maintenance instruction is an instruction to disconnect the session, the MySQL Agent program in the bastion host constructs a data packet with a quit command according to the MySQL protocol message format from the MySQL client to the MySQL server, and then replaces the data packet containing the operation and maintenance instruction with a forged data packet with a quit command, and forwards it to the MySQL server in the database server, so that the MySQL client in the client disconnects the session connection with the MySQL server in the database server. Finally, a log message is constructed and written back to the Python forwarding program in the bastion host. After receiving and parsing the log message, the Python forwarding program in the bastion host writes it into the log database for storage.
[0100] The message format of the MySQL protocol from the MySQL client to the MySQL server is:
[0101]
[0102] If the operation and maintenance instruction is an approval (blocking) instruction, the MySQL Agent program in the bastion host constructs instruction approval request information, sends it to the operation and maintenance client system through the Python forwarding program for real-time approval, and waits for the approval result from the operation and maintenance client system; if the approval result is passed, the MySQL Agent program in the bastion host forwards the operation and maintenance instruction to the MySQL server in the database server, and the MySQL server executes the operation and maintenance instruction and returns the instruction execution result. After receiving the instruction execution result, the MySQL Agent program in the bastion host forwards it to the MySQL client in the client for display;
[0103] If the approval result is failure or approval times out, the MySQL Agent program in the bastion host forwards the operation and maintenance instruction to the MySQL server. At the same time, the MySQL Agent program in the bastion host forges a warning message according to the MySQL protocol message format from the MySQL server to the MySQL client, and then forwards the forged warning message to the MySQL client in the client for display. At the same time, a log message is constructed and written back to the Python forwarding program in the bastion host. After receiving and parsing the log message, the Python forwarding program in the bastion host writes it into the log database for storage.
[0104] Instruction approval request information JSON format:
[0105] {"url":" / rpc / riskcmd","cmd":"delete","session_id":"1E971CB109","user":"testhyw","accuser":"root"}
[0106] Instruction approval result information JSON format:
[0107] {"method":"risk_approve","session_id":"1E971CB109","cmd":"delete","action":0,"approvers":"adminhyw"}
[0108] "action": 0 means approval, non-zero means approval rejection.
[0109] If the operation and maintenance instruction is an approval instruction (disconnecting the session), the MySQL Agent program in the bastion host constructs instruction approval request information, sends it to the operation and maintenance client system through the Python forwarding program for real-time approval, and waits for the approval result from the operation and maintenance client system; if the approval result is passed, the MySQL Agent program in the bastion host passes the operation and maintenance instruction to the MySQL server in the database server, the MySQL server executes the operation and maintenance instruction and returns the instruction execution result, the MySQL Agent program in the bastion host receives the instruction execution result and forwards it to the MySQL client in the client for display;
[0110] If the approval result is failure or approval times out, the MySQL Agent program in the bastion host blocks the forwarding of the operation and maintenance instruction, and constructs a data packet with a quit command according to the message format of the MySQL protocol from the MySQL client to the MySQL server. Then, the forged data packet with the quit command is used to replace the data packet containing the original operation and maintenance instruction, and forwarded to the MySQL server in the database server to disconnect the session connection with the MySQL server. Finally, the MySQL Agent program in the bastion host constructs a log message and forwards it to the Python forwarding program in the bastion host. After receiving and parsing the log message, the Python forwarding program in the bastion host writes it into the log database for storage.
[0111] If the operation and maintenance instruction is a pass-type instruction (that is, an instruction that does not belong to any of the above types), the MySQL Agent program in the bastion host forwards the operation and maintenance instruction to the MySQL server on the database server, waits for the execution result generated after the MySQL server executes the operation and maintenance instruction, and then forwards the execution result to the MySQL client in the client for display.
[0112] (10) When the maintenance operation on the database server is completed, the bastion host shuts down the MySQL Agent program and the monitoring forwarding program, establishes the maintenance end time information of the MySQL client, and sends the maintenance end time information to the bastion host.
[0113] Specifically, the bastion host is a Python forwarding program that sends the operation and maintenance end time information to the bastion host to record the time of the entire MySQL database operation and maintenance operation.
[0114] The JSON format of the operation and maintenance end time information is:
[0115] {"end_time":"2022-06-2322:25:17","conn_ip":"10.200.102.189","conn_port":"4006"}}
[0116] Experimental Results
[0117] This section tests the test environment required for the operation of the present invention. The detailed environment description is shown in Table 1:
[0118] Table 1
[0119]
[0120] For different high-risk instruction sets input by the client, the results of the bastion host's real-time review and blocking of high-risk database instructions are as follows:
[0121] Use the high-risk instruction set configured in step (4):
[0122] If you enter the alarm command: insert into c(id)values(1001);
[0123] The client displays:
[0124] Query OK,1row affected(0.01sec)
[0125] ###Alert command###
[0126] If you enter the disconnect session command: drop table d;
[0127] The session connection is disconnected
[0128] If the blocking instruction is entered: truncate table d;
[0129] The client displays blocking information:
[0130] ERROR 1141(HY000):Access denied foruser'root'
[0131] If you enter the approval instruction: delete table d;
[0132] Waiting for approval.
[0133] It will be easily understood by those skilled in the art that the above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the protection scope of the present invention.
Claims
1. A method for auditing high-risk instructions of a database of a bastion host, characterized in that: The following steps are involved: (1) The client configures a high-risk instruction set for operating and maintaining the database server and sends a connection request to the bastion host; (2) After receiving the connection request from the client, the bastion host allocates a listening port number to the client, sends the port number to the client, and starts the MySQL Agent program to listen for the connection request from the client. Step (2) includes the following sub-steps: (2-1) After the Python forwarding program in the bastion host listens to the connection request from the client, it establishes a connection with the monitoring forwarding program in the bastion host and forwards the connection request to the monitoring forwarding program; (2-2) After receiving the connection request, the monitoring forwarding program in the bastion host dynamically allocates a listening port number for the MySQL Agent program in the bastion host, sends the listening port number to the Python forwarding program in the bastion host, and starts a process to run the MySQL Agent program in the bastion host; (2-3) The MySQL Agent program in the bastion host starts to listen for connection requests from the MySQL client in the client; (3) The client sends a high-risk instruction set to the bastion host; (4) After receiving the high-risk instruction set from the client, the bastion host creates and saves the corresponding configuration file; (5) After receiving the MySQL login command entered by the user, the client initiates a connection request to the bastion host; (6) After listening to the connection request from the client, the bastion host establishes a connection with the database server; (7) The client enters operation and maintenance instructions to perform operation and maintenance operations on the database server through the bastion host; (8) The bastion host intercepts the operation and maintenance instructions input by the client and determines the type of the operation and maintenance instructions based on the configuration file established in step (4); the types of operation and maintenance instructions include alarm instructions, blocking instructions after timeout or rejection, session disconnection instructions after timeout or rejection, blocking instructions, and session disconnection instructions; (9) The bastion host performs corresponding operations on the operation and maintenance instruction according to the type of the operation and maintenance instruction determined in step (8); if the operation and maintenance instruction is an alarm-type instruction, step (9) is specifically as follows: the MySQL Agent program in the bastion host forwards the operation and maintenance instruction to the MySQL server in the database server, and the MySQL server executes the operation and maintenance instruction and returns the execution result to the MySQL Agent program in the bastion host; the MySQL Agent program in the bastion host intercepts the response result of the MySQL server in the database server, and adds an alarm message after the execution result, forwards the execution result with the added alarm message to the MySQL client in the client, and constructs log information at the same time, and writes it back to the Python forwarding program in the bastion host. Finally, after receiving and parsing the log information, the Python forwarding program in the bastion host writes it into the log database for storage; If the operation and maintenance instruction is a blocking instruction, step (9) is as follows: the MySQL Agent program in the bastion host directly blocks the forwarding operation of the operation and maintenance instruction, and then forges a warning message according to the MySQL protocol message format from the MySQL server to the MySQL client, and then forwards the forged warning message to the MySQL client for display, and at the same time constructs a log message and writes it back to the Python forwarding program in the bastion host. After receiving and parsing the log message, the Python forwarding program in the bastion host writes it into the log database for storage; (10) When the bastion host completes the maintenance operation on the database server, it shuts down the MySQL Agent program and the monitoring forwarding program, establishes the maintenance end time information of the MySQL client, and sends the maintenance end time information to the bastion host.
2. The method for auditing high-risk instructions of a database for a bastion host according to claim 1 is characterized in that: The client connects to the database server through the bastion host; The client includes the operation and maintenance client system and the MySQL client; The bastion host includes Python forwarding program, monitoring forwarding program, MySQL Agent program, and log database; A MySQL server is set on the database server.
3. The method for auditing high-risk instructions of a database for a bastion host according to claim 2 is characterized in that: Step (5) includes the following sub-steps: (5-1) The operation and maintenance client system in the client calls and opens the MySQL client; (5-2) After receiving the MySQL login command entered by the user, the MySQL client in the client initiates a connection request to the MySQL Agent program in the bastion host; Step (6) includes the following sub-steps: (6-1) After listening to the connection request from the client, the MySQL Agent program in the bastion host establishes a connection with the MySQL client in the client; (6-2) The MySQL Agent program in the bastion host establishes a connection with the operation and maintenance database server based on the connection request of the MySQL client in the client, so as to forward the instructions from the MySQL client and the response information of the database server.
4. The method for auditing high-risk instructions of a database for a bastion host according to claim 3 is characterized in that: If the operation and maintenance instruction is an instruction to disconnect the session after timeout or rejection, step (9) is specifically as follows: the MySQL Agent program in the bastion host constructs a data packet with a quit command according to the MySQL protocol message format from the MySQL client to the MySQL server, and then replaces the data packet containing the operation and maintenance instruction with a forged data packet with a quit command, and forwards it to the MySQL server in the database server, so that the MySQL client in the client disconnects the session connection with the MySQL server in the database server. Finally, a log message is constructed and written back to the Python forwarding program in the bastion host. After receiving and parsing the log message, the Python forwarding program in the bastion host writes it into the log database for storage.
5. The method for auditing high-risk instructions of a database for a bastion host according to claim 4 is characterized in that: If the operation and maintenance instruction is a timeout or rejection blocking instruction, step (9) is specifically as follows: if the operation and maintenance instruction is an approval instruction, the MySQL Agent program in the bastion host constructs instruction approval request information, sends it to the operation and maintenance client system through the Python forwarding program for real-time approval operation, and waits for the approval result from the operation and maintenance client system; if the approval result is passed, the MySQL Agent program in the bastion host forwards the operation and maintenance instruction to the MySQL server in the database server, and the MySQL server executes the operation and maintenance instruction and returns the instruction execution result. After receiving the instruction execution result, the MySQL Agent program in the bastion host forwards it to the MySQL client in the client for display; If the approval result is failure or approval timeout, the MySQL Agent program in the bastion host forwards the operation and maintenance instruction to the MySQL server. At the same time, the MySQL Agent program in the bastion host forges a warning message according to the MySQL protocol message format from the MySQL server to the MySQL client, and then forwards the forged warning message to the MySQL client in the client for display. At the same time, a log message is constructed and written back to the Python forwarding program in the bastion host. After receiving and parsing the log message, the Python forwarding program in the bastion host writes it into the log database for storage; If the operation and maintenance instruction is an instruction to disconnect the session after timeout or rejection, step (9) is specifically as follows: the MySQLAgent program in the bastion host constructs instruction approval request information, sends it to the operation and maintenance client system through the Python forwarding program for real-time approval operation, and waits to receive the approval result from the operation and maintenance client system; if the approval result is passed, the MySQL Agent program in the bastion host passes the operation and maintenance instruction to the MySQL server in the database server, the MySQL server executes the operation and maintenance instruction and returns the instruction execution result, the MySQL Agent program in the bastion host receives the instruction execution result and forwards it to the MySQL client in the client for display; If the approval result is failure or approval times out, the MySQL Agent program in the bastion host blocks the forwarding of the operation and maintenance instruction, and constructs a data packet with a quit command according to the message format of the MySQL protocol from the MySQL client to the MySQL server. Then, the forged data packet with the quit command is used to replace the data packet containing the original operation and maintenance instruction, and forwarded to the MySQL server in the database server to disconnect the session connection with the MySQL server. Finally, the MySQL Agent program in the bastion host constructs a log message and forwards it to the Python forwarding program in the bastion host. After receiving and parsing the log message, the Python forwarding program in the bastion host writes it into the log database for storage.
6. The method for auditing high-risk instructions of a database for a bastion host according to claim 5 is characterized in that: If the operation and maintenance instruction is a pass-type instruction, the MySQL Agent program in the bastion host forwards the operation and maintenance instruction to the MySQL server on the database server, waits for the execution result generated after the MySQL server executes the operation and maintenance instruction, and then forwards the execution result to the MySQL client in the client for display.
7. A database high-risk instruction review system for a bastion host, characterized in that: include: The first module is set in the client and is used to configure a high-risk instruction set for operating and maintaining the database server and send a connection request to the bastion host; The second module is set in the bastion host and is used to allocate a listening port number to the client after receiving a connection request from the client, send the port number to the client, and start the MySQL Agent program to listen for connection requests from the client; the second module includes the following submodules: The first submodule is used for the Python forwarding program in the bastion host to establish a connection with the monitoring forwarding program in the bastion host after monitoring the connection request from the client, and forward the connection request to the monitoring forwarding program; The second submodule is used for the monitoring forwarding program in the bastion host to dynamically allocate a listening port number for the MySQLAgent program of the bastion host after receiving a connection request, and send the listening port number to the Python forwarding program in the bastion host, and start a process to run the MySQL Agent program in the bastion host; The third submodule is used for the MySQL Agent program in the bastion host to start listening for connection requests from the MySQL client in the client; The third module is set in the client and is used to send a high-risk instruction set to the bastion host; The fourth module is set in the bastion host and is used to create and save the corresponding configuration file after receiving the high-risk instruction set from the client; The fifth module is set in the client and is used to initiate a connection request with the bastion host after receiving the MySQL login instruction input by the user; The sixth module is provided in the bastion host and is used to establish a connection with the database server after monitoring a connection request from a client; The seventh module is provided in the client and is used to input operation and maintenance instructions so as to perform operation and maintenance operations on the database server through the bastion host; The eighth module is set in the bastion host, and is used to intercept the operation and maintenance instructions input by the client, and determine the type of the operation and maintenance instructions according to the configuration file established by the fourth module; the types of operation and maintenance instructions include alarm instructions, blocking instructions after timeout or rejection, disconnection instructions after timeout or rejection, blocking instructions, and disconnection instructions; The ninth module is set in the bastion host, and is used to perform corresponding operations on the operation and maintenance instruction according to the type of the operation and maintenance instruction determined by the eighth module; if the operation and maintenance instruction is an alarm-type instruction, the ninth module is specifically: the MySQLAgent program in the bastion host forwards the operation and maintenance instruction to the MySQL server in the database server, and the MySQL server executes the operation and maintenance instruction and returns the execution result to the MySQL Agent program in the bastion host; the MySQL Agent program in the bastion host intercepts the response result of the MySQL server in the database server, and adds an alarm message after the execution result, forwards the execution result with the added alarm message to the MySQL client in the client, and constructs log information at the same time, and writes it back to the Python forwarding program in the bastion host, and finally the Python forwarding program in the bastion host writes the log information into the log database for storage after receiving and parsing the log information; If the operation and maintenance instruction is a blocking instruction, the ninth module is specifically as follows: the MySQL Agent program in the bastion host directly blocks the forwarding operation of the operation and maintenance instruction, and then forges a warning message according to the MySQL protocol message format from the MySQL server to the MySQL client, and then forwards the forged warning message to the MySQL client for display, and constructs a log message and writes it back to the Python forwarding program in the bastion host. After receiving and parsing the log information, the Python forwarding program in the bastion host writes it into the log database for storage; The tenth module is set in the bastion host and is used to close the MySQLAgent program and the monitoring forwarding program when the operation and maintenance operation of the database server is completed, establish the operation and maintenance end time information of the MySQL client, and send the operation and maintenance end time information to the bastion host.
