Firewall policy determination method and device, electronic equipment and storage medium
Automatically determine the host firewall policy through network information statistics program and eBPF probe, solving the problem of time-consuming and error-prone firewall policy setting in the existing technology, and achieving efficient and accurate firewall rule generation and service mutual access relationship collection to adapt to the network Environmental changes.
Patent Information
- Application Number
- CN202411130998.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-16
- Publication Date
- 2024-12-03
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
The existing host firewall policy settings rely on manual intervention, are time-consuming and error-prone, making it difficult to achieve real-time, efficient and accurate automatic generation of firewall rules, and cannot adapt to the rapid changes in the network environment.
The network information statistics program command is used to query the existing network connection information of the target host, and use the extended Berkeley packet filter eBPF probe to track new network connections. Based on the mapping relationship between the existing and new network connection information and the firewall rule elements, the white space is automatically determined based on the mapping relationship between the existing and new network connection information and the firewall rule elements. List firewall policies, build a business traffic baseline database and filter parameters to generate firewall rules.
The efficiency and accuracy of firewall policy settings are improved, and the dynamic tracking and static analysis methods have effectively improved the collection efficiency and accuracy of business mutual visit relationships, reduced the risk of human errors, and adapted to changes in the network environment.
Smart Images

Figure CN119071050A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a firewall policy determination method, device, electronic equipment and storage medium. Background Art
[0002] With the rapid development of information technology, the means of network attacks are becoming more and more innovative, and the security situation is becoming increasingly severe. In order to protect hosts in the network from malicious attacks, firewall technology is widely used. As the first line of defense for network security, host firewalls are of great significance in protecting hosts from network attacks.
[0003] In the existing technology, the setting of host firewall policies mainly relies on manual intervention, which is to manually configure firewall rules based on the experience of network administrators and network security requirements, as well as collecting and analyzing network connection information of each host. Manually setting firewall policies is time-consuming and prone to errors, resulting in low setting efficiency. Summary of the invention
[0004] The present invention provides a firewall policy determination method, device, electronic equipment and storage medium, which are used to improve the efficiency of firewall policy setting.
[0005] The present invention provides a firewall policy determination, comprising the following steps: Based on the network information statistics program command, query the established network connections in the target host, and determine the existing network connection information of the target host based on analyzing the established network connections; Based on the extended Berkeley Packet Filter (eBPF) probe, newly added network connections in the target host are tracked to obtain new network connection information in the target host; Based on the mapping relationship between the existing network connection information and the firewall rule elements, and the mapping relationship between the new network connection information and the firewall rule elements, a whitelist firewall policy for the target host is determined.
[0006] According to a firewall policy determination provided by the present invention, the whitelist firewall policy of the target host is determined based on the mapping relationship between the existing network connection information and the firewall rule elements, and the mapping relationship between the new network connection information and the firewall rule elements, including: Building a service flow baseline database of the target host based on the parameter information in the existing network connection information and the parameter information in the new network connection information; Setting a firewall policy for each parameter in the service traffic baseline database based on the received firewall setting rules for each parameter in the service traffic baseline database; Based on the firewall policies of the various parameters, a whitelist firewall policy for the target host is determined.
[0007] According to a firewall policy determination provided by the present invention, after building the service flow baseline database of the target host, the method further includes: Based on a pre-built blacklist library and a pre-built whitelist library, each parameter in the service traffic baseline database is screened to obtain a screened service traffic baseline database; The blacklist library is determined based on pre-statisticed abnormal IP address information and abnormal port information, and the whitelist library is determined based on pre-statisticed inbound library information and outbound library information.
[0008] According to a firewall policy determination provided by the present invention, the screening of each parameter in the service traffic baseline database based on a pre-built blacklist library and a pre-built whitelist library includes: Compare each parameter in the service flow baseline database with each parameter in the blacklist database, and delete the parameters in the service flow baseline database that match after comparison; The parameters in the service traffic baseline database are compared with the parameters in the whitelist database, and the parameters in the service traffic baseline database are screened based on whether the matched parameter values in the service traffic baseline database are normal.
[0009] According to a firewall policy determination provided by the present invention, the extended Berkeley packet filter eBPF probe is used to track the newly added network connection in the target host and obtain the new network connection information in the target host, including: Based on the eBPF probe, track the outbound network connections generated by the target protocol in the target host and the inbound network connections generated by the target protocol, wherein the target protocol includes the TCP protocol and the UDP protocol; Based on the outbound network connection and the inbound network connection, a newly added network connection in the target host is determined, and new network connection information of the newly added network connection is obtained.
[0010] According to a firewall policy determination provided by the present invention, the obtaining of new network connection information of the newly added network connection includes: Acquire the five-tuple information of the newly added network connection and the data packet flow direction information of the newly added network connection, and use the five-tuple information and the data packet flow direction information as the new network connection information.
[0011] The present invention also provides a firewall policy determination device, comprising the following modules: The existing network connection information determination module is used to query the established network connections in the target host based on the network information statistics program command, and determine the existing network connection information of the target host based on the analysis of the established network connections; A new network connection information determination module, used to track the newly added network connection in the target host based on an extended Berkeley Packet Filter eBPF probe, and obtain the new network connection information in the target host; A policy determination module is used to determine the whitelist firewall policy of the target host based on the mapping relationship between the existing network connection information and the firewall rule elements, and the mapping relationship between the new network connection information and the firewall rule elements.
[0012] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, any of the above-mentioned methods for determining a firewall policy is implemented.
[0013] The present invention also provides a non-transitory computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the method for determining a firewall policy as described above is implemented.
[0014] The present invention also provides a computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the firewall policy determination method described above is implemented.
[0015] The firewall policy determination method, device, electronic device and storage medium provided by the present invention determine the existing network connection information of the target host through the network information statistics program command. Based on the eBPF probe, the new network connection information in the target host is determined. Based on the mapping relationship between the acquired existing network connection information and the new network connection information and the firewall rule elements, the firewall policy determination process is automatically implemented, thereby improving the efficiency of firewall policy setting. At the same time, the method based on dynamic tracking and static analysis effectively improves the efficiency and accuracy of the collection of business mutual access relationships in the target host environment. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0017] Figure 1 It is a flow chart of the firewall policy determination method provided by the present invention.
[0018] Figure 2 It is a schematic diagram of the eBPF loading process provided by the present invention.
[0019] Figure 3 It is a schematic diagram of the custom firewall rule interface provided by the present invention.
[0020] Figure 4 It is a schematic diagram of a new network connection collection process provided by the present invention.
[0021] Figure 5 It is a schematic diagram of the structure of a device applying the firewall policy determination method provided by the present invention.
[0022] Figure 6 It is a structural diagram of the firewall policy determination device provided by the present invention.
[0023] Figure 7 It is a structural schematic diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION
[0024] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0025] With the rapid development of information technology, the means of network attacks are becoming more and more innovative, and the security situation is becoming increasingly severe. In order to protect hosts in the network from malicious attacks, firewall technology is widely used. As the first line of defense for network security, host firewalls are of great significance in protecting hosts from network attacks.
[0026] In the related methods, the generation of firewall rules is mainly achieved through the following two technical solutions: One of the related methods is to manually configure firewall rules based on the experience of network administrators and network security requirements. This method is time-consuming and labor-intensive, prone to errors, and difficult to adapt to changes in the network environment.
[0027] The second related method is to use the network information statistics program command netstat to collect network connection information of each host, and generate firewall rules by analyzing this information. However, the netstat collection method cannot collect in real time, is prone to omissions and has high consumption, resulting in low accuracy of the generated firewall rules. Both of the above methods have defects.
[0028] Specifically, in the related methods, the setting of host firewall policies mainly relies on manual intervention, which manually configures firewall rules based on the experience of network administrators and network security requirements, as well as collecting network connection information of each host and analyzing this information. However, in actual applications, this method has many shortcomings and cannot achieve the ability to automatically generate firewall rules in real time, efficiently and accurately.
[0029] First, manually setting firewall policies is time-consuming and error-prone. In a large network, there may be thousands of hosts, each with its own network connections and firewall rules. Manually setting firewall policies for each host requires a lot of time and effort, and it is easy to cause omissions and errors in policies due to human error.
[0030] Secondly, the flexibility and scalability of manually setting firewall policies are poor. With the continuous changes in the network environment and the continuous upgrading of security requirements, firewall policies need to be constantly adjusted and optimized. Manual settings are difficult to cope with a large number of changes and are prone to lag in firewall policies.
[0031] The solutions of related methods have obvious shortcomings and cannot achieve real-time, efficient and accurate automatic generation of firewall policies.
[0032] In view of the defects in the related methods, the present invention provides a firewall policy determination method. Figure 1 FIG. 1 is a flow chart of the firewall policy determination method provided by the present invention. Figure 1 As shown, the method includes the following: Step 110, based on the network information statistics program command, query the established network connections in the target host, and determine the existing network connection information of the target host based on analyzing the established network connections; Step 120, based on the extended Berkeley Packet Filter eBPF probe, tracking the newly added network connection in the target host to obtain the new network connection information in the target host; Step 130: Determine the whitelist firewall policy of the target host based on the mapping relationship between the existing network connection information and the firewall rule elements, and the mapping relationship between the new network connection information and the firewall rule elements.
[0033] The execution subject of the firewall policy determination method provided by the present invention can be an electronic device, a component in an electronic device, an integrated circuit, or a chip. The electronic device can be a mobile electronic device or a non-mobile electronic device. Exemplarily, the mobile electronic device can be a mobile phone, a tablet computer, a laptop computer, a PDA, an ultra-mobile personal computer (UMPC), a netbook, or a personal digital assistant (PDA), etc., and the non-mobile electronic device can be a server, a network attached storage (NAS), or a personal computer (PC), etc., which is not specifically limited by the present invention.
[0034] The following takes the method for determining the firewall policy provided by the present invention executed by a computer as an example to describe the technical solution of the present invention in detail.
[0035] In step 110, based on the network information statistics program command, the established network connections in the target host are queried, and based on the analysis of the established network connections, the stock network connection information of the target host is determined.
[0036] Specifically, the network information statistics program command may be a netstat command. The netstat command is a network tool widely used in various operating systems, and is used to display information such as network connections, routing tables, interface statistics, masquerading connections, and multicast membership. Based on the netstat command, established network connections in the target host may be collected.
[0037] After determining the established network connection in the target host, the established network connection in the target host is analyzed, the network connection information of the established network connection is determined, and the existing network connection information of the target host is obtained. The existing network connection information may be TCP connection information, UDP connection information, local address information, remote address information, status information, receiving queue information, etc.
[0038] Optionally, the process of determining the existing network connection information can be: using the netstat command to collect and analyze the existing network connection information, including TCP monitoring, UDP monitoring, and established network connection information. First, by using the netstat -tnlp command, the system can obtain all TCP monitoring information of the current target host, which helps to determine whether the established TCP connection is inbound or outbound. Secondly, using the netstat -unlp command, all UDP monitoring information in the target host can be collected to facilitate the determination of whether the existing UDP connection is inbound or outbound. In addition, the netstat -an command can be used to collect established network connection information, including detailed data such as the local address, remote address, protocol type, and connection status of the connection. By analyzing this information, the status of the existing network connections can be fully understood, providing a data source for further formulating firewall rules.
[0039] In step 120, based on the extended Berkeley Packet Filter (eBPF) probe, the newly added network connection in the target host is tracked to obtain the new network connection information in the target host.
[0040] Extended Berkeley Packet Filter (eBPF) is a powerful virtual machine technology that provides a mechanism for executing custom code in the kernel. It uses some extension points (also called probes) in the Linux kernel. The extension points can be system calls, network packet processing, memory access and other events. It can be used to write secure and efficient network filters and system tracing tools to meet specific needs.
[0041] Using the characteristics of net_csk_accep, tcp_v4_connect, udp_recvms, and udp_sendmsg functions that will be called during the process of establishing a new network connection, the corresponding function call entry is hooked to track the process of establishing a new network connection and obtain new network connection information in real time. The processing flow is as follows: Figure 2 As shown in the schematic diagram of the eBPF loading process provided by the present invention, the process is divided into source code precompilation, probe loading, and event association, which are described as follows: Source code precompilation: Use a preset compiler such as clang / LLVM to compile the eBPF program source code (also called eBPF probe) into eBPF bytecode (binary code that can be executed on the eBPF virtual machine); Probe loading: By calling the eBPF system, the eBPF bytecode is verified for legitimacy, and after passing the verification, it is loaded into the eBPF virtual machine in the kernel; Event association: If the eBPF bytecode passes the validity check and is successfully loaded, the new network connection establishment process in the Linux system will call inet_csk_accept (TCP inbound), tcp_v4_connect (TCP outbound), udp_recvmsg (UDP inbound), and udp_sendmsg (UDP outbound) functions according to the protocol type (TCP, UDP) and inbound and outbound traffic, and the corresponding function call entry is hooked through eBPF in the form of kprobe and kretprobe probes to form a hook to execute the eBPF bytecode when the network connection establishment event is triggered, and obtain the five-tuple information (protocol type, original IP, original port, destination IP, destination port) and data packet flow direction (outbound or inbound) and other key information in the new network connection establishment process. The obtained five-tuple information of the network connection and the key information such as the data packet flow direction are used as the new network connection information in the target host.
[0042] In step 130, based on the mapping relationship between the existing network connection information and the firewall rule elements, and the mapping relationship between the new network connection information and the firewall rule elements, a whitelist firewall policy of the target host is determined.
[0043] Firewall rule elements are the basic units that make up a firewall policy, and together they define which network traffic is allowed or denied through the firewall. These elements typically include: Source address: The source address of the data packet.
[0044] Destination address: The destination address of the data packet, that is, the IP address of the target host.
[0045] Port: The destination port of the data packet, used to distinguish different network services.
[0046] Protocol: The network protocol used by the data packet, such as TCP, UDP, etc.
[0047] Action: The action performed on packets matching the rule, such as allow, deny, or drop.
[0048] Network connection information refers to the current network activity status of the target host, including established network connections, monitored service ports, and the source and destination of network traffic. Firewall rule elements are the basic units that constitute firewall policies and are used to define which network traffic is allowed or denied to pass through the firewall. These elements usually include source address, destination address, port, protocol, and operation.
[0049] The mapping relationship between network connection information and firewall rule elements refers to matching the various parameters in the network connection information (such as source IP, destination IP, port, protocol, etc.) with the corresponding elements in the firewall rules to determine whether the network traffic is allowed to pass through the firewall.
[0050] Formulating a whitelist firewall policy based on the mapping relationship between the network connection information in the target host and the firewall rule elements can effectively improve the network security protection capabilities of the target host. Specifically, by clearly specifying the allowed source address, port and protocol combinations and rejecting other unauthorized access requests, the risk of network attacks is reduced.
[0051] Optionally, firewall policies for target hosts can be added based on user input. A convenient web page can be provided on the front end to allow users to customize firewall rules as needed, so that they can quickly respond to emergencies when needed, and as a supplement to automatically generated policies. Users can define firewall rules in the following ways: set policy name, action (deny or allow), priority (low, medium, high), packet flow direction (inbound or outbound), protocol (TCP, UDP, TCP+UDP), local port, remote IP, remote port, and description information. The specific web interface is as follows Figure 3 The schematic diagram of the custom firewall rule interface provided by the present invention is shown in FIG.
[0052] The firewall policy determination method provided by the present invention determines the existing network connection information of the target host through the network information statistics program command. Based on the eBPF probe, the new network connection information in the target host is determined. Based on the mapping relationship between the acquired existing network connection information and the new network connection information and the firewall rule elements, the automatic determination process of the firewall policy is realized, thereby improving the efficiency of the firewall policy setting. At the same time, the method based on dynamic tracking and static analysis effectively improves the efficiency and accuracy of the collection of business mutual access relationships in the target host environment.
[0053] In one embodiment, based on the mapping relationship between the existing network connection information and the firewall rule elements, and the mapping relationship between the new network connection information and the firewall rule elements, the whitelist firewall policy of the target host is determined, including: based on the parameter information in the existing network connection information and the parameter information in the new network connection information, constructing a business traffic baseline database for the target host; based on the received firewall setting rules for each parameter in the business traffic baseline database, setting a firewall policy for each parameter in the business traffic baseline database; based on the firewall policy for each parameter, determining the whitelist firewall policy of the target host.
[0054] Parameter information in the new network connection information and the existing network connection information is extracted to construct a service flow baseline database. The specific field table of the constructed service flow baseline database can be shown in Table 1, which is a field table of the service flow baseline database provided by the present invention.
[0055] Table 1 Field table of business traffic baseline database
[0056] Based on the received firewall setting rules of each parameter in the service traffic baseline database, a firewall policy is set for each parameter in the service traffic baseline database, which may be: Convert the connection data in the service traffic baseline database table into firewall rules. Each inbound and outbound rule consists of the following elements: protocol, source IP and port (source_ip and source_port), destination IP and port (destination_ip and destination_port), and action.
[0057] For incoming TCP and UDP connections, the remote port is randomly generated by the system and has no practical meaning. This parameter can be ignored. Therefore, the construction format of the inbound rule string is as follows: iptables -A INTPUT -p protocol -s<source_ip> --sport<source_port> -d<destination_ip> -j action
[0058] For outgoing TCP and UDP connections, the local port is randomly generated by the system and has no practical meaning. This parameter can be ignored. The construction format of the outbound rule string is similar to that of the inbound rule, but it is applied to the OUTPUT chain to process outgoing packets. Therefore, the construction format of the outbound rule string is as follows: iptables -A OUTPUT -p protocol -s<source_ip> -d<destination_ip> --dport<destination_port> -j action; The meaning of the parameters are as follows: -A chain: Add the rule to the INTPUT or OUTPUT chain, which processes incoming or outgoing packets.
[0059] -p protocol: specifies the protocol type, which can be TCP or UDP.
[0060] -s<source_ip> : Specifies the source IP address.
[0061] --sport<source_port> : Specifies the source port number.
[0062] -d<destination_ip> : Specify the target IP address.
[0063] --dport<destination_port> : Specifies the destination port number.
[0064] -j action: Specifies the action to be performed when the rule is matched, such as accept (ACCEPT) or reject (DROP).
[0065] By using placeholders to represent different fields in the database table, specific firewall rules can be generated based on the mapping relationship. The chain placeholder corresponds to the "data flow direction" field of the existing connection database table, and the protocol placeholder corresponds to the "protocol".<source_ip> The placeholder corresponds to "source IP",<source_port> Placeholders correspond to "source port",<destination_ip> The placeholder corresponds to "Destination IP",<destination_port> The placeholder corresponds to the "destination port" and the action placeholder corresponds to the "action". The "local IP and status value is normal" in the business traffic baseline database table is used as the screening condition for traversal. A rule is generated for each row according to the mapping relationship. Finally, a policy is added to deny all inbound and outbound traffic by default. This goal is achieved by adding the command iptables -A INPUT -j DROP; iptables -A OUTPUT -j DROP, and it will be saved in a file named after the local IP. Such a setting will effectively prevent data without explicit permission from entering or leaving the system.
[0066] When dealing with network changes after the business traffic baseline, such as cluster expansion, business adjustments, or IP address changes, every time a new network connection request is initiated, it will be compared with the entries in the whitelist library. If the new connection matches an entry in the whitelist library, the system will automatically generate a corresponding whitelist policy. If the new connection does not match any entry in the whitelist library, the system will generate a policy review ticket, which will be submitted to the security management team for manual review. By automatically generating whitelist policies or generating policy review tickets, enterprises can efficiently handle network changes after the business traffic baseline.
[0067] In one embodiment, after constructing the service traffic baseline database of the target host, it also includes: based on a pre-constructed blacklist library and a pre-constructed whitelist library, filtering each parameter in the service traffic baseline database to obtain a filtered service traffic baseline database; the blacklist library is determined based on pre-statisticed abnormal IP address information and abnormal port information, and the whitelist library is determined based on pre-statisticed inbound library information and outbound library information.
[0068] After the service traffic baseline database is constructed, each parameter in the service traffic baseline database is screened based on the constructed blacklist library and the pre-constructed whitelist library.
[0069] The blacklist library is used to store known malicious IP addresses and ports. The timeliness and accuracy of the blacklist can be ensured through regular updates. Its information sources include public intelligence sources (such as network security forums, company announcements, security organizations, etc.), industry shared databases, security agencies, internal threat intelligence, third-party services and tools, as well as user communities and forums, etc., which are used to screen abnormal traffic in business traffic. The whitelist library includes an inbound library and an outbound library. The inbound library is established through the source IP, source port, destination IP in the business traffic baseline library and the declaration on the tenant side; the outbound library is established through the source IP, destination IP, destination port in the business traffic baseline library and the declaration on the tenant side.
[0070] In one embodiment, based on a pre-built blacklist library and a pre-built whitelist library, each parameter in the business traffic baseline database is screened, including: comparing each parameter in the business traffic baseline database with each parameter in the blacklist library, and deleting the parameters in the business traffic baseline database that match after comparison; comparing each parameter in the business traffic baseline database with each parameter in the whitelist library, and screening each parameter in the business traffic baseline database based on whether the values of the parameters matched after comparison in the business traffic baseline database are normal.
[0071] The blacklist database usually contains parameters such as known malicious IP addresses, port numbers, and protocol types, which are associated with known network attacks, malware activities, or unauthorized network access. Compare each parameter in the service traffic baseline database (such as source address, destination address, port number, protocol type, etc.) with the parameters in the blacklist database one by one. If any matches are found, it means that some parameters in the service traffic baseline database may be associated with malicious activities.
[0072] All parameters that match the blacklist should be deleted from the service traffic baseline database to prevent these potential risk factors from being mistaken for normal service traffic, thereby increasing the risk of the target host being attacked.
[0073] The whitelist contains explicitly authorized or approved parameter combinations that correspond to legitimate business traffic of the target host. For parameters that match the whitelist, if their values are within the normal range, they are retained in the business traffic baseline database.
[0074] In one embodiment, based on the eBPF probe, the newly added network connection in the target host is tracked to obtain the new network connection information in the target host, including: based on the eBPF probe, tracking the outbound network connection generated by the target protocol in the target host and the inbound network connection generated by the target protocol, the target protocol including the TCP protocol and the UDP protocol; based on the outbound network connection and the inbound network connection, determining the newly added network connection in the target host, and obtaining the new network connection information of the newly added network connection.
[0075] Among them, obtaining the new network connection information of the newly added network connection includes: obtaining the quintuple information of the newly added network connection and the data packet flow direction information of the newly added network connection, and using the quintuple information and the data packet flow direction information as the new network connection information.
[0076] Specifically, the probe can be used to track the establishment of new network connections and collect five-tuple information (protocol type, original IP, original port, destination IP, destination port) and packet flow (outbound or inbound), and write the information on obtaining new network connections into the eBPF maps buffer. Finally, the data is read from the kernel state to the user area. At this time, the collection module can read the latest information on new network connections from the user buffer, which is the basis for achieving real-time adaptability to dynamically changing network environments. Therefore, the new network connection information collection and processing process is divided into four steps: eBPF collects data, writes data into the kernel buffer, sends data to the user area, and the collection process obtains data. The specific steps are as follows: Figure 4 The new network connection collection process provided by the present invention is shown in the schematic diagram.
[0077] The four steps are explained as follows: eBPF collection: When a new network connection is established, an interrupt will be triggered, and the associated eBPF program in the kernel will be triggered to execute. Different functions will be associated to handle the event according to the protocol type (TCP, UDP) and data flow (inbound and outbound). There are four types of situations: (1) When the network connection is TCP inbound, the associated eBPF program in the kernel can obtain various data about the new network connection, such as five-tuple information (protocol type, original IP, original port, destination IP, destination port) and data flow direction by accessing the return value variable of the inet_csk_accept function. (2) When the network connection is TCP outbound, the associated eBPF program in the kernel can obtain various data about the new network connection, such as five-tuple information (protocol type, original IP, original port, destination IP, destination port) and data flow direction by accessing the first parameter (arg0) of the tcp_v4_connect function. (3) When the network connection is UDP inbound, the associated eBPF program in the kernel can obtain various data about the new network connection, such as five-tuple information (protocol type, original IP, original port, destination IP, destination port) and data flow direction by accessing the first parameter (arg0) of the udp_recvmsg function. (4) When the network connection is UDP outbound, the associated eBPF program in the kernel By accessing the first parameter (arg0) of the udp_sendmsg function, the program can obtain various data about the new network connection, such as five-tuple information (protocol type, source IP, source port, destination IP, destination port) and data flow information.
[0078] Data is written to the kernel buffer: The eBPF program writes the collected data to the eBPF Map buffer in the kernel through the bpf_map_lookup_elem() function and waits for processing.
[0079] Data is sent to the userland: The eBPF program reads the new connection data from the kernel state to the userland through the bpf_perf_event_output() function for further data processing.
[0080] The collection process obtains data: The collection process reads new network connection information including five-tuple information (protocol type, source IP, source port, destination IP, destination port) and data flow direction from the user area for analysis and processing by the subsequent data processing module.
[0081] The present invention also provides a schematic diagram of the structure of a device using the firewall policy determination method provided by the present invention, such as Figure 5 As shown, the device includes: an existing connection collection module, a blacklist library and a whitelist library collection module, a kernel probe loading module, a five-tuple collection module, a data processing module, a rule generation module, a custom rule module and a policy application module.
[0082] The workflow is as follows: first, the stock collection module collects existing network connection information through netstat; the blacklist library and whitelist library collection module establishes and maintains the local blacklist library by regularly synchronizing multi-source blacklists (public intelligence, industry sharing, institutions, internal intelligence, etc.) to filter malicious traffic in the business baseline library; the whitelist library is established through the business traffic baseline library and tenant declarations, and is used to subsequently evaluate whether network changes (such as cluster expansion, business adjustment or IP address change, etc.) belong to normal business traffic; the kernel probe loading module inserts kretprobe and kprobe probes on the server side to obtain the association and monitoring of events generated by the establishment of new network connections, so as to facilitate the real-time capture of new network connections; after the kretprobe and kprobe probes injected into the kernel by the five-tuple collection module are generated, they sense and obtain the five-tuple and other related information of the network connection, transmit them from the kernel state to the user space, and then send them to the data processing module by the collection module; after receiving the new network connection information sent by the collection module, the data processing module will perform the following operations: first, it will compare this new information with the previously collected business traffic benchmark data. If no match is found, the module will then check the information with the blacklist database. If a match is found in the blacklist database, the module will mark the status as abnormal; if no match is found, the default status is normal. Regardless of the status, this new network connection information will be added to the business traffic benchmark database with the status item. If the information finds a match in the initial benchmark data comparison, the information will be discarded; then the business traffic baseline (except for abnormal status values) information is sent to the rule generation module, and the firewall rule script is generated based on the protocol type, action, and packet flow (inbound or outbound). Finally, the rule script is passed to the policy application module to be distributed to each host to take effect and complete the distribution; the custom rule module provides a convenient Web page for users to customize firewall rules on demand so that they can quickly respond to emergencies when needed, and at the same time serve as a supplement to the automatically generated strategy.
[0083] It is understandable that the introduction of eBPF technology and full use of existing host firewall functions have enabled real-time, efficient and accurate drawing of business traffic baselines in a massive host environment.
[0084] Real-time, efficient and accurate drawing of business traffic baselines (data flow direction can be distinguished): Inject ebpf into the host kernel program to collect new outbound and inbound network connections generated by TCP and UDP in real time, and combine the netstat command to collect existing network connection information at one time, automatically learn the actual traffic that has occurred, use monitoring arrays and specific functions to distinguish different types of traffic (inbound and outbound), and use blacklist libraries to detect and mark abnormal traffic, and then aggregate and count to establish business group mutual access relationships. After a period of adaptive learning, the business traffic baseline is automatically established.
[0085] Automatic generation and adaptive adjustment of firewall whitelist policies: After an adaptive learning cycle, whitelist firewall policies are automatically generated based on the mapping relationship between the service flow baseline and the firewall rule elements. For network changes after the service flow baseline, such as cluster expansion, service adjustment, or IP address change, the device will automatically evaluate whether these changes belong to normal service flow through the whitelist library, and automatically adjust the firewall policy accordingly.
[0086] Specifically, the collection of business mutual access relations includes new network connections and existing network connections. For new network connections, the generation of new network connections is tracked in the kernel program by using ebpf technology, and different functions are hooked to distinguish the flow direction of data packets (inbound or outbound) and collect network connection information to ensure that new network connections are not missed; for existing network connections, the netstat command is used for collection at one time, and the data flow direction is efficiently distinguished by comparing the local address (including port) with the listening address array, whether it is inbound or outbound. This method of dynamic tracking and static analysis effectively improves the efficiency and accuracy of collecting business mutual access relations in a massive host environment.
[0087] After a period of adaptive business interaction relationship learning, the business traffic baseline is automatically established, and then the whitelist firewall policy is automatically generated based on the mapping relationship between the business traffic baseline and the firewall rule elements. This method can significantly save time and human resources, reduce the risk of human error, and thus improve production efficiency and accuracy.
[0088] For network changes after the service traffic baseline, such as cluster expansion, service adjustment, or IP address change, the device will automatically evaluate whether these changes belong to normal service traffic through the whitelist library, and automatically adjust the firewall policy accordingly.
[0089] The firewall policy determination device provided by the present invention is described below. The firewall policy determination device described below and the firewall policy determination method described above can be referenced to each other.
[0090] like Figure 6 As shown, the device comprises: The existing network connection information determination module 610 is used to query the established network connections in the target host based on the network information statistics program command, and determine the existing network connection information of the target host based on analyzing the established network connections; A new network connection information determination module 620 is used to track the newly added network connection in the target host based on an extended Berkeley Packet Filter (eBPF) probe to obtain the new network connection information in the target host; The policy determination module 630 is used to determine the whitelist firewall policy of the target host based on the mapping relationship between the existing network connection information and the firewall rule elements, and the mapping relationship between the new network connection information and the firewall rule elements.
[0091] The firewall policy determination device provided by the present invention determines the existing network connection information of the target host through the network information statistics program command. Based on the eBPF probe, the new network connection information in the target host is determined. Based on the mapping relationship between the acquired existing network connection information and the new network connection information and the firewall rule elements, the automatic determination process of the firewall policy is realized, thereby improving the efficiency of the firewall policy setting. At the same time, the method based on dynamic tracking and static analysis effectively improves the efficiency and accuracy of the collection of business mutual access relationships in the target host environment.
[0092] In one embodiment, the policy determination module 630 is specifically configured to: Based on the mapping relationship between the existing network connection information and the firewall rule elements, and the mapping relationship between the new network connection information and the firewall rule elements, determining the whitelist firewall policy of the target host includes: Building a service flow baseline database of the target host based on the parameter information in the existing network connection information and the parameter information in the new network connection information; Setting a firewall policy for each parameter in the service traffic baseline database based on the received firewall setting rules for each parameter in the service traffic baseline database; Based on the firewall policies of the various parameters, a whitelist firewall policy for the target host is determined.
[0093] In one embodiment, the policy determination module 630 is further specifically configured to: After building the service flow baseline database of the target host, it also includes: Based on a pre-built blacklist library and a pre-built whitelist library, each parameter in the service traffic baseline database is screened to obtain a screened service traffic baseline database; The blacklist library is determined based on pre-statisticed abnormal IP address information and abnormal port information, and the whitelist library is determined based on pre-statisticed inbound library information and outbound library information.
[0094] In one embodiment, the policy determination module 630 is further specifically configured to: Based on the pre-built blacklist library and the pre-built whitelist library, each parameter in the service traffic baseline database is screened, including: Compare each parameter in the service flow baseline database with each parameter in the blacklist database, and delete the parameters in the service flow baseline database that match after comparison; The parameters in the service traffic baseline database are compared with the parameters in the whitelist database, and the parameters in the service traffic baseline database are screened based on whether the matched parameter values in the service traffic baseline database are normal.
[0095] In one embodiment, the new network connection information determination module 620 is specifically used to: Based on the extended Berkeley Packet Filter eBPF probe, the newly added network connection in the target host is tracked to obtain the new network connection information in the target host, including: Based on the eBPF probe, track the outbound network connections generated by the target protocol in the target host and the inbound network connections generated by the target protocol, wherein the target protocol includes the TCP protocol and the UDP protocol; Based on the outbound network connection and the inbound network connection, a newly added network connection in the target host is determined, and new network connection information of the newly added network connection is obtained.
[0096] In one embodiment, the new network connection information determination module 620 is further specifically configured to: Obtaining new network connection information of the newly added network connection includes: Acquire the five-tuple information of the newly added network connection and the data packet flow direction information of the newly added network connection, and use the five-tuple information and the data packet flow direction information as the new network connection information.
[0097] Figure 7 An example of a physical structure diagram of an electronic device is shown in FIG. Figure 7As shown, the electronic device may include: a processor 710, a communications interface 720, a memory 730 and a communication bus 740, wherein the processor 710, the communications interface 720 and the memory 730 communicate with each other through the communication bus 740. The processor 710 may call the logic instructions in the memory 730 to execute the firewall policy determination method, which includes: based on the network information statistics program command, querying the established network connection in the target host, and determining the stock network connection information of the target host based on analyzing the established network connection; Based on the extended Berkeley Packet Filter (eBPF) probe, newly added network connections in the target host are tracked to obtain new network connection information in the target host; Based on the mapping relationship between the existing network connection information and the firewall rule elements, and the mapping relationship between the new network connection information and the firewall rule elements, a whitelist firewall policy for the target host is determined.
[0098] In addition, the logic instructions in the above-mentioned memory 730 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on this understanding, the technical solution of the present invention can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium, including several instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc. Various media that can store program codes.
[0099] On the other hand, the present invention further provides a computer program product, the computer program product includes a computer program, the computer program can be stored on a non-transitory computer-readable storage medium, when the computer program is executed by a processor, the computer can execute the firewall policy determination method provided by the above methods, the method comprising: based on a network information statistics program command, querying the established network connection in the target host, and based on analyzing the established network connection, determining the stock network connection information of the target host; Based on the extended Berkeley Packet Filter (eBPF) probe, newly added network connections in the target host are tracked to obtain new network connection information in the target host; Based on the mapping relationship between the existing network connection information and the firewall rule elements, and the mapping relationship between the new network connection information and the firewall rule elements, a whitelist firewall policy for the target host is determined.
[0100] In another aspect, the present invention further provides a non-transitory computer-readable storage medium having a computer program stored thereon, which is implemented when the computer program is executed by a processor to execute the firewall policy determination method provided by the above methods, the method comprising: querying the established network connections in the target host based on the network information statistics program command, and determining the stock network connection information of the target host based on analyzing the established network connections; Based on the extended Berkeley Packet Filter (eBPF) probe, newly added network connections in the target host are tracked to obtain new network connection information in the target host; Based on the mapping relationship between the existing network connection information and the firewall rule elements, and the mapping relationship between the new network connection information and the firewall rule elements, a whitelist firewall policy for the target host is determined.
[0101] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0102] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0103] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for determining a firewall policy, characterized in that: The method comprises: Based on the network information statistics program command, query the established network connections in the target host, and determine the existing network connection information of the target host based on analyzing the established network connections; Based on the extended Berkeley Packet Filter (eBPF) probe, newly added network connections in the target host are tracked to obtain new network connection information in the target host; Based on the mapping relationship between the existing network connection information and the firewall rule elements, and the mapping relationship between the new network connection information and the firewall rule elements, a whitelist firewall policy for the target host is determined.
2. The method for determining a firewall policy according to claim 1, characterized in that: The determining of the whitelist firewall policy of the target host based on the mapping relationship between the existing network connection information and the firewall rule elements, and the mapping relationship between the new network connection information and the firewall rule elements, includes: Building a service flow baseline database of the target host based on the parameter information in the existing network connection information and the parameter information in the new network connection information; Setting a firewall policy for each parameter in the service traffic baseline database based on the received firewall setting rules for each parameter in the service traffic baseline database; Based on the firewall policies of the various parameters, a whitelist firewall policy for the target host is determined.
3. The method for determining a firewall policy according to claim 2, characterized in that: After the service flow baseline database of the target host is constructed, the method further includes: Based on a pre-built blacklist library and a pre-built whitelist library, each parameter in the service traffic baseline database is screened to obtain a screened service traffic baseline database; The blacklist library is determined based on pre-statisticed abnormal IP address information and abnormal port information, and the whitelist library is determined based on pre-statisticed inbound library information and outbound library information.
4. The method for determining a firewall policy according to claim 3, characterized in that: The screening of the parameters in the service traffic baseline database based on the pre-built blacklist library and the pre-built whitelist library includes: Compare each parameter in the service flow baseline database with each parameter in the blacklist database, and delete the parameters in the service flow baseline database that match after comparison; The parameters in the service traffic baseline database are compared with the parameters in the whitelist database, and the parameters in the service traffic baseline database are screened based on whether the matched parameter values in the service traffic baseline database are normal.
5. The method for determining a firewall policy according to claim 1, characterized in that: The extended Berkeley packet filter eBPF probe tracks the newly added network connection in the target host and obtains the new network connection information in the target host, including: Based on the eBPF probe, track the outbound network connections generated by the target protocol in the target host and the inbound network connections generated by the target protocol, wherein the target protocol includes the TCP protocol and the UDP protocol; Based on the outbound network connection and the inbound network connection, a newly added network connection in the target host is determined, and new network connection information of the newly added network connection is obtained.
6. The method for determining a firewall policy according to claim 5, characterized in that: The acquiring new network connection information of the newly added network connection includes: Acquire the five-tuple information of the newly added network connection and the data packet flow direction information of the newly added network connection, and use the five-tuple information and the data packet flow direction information as the new network connection information.
7. An industrial product quantifiable design device, characterized in that: include: The existing network connection information determination module is used to query the established network connections in the target host based on the network information statistics program command, and determine the existing network connection information of the target host based on the analysis of the established network connections; A new network connection information determination module, used to track the newly added network connection in the target host based on an extended Berkeley Packet Filter eBPF probe, and obtain the new network connection information in the target host; A policy determination module is used to determine the whitelist firewall policy of the target host based on the mapping relationship between the existing network connection information and the firewall rule elements, and the mapping relationship between the new network connection information and the firewall rule elements.
8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the firewall policy determination method according to any one of claims 1 to 6 is implemented.
9. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the firewall policy determination method according to any one of claims 1 to 6 is implemented.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the firewall policy determination method according to any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Network connection processing method and device, equipment and storage medium
CN115664832A
Network micro-isolation method and system and virtualized cloud host
CN117478438A
Network access control method and device, equipment and storage medium
CN117499148A
Real-time communication application-oriented dynamic management firewall policy system and method
CN117614733A
Cited By
TCP connection filtering method and device, equipment and storage medium
CN121887460A
A TCP connection filtering method, device, equipment and storage medium
CN121887460B
