Detailed Description
It should be noted that, without conflict, the embodiments of the present application and features of the embodiments may be combined with each other. The application will be described in detail below with reference to the drawings in connection with embodiments.
It should be noted that the steps illustrated in the flowcharts of the figures may be performed in a computer system such as a set of computer executable instructions, and that although a logical order is illustrated in the flowcharts, in some cases the steps illustrated or described may be performed in an order other than that illustrated herein.
Database auditing, firewalls, and the like are referred to in the following embodiments, and technical terms in the following embodiments will be first described.
TCP protocol
The transmission control protocol (TransmissionControlProtocol, abbreviated TCP) is a connection-oriented, reliable, byte-stream based transport layer communication protocol defined by IETF RFC 793. TCP is intended to accommodate a layered protocol hierarchy that supports multiple network applications. Reliable communication services are provided by means of TCP between pairs of processes in host computers connected to different but interconnected computer communication networks. TCP assumes that it can obtain simple, possibly unreliable datagram services from lower level protocols. In principle, TCP should be able to operate over a variety of communication systems from hardwired to packet-switched or circuit-switched networks.
TCP connection
A TCP connection is a connection established at two communication ends using the TCP protocol, e.g., a client and a server may establish a TCP connection via the TCP protocol.
In a TCP connection there are a plurality of states, the following are meanings of the respective states:
CLOSED state (CLOSED): no connected state.
Listening state (LISTEN) LISTENs for connection requests from a remote TCP port.
And a synchronous packet transmission state (SYN-SENT) for retransmitting the connection request and waiting for a matched connection request (client).
And a synchronization packet receiving state (SYN-RCVD) for waiting for the confirmation of the connection request (server) by the opposite party after receiving and transmitting a connection request again.
The ESTABLISHED state (ESTABLISHED) represents an ESTABLISHED connection.
The following describes a state change in a connection in a TCP connection. Initially, both the server and the client are in a CLOSED state before the connection is established, and after the server starts to create a socket (socket), the server starts to monitor and changes to a list state. The client requests to establish a connection, sends a synchronization (synchronize, abbreviated as SYN) message to the server, and the state of the client changes to syn_send. After receiving the message from the client, the server sends an Acknowledgement (ACK) and a SYN message to the client, and the state of the server becomes syn_rcvd. Then, after receiving the ACK and SYN messages, the client sends an ACK to the server, the client state becomes ESTABLISHED, and the server also becomes ESTABLISHED after receiving the ACK from the client. At this time, the three-way handshake is completed and the connection is established.
The three-way handshake process may be as follows:
1. Firstly, a client sends a connection establishment request with syn=1 to a server, and seq is a data packet sequence number.
2. After the service end receives the data packet, the ACK is set to 1 to indicate that the data packet is received, and the ACK field is set to x+1 to indicate that the data packet with the sequence number x is received, so that the next data packet with the sequence number x+1 is expected to be received. Syn=1 is then sent, indicating a request to establish a connection (this ensures full duplex communication).
3. The client sends a message confirming receipt to the server, ack=1 represents the message in the process of confirming receipt of 2, and similarly, ACK is set to y+1, which means that the next data packet y+1 is expected to be received, and then the data packet x+1 expected to be sent by the server is sent.
Fig. 1 is a schematic diagram of a system for auditing a database with a firewall according to an embodiment of the present application, as shown in fig. 1, where the system may include a plurality of firewalls (two firewalls, namely, firewall 1 and firewall 2, are shown in fig. 1), the database access traffic may pass through a load balancing server, the load balancing server may send the database access traffic to the firewall 1 or firewall 2 according to the operation states of the firewall 1 and firewall 2, the firewall 1 and firewall 2 may send the database access traffic to the database on the one hand, and audit the database access traffic and the access results returned by the database on the other hand, that is, audit programs (not shown in fig. 1) are provided on the firewall 1 and firewall 2, and the access (including the database access traffic and the access results returned by the database) of the database is audited by the audit programs on the firewall 1 and firewall 2.
In fig. 1, due to the existence of the load balancing server, the database access traffic of the same session may be sent to the firewall 1 and the firewall 2 by the load balancing server, which may cause the audit result to be scattered on the firewall 1 and the firewall 2, so that the complete audit result cannot be obtained.
In order to solve the above-mentioned problems, in the following embodiments, a multi-firewall-based database auditing method is provided, and fig. 2 is a flowchart of the multi-firewall-based database auditing method according to an embodiment of the present application, as shown in fig. 2, and the steps included in the method referred to in fig. 2 are described below.
Step S202, each firewall in the plurality of firewalls sends session information of a session established through the firewall to other firewalls in the plurality of firewalls, wherein the session is established between a database client and a database through at least one of the plurality of protection walls, and each firewall is provided with an audit program used for auditing data packets interacted between the database client and the database.
In step S204, a first firewall receives a data packet interacted between the database client and the database, where the first firewall is one of the plurality of firewalls.
Step S206, the first firewall judges whether the session to which the data packet belongs is established through the first firewall, if so, the first firewall sends the data packet to an auditing program arranged on the first firewall for auditing.
Step S208, if not, the first firewall obtains a second firewall that establishes a session to which the data packet belongs, and sends the data packet to the second firewall, where the second firewall is one of the multiple firewalls.
Step S210, after receiving the data packet, the second firewall sends the data packet to an auditing program set on the second firewall for auditing.
In the above steps, each firewall records all sessions created by the firewall, so that each firewall can clearly know the firewall where the session to which a data packet belongs, and thus the data packet can be sent to the firewall where the session belongs, and the data packets of the same session can be ensured to be audited by the same firewall. The method solves the problem that the complete auditing result cannot be obtained because the flow accessing the database is scattered to different firewalls for auditing in the prior art, and can ensure the integrity of the auditing result of the database to a certain extent.
Fig. 3 is a schematic diagram of sending session information between firewalls according to an embodiment of the present application, where the system shown in fig. 3 is basically the same as that shown in fig. 1, and includes multiple firewalls, where the database access traffic passes through a load balancing server, and the load balancing server sends the database access traffic to the firewall 1 or the firewall 2 according to the operation states of the firewall 1 and the firewall 2, where the firewall 1 and the firewall 2 send the database access traffic to the database on one hand, and audit the database access traffic and the access results returned by the database on the other hand, that is, audit programs are provided on the firewall 1 and the firewall 2, and the database access is audited through the audit programs on the firewall 1 and the firewall 2. Unlike fig. 1, in fig. 3, information interaction is performed between the firewall 1 and the firewall 2, the firewall 1 transmits session information of a session established thereon to the firewall 2, and the firewall 2 transmits session information of a session established on the firewall to the firewall 1.
As an optional implementation manner, the load balancing server is connected with a plurality of firewalls, and when the load balancing server receives a first synchronous message for establishing a TCP connection from a database client, the load balancing server obtains loads of all auditing programs on the fireproof walls or the number of data packets for which the auditing programs on all the fireproof walls have completed auditing, the load balancing server selects a firewall where the auditing program with the smallest load is located or a firewall where the auditing program with the smallest number of auditing data packets has been completed, and the load balancing server sends the first synchronous message to the selected firewall.
And under the condition that the selected firewall receives the first synchronous message, judging whether the number of data packets which are not audited by an audit program on the firewall exceeds a threshold value, if so, forwarding the first synchronous message to the database, and if so, retransmitting the first synchronous message to the load balancing server by the selected firewall, and retransmitting the firewall by the load balancing server and transmitting the first synchronous message to the reselected firewall.
The session information may include a network address of the database client, a port number of the database client, a network address of the database, and a port number of the database. In this case, the connections established by different database clients with the same database belong to different sessions, as do the connections of the same database client with different databases. In an optional implementation manner, the first firewall judges whether the session to which the data packet belongs is established through the first firewall, wherein the first firewall searches session information recorded in the first firewall according to a source network address and a port number of the data packet and a destination network address and a port number, the session information comprises a network address of a database client, the port number of the database client, the network address of the database and the port number of the database, and if the first firewall can find session information matched with the source network address and the port number of the data packet and the destination network address and the port number, whether the session corresponding to the matched session information is established in the first firewall is judged.
And the second firewall can also distinguish whether the data packet comes from other firewalls or not, so that different processing is carried out, namely the second firewall judges whether the data packet comes from other firewalls or not, and after the second firewall determines that the data packet comes from other firewalls, the second firewall sends the data packet to an auditing program arranged on the second firewall for auditing.
As an optional implementation manner, if the second firewall determines that the data packet originates from another firewall, on one hand, the second firewall sends the data packet to an auditing program set on the second firewall for auditing, and on the other hand, the second firewall also obtains a source network address, a port number, a destination network address and a port number of the data packet, and sends the obtained network address and port number as session information to the other firewall, so as to instruct the other firewall that the session to which the data packet belongs is located in the second firewall.
And under the condition that the second firewall determines that the data packet originates from the database client or the database, the second firewall searches the session to which the data packet belongs in the locally recorded session information, and under the condition that the session to which the data packet belongs is established by the second firewall, the second firewall sends the data packet to an auditing program arranged on the second firewall for auditing.
After the data packet reaches the firewall, whether the data packet is a packet of the database protected by the firewall is judged, only the packet accessing the protected database enters the following processing flow, the packet not accessing the protected database is not accessed, and the firewall does not need to process the data packet and transfer the data packet.
In the case of two firewalls, the first firewall (i.e., firewall 1) receives a syn+ack packet (or called a message) for a session, since the received data packets are a SYN message and an ACK message, indicating that there is already a database client sending the first SYN packet to the database. In this case the first firewall records the sequence number (seq) and ACK information carried in the SYN message and ACK message. After the first firewall records the SYN message and the ACK message, the SYN message and the ACK message are transferred to the second firewall (namely, the firewall 2), the second firewall records the seq and the ACK information after receiving the SYN message and the ACK message, and the second firewall forwards the information to the first firewall (receives the SYNACK packet), and through the forwarding operation, the first firewall informs the second firewall that the session established through the SYN message and the ACK message is processed by the first firewall.
The first firewall receives a non-SYN request packet for a session and creates the session. At this time, if the first firewall has recorded the SYN packet and the ACK packet of the session, it is determined that the data packet of the session is processed by the first firewall, and then the non-SYN request packet is sent to a protocol analysis process (NPP), and the protocol analysis process directly transfers the data packet to an auditing program for auditing.
If the second firewall receives the response packet of the session, the second firewall also records that the session is processed by the first firewall, the response packet of the session is directly transferred to the first firewall, the first firewall judges that the session is established, the second firewall is put on the first firewall for auditing, and the response packet is transferred away according to the port record of the session after the auditing. If the first firewall does not create the session, the session is transferred back to the second firewall, the second firewall judges whether to process on the second firewall after receiving the response packet, if yes, the session is processed on the second firewall, and if not, the session is transferred to the other firewall for processing.
In an alternative embodiment, in order to prevent the data packet from being forwarded between the first firewall and the second firewall, at this time, after the first firewall receives the data packet sent by the second firewall, if the first firewall finds that the session corresponding to the data packet is not processed on the first firewall, the first firewall records the data packet, where the record is used to instruct the first firewall to forward the received data packet to the second firewall, if the first firewall receives the data packet again, the first firewall determines that the data packet has been forwarded to the second firewall once, the first firewall forwards the data packet to other firewalls except the second firewall, if the data packet has been forwarded to all firewalls, the first firewall audits the data packet, records session information corresponding to the data packet, and processes the data packet of the session in future by the first firewall.
By the embodiment, the session can be judged to be created by which firewall, and all data packets of the session are audited on the firewall when the session is created by which firewall. Thus, the database access flow of one session can be ensured to be audited on the same firewall.
In this embodiment, there is provided an electronic device including a memory in which a computer program is stored, and a processor configured to run the computer program to perform the method in the above embodiment.
The above-described programs may be run on a processor or may also be stored in memory (or referred to as computer-readable media), including both permanent and non-permanent, removable and non-removable media, and information storage may be implemented by any method or technique. The information may be computer readable instructions, data structures, modules of a program, or other data. Examples of storage media for a computer include, but are not limited to, phase change memory (PRAM), static Random Access Memory (SRAM), dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), read Only Memory (ROM), electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), digital Versatile Discs (DVD) or other optical storage, magnetic cassettes, magnetic tape disk storage or other magnetic storage devices, or any other non-transmission medium, which can be used to store information that can be accessed by a computing device.
These computer programs may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart block or blocks and/or block diagram block or blocks, and corresponding steps may be implemented in different modules.
Such an apparatus or system is provided in this embodiment. The device is called a multi-firewall-based database auditing device and is located in a first firewall, and comprises a sending module, a judging module and an auditing module, wherein the sending module is used for sending session information of a session established through the firewall to other firewalls in a plurality of firewalls, the session is established between a database client and a database through at least one of a plurality of protection walls, each firewall is provided with an auditing program, the auditing program is used for auditing data packets interacted between the database client and the database, the receiving module is used for receiving the data packets interacted between the database client and the database, the first firewall is one of the firewalls, the judging module is used for judging whether the session to which the data packets belong is established through the first firewall, if so, the first firewall sends the data packets to the auditing program arranged on the first firewall, if not, the second firewall is obtained, the data packets to which the data packets belong are established are sent to the second firewall, the second firewall is used for auditing the second firewall, and the second firewall is arranged after the second firewall receives the data packets.
The system or the device is used for realizing the functions of the method in the above embodiment, and each module in the system or the device corresponds to each step in the method, which has been described in the method, and will not be described herein.
Optionally, the judging module is configured to search for session information recorded in the first firewall according to the source network address and the port number and the destination network address and the port number of the data packet, where the session information includes the network address of the database client, the port number of the database client, the network address of the database, and the port number of the database, and if session information matched with the source network address and the port number and the destination network address and the port number of the data packet can be found, judge whether a session corresponding to the matched session information is established in the first firewall.
Optionally, the system further comprises a second judging module and a second sending module, wherein the second judging module and the second sending module are located in the second firewall, the second judging module is used for judging whether the data packet is sourced from other firewalls, and the second sending module is used for sending the data packet to an auditing program arranged on the second firewall for auditing after determining that the data packet is sourced from the other firewalls.
Optionally, the second sending module is configured to, when it is determined that the data packet originates from the database client or the database, search, by the second firewall, a session to which the data packet belongs in locally recorded session information, and when the session to which the data packet belongs is established by the second firewall, send, by the second firewall, the data packet to an audit program set on the second firewall for auditing.
The method and the device solve the problem that in the prior art, the flow accessing the database is scattered to different firewalls for auditing, so that a complete auditing result cannot be obtained, and the integrity of the auditing result of the database can be ensured to a certain extent.
The foregoing is merely exemplary of the present application and is not intended to limit the present application. Various modifications and variations of the present application will be apparent to those skilled in the art. Any modification, equivalent replacement, improvement, etc. which come within the spirit and principles of the application are to be included in the scope of the claims of the present application.