Method and device for retrieving pcapng data packet files

By adding a custom index block at the end of the pcapng packet file to store packet index information and quickly locate it, the problem of slow retrieval speed in network traceability analysis is solved, and fast retrieval and efficient packet file retrieval are achieved.

CN114896207BActive Publication Date: 2024-10-22HANGZHOU DPTECH TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210309317.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-03-27
Publication Date
2024-10-22
Estimated Expiration
2042-03-27

AI Technical Summary

Technical Problem

In network traceability analysis, when using pcapng packet files for retrieval, due to the huge amount of data, traditional methods need to traverse the entire file, resulting in slow query speed and difficulty in meeting user needs.

Method used

Add a custom index block at the end of the pcapng packet file to store the index information of the packet, quickly locate and read qualified packets in the index block according to user search conditions, and reduce disk IO performance and CPU utilization.

Benefits of technology

It greatly improves the retrieval speed, shortens the retrieval time, and improves the user experience without affecting the use of other data package tools.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114896207B_ABST
    Figure CN114896207B_ABST
Patent Text Reader

Abstract

The present disclosure relates to a method and device for retrieving a pcapng data packet file. The method comprises: forming a pcapng extended data packet file by adding a custom index block at the end of a pcapng data packet file containing an enhanced data packet block or a simple data packet block, wherein the custom index block includes an index for the message contained in the enhanced data packet block; after receiving a user search condition, searching the custom index block according to the user search condition, and when an index that meets the user search condition is retrieved in the custom index block, obtaining the message in the enhanced data packet block or the simple data packet block according to the file offset contained in the index, and sending all messages that meet the user search condition to the user after the search is completed. The disk IO overhead and CPU utilization can be greatly reduced, and the search time is short. In addition, by adding a custom index block, the data packet tool can still be opened, which does not affect the user's viewing of the data packet.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the technical field of data retrieval, and in particular to a method and device for retrieving a pcapng data packet file. Background Art

[0002] When using the network tracing system for retrospective analysis, it is necessary to first store the network data by capturing packets. Subsequently, retrospective analysis of the original data packets in the stored network data is performed to perform retrospective analysis of the network behavior, application data, and host data that has occurred, such as checking for viruses, attacks, leaks, and network behavior analysis.

[0003] Pcap and pcapng files are commonly used data packet storage format files. pcapng is the next generation data packet storage format of pcap. Compared with pcap files, pcapng files can contain more information, such as interface statistics and interface description information. Use ethereal, wireshark and other packet capture software to open pcapng files, view network datagrams in pcapng files, and retrieve and analyze original data packets.

[0004] Specifically, when conducting network source tracing analysis, the original data packet can be queried based on the user's source IP address, source port, destination IP address, destination port, protocol, time and other conditions. The original data packet can also be exported to data packet software such as Wireshark for further analysis, providing a basis for quickly locating the cause of the problem, while providing strong data analysis support for network security.

[0005] When searching and analyzing network data, it is usually necessary to search and analyze the data packets. When searching and analyzing the data packets, it is necessary to traverse the entire file. After the search is completed, the data is returned to the user. Specifically, it is necessary to open the corresponding data packet file, traverse the data in the message, and search according to the user input information. With the development of the Internet, the network bandwidth is getting higher and higher. Calculated with an ordinary 100M network bandwidth, assuming that 12.5M data is stored per second, 750M per minute, 4.5G per hour, and 108G data per day. When the network bandwidth reaches 1G or even 10G, the space occupied by network data will become very large. Due to the limited disk IO performance, IO reading and writing is a major bottleneck, resulting in very slow query speed. If you query one day's data, you need to search in 108G data. At a rate of 100M per second, the search takes 18 minutes, resulting in a poor user experience and even difficult to meet user needs.

[0006] Therefore, a method and device for retrieving pcapng data packet files that can overcome the low retrieval efficiency is needed. Summary of the invention

[0007] In view of this, the present disclosure provides a method and device for retrieving a pcapng data packet file. According to one aspect of the present disclosure, a method for retrieving a pcapng data packet file is proposed, which includes: forming a pcapng extended data packet file by adding a custom index block at the end of a pcapng data packet file containing an enhanced data packet block or a simple data packet block, wherein the custom index block includes an index for a message contained in the enhanced data packet block; after receiving a user search condition, searching the custom index block according to the user search condition, and when an index that meets the user search condition is retrieved in the custom index block, obtaining the message in the enhanced data packet block or the simple data packet block according to the file offset contained in the index, and sending all messages that meet the user search condition to the user after the search is completed.

[0008] According to the method for retrieving a pcapng data packet file disclosed in the present invention, the custom index block includes: a block type field, a first block total length field, a magic field, an index area and a second block total length field; the block type field is used to identify the custom index block; the first block total length field is used to record the total length of the custom index block; the magic number field stores a magic number preset fixed value, which is used to identify the starting file position of the index area; the index area is used to store an index for a message contained in an enhanced data packet block or a simple data packet block; the value of the second block total length field is the same as that of the first block total length field, which is used to verify the custom index block.

[0009] According to the method for retrieving pcapng data packet files disclosed in the present invention, the index contained in the index area includes: an index type field, a file offset field and a five-tuple in sequence, wherein the five-tuple includes: a source IP field, a destination IP field, a source port field, a destination port field, and a transport layer protocol type field.

[0010] According to the method for retrieving a pcapng data packet file disclosed in the present invention, when searching in the custom index block according to the user search condition, the method includes: obtaining the total length field value of the second block; calculating the starting file position of the custom index block according to the total length field value of the second block; obtaining the block type field value and the magic field value based on the starting file position of the custom index block, and verifying the obtained block type field value and the magic field value; when the block type field value and the magic field value pass the verification, parsing each index contained in the index area, and comparing the five-tuple contained in the index obtained after parsing with the user search condition, when the five-tuple contained in the index matches the user search condition, directly reading the message through the file offset field content contained in the index obtained after parsing so as to send all messages whose five-tuple contained in the index matches the user search condition to the user after the search is completed.

[0011] According to the method for retrieving a pcapng data packet file disclosed in the present invention, the value of the index type field includes: ipv4, ipv6, arp or other types.

[0012] Another aspect of the present disclosure proposes a device for retrieving a pcapng data packet file, which includes: a pcapng extended data packet file forming component, used to form a pcapng extended data packet file by adding a custom index block at the end of a pcapng data packet file containing an enhanced data packet block or a simple data packet block, wherein the custom index block includes an index for the message contained in the enhanced data block; a retrieval component, used to, after receiving a user retrieval condition, first search in the custom index block according to the user retrieval condition, and when an index that meets the user retrieval condition is retrieved in the custom index block, obtain the message in the enhanced data packet block or the simple data packet block according to the file offset contained in the index; and a sending component, used to send all messages that meet the user retrieval condition to the user after the retrieval is completed.

[0013] According to the device for retrieving pcapng data packet files disclosed in the present invention, the custom index block includes: a block type field, a first block total length field, a magic field, an index area and a second block total length field; the block type field is used to identify the custom index block; the first block total length field is used to record the total length of the custom index block; the magic number field stores a magic number preset fixed value, which is used to identify the starting file position of the index area; the index area is used to store the index of the message contained in the enhanced data packet block or the simple data packet block; the value of the second block total length field is the same as the first block total length field, which is used to verify the custom index block.

[0014] According to the device for retrieving pcapng data packet files disclosed in the present invention, the index contained in the index area includes: an index type field, a file offset field and a quintuple in sequence, wherein the quintuple includes: a source IP field, a destination IP field, a source port field, a destination port field, and a transport layer protocol type field.

[0015] According to the device for retrieving pcapng data packet files disclosed in the present invention, the retrieval component, when searching in the custom index block according to the user search condition, includes: a custom index block positioning component, used to obtain the second block total length field value and calculate the starting file position of the custom index block according to the second block total length field value; a verification component, used to obtain the block type field value and the magic field value based on the starting file position of the custom index block, and verify the obtained block type field value and the magic field value; a parsing and matching component, used to parse the indexes contained in the index area when the block type field value and the magic field value pass the verification, and compare the five-tuple field content contained in the index obtained after parsing with the user search condition, when the five-tuple field content contained in the index matches the user search condition, directly read the message through the file offset field content contained in the index obtained after parsing, so that after the retrieval is completed, the sending component sends all messages whose five-tuple field content contained in the index matches the user search condition to the user.

[0016] According to the device for retrieving pcapng data packet files disclosed in the present invention, the value of the index type field includes: ipv4, ipv6, arp or other types.

[0017] In summary, the disclosed method and device for retrieving pcapng data packet files are adopted, by extending the pcapang data packet file, adding a custom index block at the end of the pcapng data packet file, and storing message index data and data packet file offset information according to the message type. When searching, first, according to the last 4-byte block length of the pcapng data packet file, it is offset forward to the custom index block, rather than parsing the file data from front to back in order to parse to the custom index block, so that the custom index block can be quickly located. According to the search conditions, the data packet is retrieved in the index, and when the data packet is retrieved, the specified data packet is read by the file offset, which greatly reduces the reading file IO performance, reduces the disk IO overhead and CPU utilization, and the retrieval time is short. In addition, by adding the custom index block, other data packet tools (such as wireshark, etc.) can still be opened, and the user's viewing of the data packet is not affected.

[0018] It is to be understood that the foregoing general description and the following detailed description are exemplary only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] The above and other objects, features and advantages of the present disclosure will become more apparent by describing in detail its exemplary embodiments with reference to the accompanying drawings. The accompanying drawings described below are only some embodiments of the present disclosure, and it is clear to a person skilled in the art that other accompanying drawings can be obtained from these accompanying drawings without creative work.

[0020] Figure 1 Shown is a flowchart of a method for retrieving a pcapng data packet file according to an embodiment of the present disclosure.

[0021] Figure 2 What is shown is a schematic diagram of the composition structure of a custom index block in a pcapng extended data packet file according to an embodiment of the present disclosure.

[0022] Figure 3 A schematic diagram of the composition structure of the index contained in the index area in the custom index block according to an embodiment of the present disclosure is shown.

[0023] Figure 4 What is shown is a flowchart of creating an index through an enhanced data packet block EPB or a simple data packet block SPB in a method for retrieving a pcapng data packet file according to an embodiment of the present disclosure.

[0024] Figure 5 What is shown is a schematic diagram of a device for retrieving a pcapng data packet file according to an embodiment of the present disclosure. DETAILED DESCRIPTION

[0025] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be implemented in many forms and should not be construed as limited to the embodiments set forth herein; rather, these embodiments are provided so that this disclosure will be comprehensive and complete and will fully convey the concepts of the example embodiments to those skilled in the art. The same reference numerals in the figures represent the same or similar parts, and thus their repeated description will be omitted.

[0026] In addition, the described features, structures or characteristics may be combined in one or more embodiments in any suitable manner. In the following description, many specific details are provided to provide a full understanding of the embodiments of the present disclosure. However, those skilled in the art will appreciate that the technical solutions of the present disclosure may be practiced without one or more of the specific details, or other methods, components, devices, steps, etc. may be adopted. In other cases, known methods, systems, implementations or operations are not shown or described in detail to avoid blurring the various aspects of the present disclosure.

[0027] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities may be implemented in software form, or in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices.

[0028] The flowcharts shown in the accompanying drawings are only exemplary and do not necessarily include all the contents and operations / steps, nor must they be executed in the order described. For example, some operations / steps can be decomposed, and some operations / steps can be combined or partially combined, so the actual execution order may change according to actual conditions.

[0029] Those skilled in the art will appreciate that the drawings are merely schematic diagrams of example embodiments, and the modules or processes in the drawings are not necessarily necessary for implementing the present disclosure, and therefore cannot be used to limit the protection scope of the present disclosure.

[0030] The pcap file is a commonly used datagram storage format file. Since the pcap file has a specific file format, it needs to be opened with a packet capture tool such as ethereal or wireshark to view the network datagrams it contains, and then to retrieve and analyze the network datagrams. The pcapng file is the next generation datagram file storage format of the pcap file. Compared with the pcap file, the pcapng file can contain more information, such as interface statistics, interface description information, etc.

[0031] The pcapng file contains multiple data blocks, each containing different types of information, such as Section Header Block (SHB), Interface Statistics Block (ISB), Interface Description Block (IDB), Name Resolution Block (NRB), Enhanced Packet Block (EPB), Simple Packet Block (SPB), and Custom Block (CB). Among them, EPB is a standard container for storing data packets from the network, and SPB is a lightweight container. Therefore, datagrams are generally stored in EPB or SPB in the pcapng file.

[0032] When performing network tracing analysis, searching for messages in data packets according to specific conditions can improve the efficiency of network tracing analysis.

[0033] Figure 1Shown is a flowchart of a method for retrieving a pcapng data packet file according to an embodiment of the present disclosure.

[0034] like Figure 1 As shown, in step S102, a pcapng extended data packet file is formed, and the pcapng extended data packet file includes a custom index block. Specifically, the pcapng extended data packet file is formed by adding a custom index block to the tail of a pcapng data packet file including an enhanced data packet block EPB or a simple data packet block SPB, and the custom index block includes an index for the message included in the enhanced data packet block.

[0035] When performing network tracing analysis, the network data is first stored in the pcapng data packet file by capturing the message. Specifically, the network data is usually stored in the enhanced data packet block EPB or the simple data packet block SPB of the pcapng data packet file. According to the method for retrieving the pcapng data packet file in the embodiment of the present disclosure, after obtaining the pcapng data packet file containing the message, a custom data block is added to the end of the pcapng data packet file, that is, the custom index block in the embodiment of the present disclosure, and the custom index block is used to store the index of the message contained in the enhanced data packet block EPB or the simple data packet block SPB in the pcapng data packet file.

[0036] In step S104, a search is performed in the custom index block according to the user search condition and a message is obtained based on the retrieved index. Specifically, after receiving the user search condition, a search is performed in the custom index block according to the user search condition, and when an index that meets the user search condition is retrieved in the custom index block, a message in the enhanced data packet block EPB or the simple data packet block SPB is obtained according to the file offset contained in the index.

[0037] In step S106, after the search is completed, all messages that meet the user's search conditions are sent to the user.

[0038] Figure 2 What is shown is a schematic diagram of the composition structure of a custom index block in a pcapng extended data packet file according to an embodiment of the present disclosure.

[0039] like Figure 2 As shown, the custom index block includes: a block type field, a first block total length field, a magic field, an index area, and a second block total length field.

[0040] The block type field is used to identify a custom index block. More specifically, the block type field is stored in the block header and is used to identify the data block type as a custom index block. Its value is a 32-bit integer value that complies with the pcapng data packet file definition specification and is used to uniquely identify the custom index block.

[0041] The first block total length field is used to record the total length of the custom index block.

[0042] The magic number field stores a magic number preset fixed value, which is used to identify the starting file position of the index area. In the method for retrieving a pcapng data packet file in the embodiment of the present disclosure, the value of the magic number field is "0xacebeedd".

[0043] The index area is used to store indexes of messages included in the enhanced data packet block or the simple data packet block.

[0044] The value of the second block total length field is the same as that of the first block total length field, and is used to verify the custom index block.

[0045] Figure 3 A schematic diagram of the composition structure of the index contained in the index area in the custom index block according to an embodiment of the present disclosure is shown.

[0046] like Figure 3 As shown, the index includes an index type field, a file offset field, a source IP field, a destination IP field, a source port field, a destination port field, and a transport layer protocol type field.

[0047] Among them, the value of the index type field is the message type of the message. According to the method for retrieving a pcapng data packet file in an embodiment of the present disclosure, the value of the index type field can be 1, 2, 3, and 4. Specifically, when the value of the index type field is 1, it indicates that the message type is an ipv4 message; when the value of the index type field is 2, it indicates that the message type is an ipv6 message; when the value of the index type field is 3, it indicates that the message type is an arp message; when the value of the index type field is 4, it indicates that the message type is a message other than ipv4, ipv6, and arp.

[0048] The file offset field has a value of the offset of the message in the file, and the physical position of the message in the file is determined based on the offset.

[0049] Among them, the source IP, destination IP, source port, destination port and transport layer protocol type (TCP / UDP) are the five-tuple information of the message.

[0050] Figure 4What is shown is a flowchart of creating an index through an enhanced data packet block EPB or a simple data packet block SPB in a method for retrieving a pcapng data packet file according to an embodiment of the present disclosure.

[0051] like Figure 4 As shown, in step S402, the pcapng data packet file is read.

[0052] In step S404, it is determined whether it is an enhanced data packet block EPB or a simple data packet block SPB.

[0053] When the result of determining whether it is an enhanced data packet block EPB or a simple data packet block SPB in step S404 is "yes", proceed to step S406. In step S406, the message contained in the enhanced data packet block EPB or the simple data packet block SPB is parsed, index data information and file offset are extracted, and an index is established. More specifically, the message is parsed based on the message format and the message type, file offset and five-tuple information (source IP, destination IP, source port, destination port and transport layer protocol type) of the message are extracted as index information.

[0054] The specific message parsing process is as follows: start parsing from the MAC header of the message, and parse the protocol type of the upper layer protocol according to the MAC header. For example, if the upper layer protocol field value in the MAC header is "0x0800", it means that the protocol type of the upper layer protocol of the message is ipv4; if the upper layer protocol field value is "0x86dd", it means that the protocol type of the upper layer protocol is ipv6; if the upper layer protocol field value is "0x0806", it means that the protocol type of the upper layer protocol is arp; if the upper layer protocol field value is "0x8100", it means that the protocol type of the upper layer protocol is vlan.

[0055] Afterwards, according to the message format corresponding to the protocol type, extract the four-tuple information of the transport layer in the message, namely: source IP, destination IP, source port, destination port. For example, if the upper layer protocol is IPv4, further parse it according to the protocol field in the protocol header; if the upper layer protocol is IPv6, further parse it according to the next header field in the header. If the protocol field in the IPv4 header or the next header field in the IPV6 header is 6, it means that the protocol type is TCP. If the protocol field in the IPv4 header or the next header field in the IPv6 header is 17, it means that the protocol type is UDP protocol. Further, extract the four-layer port information from the header of the TCP protocol message or the header of the UDP protocol message. If the protocol type of the upper layer protocol is VLAN, it is necessary to strip off the VLAN header for further parsing. If it is not a message of the above three types, IPv4 type, IPv6 type, or ARP type, it is other types, and the index record of other types of messages is "0xff".

[0056] According to the method for retrieving a pcapng data packet file according to an embodiment of the present disclosure, the index information for the message extracted in step S406 is Figure 3 The index format shown is written into the index area in the custom index block, that is, for each message, the extracted message index information is uniformly stored in the index block in the following format: index type, file offset, source IP, destination IP, source port, destination port, and transport layer protocol type.

[0057] Among them, index type and file offset are mandatory. Source IP, destination IP, source port, destination port and transport layer protocol type are optional. When the index information does not include the contents of the above four optional items, the value of the corresponding field can be 0.

[0058] Depending on the index type, indexes of different lengths can be used for storage. For example, the index type of IPv4 messages takes up 1 byte, the file offset takes up 4 bytes, the source IP takes up 4 bytes, the destination IP takes up 4 bytes, the source port takes up 2 bytes, the destination port takes up 2 bytes, and the transport layer protocol type takes up 1 byte. For another example, the index type of IPv6 messages takes up 1 byte, the file offset takes up 4 bytes, the source IP takes up 8 bytes, the destination IP takes up 8 bytes, the source port takes up 2 bytes, the destination port takes up 2 bytes, and the transport layer protocol type takes up 1 byte.

[0059] In step S408, it is determined whether the traversal is complete.

[0060] When the result of judging whether the traversal is completed in step S408 is "yes", proceed to step S410. In step S410, the total length of the index contained in the index area and the total length of the custom block index block are calculated, and the total length of the custom index block is written to the specified file location. More specifically, after the message contained in the enhanced data packet block EPB or the simple data packet block SPB in the pcapng data packet file is traversed and all indexes are generated, the total length of the index is calculated. When the total length of the index is less than 4 bytes, it is aligned according to 4 bytes, and the index content is padded with 0 to meet the 4-byte alignment. Finally, the total length of the custom index block is calculated and saved in the total length field of the block in the custom index block according to the pcapng file format requirements.

[0061] When the result of determining whether the traversal is complete in step S408 is "No", the process re-enters step S404 until the traversal is complete.

[0062] According to the method for retrieving a pcapng data packet file according to an embodiment of the present disclosure, when performing message retrieval according to a user's retrieval condition, the method includes the following steps: obtaining a second block total length field value; calculating a starting file position of the custom index block according to the second block total length field value; obtaining a block type field value and a magic field value based on the starting file position of the custom index block, and verifying the obtained block type field value and the magic field value; when the block type field value and the magic field value pass the verification, parsing each index contained in the index area, and comparing the five-tuple contained in the index obtained after parsing with the user's retrieval condition, when the five-tuple contained in the index matches the user's retrieval condition, directly reading the message through the file offset field content contained in the index obtained after parsing, so as to send all messages whose five-tuple contained in the index matches the user's retrieval condition to the user after the retrieval is completed.

[0063] More specifically, when searching according to the user's search conditions, first open the pcapng data packet file to be searched, locate the 4 bytes at the end of the pcapng data packet file, and since it represents the total block length of the custom index block, after offsetting forward to the file start position of the custom index block according to the total block length of the custom index block, check the block type and magic number. If the check fails, it means that it is an ordinary pcapng file without an index, and it is necessary to traverse the entire file for retrieval. If it is a pcapng file containing a custom index block, then parse the index according to the index format, extract the five-tuple information and compare it with the search conditions entered by the user. If a message that meets the search conditions is found, the message content is directly read through the file offset, and finally the messages that meet the search conditions are uniformly returned to the user for display.

[0064] Figure 5FIG. 1 is a schematic diagram of a device for retrieving a pcapng data packet file according to an embodiment of the present disclosure. Figure 5 As shown, the device for retrieving a pcapng data packet file according to an embodiment of the present disclosure includes: a pcapng extended data packet file forming component 502, a retrieval component 504 and a sending component 506.

[0065] Among them, the pcapng extended data packet file forming component 502 is used to form a pcapng extended data packet file by adding a custom index block at the end of a pcapng data packet file containing an enhanced data packet block or a simple data packet block, and the custom index block includes an index for the message contained in the enhanced data packet block; the retrieval component 504 is used to, after receiving the user's retrieval conditions, first search in the custom index block according to the user's retrieval conditions, when an index that meets the user's retrieval conditions is retrieved in the custom index block, obtain the message in the enhanced data packet block or the simple data packet block according to the file offset contained in the index; and the sending component 506 is used to send all messages that meet the user's retrieval conditions to the user after the retrieval is completed.

[0066] According to an apparatus for retrieving a pcapng data packet file according to an embodiment of the present disclosure, the custom index block includes: a block type field, a first block total length field, a magic field, an index area and a second block total length field; the block type field is used to identify the custom index block; the first block total length field is used to record the total length of the custom index block; the magic number field stores a magic number preset fixed value, which is used to identify the starting file position of the index area; the index area is used to store an index for a message contained in an enhanced data packet block or a simple data packet block; the value of the second block total length field is the same as that of the first block total length field, and it is used to verify the custom index block.

[0067] According to the device for retrieving pcapng data packet files according to an embodiment of the present disclosure, the index contained in the index area includes, in sequence: an index type field, a file offset field and a five-tuple, wherein the five-tuple includes: a source IP field, a destination IP field, a source port field, a destination port field, and a transport layer protocol type field.

[0068] According to the apparatus for retrieving a pcapng data packet file according to an embodiment of the present disclosure, the retrieval component 504 includes: a custom index block positioning component 504a, a verification component 504b and a parsing and matching component 504c.

[0069] Among them, the custom index block positioning component 504a is used to obtain the second block total length field value and calculate the starting file position of the custom index block according to the second block total length field value; the verification component 504b is used to obtain the block type field value and the magic field value based on the starting file position of the custom index block, and verify the obtained block type field value and the magic field value; the parsing and matching component 504c is used to parse the indexes contained in the index area when the block type field value and the magic field value pass the verification, and compare the five-tuple field content contained in the index obtained after parsing with the user search condition. When the five-tuple field content contained in the index matches the user search condition, the file offset field content contained in the index obtained after parsing is used to directly read the message so that after the retrieval is completed, the sending component 506 sends all messages whose five-tuple field content contained in the index matches the user search condition to the user.

[0070] According to the device for retrieving a pcapng data packet file according to an embodiment of the present disclosure, the value of the index type field includes: ipv4, ipv6, arp or other types.

[0071] In summary, the disclosed method and device for retrieving pcapng data packet files are adopted, by extending the pcapang data packet file, adding a custom index block at the end of the pcapng data packet file, and storing message index data and data packet file offset information according to the message type. When searching, first, according to the last 4-byte block length of the pcapng data packet file, it is offset forward to the custom index block, rather than parsing the file data from front to back in order to parse to the custom index block, so that the custom index block can be quickly located. According to the search conditions, the data packet is retrieved in the index, and when the data packet is retrieved, the specified data packet is read by the file offset, which greatly reduces the reading file IO performance, reduces the disk IO overhead and CPU utilization, and the retrieval time is short. In addition, by adding the custom index block, other data packet tools (such as wireshark, etc.) can still be opened, and the user's viewing of the data packet is not affected.

[0072] In general, the pcapng file disclosed in the present invention contains multiple data blocks, each of which contains different types of information. Such as section header block SHB Section Header Block, interface statistics information block ISB Interface StatisticsBlock, interface description information block IDB Interface description Block, domain name resolution information block NRB NameResolution Block, enhanced packet block EPB Enhanced Packet Block, simple packet block SPB SimplePacket Block, custom data block CB Custom Block. The present invention provides a solution that extends the data packet pcpang format file, adds a custom block at the end of the pcapng file for message indexing, and the custom block format is: block type (custom block) + total block length + magic + index area + total block length, where magic is 4 bytes, the content 0xacebeedd, which is used to identify that it is a custom index block, by extracting the five-tuple information of each data packet and the data packet file offset, and storing it in the custom index block index area, when searching according to the five-tuple condition, first read the custom index block and search in the index block. The process of adding index blocks is as follows: read the saved pcapng format data packets. Generally speaking, pcapng format files save data packets in enhanced data packet blocks EPB, and also in simple data packet blocks SPB; parse the data packet file according to the pcapng format, and extract the message data when parsing to EPB or SPB data packet blocks. Currently, the message is parsed into 4 types, namely IPV4 type, IPV6 type, arp type, and other types. Specific message parsing process: the message data starts from the second-layer mac header, and the upper-layer protocol is parsed according to the mac header. If the upper-layer protocol on the mac header is 0x0800, it means that the upper layer is ipv4, and if the upper-layer protocol is 0x86dd, it means that the upper layer is ipv6; if the upper-layer protocol is ipv4, further parse it according to the protool field of the protocol header; if the upper-layer protocol is ipv6, further parse it according to the next header field of the header; the protocol field of the ipv4 header or the next header field of the ipv6 header is 6 for TCP, and 17 for UDP protocol. The four-layer port information can be further extracted from the TCP and UDP headers.In addition, if the upper layer protocol of the mac header is 0x0806, it indicates an arp message. If it is 0x8100, it is a vlan message, and the vlan header needs to be stripped for further analysis. In short, the message is parsed according to the message format, and the message type, five-tuple information (source and destination IP, source and destination port, four-layer protocol), and file offset position are extracted. If it is not an IPV4 type, IPV6 type, or arp type, it is other types, and the index record of other types of messages is 0xff. For each message, the extracted message index information is uniformly stored in the index block in the following format: index type (1 byte, required) + file offset position (4 bytes, required) + source IP (optional) + destination IP (optional) + source port (optional) + destination port format (optional) + 4-layer protocol (optional). For example, if the IPV4 index type is 1 and the ipv6 index type is 2, the corresponding index of ipv4 is: 1-byte index value is 1+4-byte file offset+4-byte source IP+4-byte destination IP+2-byte source port+2-byte destination port+4-layer protocol, and the missing fields are filled with 0; the corresponding index of ipv6 is: 1-byte index value is 2+4-byte file offset+8-byte source IP+8-byte destination IP+2-byte source port+2-byte destination port+4-layer protocol, and the missing fields are filled with 0. According to the index type, different length indexes are saved separately. Each time a data packet is parsed, the index information is written to the custom index block at the end of the pcapng file. When the data packet is traversed and all indexes are generated, the total length of the index is calculated. If the total length of the index is less than 4 bytes, it is aligned to 4 bytes, and the index content is padded with 0 to meet the 4-byte alignment. Finally, the total length of the custom block is calculated and saved to the total length of the custom block according to the pcapng file format requirements. The retrieval process mainly includes: first open the data packet file to be retrieved, locate the 4 bytes at the end of the file, which represents the custom block length, and then offset forward to the custom block length, and check the block type and magic. If it is not a custom index block and magic, it means that it is an ordinary pcapng file without an index, and the entire file needs to be traversed for retrieval; if it is a custom index block file, then parse the index according to the custom index format, extract the five-tuple information and compare it with the user input conditions. If a message that meets the conditions is found, the data packet content is directly read through the file offset, and finally the data packet information that meets the conditions is uniformly returned to the user for display.

[0073] The basic principles of the present disclosure are described above in conjunction with specific embodiments. However, it should be pointed out that a person skilled in the art can understand that all or any steps or components of the method and apparatus of the present disclosure can be implemented in hardware, firmware, software or a combination thereof in any computing device (including a processor, storage medium, etc.) or a network of computing devices. This can be achieved by a person skilled in the art using their basic programming skills after reading the description of the present disclosure.

[0074] Therefore, the purpose of the present disclosure can also be achieved by running a program or a group of programs on any computing device. The computing device can be a well-known general-purpose device. Therefore, the purpose of the present disclosure can also be achieved by simply providing a program product containing a program code that implements the method or device. In other words, such a program product also constitutes the present disclosure, and a storage medium storing such a program product also constitutes the present disclosure. Obviously, the storage medium can be any well-known storage medium or any storage medium developed in the future.

[0075] It should also be noted that, in the apparatus and method of the present disclosure, it is obvious that each component or each step can be decomposed and / or recombined. These decompositions and / or recombinations should be regarded as equivalent schemes of the present disclosure. In addition, the steps of performing the above series of processes can naturally be performed in chronological order according to the order of description, but do not necessarily need to be performed in chronological order. Some steps can be performed in parallel or independently of each other.

[0076] The above specific implementations do not constitute a limitation on the protection scope of the present disclosure. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present disclosure shall be included in the protection scope of the present disclosure.

Claims

1. A method for retrieving a pcapng data packet file, comprising: A pcapng extended data packet file is formed by adding a custom index block at the end of a pcapng data packet file containing an enhanced data packet block or a simple data packet block, wherein the custom index block includes an index for a message contained in the enhanced data packet block, including: a block type field, a first block total length field, a magic number field, an index area, and a second block total length field, wherein the block type field is used to identify the custom index block, the first block total length field is used to record the total length of the custom index block, the magic number field stores a preset fixed value of the magic number, and is used to identify the starting file position of the index area, the index area is used to store an index for the message contained in the enhanced data packet block or the simple data packet block, and the index contained in the index area includes: an index type field, a file offset field, and a five-tuple in sequence, wherein the five-tuple includes: a source IP field, a destination IP field, a source port field, a destination port field, a transport layer protocol type field, and the value of the second block total length field is the same as that of the first block total length field, and is used to verify the custom index block; After receiving the user search condition, searching is performed in the custom index block according to the user search condition. When an index that meets the user search condition is found in the custom index block, the message in the enhanced data packet block or the simple data packet block is obtained according to the file offset contained in the index. After the search is completed, all messages that meet the user's search conditions are sent to the user.

2. The method for retrieving a pcapng data packet file as claimed in claim 1, wherein when searching in the custom index block according to the user search condition, it comprises: Get the total length field value of the second block; Calculate the starting file position of the custom index block according to the total length field value of the second block; Obtaining a block type field value and a magic field value based on the starting file position of the custom index block, and verifying the obtained block type field value and the magic field value; When the block type field value and the magic number field value pass the verification, the indexes contained in the index area are parsed, and the five-tuple contained in the index obtained after the parsing is compared with the user search condition. When the five-tuple contained in the index matches the user search condition, the message is directly read through the file offset field content contained in the index obtained after the parsing, so as to send all messages whose five-tuple contained in the index matches the user search condition to the user after the retrieval is completed.

3. The method for retrieving a pcapng data packet file as claimed in claim 1, wherein the value of the index type field comprises: ipv4, ipv6, arp or other types.

4. A device for retrieving a pcapng data packet file, comprising: A pcapng extended data packet file forming component, used to form a pcapng extended data packet file by adding a custom index block at the end of a pcapng data packet file containing an enhanced data packet block or a simple data packet block, wherein the custom index block includes an index for a message contained in the enhanced data packet block; A retrieval component is used to, after receiving a user retrieval condition, first search in the custom index block according to the user retrieval condition, and when an index that meets the user retrieval condition is retrieved in the custom index block, obtain the message in the enhanced data packet block or the simple data packet block according to the file offset contained in the index; A sending component is used to send all messages that meet the user's search conditions to the user after the search is completed; in, The user-defined index block includes: a block type field, a first block total length field, a magic number field, an index area, and a second block total length field; The block type field is used to identify a custom index block; The first block total length field is used to record the total length of the custom index block; The magic number field stores a magic number preset fixed value, which is used to identify the starting file position of the index area; The index area is used to store an index for a message contained in an enhanced data packet block or a simple data packet block, wherein the index contained in the index area includes: an index type field, a file offset field, and a five-tuple in sequence, wherein the five-tuple includes: a source IP field, a destination IP field, a source port field, a destination port field, and a transport layer protocol type field; The value of the second block total length field is the same as that of the first block total length field, and is used to verify the custom index block.

5. The device for retrieving a pcapng data packet file as claimed in claim 4, wherein the retrieval component, when searching in the user-defined index block according to the user retrieval condition, comprises: A custom index block positioning component, used to obtain the second block total length field value and calculate the starting file position of the custom index block according to the second block total length field value; A verification component, used for obtaining a block type field value and a magic field value based on a starting file position of the custom index block, and verifying the obtained block type field value and the magic field value; A parsing and matching component is used to parse the indexes contained in the index area when the block type field value and the magic field value pass the verification, and compare the five-tuple field content contained in the index obtained after the parsing with the user search condition. When the five-tuple field content contained in the index matches the user search condition, the message is directly read through the file offset field content contained in the index obtained after the parsing so that after the retrieval is completed, the sending component sends to the user all messages whose five-tuple field content contained in the index matches the user search condition.

6. The device for retrieving a pcapng data packet file as claimed in claim 4, wherein the value of the index type field comprises: ipv4, ipv6, arp or other types.