Session data packet multi-mode character string matching method and system based on P4

By implementing multi-mode string matching of session data packets on P4 network equipment, using NFA state transfer and five-tuple hash matching technology, the problem of insufficient detection accuracy of traditional methods in high-bandwidth environments is solved, and efficient session levels are achieved. Packet analysis and attack behavior identification.

CN118540107APending Publication Date: 2024-08-23GUANGZHOU UNIVERSITY
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410543583.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-04-30
Publication Date
2024-08-23

AI Technical Summary

Technical Problem

Traditional multi-pattern matching methods are difficult to meet the needs of high bandwidth and processing power, and cannot effectively detect and analyze session-level data packets, resulting in a decrease in detection accuracy.

Method used

Using the P4-based multi-mode string matching method for session data packets, the P4 network device obtains NFA state transfer entries and session rule entries from the entry input port, parses the data packet header, determines whether it is a session data packet, and performs NFA state transfer processing , calculate the five-tuple hash, determine the packet type, combine the rule number for matching, and upload the session rule number to the server if there is a hit.

Benefits of technology

It achieves efficient extraction of session rules without caching data packets, reduces computing resource overhead, improves detection accuracy, and reduces the probability of false positives and false negatives.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118540107A
    Figure CN118540107A
Patent Text Reader

Abstract

The invention provides a P4-based session data packet multi-mode character string matching method and system, and belongs to the technical field of network security. According to the method, a P4 is used for executing a deep packet detection algorithm, and an NFA state transition algorithm is used for converting an effective load into a bitmap form and recording the bitmap form in a local register; and when the P4 network equipment receives a response packet, calculating a hash result based on the 32-bit MD5 of the quintuple uniquely determining the data packet type so as to find a corresponding request packet, and detecting the session rule based on the NFA state of the request packet. By implementing the method and the device, the calculation overhead of multi-mode character string matching can be effectively reduced, and the efficiency of extracting the session rule by the system can be remarkably improved on the premise of not caching the session request data packet.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the technical field of network security, and in particular relates to a multi-mode string matching method and system for session data packets based on P4. Background Art

[0002] Session is an important concept in the field of network security. It is usually used to consist of a set of request packets and response packets. Session rules refer to multi-pattern string matching rules that carry pattern information in a specified database in the payload of request packets and response packets in a set of sessions. As network attack techniques become increasingly complex and covert, session-level attacks are becoming more and more serious in network security, such as man-in-the-middle attacks, phishing attacks, and session hijacking attacks. These attacks are usually not carried out through a single packet, but through a series of ordered and related packets in a session. These attacks may involve multiple stages, including reconnaissance, exploitation, command and control communications, and data theft or service destruction. Session-level rule matching can track and analyze packets throughout the session, thereby revealing the attacker's behavior patterns and attack links. Through comprehensive analysis of all packets in a session, attacks that are not obvious in the analysis of a single packet can be identified. This approach can reduce the probability of false positives and false negatives, thereby improving the accuracy of detection. In this context, multi-pattern matching of session-level packets is particularly important.

[0003] Multi-pattern matching is a key technology in the field of network security, which involves real-time identification and matching of specific pattern sets in network traffic to detect malware, prevent network intrusions, and achieve data loss prevention. However, with the growing demand for network bandwidth and processing power, traditional multi-pattern matching methods are gradually unable to meet these needs.

[0004] With the emergence of programmable networks, P4 (Programming Protocol-Independent Packet Processors) programmable switches provide a new solution for multi-mode matching of session-level packets. P4 switches allow developers to write code to customize the way packets are processed, which can meet specific network functions. For example, PPS and BOLT systems can meet the multi-mode matching of simple environments in today's high-bandwidth network environments. However, in the context of session packet flows, PPS and BOLT cannot detect session-level packets, and the lack of comprehensive analysis of session flows will lead to a lack of detection accuracy. Summary of the invention

[0005] In order to solve the above problems, the present invention provides a P4-based session data packet multi-mode string matching method and system.

[0006] In a first aspect, an embodiment of the present invention provides a method for matching session data packets using multiple modes based on P4, the method comprising the following steps:

[0007] S1: The P4 network device obtains the NFA state transition entry and session rule entry from the entry input port;

[0008] S2: The P4 network device receives a data packet from a receiving port and parses the data packet header;

[0009] S3: the P4 network device mirrors the data packet, inputs the mirrored data packet into the recirculation port, and forwards the data packet from the forwarding port;

[0010] S4: Based on the data packet header information, determine whether the mirrored data packet is a session data packet; if the mirrored data packet is not a session data packet, end the entire process; if the mirrored data packet is a session data packet, execute step S5;

[0011] S5: According to the NFA state transition entry, perform NFA state transition processing on the payload part of the mirrored data packet; when the P4 network device pipeline completes the state transition of all payloads, return a mode bitmap and enter step S6, otherwise forward the mirrored data packet to the recirculation port;

[0012] S6: The P4 network device maps the mode bitmap into a unidirectional flow rule and temporarily stores it in a memory;

[0013] S7: The P4 network device calculates the five-tuple hash of the mirrored data packet, and determines whether the mirrored data packet is a request packet or a response packet; if the mirrored data packet is a request packet in the session, the P4 network device reads a register based on the five-tuple hash index value; if the mirrored data packet is a response packet in the session, the P4 network device reads the one-way flow rule number of the request packet in the register based on the reverse five-tuple hash index value, and enters step S8;

[0014] S8: Combine the unidirectional flow rule number of the register request packet and the unidirectional flow rule number of the mirror data packet to determine whether they hit the session rule number of the input session rule entry; if they hit, it means that the session where the mirror data packet is located may have attack behavior, and then upload the session rule number to the server; if they do not hit, then end the entire process.

[0015] In some possible implementations, the NFA state transition entry includes the logical content of the NFA state transition, and the P4 network device can parse the data packet payload based on the NFA state transition entry; each of the NFA state transition entries includes the following components: current state, input symbol, and transition type.

[0016] In some possible implementations, the session rule entry is used to perform rule matching on the session flow, and specifically includes: pattern, pattern bitmaps, unidirectional flow bitmaps, unidirectional flow rule number unidirectional rule id, and session rule number session rule id.

[0017] In some possible implementations, the session rule entry is designed through a Snort3 intrusion detection system.

[0018] In some possible implementations, parsing the data packet header includes: the P4 network device gradually extracting each field in the packet header in a predefined order and performing recursive parsing; and storing the source port number, destination port number, and IP number of the data packet obtained by parsing into the memory of the P4 network device.

[0019] In some possible implementations, determining whether the mirrored data packet is a session data packet based on data packet header information includes: determining whether the data packet is a session data packet by parsing a session identifier and a protocol interaction feature in the data packet.

[0020] In some possible implementations, the pattern bitmap in step S5 maps a set of patterns matched by the payload of the mirrored data packet in all pipelines of the P4 network device.

[0021] In some possible implementations, if the mirrored data packet is a request packet in a session, the P4 network device reads a register based on a five-tuple hash index value, including: if there is no hash value conflict, updating the five-tuple information, mode bitmap, and unidirectional flow rule number of the mirrored data packet to the register offset corresponding to the hash value; if a hash conflict occurs, using a linear detection method in an open addressing method to gradually detect empty hash buckets, and writing the five-tuple information, mode bitmap, and unidirectional flow rule number of the mirrored data packet into the hash bucket.

[0022] In some possible implementations, in step S7, the P4 network device uses an MD5 algorithm to calculate a five-tuple hash of the mirrored data packet.

[0023] In a second aspect, the present application also proposes a session data packet multi-mode string matching system based on P4, the system specifically comprising:

[0024] A sending module, used for inputting NFA state transition entries and session rule entries into an entry input port of a P4 network device;

[0025] A P4 network device module, comprising a P4 network device, configured to execute any one of the P4-based session data packet multi-mode string matching methods described in the first aspect above;

[0026] The server module includes a server, which is used to receive a session rule number from the P4 network device, extract corresponding session rule information according to the session rule number, and update a database log based on the session rule information.

[0027] By implementing the present invention, the following beneficial technical effects are achieved but not limited to:

[0028] (1) Compared with the traditional multi-pattern matching algorithm, the method of the present invention offloads the multi-pattern string matching method to the programmable switch, thereby reducing the computing resource overhead.

[0029] (2) The present invention proposes a deep packet inspection (DPI) method that does not require caching, which can efficiently extract session rules without caching session request packets.

[0030] (3) The present invention utilizes P4 to execute a deep packet inspection algorithm. It does not cache data packets, but directly extracts the payload in the data packets. It converts the payload into a bitmap using the NFA state transition algorithm and records it in a local register, thereby avoiding the memory overhead of caching data packets. BRIEF DESCRIPTION OF THE DRAWINGS

[0031] The drawings constituting a part of the present application are used to provide a further understanding of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application.

[0032] Figure 1 It is a flow chart of a multi-mode string matching method for session data packets based on P4 provided in an embodiment of the present application;

[0033] Figure 2 It is a schematic diagram of a P4-based session data packet multi-mode string matching system framework provided according to an embodiment of the present application;

[0034] Figure 3 It is the operating status of the P4 network device register in the application scenario provided in the embodiment of the present application. DETAILED DESCRIPTION

[0035] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only 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.

[0036] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by those skilled in the art to which the present disclosure belongs. Although any methods similar or equivalent to those described herein can also be used in the practice or testing of the present disclosure, only exemplary methods are now described.

[0037] It should be understood that when used in this specification and the appended claims, the terms "include" and "comprises" indicate the presence of described features, integers, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or combinations thereof.

[0038] It should also be understood that the terms used in this specification of the present invention are only for the purpose of describing specific embodiments and are not intended to limit the present invention. As used in the specification of the present invention and the appended claims, unless the context clearly indicates otherwise, the singular forms "a", "an" and "the" are intended to include plural forms.

[0039] First, see Figure 1-2 , Figure 1 A multi-mode string matching method for session data packets based on P4 is provided in an embodiment of the present application, comprising the following steps:

[0040] S1: The P4 network device obtains the NFA state transition entry and the session rule entry from the entry input port.

[0041] Specifically, the NFA state transition entry includes the logical content of the NFA state transition, and the P4 network device can parse the data packet payload based on the NFA state transition entry. For example, each of the NFA state transition entries can include the following components: current state, input symbol, transition type, etc.

[0042] The session rule entry is used to perform rule matching on the session flow. In some possible implementations, the session rule entry may include: pattern, pattern bitmaps, unidirectional flow bitmaps, unidirectional rule id, and session rule id.

[0043] Preferably, the session rule entry can be designed by a Snort3 intrusion detection system.

[0044] S2: The P4 network device receives a data packet from a receiving port and parses the data packet header.

[0045] Specifically, the parsing of the data packet header includes parsing to obtain the source port number, destination port number and IP number of the data packet, and storing them in the memory of the P4 network device. The process of parsing the data packet header occurs in the "parsing stage" (Parser). In this stage, the P4 network device gradually extracts each field in the packet header in a predefined order and performs recursive parsing to process some multi-layer encapsulation protocols, such as IP-in-IP, GRE, VXLAN, etc. The P4 network device parser can define multiple parsing states, each state is responsible for parsing a specific packet header or performing a specific action, such as jumping to the next state, extracting field values, discarding the packet header, etc.

[0046] S3: The P4 network device mirrors the data packet and inputs the mirrored data packet into a recirculation port, and forwards the data packet from a forwarding port.

[0047] S4: Based on the data packet header information, determine whether the mirrored data packet is a session data packet; if the mirrored data packet is not a session data packet, end the entire process; if the mirrored data packet is a session data packet, execute step S5.

[0048] Specifically, it is possible to determine whether the data packet is a session data packet by parsing the session identifier (such as a five-tuple, etc.) or the protocol interaction characteristics (such as the protocol handshake and termination process, request and response mode, etc.) in the data packet, or to query whether the data packet belongs to a known session through the network device session table maintained by the P4 network device. For example, if the source port number or the destination port number of the mirrored data packet obtained by parsing is 80, it can be determined that the data packet is an HTTP session data packet.

[0049] S5: According to the NFA state transfer entry, perform NFA state transfer processing on the payload part of the mirrored data packet; when the P4 network device pipeline completes the state transfer of all payloads, return a mode bitmap and enter step S6, otherwise forward the mirrored data packet to the recycling port.

[0050] Specifically, the pattern bitmap maps a set of patterns matched by the payload of the mirrored data packet in all pipelines of the P4 network device.

[0051] S6: The P4 network device maps the mode bitmap into a unidirectional flow rule and temporarily stores it in the memory. The unidirectional flow rule exists in the form of a compressed bitmap, which is responsible for recording the rule number matched by the current data packet mode bitmap.

[0052] S7: The P4 network device calculates the five-tuple hash of the mirrored data packet and determines whether the mirrored data packet is a request packet or a response packet; if the mirrored data packet is a request packet in a session, the P4 network device reads the register based on the five-tuple hash index value; if the mirrored data packet is a response packet in a session, the P4 network device reads the one-way flow rule number of the request packet in the register based on the reverse five-tuple hash index value, and enters step S8. Figure 3 As shown, Figure 3 It is one of the operating states of the P4 network device register in this embodiment.

[0053] Specifically, the five-tuple consists of a source IP, a destination IP, a source port, a destination port, and a transport layer protocol type. After locating the response characteristics of the data packet based on the data packet header information and the five-tuple hash, it can be determined whether the mirror data packet is a request packet or a response packet. If the mirror data packet is a request packet in a session, the P4 network device reads the register based on the five-tuple hash index value, including: if there is no hash value conflict, the five-tuple information, mode bitmap, and unidirectional flow rule number of the mirror data packet are updated to the register offset corresponding to the hash value; if a hash conflict occurs, the linear detection method in the open addressing method is used to gradually detect empty hash buckets, and the five-tuple information, mode bitmap, and unidirectional flow rule number of the mirror data packet are written into the hash bucket.

[0054] Preferably, the P4 network device may use an MD5 algorithm in a hash function to calculate a five-tuple hash of the mirrored data packet.

[0055] S8: Combine the unidirectional flow rule number of the register request packet and the unidirectional flow rule number of the mirror data packet to determine whether they hit the session rule number of the input session rule entry; if they hit, it means that the session where the mirror data packet is located may have attack behavior, and then upload the session rule number to the server; if they do not hit, then end the entire process.

[0056] In a second aspect, an embodiment of the present invention further provides a session data packet multi-mode string matching system based on P4, the system comprising the following modules:

[0057] The sending module is used to input NFA state transition entries and session rule entries to the entry input port of the P4 network device.

[0058] The P4 network device module includes a P4 network device, which is used to execute the P4-based session data packet multi-mode string matching method described in the first aspect embodiment.

[0059] The server module includes a server, which is used to receive a session rule number from the P4 network device, extract corresponding session rule information according to the session rule number, and update a database log based on the session rule information.

[0060] In the embodiments provided by the present invention, it should be understood that the disclosed systems and methods can be implemented in other ways. For example, the system embodiments described above are only schematic. For example, the division of each module is only a logical function division, and there may be other division methods in actual implementation. In addition, the steps in the method of the embodiment of the present invention can also be adjusted in order, merged and deleted according to actual needs.

[0061] The preferred specific embodiments of the present invention are described in detail above. It should be understood that ordinary technicians in the field can make many modifications and changes based on the concept of the present invention without creative work. Therefore, all technical solutions that can be obtained by technicians in the technical field based on the concept of the present invention through logical analysis, reasoning or limited experiments on the basis of the prior art should be within the scope of protection determined by the claims.

Claims

1. A multi-mode string matching method for session data packets based on P4, characterized in that: The following steps are involved: S1: The P4 network device obtains the NFA state transition entry and session rule entry from the entry input port; S2: The P4 network device receives a data packet from a receiving port and parses the data packet header; S3: the P4 network device mirrors the data packet, inputs the mirrored data packet into the recirculation port, and forwards the data packet from the forwarding port; S4: Based on the data packet header information, determine whether the mirrored data packet is a session data packet; if the mirrored data packet is not a session data packet, end the entire process; if the mirrored data packet is a session data packet, execute step S5; S5: performing NFA state transfer processing on the payload portion of the mirrored data packet according to the NFA state transfer entry; When the P4 network device pipeline completes the state transfer of all effective loads, a mode bitmap is returned and step S6 is entered, otherwise the mirrored data packet is forwarded to the recirculation port; S6: The P4 network device maps the mode bitmap into a unidirectional flow rule and temporarily stores it in a memory; S7: The P4 network device calculates the five-tuple hash of the mirrored data packet, and determines whether the mirrored data packet is a request packet or a response packet; If the mirrored data packet is a request packet in the session, the P4 network device reads the register based on the five-tuple hash index value; if the mirrored data packet is a response packet in the session, the P4 network device reads the one-way flow rule number of the request packet in the register based on the reverse five-tuple hash index value, and enters step S8; S8: combining the unidirectional flow rule number of the register request packet and the unidirectional flow rule number of the mirror data packet to determine whether the session rule number of the input session rule entry is hit; If it is a hit, it means that the session where the mirrored data packet is located may have attack behavior, and the session rule number is uploaded to the server. If it is not a hit, the whole process ends.

2. The method for multi-mode string matching of session data packets based on P4 according to claim 1, characterized in that: The NFA state transition entry includes the logical content of the NFA state transition, and the P4 network device can parse the data packet payload based on the NFA state transition entry; each of the NFA state transition entries includes the following components: current state, input symbol, and transition type.

3. The method for multi-mode string matching of session data packets based on P4 according to claim 1, characterized in that: The session rule entry is used to perform rule matching on the session flow, and specifically includes: pattern pattern, pattern bitmaps, unidirectional flow bitmaps, unidirectional flow rule number unidirectionalruleid, and session rule number session ruleid.

4. The method for multi-mode string matching of session data packets based on P4 according to claim 1, characterized in that: The session rule entries are designed through the Snort3 intrusion detection system.

5. The method for multi-mode string matching of session data packets based on P4 according to claim 1, characterized in that: The parsing of the data packet header includes: The P4 network device gradually extracts each field in the packet header in a predefined order and performs recursive parsing; the source port number, destination port number and IP number of the data packet obtained by parsing are stored in the memory of the P4 network device.

6. The method for multi-mode string matching of session data packets based on P4 according to claim 1, characterized in that: The determining, based on the data packet header information, whether the mirrored data packet is a session data packet comprises: By parsing the session identifier and protocol interaction characteristics in the data packet, it is determined whether the data packet is a session data packet.

7. The method for multi-mode string matching of session data packets based on P4 according to claim 1, characterized in that: The pattern bitmap in step S5 maps the pattern set matched by the payload of the mirrored data packet in all pipelines of the P4 network device.

8. The method for multi-mode string matching of session data packets based on P4 according to claim 1, characterized in that: If the mirrored data packet is a request packet in a session, the P4 network device reads a register based on a five-tuple hash index value, including: If there is no conflict in the hash value, the five-tuple information, mode bitmap and unidirectional flow rule number of the mirrored data packet are updated to the register offset corresponding to the hash value; If a hash conflict occurs, a linear detection method in an open addressing method is used to gradually detect empty hash buckets, and the five-tuple information, mode bitmap and unidirectional flow rule number of the mirrored data packet are written into the hash bucket.

9. The method for multi-mode string matching of session data packets based on P4 according to claim 1, characterized in that: In step S7, the P4 network device uses the MD5 algorithm to calculate the five-tuple hash of the mirrored data packet.

10. A multi-mode string matching system for session data packets based on P4, characterized in that: include: A sending module, used for inputting NFA state transition entries and session rule entries into an entry input port of a P4 network device; A P4 network device module, comprising a P4 network device, for executing a P4-based session data packet multi-mode string matching method according to any one of claims 1 to 9; The server module includes a server, which is used to receive a session rule number from the P4 network device, extract corresponding session rule information according to the session rule number, and update a database log based on the session rule information.